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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
fillup/walmart-partner-api-sdk-php | src/Order.php | Order.refund | public function refund($purchaseOrderId, $order)
{
if(!is_numeric($purchaseOrderId)){
throw new \Exception("purchaseOrderId must be numeric",1448480783);
}
$schema = [
'/orderRefund' => [
'namespace' => 'ns3',
'childNamespace' => 'ns3',
],
'/orderRefund/orderLines' => [
'sendItemsAs' => 'orderLine',
],
'/orderRefund/orderLines/orderLine/refunds' => [
'sendItemsAs' => 'refund',
],
'/orderRefund/orderLines/orderLine/refunds/refund/refundCharges' => [
'sendItemsAs' => 'refundCharge',
],
'@namespaces' => [
'ns3' => 'http://walmart.com/mp/v3/orders'
],
];
$a2x = new A2X($order, $schema);
$xml = $a2x->asXml();
return $this->refundOrder([
'purchaseOrderId' => $purchaseOrderId,
'order' => $xml,
]);
} | php | public function refund($purchaseOrderId, $order)
{
if(!is_numeric($purchaseOrderId)){
throw new \Exception("purchaseOrderId must be numeric",1448480783);
}
$schema = [
'/orderRefund' => [
'namespace' => 'ns3',
'childNamespace' => 'ns3',
],
'/orderRefund/orderLines' => [
'sendItemsAs' => 'orderLine',
],
'/orderRefund/orderLines/orderLine/refunds' => [
'sendItemsAs' => 'refund',
],
'/orderRefund/orderLines/orderLine/refunds/refund/refundCharges' => [
'sendItemsAs' => 'refundCharge',
],
'@namespaces' => [
'ns3' => 'http://walmart.com/mp/v3/orders'
],
];
$a2x = new A2X($order, $schema);
$xml = $a2x->asXml();
return $this->refundOrder([
'purchaseOrderId' => $purchaseOrderId,
'order' => $xml,
]);
} | [
"public",
"function",
"refund",
"(",
"$",
"purchaseOrderId",
",",
"$",
"order",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"purchaseOrderId",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"purchaseOrderId must be numeric\"",
",",
"1448480783"... | Refund an order
@param string $purchaseOrderId
@param array $order
@return array
@throws \Exception | [
"Refund",
"an",
"order"
] | 8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7 | https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/Order.php#L226-L258 | train |
fillup/walmart-partner-api-sdk-php | src/Utils.php | Utils.stripNamespacesFromXml | public static function stripNamespacesFromXml($xml)
{
$xml = preg_replace('/<[a-zA-Z0-9]+:/','<',$xml);
$xml = preg_replace('/<\/[a-zA-Z0-9]+:/','</',$xml);
$xml = preg_replace('/ xmlns:[a-zA-Z0-9]+=".*">/','>',$xml);
return $xml;
} | php | public static function stripNamespacesFromXml($xml)
{
$xml = preg_replace('/<[a-zA-Z0-9]+:/','<',$xml);
$xml = preg_replace('/<\/[a-zA-Z0-9]+:/','</',$xml);
$xml = preg_replace('/ xmlns:[a-zA-Z0-9]+=".*">/','>',$xml);
return $xml;
} | [
"public",
"static",
"function",
"stripNamespacesFromXml",
"(",
"$",
"xml",
")",
"{",
"$",
"xml",
"=",
"preg_replace",
"(",
"'/<[a-zA-Z0-9]+:/'",
",",
"'<'",
",",
"$",
"xml",
")",
";",
"$",
"xml",
"=",
"preg_replace",
"(",
"'/<\\/[a-zA-Z0-9]+:/'",
",",
"'</'"... | Remove namespaces from XML
@param string $xml
@return string | [
"Remove",
"namespaces",
"from",
"XML"
] | 8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7 | https://github.com/fillup/walmart-partner-api-sdk-php/blob/8344dc8e7580364a6ad9ce6f3cf8f050e0a463c7/src/Utils.php#L20-L27 | train |
Wandu/Framework | src/Wandu/Http/Factory/ServerRequestFactory.php | ServerRequestFactory.getPhpServerValuesFromPlainHeader | protected function getPhpServerValuesFromPlainHeader(array $plainHeaders)
{
$httpInformation = explode(' ', array_shift($plainHeaders));
$servers = [
'REQUEST_METHOD' => $httpInformation[0],
'REQUEST_URI' => $httpInformation[1],
'SERVER_PROTOCOL' => $httpInformation[2],
];
foreach ($plainHeaders as $plainHeader) {
list($key, $value) = array_map('trim', explode(':', $plainHeader, 2));
$servers['HTTP_' . strtoupper(str_replace('-', '_', $key))] = $value;
}
return $servers;
} | php | protected function getPhpServerValuesFromPlainHeader(array $plainHeaders)
{
$httpInformation = explode(' ', array_shift($plainHeaders));
$servers = [
'REQUEST_METHOD' => $httpInformation[0],
'REQUEST_URI' => $httpInformation[1],
'SERVER_PROTOCOL' => $httpInformation[2],
];
foreach ($plainHeaders as $plainHeader) {
list($key, $value) = array_map('trim', explode(':', $plainHeader, 2));
$servers['HTTP_' . strtoupper(str_replace('-', '_', $key))] = $value;
}
return $servers;
} | [
"protected",
"function",
"getPhpServerValuesFromPlainHeader",
"(",
"array",
"$",
"plainHeaders",
")",
"{",
"$",
"httpInformation",
"=",
"explode",
"(",
"' '",
",",
"array_shift",
"(",
"$",
"plainHeaders",
")",
")",
";",
"$",
"servers",
"=",
"[",
"'REQUEST_METHOD... | Parse plain headers.
@param array $plainHeaders
@return array | [
"Parse",
"plain",
"headers",
"."
] | 765c9af25a649a5a33985f7bdb267b8f05d3d782 | https://github.com/Wandu/Framework/blob/765c9af25a649a5a33985f7bdb267b8f05d3d782/src/Wandu/Http/Factory/ServerRequestFactory.php#L105-L118 | train |
oat-sa/lib-tao-dtms | src/DateTime.php | DateTime.getMicroseconds | public function getMicroseconds($asSeconds = false)
{
if ($asSeconds) {
return round($this->microseconds * 1/1e6, 6);
}
return intval($this->microseconds);
} | php | public function getMicroseconds($asSeconds = false)
{
if ($asSeconds) {
return round($this->microseconds * 1/1e6, 6);
}
return intval($this->microseconds);
} | [
"public",
"function",
"getMicroseconds",
"(",
"$",
"asSeconds",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"asSeconds",
")",
"{",
"return",
"round",
"(",
"$",
"this",
"->",
"microseconds",
"*",
"1",
"/",
"1e6",
",",
"6",
")",
";",
"}",
"return",
"intval... | Gets microseconds data from object
@param boolean $asSeconds If defined, microseconds will be converted to seconds with fractions
@return int|float | [
"Gets",
"microseconds",
"data",
"from",
"object"
] | dc3979af897154850756bc72e19a9670064b9f25 | https://github.com/oat-sa/lib-tao-dtms/blob/dc3979af897154850756bc72e19a9670064b9f25/src/DateTime.php#L35-L42 | train |
oat-sa/lib-tao-dtms | src/DateTime.php | DateTime.addMicroseconds | protected function addMicroseconds($microseconds)
{
if ($microseconds < 0) {
throw new \InvalidArgumentException("Value of microseconds should be positive.");
}
$diff = $this->getMicroseconds() + $microseconds;
$seconds = floor($diff / 1e6);
$diff -= $seconds * 1e6;
if ($diff >= 1e6) {
$diff -= 1e6;
$seconds++;
}
$this->modify("+$seconds seconds");
$this->setMicroseconds($diff);
} | php | protected function addMicroseconds($microseconds)
{
if ($microseconds < 0) {
throw new \InvalidArgumentException("Value of microseconds should be positive.");
}
$diff = $this->getMicroseconds() + $microseconds;
$seconds = floor($diff / 1e6);
$diff -= $seconds * 1e6;
if ($diff >= 1e6) {
$diff -= 1e6;
$seconds++;
}
$this->modify("+$seconds seconds");
$this->setMicroseconds($diff);
} | [
"protected",
"function",
"addMicroseconds",
"(",
"$",
"microseconds",
")",
"{",
"if",
"(",
"$",
"microseconds",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Value of microseconds should be positive.\"",
")",
";",
"}",
"$",
"diff",
... | Subtracts an amount of microseconds from a DateTime object
@param $microseconds | [
"Subtracts",
"an",
"amount",
"of",
"microseconds",
"from",
"a",
"DateTime",
"object"
] | dc3979af897154850756bc72e19a9670064b9f25 | https://github.com/oat-sa/lib-tao-dtms/blob/dc3979af897154850756bc72e19a9670064b9f25/src/DateTime.php#L104-L121 | train |
oat-sa/lib-tao-dtms | src/DateTime.php | DateTime.subMicroseconds | protected function subMicroseconds($microseconds)
{
if ($microseconds < 0) {
throw new \InvalidArgumentException("Value of microseconds should be positive.");
}
$diff = $this->getMicroseconds() - $microseconds;
$seconds = floor($diff / 1e6);
$diff -= $seconds * 1e6;
if ($diff < 0) {
$diff = abs($diff);
$seconds++;
}
$this->modify("$seconds seconds");
$this->setMicroseconds($diff);
} | php | protected function subMicroseconds($microseconds)
{
if ($microseconds < 0) {
throw new \InvalidArgumentException("Value of microseconds should be positive.");
}
$diff = $this->getMicroseconds() - $microseconds;
$seconds = floor($diff / 1e6);
$diff -= $seconds * 1e6;
if ($diff < 0) {
$diff = abs($diff);
$seconds++;
}
$this->modify("$seconds seconds");
$this->setMicroseconds($diff);
} | [
"protected",
"function",
"subMicroseconds",
"(",
"$",
"microseconds",
")",
"{",
"if",
"(",
"$",
"microseconds",
"<",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Value of microseconds should be positive.\"",
")",
";",
"}",
"$",
"diff",
... | Adds an amount of microseconds to a DateTime object
@param $microseconds | [
"Adds",
"an",
"amount",
"of",
"microseconds",
"to",
"a",
"DateTime",
"object"
] | dc3979af897154850756bc72e19a9670064b9f25 | https://github.com/oat-sa/lib-tao-dtms/blob/dc3979af897154850756bc72e19a9670064b9f25/src/DateTime.php#L128-L145 | train |
oat-sa/lib-tao-dtms | src/DateTime.php | DateTime.add | public function add($interval)
{
parent::add($interval);
if ($interval instanceof DateInterval) {
if ($interval->invert) { // is negative, then sub
$this->subMicroseconds($interval->u);
} else {
$this->addMicroseconds($interval->u);
}
}
return $this;
} | php | public function add($interval)
{
parent::add($interval);
if ($interval instanceof DateInterval) {
if ($interval->invert) { // is negative, then sub
$this->subMicroseconds($interval->u);
} else {
$this->addMicroseconds($interval->u);
}
}
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"interval",
")",
"{",
"parent",
"::",
"add",
"(",
"$",
"interval",
")",
";",
"if",
"(",
"$",
"interval",
"instanceof",
"DateInterval",
")",
"{",
"if",
"(",
"$",
"interval",
"->",
"invert",
")",
"{",
"// is negativ... | Adds an amount of days, months, years, hours, minutes, seconds and microseconds to a DateTime object
@param DateInterval $interval
@return DateTime $this | [
"Adds",
"an",
"amount",
"of",
"days",
"months",
"years",
"hours",
"minutes",
"seconds",
"and",
"microseconds",
"to",
"a",
"DateTime",
"object"
] | dc3979af897154850756bc72e19a9670064b9f25 | https://github.com/oat-sa/lib-tao-dtms/blob/dc3979af897154850756bc72e19a9670064b9f25/src/DateTime.php#L153-L166 | train |
eleven-lab/laravel-geo | src/Eloquent/Model.php | Model.boot | protected static function boot()
{
parent::boot();
static::creating(function($model){
self::updateGeoAttributes($model);
});
static::created(function($model){
self::updateGeoAttributes($model);
});
static::updating(function($model){
self::updateGeoAttributes($model);
});
static::updated(function($model){
self::updateGeoAttributes($model);
});
} | php | protected static function boot()
{
parent::boot();
static::creating(function($model){
self::updateGeoAttributes($model);
});
static::created(function($model){
self::updateGeoAttributes($model);
});
static::updating(function($model){
self::updateGeoAttributes($model);
});
static::updated(function($model){
self::updateGeoAttributes($model);
});
} | [
"protected",
"static",
"function",
"boot",
"(",
")",
"{",
"parent",
"::",
"boot",
"(",
")",
";",
"static",
"::",
"creating",
"(",
"function",
"(",
"$",
"model",
")",
"{",
"self",
"::",
"updateGeoAttributes",
"(",
"$",
"model",
")",
";",
"}",
")",
";"... | Overriding the "booting" method of the model.
@return void | [
"Overriding",
"the",
"booting",
"method",
"of",
"the",
"model",
"."
] | 3bd89e4b20563f79153c5dacc7b7f79a0c2ae0fa | https://github.com/eleven-lab/laravel-geo/blob/3bd89e4b20563f79153c5dacc7b7f79a0c2ae0fa/src/Eloquent/Model.php#L31-L50 | train |
theodorejb/peachy-sql | lib/SqlServer.php | SqlServer.query | public function query(string $sql, array $params = []): Statement
{
if (!$stmt = sqlsrv_query($this->connection, $sql, $params)) {
throw new SqlException('Query failed', sqlsrv_errors(), $sql, $params);
}
$statement = new Statement($stmt, false, $sql, $params);
$statement->execute();
return $statement;
} | php | public function query(string $sql, array $params = []): Statement
{
if (!$stmt = sqlsrv_query($this->connection, $sql, $params)) {
throw new SqlException('Query failed', sqlsrv_errors(), $sql, $params);
}
$statement = new Statement($stmt, false, $sql, $params);
$statement->execute();
return $statement;
} | [
"public",
"function",
"query",
"(",
"string",
"$",
"sql",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
":",
"Statement",
"{",
"if",
"(",
"!",
"$",
"stmt",
"=",
"sqlsrv_query",
"(",
"$",
"this",
"->",
"connection",
",",
"$",
"sql",
",",
"$",
"... | Prepares and executes a single SQL Server query with bound parameters
@throws SqlException if an error occurs | [
"Prepares",
"and",
"executes",
"a",
"single",
"SQL",
"Server",
"query",
"with",
"bound",
"parameters"
] | f179c6fa6c4293c2713b6b59022f3cfc90890a98 | https://github.com/theodorejb/peachy-sql/blob/f179c6fa6c4293c2713b6b59022f3cfc90890a98/lib/SqlServer.php#L101-L110 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.values2string | public static function values2string(array $array, $arrayColumnKey = '', $separator = ',')
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$values = [];
foreach ($array as $key => $value) {
$appendMe = null;
if (is_array($value)) {
$appendMe = self::values2string($value, $arrayColumnKey, $separator);
} elseif (empty($arrayColumnKey)) {
$appendMe = $value;
} elseif ($key === $arrayColumnKey) {
$appendMe = $array[$arrayColumnKey];
}
/*
* Part to append is unknown?
* Let's go to next part
*/
if (null === $appendMe) {
continue;
}
$values[] = $appendMe;
}
/*
* No values found?
* Nothing to do
*/
if (empty($values)) {
return null;
}
return implode($separator, $values);
} | php | public static function values2string(array $array, $arrayColumnKey = '', $separator = ',')
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$values = [];
foreach ($array as $key => $value) {
$appendMe = null;
if (is_array($value)) {
$appendMe = self::values2string($value, $arrayColumnKey, $separator);
} elseif (empty($arrayColumnKey)) {
$appendMe = $value;
} elseif ($key === $arrayColumnKey) {
$appendMe = $array[$arrayColumnKey];
}
/*
* Part to append is unknown?
* Let's go to next part
*/
if (null === $appendMe) {
continue;
}
$values[] = $appendMe;
}
/*
* No values found?
* Nothing to do
*/
if (empty($values)) {
return null;
}
return implode($separator, $values);
} | [
"public",
"static",
"function",
"values2string",
"(",
"array",
"$",
"array",
",",
"$",
"arrayColumnKey",
"=",
"''",
",",
"$",
"separator",
"=",
"','",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"ar... | Converts given array's column to string.
Recursive call is made for multi-dimensional arrays.
@param array $array Data to be converted
@param int|string $arrayColumnKey (optional) Column name. Default: "".
@param string $separator (optional) Separator used between values. Default: ",".
@return null|string | [
"Converts",
"given",
"array",
"s",
"column",
"to",
"string",
".",
"Recursive",
"call",
"is",
"made",
"for",
"multi",
"-",
"dimensional",
"arrays",
"."
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L35-L78 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.values2csv | public static function values2csv(array $array, $separator = ',')
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$rows = [];
$lineSeparator = "\n";
foreach ($array as $row) {
/*
* I have to use html_entity_decode() function here, because some string values can contain
* entities with semicolon and this can destroy the CSV column order.
*/
if (is_array($row) && !empty($row)) {
foreach ($row as $key => $value) {
$row[$key] = html_entity_decode($value);
}
$rows[] = implode($separator, $row);
}
}
if (empty($rows)) {
return '';
}
return implode($lineSeparator, $rows);
} | php | public static function values2csv(array $array, $separator = ',')
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$rows = [];
$lineSeparator = "\n";
foreach ($array as $row) {
/*
* I have to use html_entity_decode() function here, because some string values can contain
* entities with semicolon and this can destroy the CSV column order.
*/
if (is_array($row) && !empty($row)) {
foreach ($row as $key => $value) {
$row[$key] = html_entity_decode($value);
}
$rows[] = implode($separator, $row);
}
}
if (empty($rows)) {
return '';
}
return implode($lineSeparator, $rows);
} | [
"public",
"static",
"function",
"values2csv",
"(",
"array",
"$",
"array",
",",
"$",
"separator",
"=",
"','",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"null",
"... | Converts given array's rows to csv string
@param array $array Data to be converted. It have to be an array that represents database table.
@param string $separator (optional) Separator used between values. Default: ",".
@return null|string | [
"Converts",
"given",
"array",
"s",
"rows",
"to",
"csv",
"string"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L128-L161 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.isFirstElement | public static function isFirstElement(array $array, $element, $firstLevelOnly = true)
{
$firstElement = self::getFirstElement($array, $firstLevelOnly);
return $element === $firstElement;
} | php | public static function isFirstElement(array $array, $element, $firstLevelOnly = true)
{
$firstElement = self::getFirstElement($array, $firstLevelOnly);
return $element === $firstElement;
} | [
"public",
"static",
"function",
"isFirstElement",
"(",
"array",
"$",
"array",
",",
"$",
"element",
",",
"$",
"firstLevelOnly",
"=",
"true",
")",
"{",
"$",
"firstElement",
"=",
"self",
"::",
"getFirstElement",
"(",
"$",
"array",
",",
"$",
"firstLevelOnly",
... | Returns information if given element is the first one
@param array $array The array to get the first element of
@param mixed $element The element to check / verify
@param bool $firstLevelOnly (optional) If is set to true, first element is returned. Otherwise - totally
first element is returned (first of the First array).
@return bool | [
"Returns",
"information",
"if",
"given",
"element",
"is",
"the",
"first",
"one"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L172-L177 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.getFirstElement | public static function getFirstElement(array $array, $firstLevelOnly = true)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$firstKey = self::getFirstKey($array);
$first = $array[$firstKey];
if (!$firstLevelOnly && is_array($first)) {
$first = self::getFirstElement($first, $firstLevelOnly);
}
return $first;
} | php | public static function getFirstElement(array $array, $firstLevelOnly = true)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$firstKey = self::getFirstKey($array);
$first = $array[$firstKey];
if (!$firstLevelOnly && is_array($first)) {
$first = self::getFirstElement($first, $firstLevelOnly);
}
return $first;
} | [
"public",
"static",
"function",
"getFirstElement",
"(",
"array",
"$",
"array",
",",
"$",
"firstLevelOnly",
"=",
"true",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
... | Returns the first element of given array
It may be first element of given array or the totally first element from the all elements (first element of the
first array).
@param array $array The array to get the first element of
@param bool $firstLevelOnly (optional) If is set to true, first element is returned. Otherwise - totally
first element is returned (first of the first array).
@return mixed | [
"Returns",
"the",
"first",
"element",
"of",
"given",
"array"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L190-L208 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.isLastElement | public static function isLastElement(array $array, $element, $firstLevelOnly = true)
{
$lastElement = self::getLastElement($array, $firstLevelOnly);
return $element === $lastElement;
} | php | public static function isLastElement(array $array, $element, $firstLevelOnly = true)
{
$lastElement = self::getLastElement($array, $firstLevelOnly);
return $element === $lastElement;
} | [
"public",
"static",
"function",
"isLastElement",
"(",
"array",
"$",
"array",
",",
"$",
"element",
",",
"$",
"firstLevelOnly",
"=",
"true",
")",
"{",
"$",
"lastElement",
"=",
"self",
"::",
"getLastElement",
"(",
"$",
"array",
",",
"$",
"firstLevelOnly",
")"... | Returns information if given element is the last one
@param array $array The array to get the last element of
@param mixed $element The element to check / verify
@param bool $firstLevelOnly (optional) If is set to true, last element is returned. Otherwise - totally
last element is returned (last of the latest array).
@return bool | [
"Returns",
"information",
"if",
"given",
"element",
"is",
"the",
"last",
"one"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L240-L245 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.getLastElement | public static function getLastElement(array $array, $firstLevelOnly = true)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$last = end($array);
if (!$firstLevelOnly && is_array($last)) {
$last = self::getLastElement($last, $firstLevelOnly);
}
return $last;
} | php | public static function getLastElement(array $array, $firstLevelOnly = true)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$last = end($array);
if (!$firstLevelOnly && is_array($last)) {
$last = self::getLastElement($last, $firstLevelOnly);
}
return $last;
} | [
"public",
"static",
"function",
"getLastElement",
"(",
"array",
"$",
"array",
",",
"$",
"firstLevelOnly",
"=",
"true",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"... | Returns the last element of given array
It may be last element of given array or the totally last element from the all elements (last element of the
latest array).
@param array $array The array to get the last element of
@param bool $firstLevelOnly (optional) If is set to true, last element is returned. Otherwise - totally
last element is returned (last of the latest array).
@return mixed | [
"Returns",
"the",
"last",
"element",
"of",
"given",
"array"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L258-L275 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.getLastRow | public static function getLastRow(array $array)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$effect = [];
$last = end($array);
if (is_array($last)) {
// We've got an array, so looking for the last row of array will be done recursively
$effect = self::getLastRow($last);
/*
* The last row is not an array or it's an empty array?
* Let's use the previous candidate
*/
if (!is_array($effect) || (is_array($effect) && empty($effect))) {
$effect = $last;
}
}
return $effect;
} | php | public static function getLastRow(array $array)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$effect = [];
$last = end($array);
if (is_array($last)) {
// We've got an array, so looking for the last row of array will be done recursively
$effect = self::getLastRow($last);
/*
* The last row is not an array or it's an empty array?
* Let's use the previous candidate
*/
if (!is_array($effect) || (is_array($effect) && empty($effect))) {
$effect = $last;
}
}
return $effect;
} | [
"public",
"static",
"function",
"getLastRow",
"(",
"array",
"$",
"array",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"effect",
"=",
"[",
... | Returns the last row of array
@param array $array The array to get the last row of
@return mixed | [
"Returns",
"the",
"last",
"row",
"of",
"array"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L317-L344 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.replaceArrayKeys | public static function replaceArrayKeys($dataArray, $oldKeyPattern, $newKey)
{
$effect = [];
if (is_array($dataArray) && !empty($dataArray)) {
foreach ($dataArray as $key => $value) {
if (preg_match($oldKeyPattern, $key)) {
$key = $newKey;
}
if (is_array($value)) {
$value = self::replaceArrayKeys($value, $oldKeyPattern, $newKey);
}
$effect[$key] = $value;
}
}
return $effect;
} | php | public static function replaceArrayKeys($dataArray, $oldKeyPattern, $newKey)
{
$effect = [];
if (is_array($dataArray) && !empty($dataArray)) {
foreach ($dataArray as $key => $value) {
if (preg_match($oldKeyPattern, $key)) {
$key = $newKey;
}
if (is_array($value)) {
$value = self::replaceArrayKeys($value, $oldKeyPattern, $newKey);
}
$effect[$key] = $value;
}
}
return $effect;
} | [
"public",
"static",
"function",
"replaceArrayKeys",
"(",
"$",
"dataArray",
",",
"$",
"oldKeyPattern",
",",
"$",
"newKey",
")",
"{",
"$",
"effect",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"dataArray",
")",
"&&",
"!",
"empty",
"(",
"$",
"d... | Replaces array keys that match given pattern with new key name
@param array $dataArray The array
@param string $oldKeyPattern Old key pattern
@param string $newKey New key name
@return array | [
"Replaces",
"array",
"keys",
"that",
"match",
"given",
"pattern",
"with",
"new",
"key",
"name"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L354-L373 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.array2JavaScript | public static function array2JavaScript(array $array, $jsVariableName = '', $preserveIndexes = false)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$result = '';
$counter = 0;
$arrayCount = count($array);
$arrayPrepared = self::quoteStrings($array);
$isMultiDimensional = self::isMultiDimensional($arrayPrepared);
/*
* Name of the variable was not provided and it's a multi dimensional array?
* Let's create the name, because variable is required for later usage (related to multi dimensional array)
*/
if (empty($jsVariableName) && $isMultiDimensional) {
$jsVariableName = 'autoGeneratedVariable';
}
if (!empty($jsVariableName) && is_string($jsVariableName)) {
$result .= sprintf('var %s = ', $jsVariableName);
}
$result .= 'new Array(';
if ($preserveIndexes || $isMultiDimensional) {
$result .= $arrayCount;
$result .= ');';
}
foreach ($arrayPrepared as $index => $value) {
++$counter;
if (is_array($value)) {
$variable = $index;
if (is_int($index)) {
$variable = 'value_' . $variable;
}
$value = self::array2JavaScript($value, $variable, $preserveIndexes);
if (null !== $value && '' !== $value) {
/*
* Add an empty line for the 1st iteration only. Required to avoid missing empty line after
* declaration of variable:
*
* var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...);
* autoGeneratedVariable[1] = new Array(...);
*/
if (1 === $counter) {
$result .= "\n";
}
$result .= $value . "\n";
$result .= sprintf('%s[%s] = %s;', $jsVariableName, Miscellaneous::quoteValue($index), $variable);
if ($counter !== $arrayCount) {
$result .= "\n";
}
}
} elseif ($preserveIndexes) {
if (!empty($jsVariableName)) {
$index = Miscellaneous::quoteValue($index);
$result .= sprintf("\n%s[%s] = %s;", $jsVariableName, $index, $value);
}
} else {
$format = '%s';
if ($counter < $arrayCount) {
$format .= ', ';
}
$result .= sprintf($format, $value);
}
}
if (!$preserveIndexes && !$isMultiDimensional) {
$result .= ');';
}
return $result;
} | php | public static function array2JavaScript(array $array, $jsVariableName = '', $preserveIndexes = false)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$result = '';
$counter = 0;
$arrayCount = count($array);
$arrayPrepared = self::quoteStrings($array);
$isMultiDimensional = self::isMultiDimensional($arrayPrepared);
/*
* Name of the variable was not provided and it's a multi dimensional array?
* Let's create the name, because variable is required for later usage (related to multi dimensional array)
*/
if (empty($jsVariableName) && $isMultiDimensional) {
$jsVariableName = 'autoGeneratedVariable';
}
if (!empty($jsVariableName) && is_string($jsVariableName)) {
$result .= sprintf('var %s = ', $jsVariableName);
}
$result .= 'new Array(';
if ($preserveIndexes || $isMultiDimensional) {
$result .= $arrayCount;
$result .= ');';
}
foreach ($arrayPrepared as $index => $value) {
++$counter;
if (is_array($value)) {
$variable = $index;
if (is_int($index)) {
$variable = 'value_' . $variable;
}
$value = self::array2JavaScript($value, $variable, $preserveIndexes);
if (null !== $value && '' !== $value) {
/*
* Add an empty line for the 1st iteration only. Required to avoid missing empty line after
* declaration of variable:
*
* var autoGeneratedVariable = new Array(...);autoGeneratedVariable[0] = new Array(...);
* autoGeneratedVariable[1] = new Array(...);
*/
if (1 === $counter) {
$result .= "\n";
}
$result .= $value . "\n";
$result .= sprintf('%s[%s] = %s;', $jsVariableName, Miscellaneous::quoteValue($index), $variable);
if ($counter !== $arrayCount) {
$result .= "\n";
}
}
} elseif ($preserveIndexes) {
if (!empty($jsVariableName)) {
$index = Miscellaneous::quoteValue($index);
$result .= sprintf("\n%s[%s] = %s;", $jsVariableName, $index, $value);
}
} else {
$format = '%s';
if ($counter < $arrayCount) {
$format .= ', ';
}
$result .= sprintf($format, $value);
}
}
if (!$preserveIndexes && !$isMultiDimensional) {
$result .= ');';
}
return $result;
} | [
"public",
"static",
"function",
"array2JavaScript",
"(",
"array",
"$",
"array",
",",
"$",
"jsVariableName",
"=",
"''",
",",
"$",
"preserveIndexes",
"=",
"false",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
... | Generates JavaScript code for given PHP array
@param array $array The array that should be generated to JavaScript
@param string $jsVariableName (optional) Name of the variable that will be in generated JavaScript code
@param bool $preserveIndexes (optional) If is set to true and $jsVariableName isn't empty, indexes also
will be added to the JavaScript code. Otherwise not.
@return null|string | [
"Generates",
"JavaScript",
"code",
"for",
"given",
"PHP",
"array"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L384-L472 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.setKeysAsValues | public static function setKeysAsValues(array $array, $ignoreDuplicatedValues = true)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$replaced = [];
foreach ($array as $key => $value) {
/*
* The value it's an array?
* Let's replace keys with values in this array first
*/
if (is_array($value)) {
$replaced[$key] = self::setKeysAsValues($value, $ignoreDuplicatedValues);
continue;
}
// Duplicated values shouldn't be ignored and processed value is used as key already?
// Let's use an array and that will contain all values (to avoid ignoring / overriding duplicated values)
if (!$ignoreDuplicatedValues && isset($replaced[$value])) {
$existing = self::makeArray($replaced[$value]);
$replaced[$value] = array_merge($existing, [
$key,
]);
continue;
}
// Standard behaviour
$replaced[$value] = $key;
}
return $replaced;
} | php | public static function setKeysAsValues(array $array, $ignoreDuplicatedValues = true)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$replaced = [];
foreach ($array as $key => $value) {
/*
* The value it's an array?
* Let's replace keys with values in this array first
*/
if (is_array($value)) {
$replaced[$key] = self::setKeysAsValues($value, $ignoreDuplicatedValues);
continue;
}
// Duplicated values shouldn't be ignored and processed value is used as key already?
// Let's use an array and that will contain all values (to avoid ignoring / overriding duplicated values)
if (!$ignoreDuplicatedValues && isset($replaced[$value])) {
$existing = self::makeArray($replaced[$value]);
$replaced[$value] = array_merge($existing, [
$key,
]);
continue;
}
// Standard behaviour
$replaced[$value] = $key;
}
return $replaced;
} | [
"public",
"static",
"function",
"setKeysAsValues",
"(",
"array",
"$",
"array",
",",
"$",
"ignoreDuplicatedValues",
"=",
"true",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"ret... | Sets keys as values and values as keys in given array.
Replaces keys with values.
@param array $array The array to change values with keys
@param bool $ignoreDuplicatedValues (optional) If is set to true, duplicated values are ignored. This means that
when there is more than 1 value and that values become key, only the last
value will be used with it's key, because other will be overridden.
Otherwise - values are preserved and keys assigned to that values are
returned as an array.
@return null|array
Example of $ignoreDuplicatedValues = false:
- provided array
$array = [
'lorem' => 100, // <-- Duplicated value
'ipsum' => 200,
'dolor' => 100, // <-- Duplicated value
];
- result
$replaced = [
100 => [
'lorem', // <-- Key of duplicated value
'dolor', // <-- Key of duplicated value
],
200 => 'ipsum',
]; | [
"Sets",
"keys",
"as",
"values",
"and",
"values",
"as",
"keys",
"in",
"given",
"array",
".",
"Replaces",
"keys",
"with",
"values",
"."
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L656-L696 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.string2array | public static function string2array($string, $separator = '|', $valuesKeysSeparator = ':')
{
/*
* Empty string?
* Nothing to do
*/
if (empty($string)) {
return null;
}
$array = [];
$exploded = explode($separator, $string);
foreach ($exploded as $item) {
$exploded2 = explode($valuesKeysSeparator, $item);
if (2 === count($exploded2)) {
$key = trim($exploded2[0]);
$value = trim($exploded2[1]);
$array[$key] = $value;
}
}
return $array;
} | php | public static function string2array($string, $separator = '|', $valuesKeysSeparator = ':')
{
/*
* Empty string?
* Nothing to do
*/
if (empty($string)) {
return null;
}
$array = [];
$exploded = explode($separator, $string);
foreach ($exploded as $item) {
$exploded2 = explode($valuesKeysSeparator, $item);
if (2 === count($exploded2)) {
$key = trim($exploded2[0]);
$value = trim($exploded2[1]);
$array[$key] = $value;
}
}
return $array;
} | [
"public",
"static",
"function",
"string2array",
"(",
"$",
"string",
",",
"$",
"separator",
"=",
"'|'",
",",
"$",
"valuesKeysSeparator",
"=",
"':'",
")",
"{",
"/*\n * Empty string?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"string... | Converts given string with special separators to array
Example:
~ string:
"light:jasny|dark:ciemny"
~ array as a result:
[
'light' => 'jasny',
'dark' => 'ciemny',
]
@param string $string The string to be converted
@param string $separator (optional) Separator used between name-value pairs in the string.
Default: "|".
@param string $valuesKeysSeparator (optional) Separator used between name and value in the string. Default: ":".
@return array | [
"Converts",
"given",
"string",
"with",
"special",
"separators",
"to",
"array"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L777-L802 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.areKeysInArray | public static function areKeysInArray(array $keys, array $array, $explicit = true)
{
$result = false;
if (!empty($array)) {
$firstKey = true;
foreach ($keys as $key) {
$exists = array_key_exists($key, $array);
if ($firstKey) {
$result = $exists;
$firstKey = false;
} elseif ($explicit) {
$result = $result && $exists;
if (!$result) {
break;
}
} else {
$result = $result || $exists;
if ($result) {
break;
}
}
}
}
return $result;
} | php | public static function areKeysInArray(array $keys, array $array, $explicit = true)
{
$result = false;
if (!empty($array)) {
$firstKey = true;
foreach ($keys as $key) {
$exists = array_key_exists($key, $array);
if ($firstKey) {
$result = $exists;
$firstKey = false;
} elseif ($explicit) {
$result = $result && $exists;
if (!$result) {
break;
}
} else {
$result = $result || $exists;
if ($result) {
break;
}
}
}
}
return $result;
} | [
"public",
"static",
"function",
"areKeysInArray",
"(",
"array",
"$",
"keys",
",",
"array",
"$",
"array",
",",
"$",
"explicit",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"$",
... | Returns information if given keys exist in given array
@param array $keys The keys to find
@param array $array The array that maybe contains keys
@param bool $explicit (optional) If is set to true, all keys should exist in given array. Otherwise - not all.
@return bool | [
"Returns",
"information",
"if",
"given",
"keys",
"exist",
"in",
"given",
"array"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L812-L842 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.getLastElementsPaths | public static function getLastElementsPaths(array $array, $separator = '.', $parentPath = '', $stopIfMatchedBy = '')
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
if (!empty($stopIfMatchedBy)) {
$stopIfMatchedBy = self::makeArray($stopIfMatchedBy);
}
$paths = [];
foreach ($array as $key => $value) {
$path = $key;
$stopRecursion = false;
$valueIsArray = is_array($value);
/*
* If the path of parent element is delivered,
* I have to use it and build longer path
*/
if (!empty($parentPath)) {
$pathTemplate = '%s%s%s';
$path = sprintf($pathTemplate, $parentPath, $separator, $key);
}
/*
* Check if the key or current path matches one of patterns at which the process should be stopped,
* the recursive not used. It means that I have to pass current value and stop processing of the
* array (don't go to the next step).
*/
if (!empty($stopIfMatchedBy)) {
foreach ($stopIfMatchedBy as $rawPattern) {
$pattern = sprintf('|%s|', $rawPattern);
if (preg_match($pattern, $key) || preg_match($pattern, $path)) {
$stopRecursion = true;
break;
}
}
}
/*
* The value is passed to the returned array if:
* - it's not an array
* or
* - the process is stopped, recursive is not used
*/
if (!$valueIsArray || ($valueIsArray && empty($value)) || $stopRecursion) {
$paths[$path] = $value;
continue;
}
// Let's iterate through the next level, using recursive
if ($valueIsArray) {
$recursivePaths = self::getLastElementsPaths($value, $separator, $path, $stopIfMatchedBy);
$paths += $recursivePaths;
}
}
return $paths;
} | php | public static function getLastElementsPaths(array $array, $separator = '.', $parentPath = '', $stopIfMatchedBy = '')
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
if (!empty($stopIfMatchedBy)) {
$stopIfMatchedBy = self::makeArray($stopIfMatchedBy);
}
$paths = [];
foreach ($array as $key => $value) {
$path = $key;
$stopRecursion = false;
$valueIsArray = is_array($value);
/*
* If the path of parent element is delivered,
* I have to use it and build longer path
*/
if (!empty($parentPath)) {
$pathTemplate = '%s%s%s';
$path = sprintf($pathTemplate, $parentPath, $separator, $key);
}
/*
* Check if the key or current path matches one of patterns at which the process should be stopped,
* the recursive not used. It means that I have to pass current value and stop processing of the
* array (don't go to the next step).
*/
if (!empty($stopIfMatchedBy)) {
foreach ($stopIfMatchedBy as $rawPattern) {
$pattern = sprintf('|%s|', $rawPattern);
if (preg_match($pattern, $key) || preg_match($pattern, $path)) {
$stopRecursion = true;
break;
}
}
}
/*
* The value is passed to the returned array if:
* - it's not an array
* or
* - the process is stopped, recursive is not used
*/
if (!$valueIsArray || ($valueIsArray && empty($value)) || $stopRecursion) {
$paths[$path] = $value;
continue;
}
// Let's iterate through the next level, using recursive
if ($valueIsArray) {
$recursivePaths = self::getLastElementsPaths($value, $separator, $path, $stopIfMatchedBy);
$paths += $recursivePaths;
}
}
return $paths;
} | [
"public",
"static",
"function",
"getLastElementsPaths",
"(",
"array",
"$",
"array",
",",
"$",
"separator",
"=",
"'.'",
",",
"$",
"parentPath",
"=",
"''",
",",
"$",
"stopIfMatchedBy",
"=",
"''",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n ... | Returns paths of the last elements
@param array $array The array with elements
@param string $separator (optional) Separator used between elements. Default: ".".
@param string $parentPath (optional) Path of the parent element. Default: "".
@param array|string $stopIfMatchedBy (optional) Patterns of keys or paths that matched will stop the process
of path building and including children of those keys or paths (recursive
will not be used for keys in lower level of given array). Default: "".
@return null|array
Examples - $stopIfMatchedBy argument:
a) "\d+"
b) [
"lorem\-",
"\d+",
]; | [
"Returns",
"paths",
"of",
"the",
"last",
"elements"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L862-L929 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.getValueByKeysPath | public static function getValueByKeysPath(array $array, array $keys)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$value = null;
if (self::issetRecursive($array, $keys)) {
foreach ($keys as $key) {
$value = $array[$key];
array_shift($keys);
if (is_array($value) && !empty($keys)) {
$value = self::getValueByKeysPath($value, $keys);
}
break;
}
}
return $value;
} | php | public static function getValueByKeysPath(array $array, array $keys)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$value = null;
if (self::issetRecursive($array, $keys)) {
foreach ($keys as $key) {
$value = $array[$key];
array_shift($keys);
if (is_array($value) && !empty($keys)) {
$value = self::getValueByKeysPath($value, $keys);
}
break;
}
}
return $value;
} | [
"public",
"static",
"function",
"getValueByKeysPath",
"(",
"array",
"$",
"array",
",",
"array",
"$",
"keys",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"null",
";"... | Returns value of given array set under given path of keys, of course if the value exists.
The keys should be delivered in the same order as used by source array.
@param array $array The array which should contains a value
@param array $keys Keys, path of keys, to find in given array
@return mixed
Examples:
a) $array
[
'some key' => [
'another some key' => [
'yet another key' => 123,
],
'some different key' => 456,
]
]
b) $keys
[
'some key',
'another some key',
'yet another key',
]
Based on the above examples will return:
123 | [
"Returns",
"value",
"of",
"given",
"array",
"set",
"under",
"given",
"path",
"of",
"keys",
"of",
"course",
"if",
"the",
"value",
"exists",
".",
"The",
"keys",
"should",
"be",
"delivered",
"in",
"the",
"same",
"order",
"as",
"used",
"by",
"source",
"array... | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1043-L1069 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.issetRecursive | public static function issetRecursive(array $array, array $keys)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return false;
}
$isset = false;
foreach ($keys as $key) {
$isset = isset($array[$key]);
if ($isset) {
$newArray = $array[$key];
array_shift($keys);
if (is_array($newArray) && !empty($keys)) {
$isset = self::issetRecursive($newArray, $keys);
}
}
break;
}
return $isset;
} | php | public static function issetRecursive(array $array, array $keys)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return false;
}
$isset = false;
foreach ($keys as $key) {
$isset = isset($array[$key]);
if ($isset) {
$newArray = $array[$key];
array_shift($keys);
if (is_array($newArray) && !empty($keys)) {
$isset = self::issetRecursive($newArray, $keys);
}
}
break;
}
return $isset;
} | [
"public",
"static",
"function",
"issetRecursive",
"(",
"array",
"$",
"array",
",",
"array",
"$",
"keys",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"false",
";",
... | Returns information if given path of keys are set is given array.
The keys should be delivered in the same order as used by source array.
@param array $array The array to check
@param array $keys Keys, path of keys, to find in given array
@return bool
Examples:
a) $array
[
'some key' => [
'another some key' => [
'yet another key' => 123,
],
'some different key' => 456,
]
]
b) $keys
[
'some key',
'another some key',
'yet another key',
] | [
"Returns",
"information",
"if",
"given",
"path",
"of",
"keys",
"are",
"set",
"is",
"given",
"array",
".",
"The",
"keys",
"should",
"be",
"delivered",
"in",
"the",
"same",
"order",
"as",
"used",
"by",
"source",
"array",
"."
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1097-L1125 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.getAllValuesOfKey | public static function getAllValuesOfKey(array $array, $key)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$values = [];
foreach ($array as $index => $value) {
if ($index === $key) {
$values[] = $value;
continue;
}
if (is_array($value)) {
$recursiveValues = self::getAllValuesOfKey($value, $key);
if (!empty($recursiveValues)) {
$merged = array_merge($values, $recursiveValues);
$values = $merged;
}
}
}
return $values;
} | php | public static function getAllValuesOfKey(array $array, $key)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$values = [];
foreach ($array as $index => $value) {
if ($index === $key) {
$values[] = $value;
continue;
}
if (is_array($value)) {
$recursiveValues = self::getAllValuesOfKey($value, $key);
if (!empty($recursiveValues)) {
$merged = array_merge($values, $recursiveValues);
$values = $merged;
}
}
}
return $values;
} | [
"public",
"static",
"function",
"getAllValuesOfKey",
"(",
"array",
"$",
"array",
",",
"$",
"key",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"null",
";",
"}",
"$... | Returns all values of given key.
It may be useful when you want to retrieve all values of one column.
@param array $array The array which should contain values of the key
@param string $key The key
@return null|array | [
"Returns",
"all",
"values",
"of",
"given",
"key",
".",
"It",
"may",
"be",
"useful",
"when",
"you",
"want",
"to",
"retrieve",
"all",
"values",
"of",
"one",
"column",
"."
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1135-L1165 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.trimRecursive | public static function trimRecursive(array $array)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return [];
}
$result = [];
foreach ($array as $key => $value) {
if (is_array($value)) {
$result[$key] = self::trimRecursive($value);
continue;
}
if (is_string($value)) {
$value = trim($value);
}
$result[$key] = $value;
}
return $result;
} | php | public static function trimRecursive(array $array)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return [];
}
$result = [];
foreach ($array as $key => $value) {
if (is_array($value)) {
$result[$key] = self::trimRecursive($value);
continue;
}
if (is_string($value)) {
$value = trim($value);
}
$result[$key] = $value;
}
return $result;
} | [
"public",
"static",
"function",
"trimRecursive",
"(",
"array",
"$",
"array",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"result",
"=",
... | Trims string values of given array and returns the new array
@param array $array The array which values should be trimmed
@return array | [
"Trims",
"string",
"values",
"of",
"given",
"array",
"and",
"returns",
"the",
"new",
"array"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1211-L1238 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.sortByCustomKeysOrder | public static function sortByCustomKeysOrder(array $array, array $keysOrder)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$ordered = [];
/*
* 1st iteration:
* Get elements in proper / required order
*/
if (!empty($keysOrder)) {
foreach ($keysOrder as $key) {
if (isset($array[$key])) {
$ordered[$key] = $array[$key];
unset($array[$key]);
}
}
}
/*
* 2nd iteration:
* Get the rest of elements
*/
if (!empty($array)) {
foreach ($array as $key => $element) {
$ordered[$key] = $element;
}
}
return $ordered;
} | php | public static function sortByCustomKeysOrder(array $array, array $keysOrder)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
$ordered = [];
/*
* 1st iteration:
* Get elements in proper / required order
*/
if (!empty($keysOrder)) {
foreach ($keysOrder as $key) {
if (isset($array[$key])) {
$ordered[$key] = $array[$key];
unset($array[$key]);
}
}
}
/*
* 2nd iteration:
* Get the rest of elements
*/
if (!empty($array)) {
foreach ($array as $key => $element) {
$ordered[$key] = $element;
}
}
return $ordered;
} | [
"public",
"static",
"function",
"sortByCustomKeysOrder",
"(",
"array",
"$",
"array",
",",
"array",
"$",
"keysOrder",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"null... | Sorts an array by keys given in second array as values.
Keys which are not in array with order are pushed after sorted elements.
Example:
- array to sort:
<code>
array(
'lorem' => array(
'ipsum'
),
'dolor' => array(
'sit',
'amet'
),
'neque' => 'neque'
)
</code>
- keys order:
<code>
array(
'dolor',
'lorem'
)
</code>
- the result:
<code>
array(
'dolor' => array(
'sit',
'amet'
),
'lorem' => array(
'ipsum'
),
'neque' => 'neque' // <-- the rest, values of other keys
)
</code>
@param array $array An array to sort
@param array $keysOrder An array with keys of the 1st argument in proper / required order
@return null|array | [
"Sorts",
"an",
"array",
"by",
"keys",
"given",
"in",
"second",
"array",
"as",
"values",
".",
"Keys",
"which",
"are",
"not",
"in",
"array",
"with",
"order",
"are",
"pushed",
"after",
"sorted",
"elements",
"."
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1283-L1319 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.implodeSmart | public static function implodeSmart(array $array, $separator)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
foreach ($array as &$element) {
if (is_array($element)) {
$element = self::implodeSmart($element, $separator);
}
if (Regex::startsWith($element, $separator)) {
$element = substr($element, 1);
}
if (Regex::endsWith($element, $separator)) {
$element = substr($element, 0, -1);
}
}
return implode($separator, $array);
} | php | public static function implodeSmart(array $array, $separator)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return null;
}
foreach ($array as &$element) {
if (is_array($element)) {
$element = self::implodeSmart($element, $separator);
}
if (Regex::startsWith($element, $separator)) {
$element = substr($element, 1);
}
if (Regex::endsWith($element, $separator)) {
$element = substr($element, 0, -1);
}
}
return implode($separator, $array);
} | [
"public",
"static",
"function",
"implodeSmart",
"(",
"array",
"$",
"array",
",",
"$",
"separator",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"null",
";",
"}",
"... | Returns smartly imploded string
Separators located at the beginning or end of elements are removed.
It's required to avoid problems with duplicated separator, e.g. "first//second/third", where separator is a
"/" string.
@param array $array The array with elements to implode
@param string $separator Separator used to stick together elements of given array
@return null|string | [
"Returns",
"smartly",
"imploded",
"string"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1332-L1357 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.areAllValuesEmpty | public static function areAllValuesEmpty(array $array, $strictNull = false)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return false;
}
foreach ($array as $element) {
/*
* If elements are verified if they are exactly null and the element is:
* - not an array
* - not null
* or elements are NOT verified if they are exactly null and the element is:
* - not empty (e.g. null, '', 0, array())
*
* If one of the above is true, not all elements of given array are empty
*/
if ((!is_array($element) && $strictNull && null !== $element) || !empty($element)) {
return false;
}
}
return true;
} | php | public static function areAllValuesEmpty(array $array, $strictNull = false)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return false;
}
foreach ($array as $element) {
/*
* If elements are verified if they are exactly null and the element is:
* - not an array
* - not null
* or elements are NOT verified if they are exactly null and the element is:
* - not empty (e.g. null, '', 0, array())
*
* If one of the above is true, not all elements of given array are empty
*/
if ((!is_array($element) && $strictNull && null !== $element) || !empty($element)) {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"areAllValuesEmpty",
"(",
"array",
"$",
"array",
",",
"$",
"strictNull",
"=",
"false",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"... | Returns information if given array is empty, iow. information if all elements of given array are empty
@param array $array The array to verify
@param bool $strictNull (optional) If is set to true elements are verified if they are null. Otherwise - only
if they are empty (e.g. null, '', 0, array()).
@return bool | [
"Returns",
"information",
"if",
"given",
"array",
"is",
"empty",
"iow",
".",
"information",
"if",
"all",
"elements",
"of",
"given",
"array",
"are",
"empty"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1367-L1393 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.arrayDiffRecursive | public static function arrayDiffRecursive(array $array1, array $array2, $valuesOnly = false)
{
$effect = [];
/*
* Values should be compared only and both arrays are one-dimensional?
* Let's find difference by using simple function
*/
if ($valuesOnly && 1 === self::getDimensionsCount($array1) && 1 === self::getDimensionsCount($array2)) {
return array_diff($array1, $array2);
}
foreach ($array1 as $key => $value) {
$array2HasKey = array_key_exists($key, $array2);
// Values should be compared only?
if ($valuesOnly) {
$difference = null;
if (is_array($value)) {
if ($array2HasKey && is_array($array2[$key])) {
$difference = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly);
}
} elseif (!$array2HasKey || ($array2HasKey && $value !== $array2[$key])) {
/*
* We are here, because:
* a) 2nd array hasn't key from 1st array
* OR
* b) key exists in both, 1st and 2nd array, but values are different
*/
$difference = $value;
}
if (null !== $difference) {
$effect[] = $difference;
}
// The key exists in 2nd array?
} elseif ($array2HasKey) {
// The value it's an array (it's a nested array)?
if (is_array($value)) {
$diff = [];
if (is_array($array2[$key])) {
// Let's verify the nested array
$diff = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly);
}
if (empty($diff)) {
continue;
}
$effect[$key] = $diff;
} elseif ($value !== $array2[$key]) {
// Value is different than in 2nd array?
// OKay, I've got difference
$effect[$key] = $value;
}
} else {
// OKay, I've got difference
$effect[$key] = $value;
}
}
return $effect;
} | php | public static function arrayDiffRecursive(array $array1, array $array2, $valuesOnly = false)
{
$effect = [];
/*
* Values should be compared only and both arrays are one-dimensional?
* Let's find difference by using simple function
*/
if ($valuesOnly && 1 === self::getDimensionsCount($array1) && 1 === self::getDimensionsCount($array2)) {
return array_diff($array1, $array2);
}
foreach ($array1 as $key => $value) {
$array2HasKey = array_key_exists($key, $array2);
// Values should be compared only?
if ($valuesOnly) {
$difference = null;
if (is_array($value)) {
if ($array2HasKey && is_array($array2[$key])) {
$difference = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly);
}
} elseif (!$array2HasKey || ($array2HasKey && $value !== $array2[$key])) {
/*
* We are here, because:
* a) 2nd array hasn't key from 1st array
* OR
* b) key exists in both, 1st and 2nd array, but values are different
*/
$difference = $value;
}
if (null !== $difference) {
$effect[] = $difference;
}
// The key exists in 2nd array?
} elseif ($array2HasKey) {
// The value it's an array (it's a nested array)?
if (is_array($value)) {
$diff = [];
if (is_array($array2[$key])) {
// Let's verify the nested array
$diff = self::arrayDiffRecursive($value, $array2[$key], $valuesOnly);
}
if (empty($diff)) {
continue;
}
$effect[$key] = $diff;
} elseif ($value !== $array2[$key]) {
// Value is different than in 2nd array?
// OKay, I've got difference
$effect[$key] = $value;
}
} else {
// OKay, I've got difference
$effect[$key] = $value;
}
}
return $effect;
} | [
"public",
"static",
"function",
"arrayDiffRecursive",
"(",
"array",
"$",
"array1",
",",
"array",
"$",
"array2",
",",
"$",
"valuesOnly",
"=",
"false",
")",
"{",
"$",
"effect",
"=",
"[",
"]",
";",
"/*\n * Values should be compared only and both arrays are one-... | Returns an array containing all the entries from 1st array that are not present in 2nd array.
An item from 1st array is the same as in 2nd array if both, keys and values, are the same.
Example of difference:
$array1 = [
1 => 'Lorem',
2 => 'ipsum,
];
$array2 = [
1 => 'Lorem',
5 => 'ipsum, // <-- The same values, but different key. Here we got 5, in 1st array - 2.
];
@param array $array1 The 1st array to verify
@param array $array2 The 2nd array to verify
@param bool $valuesOnly (optional) If is set to true, compares values only. Otherwise - keys and values
(default behaviour).
@return array | [
"Returns",
"an",
"array",
"containing",
"all",
"the",
"entries",
"from",
"1st",
"array",
"that",
"are",
"not",
"present",
"in",
"2nd",
"array",
".",
"An",
"item",
"from",
"1st",
"array",
"is",
"the",
"same",
"as",
"in",
"2nd",
"array",
"if",
"both",
"k... | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1416-L1481 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.getDimensionsCount | public static function getDimensionsCount(array $array)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return 0;
}
$dimensionsCount = 1;
foreach ($array as $value) {
if (is_array($value)) {
/*
* I have to increment returned value, because that means we've got 1 level more (if the value is an
* array)
*/
$count = self::getDimensionsCount($value) + 1;
if ($count > $dimensionsCount) {
$dimensionsCount = $count;
}
}
}
return $dimensionsCount;
} | php | public static function getDimensionsCount(array $array)
{
/*
* No elements?
* Nothing to do
*/
if (empty($array)) {
return 0;
}
$dimensionsCount = 1;
foreach ($array as $value) {
if (is_array($value)) {
/*
* I have to increment returned value, because that means we've got 1 level more (if the value is an
* array)
*/
$count = self::getDimensionsCount($value) + 1;
if ($count > $dimensionsCount) {
$dimensionsCount = $count;
}
}
}
return $dimensionsCount;
} | [
"public",
"static",
"function",
"getDimensionsCount",
"(",
"array",
"$",
"array",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"array",
")",
")",
"{",
"return",
"0",
";",
"}",
"$",
"dimensionsCount",
... | Returns count of dimensions, maximum nesting level actually, in given array
@param array $array The array to verify
@return int | [
"Returns",
"count",
"of",
"dimensions",
"maximum",
"nesting",
"level",
"actually",
"in",
"given",
"array"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1618-L1645 | train |
meritoo/common-library | src/Utilities/Arrays.php | Arrays.getNonEmptyValuesAsString | public static function getNonEmptyValuesAsString(array $values, $separator = ', ')
{
/*
* No elements?
* Nothing to do
*/
if (empty($values)) {
return null;
}
$nonEmpty = self::getNonEmptyValues($values);
/*
* No values?
* Nothing to do
*/
if (empty($nonEmpty)) {
return '';
}
return implode($separator, $nonEmpty);
} | php | public static function getNonEmptyValuesAsString(array $values, $separator = ', ')
{
/*
* No elements?
* Nothing to do
*/
if (empty($values)) {
return null;
}
$nonEmpty = self::getNonEmptyValues($values);
/*
* No values?
* Nothing to do
*/
if (empty($nonEmpty)) {
return '';
}
return implode($separator, $nonEmpty);
} | [
"public",
"static",
"function",
"getNonEmptyValuesAsString",
"(",
"array",
"$",
"values",
",",
"$",
"separator",
"=",
"', '",
")",
"{",
"/*\n * No elements?\n * Nothing to do\n */",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"retu... | Returns non-empty values concatenated by given separator
@param array $values The values to filter
@param string $separator (optional) Separator used to implode the values. Default: ", ".
@return null|string | [
"Returns",
"non",
"-",
"empty",
"values",
"concatenated",
"by",
"given",
"separator"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Arrays.php#L1678-L1699 | train |
CeusMedia/Common | src/Deprecation.php | Deprecation.message | public function message( $message ){
$trace = debug_backtrace();
$caller = next( $trace );
$message .= ', invoked in '.$caller['file'].' on line '.$caller['line'];
if( $this->exceptionVersion )
if( version_compare( $this->version, $this->exceptionVersion ) >= 0 )
throw new Exception( 'Deprecated: '.$message );
if( version_compare( $this->version, $this->errorVersion ) >= 0 ){
self::notify( $message );
}
} | php | public function message( $message ){
$trace = debug_backtrace();
$caller = next( $trace );
$message .= ', invoked in '.$caller['file'].' on line '.$caller['line'];
if( $this->exceptionVersion )
if( version_compare( $this->version, $this->exceptionVersion ) >= 0 )
throw new Exception( 'Deprecated: '.$message );
if( version_compare( $this->version, $this->errorVersion ) >= 0 ){
self::notify( $message );
}
} | [
"public",
"function",
"message",
"(",
"$",
"message",
")",
"{",
"$",
"trace",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"caller",
"=",
"next",
"(",
"$",
"trace",
")",
";",
"$",
"message",
".=",
"', invoked in '",
".",
"$",
"caller",
"[",
"'file'",
... | Show message as exception or deprecation error, depending on set versions and PHP version.
Will throw an exception if set exception version reached detected library version.
Will throw a deprecation error if set error version reached detected library version using PHP 5.3+.
Will throw a deprecation notice if set error version reached detected library version using PHP lower 5.3.
@access public
@param string $version Library version to start showing deprecation error or notice
@return void
@throws Exception if set exception version reached detected library version | [
"Show",
"message",
"as",
"exception",
"or",
"deprecation",
"error",
"depending",
"on",
"set",
"versions",
"and",
"PHP",
"version",
".",
"Will",
"throw",
"an",
"exception",
"if",
"set",
"exception",
"version",
"reached",
"detected",
"library",
"version",
".",
"... | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Deprecation.php#L68-L78 | train |
CeusMedia/Common | src/XML/DOM/GoogleSitemapBuilder.php | XML_DOM_GoogleSitemapBuilder.buildSitemap | public static function buildSitemap( $links, $baseUrl = "" )
{
$root = new XML_DOM_Node( "urlset" );
$root->setAttribute( 'xmlns', "http://www.google.com/schemas/sitemap/0.84" );
foreach( $links as $link )
{
$child = new XML_DOM_Node( "url" );
$loc = new XML_DOM_Node( "loc", $baseUrl.$link );
$child->addChild( $loc );
$root->addChild( $child );
}
$builder = new XML_DOM_Builder();
return $builder->build( $root );
} | php | public static function buildSitemap( $links, $baseUrl = "" )
{
$root = new XML_DOM_Node( "urlset" );
$root->setAttribute( 'xmlns', "http://www.google.com/schemas/sitemap/0.84" );
foreach( $links as $link )
{
$child = new XML_DOM_Node( "url" );
$loc = new XML_DOM_Node( "loc", $baseUrl.$link );
$child->addChild( $loc );
$root->addChild( $child );
}
$builder = new XML_DOM_Builder();
return $builder->build( $root );
} | [
"public",
"static",
"function",
"buildSitemap",
"(",
"$",
"links",
",",
"$",
"baseUrl",
"=",
"\"\"",
")",
"{",
"$",
"root",
"=",
"new",
"XML_DOM_Node",
"(",
"\"urlset\"",
")",
";",
"$",
"root",
"->",
"setAttribute",
"(",
"'xmlns'",
",",
"\"http://www.googl... | Builds and return XML of Sitemap.
@access public
@static
@param string $links List of Sitemap Link
@param string $baseUrl Basic URL to add to every Link
@return bool | [
"Builds",
"and",
"return",
"XML",
"of",
"Sitemap",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/GoogleSitemapBuilder.php#L77-L90 | train |
CeusMedia/Common | src/FS/File/CSS/Theme/Finder.php | FS_File_CSS_Theme_Finder.getThemes | public function getThemes( $withBrowsers = FALSE )
{
$list = array();
$dir = new DirectoryIterator( $this->themePath );
foreach( $dir as $entry )
{
if( !$entry->isDir() )
continue;
if( substr( $entry->getFilename(), 0, 1 ) == "." )
continue;
$themeName = $entry->getFilename();
if( $withBrowsers )
{
$cssPath = $this->themePath.$entry->getFilename()."/".$this->cssPath;
$subdir = new DirectoryIterator( $cssPath );
foreach( $subdir as $browser )
{
if( !$browser->isDir() )
continue;
if( substr( $browser->getFilename(), 0, 1 ) == "." )
continue;
$browserName = $browser->getFilename();
$list[$themeName][$themeName.":".$browserName] = $browserName;
}
}
else
$list[] = $themeName;
}
return $list;
} | php | public function getThemes( $withBrowsers = FALSE )
{
$list = array();
$dir = new DirectoryIterator( $this->themePath );
foreach( $dir as $entry )
{
if( !$entry->isDir() )
continue;
if( substr( $entry->getFilename(), 0, 1 ) == "." )
continue;
$themeName = $entry->getFilename();
if( $withBrowsers )
{
$cssPath = $this->themePath.$entry->getFilename()."/".$this->cssPath;
$subdir = new DirectoryIterator( $cssPath );
foreach( $subdir as $browser )
{
if( !$browser->isDir() )
continue;
if( substr( $browser->getFilename(), 0, 1 ) == "." )
continue;
$browserName = $browser->getFilename();
$list[$themeName][$themeName.":".$browserName] = $browserName;
}
}
else
$list[] = $themeName;
}
return $list;
} | [
"public",
"function",
"getThemes",
"(",
"$",
"withBrowsers",
"=",
"FALSE",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"$",
"dir",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"this",
"->",
"themePath",
")",
";",
"foreach",
"(",
"$",
"dir",
"as... | Returns found Themes as List.
@access public
@param bool $withBrowsers Flag: Stylesheets with Browser Folders
@return array | [
"Returns",
"found",
"Themes",
"as",
"List",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/CSS/Theme/Finder.php#L59-L88 | train |
CeusMedia/Common | src/Alg/Math/Analysis/Progression.php | Alg_Math_Analysis_Progression.getPartialSum | public function getPartialSum( $from, $to )
{
for( $i=$from; $i<=$to; $i++ )
$sum += $this->getValue( $i );
return $sum;
} | php | public function getPartialSum( $from, $to )
{
for( $i=$from; $i<=$to; $i++ )
$sum += $this->getValue( $i );
return $sum;
} | [
"public",
"function",
"getPartialSum",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"$",
"from",
";",
"$",
"i",
"<=",
"$",
"to",
";",
"$",
"i",
"++",
")",
"$",
"sum",
"+=",
"$",
"this",
"->",
"getValue",
"(",
"$",
... | Calculates partial Sum of Progression.
@access public
@param int $from Interval Start
@param int $to Interval End
@return double | [
"Calculates",
"partial",
"Sum",
"of",
"Progression",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Analysis/Progression.php#L73-L78 | train |
CeusMedia/Common | src/Alg/Math/Analysis/Progression.php | Alg_Math_Analysis_Progression.isConvergent | public function isConvergent ()
{
$is = true;
for( $i=$this->interval->getStart(); $i<$this->interval->getEnd(); $i++ )
{
$an = $this->getPartialSum( $this->interval->getStart(), $i );
$an1 = $this->getPartialSum( $this->interval->getStart(), $i+1 );
$diff = abs( $an1 - $an );
// echo "<br>an1: ".$an1." | an: ".$an." | diff: ".$diff;
if (!$old_diff) $old_diff = $diff;
else if( $diff >= $old_diff )
$is = false;
}
return $is;
} | php | public function isConvergent ()
{
$is = true;
for( $i=$this->interval->getStart(); $i<$this->interval->getEnd(); $i++ )
{
$an = $this->getPartialSum( $this->interval->getStart(), $i );
$an1 = $this->getPartialSum( $this->interval->getStart(), $i+1 );
$diff = abs( $an1 - $an );
// echo "<br>an1: ".$an1." | an: ".$an." | diff: ".$diff;
if (!$old_diff) $old_diff = $diff;
else if( $diff >= $old_diff )
$is = false;
}
return $is;
} | [
"public",
"function",
"isConvergent",
"(",
")",
"{",
"$",
"is",
"=",
"true",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"this",
"->",
"interval",
"->",
"getStart",
"(",
")",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"interval",
"->",
"getEnd",
"(",
")",
... | Indicates whether this Progression is convergent.
@access public
@return bool
@todo correct Function: harmonic progression is convergent which is WRONG | [
"Indicates",
"whether",
"this",
"Progression",
"is",
"convergent",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Analysis/Progression.php#L96-L110 | train |
CeusMedia/Common | src/Alg/Math/Analysis/Progression.php | Alg_Math_Analysis_Progression.toArray | public function toArray()
{
$array = array();
for( $i=$this->interval->getStart(); $i<$this->interval->getEnd(); $i++ )
{
$value = $this->getPartialSum( $this->interval->getStart(), $i );
$array[$i] = $value;
}
return $array;
} | php | public function toArray()
{
$array = array();
for( $i=$this->interval->getStart(); $i<$this->interval->getEnd(); $i++ )
{
$value = $this->getPartialSum( $this->interval->getStart(), $i );
$array[$i] = $value;
}
return $array;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"array",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"this",
"->",
"interval",
"->",
"getStart",
"(",
")",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"interval",
"->",
"getEnd",
... | Returns Sequence of Partial Sums as Array.
@access public
@return array | [
"Returns",
"Sequence",
"of",
"Partial",
"Sums",
"as",
"Array",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Analysis/Progression.php#L128-L137 | train |
CeusMedia/Common | src/Alg/Math/Analysis/Progression.php | Alg_Math_Analysis_Progression.toTable | public function toTable()
{
$array = $this->toArray();
$code = "<table cellpadding=2 cellspacing=0 border=1>";
foreach( $array as $key => $value )
$code .= "<tr><td>".$key."</td><td>".round( $value,8 )."</td></tr>";
$code .= "</table>";
return $code;
} | php | public function toTable()
{
$array = $this->toArray();
$code = "<table cellpadding=2 cellspacing=0 border=1>";
foreach( $array as $key => $value )
$code .= "<tr><td>".$key."</td><td>".round( $value,8 )."</td></tr>";
$code .= "</table>";
return $code;
} | [
"public",
"function",
"toTable",
"(",
")",
"{",
"$",
"array",
"=",
"$",
"this",
"->",
"toArray",
"(",
")",
";",
"$",
"code",
"=",
"\"<table cellpadding=2 cellspacing=0 border=1>\"",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
... | Returns Sequence of Partial Sums as HTML Table.
@access public
@return array | [
"Returns",
"Sequence",
"of",
"Partial",
"Sums",
"as",
"HTML",
"Table",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Analysis/Progression.php#L144-L152 | train |
RhubarbPHP/Scaffold.TokenBasedRestApi | src/Model/ApiToken.php | ApiToken.validateToken | public static function validateToken($tokenString)
{
$tokens = ApiToken::find(new AndGroup(
[
new Equals("Token", $tokenString),
new GreaterThan("Expires", "now", true)
]
));
if (count($tokens) != 1) {
throw new TokenInvalidException();
}
/** @var ApiToken $token */
$token = $tokens[0];
$settings = ApiSettings::singleton();
if ($settings->extendTokenExpirationOnUse) {
$token->Expires = $settings->tokenExpiration;
$token->save();
}
return $token->AuthenticatedUser;
} | php | public static function validateToken($tokenString)
{
$tokens = ApiToken::find(new AndGroup(
[
new Equals("Token", $tokenString),
new GreaterThan("Expires", "now", true)
]
));
if (count($tokens) != 1) {
throw new TokenInvalidException();
}
/** @var ApiToken $token */
$token = $tokens[0];
$settings = ApiSettings::singleton();
if ($settings->extendTokenExpirationOnUse) {
$token->Expires = $settings->tokenExpiration;
$token->save();
}
return $token->AuthenticatedUser;
} | [
"public",
"static",
"function",
"validateToken",
"(",
"$",
"tokenString",
")",
"{",
"$",
"tokens",
"=",
"ApiToken",
"::",
"find",
"(",
"new",
"AndGroup",
"(",
"[",
"new",
"Equals",
"(",
"\"Token\"",
",",
"$",
"tokenString",
")",
",",
"new",
"GreaterThan",
... | Validates a given token string is valid and returns the authenticated user model.
@param $tokenString
@return mixed
@throws \Rhubarb\Scaffolds\TokenBasedRestApi\Exceptions\TokenInvalidException Thrown if the token is invalid. | [
"Validates",
"a",
"given",
"token",
"string",
"is",
"valid",
"and",
"returns",
"the",
"authenticated",
"user",
"model",
"."
] | 581deee0eb6a675afa82c55f792a67a7895fdda2 | https://github.com/RhubarbPHP/Scaffold.TokenBasedRestApi/blob/581deee0eb6a675afa82c55f792a67a7895fdda2/src/Model/ApiToken.php#L68-L90 | train |
RhubarbPHP/Scaffold.TokenBasedRestApi | src/Model/ApiToken.php | ApiToken.retrieveOrCreateToken | public static function retrieveOrCreateToken(Model $user, $ipAddress)
{
try {
$token = self::findFirst(new AndGroup([
new Equals("AuthenticatedUserID", $user->UniqueIdentifier),
new Equals("IpAddress", $ipAddress),
new GreaterThan("Expires", "now", true)
]));
$token->Expires = ApiSettings::singleton()->tokenExpiration;
$token->save();
} catch (RecordNotFoundException $ex) {
$token = self::createToken($user, $ipAddress);
}
return $token;
} | php | public static function retrieveOrCreateToken(Model $user, $ipAddress)
{
try {
$token = self::findFirst(new AndGroup([
new Equals("AuthenticatedUserID", $user->UniqueIdentifier),
new Equals("IpAddress", $ipAddress),
new GreaterThan("Expires", "now", true)
]));
$token->Expires = ApiSettings::singleton()->tokenExpiration;
$token->save();
} catch (RecordNotFoundException $ex) {
$token = self::createToken($user, $ipAddress);
}
return $token;
} | [
"public",
"static",
"function",
"retrieveOrCreateToken",
"(",
"Model",
"$",
"user",
",",
"$",
"ipAddress",
")",
"{",
"try",
"{",
"$",
"token",
"=",
"self",
"::",
"findFirst",
"(",
"new",
"AndGroup",
"(",
"[",
"new",
"Equals",
"(",
"\"AuthenticatedUserID\"",
... | Looks up an existing valid token for the user at the specified IP address. If none is found, it
creates a new one.
@param Model $user
@param string $ipAddress Usually the current HTTP requester's IP, retrieved from $_SERVER[REMOTE_ADDR]
@return ApiToken | [
"Looks",
"up",
"an",
"existing",
"valid",
"token",
"for",
"the",
"user",
"at",
"the",
"specified",
"IP",
"address",
".",
"If",
"none",
"is",
"found",
"it",
"creates",
"a",
"new",
"one",
"."
] | 581deee0eb6a675afa82c55f792a67a7895fdda2 | https://github.com/RhubarbPHP/Scaffold.TokenBasedRestApi/blob/581deee0eb6a675afa82c55f792a67a7895fdda2/src/Model/ApiToken.php#L113-L128 | train |
CeusMedia/Common | src/XML/DOM/FeedIdentifier.php | XML_DOM_FeedIdentifier.identifyFromFile | public function identifyFromFile( $fileName )
{
$file = new FS_File_Reader( $fileName );
$xml = $file->readString();
return $this->identify( $xml );
} | php | public function identifyFromFile( $fileName )
{
$file = new FS_File_Reader( $fileName );
$xml = $file->readString();
return $this->identify( $xml );
} | [
"public",
"function",
"identifyFromFile",
"(",
"$",
"fileName",
")",
"{",
"$",
"file",
"=",
"new",
"FS_File_Reader",
"(",
"$",
"fileName",
")",
";",
"$",
"xml",
"=",
"$",
"file",
"->",
"readString",
"(",
")",
";",
"return",
"$",
"this",
"->",
"identify... | Identifies Feed from a File.
@access public
@param string $fileName XML File of Feed
@return string | [
"Identifies",
"Feed",
"from",
"a",
"File",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/FeedIdentifier.php#L88-L93 | train |
CeusMedia/Common | src/XML/DOM/FeedIdentifier.php | XML_DOM_FeedIdentifier.identifyFromTree | public function identifyFromTree( $tree )
{
$this->type = "";
$this->version = "";
$nodename = strtolower( $tree->getNodeName() );
switch( $nodename )
{
case 'feed':
$type = "ATOM";
$version = $tree->getAttribute( 'version' );
break;
case 'rss':
$type = "RSS";
$version = $tree->getAttribute( 'version' );
break;
case 'rdf:rdf':
$type = "RSS";
$version = "1.0";
break;
}
if( $type && $version )
{
$this->type = $type;
$this->version = $version;
return $type."/".$version;
}
return false;
} | php | public function identifyFromTree( $tree )
{
$this->type = "";
$this->version = "";
$nodename = strtolower( $tree->getNodeName() );
switch( $nodename )
{
case 'feed':
$type = "ATOM";
$version = $tree->getAttribute( 'version' );
break;
case 'rss':
$type = "RSS";
$version = $tree->getAttribute( 'version' );
break;
case 'rdf:rdf':
$type = "RSS";
$version = "1.0";
break;
}
if( $type && $version )
{
$this->type = $type;
$this->version = $version;
return $type."/".$version;
}
return false;
} | [
"public",
"function",
"identifyFromTree",
"(",
"$",
"tree",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"\"\"",
";",
"$",
"this",
"->",
"version",
"=",
"\"\"",
";",
"$",
"nodename",
"=",
"strtolower",
"(",
"$",
"tree",
"->",
"getNodeName",
"(",
")",
")... | Identifies Feed from XML Tree.
@access public
@param XML_DOM_Node $tree XML Tree of Feed
@return string | [
"Identifies",
"Feed",
"from",
"XML",
"Tree",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/FeedIdentifier.php#L101-L128 | train |
CeusMedia/Common | src/UI/Image/Rotator.php | UI_Image_Rotator.rotate | public function rotate( $angle, $type = NULL )
{
if( !$this->sourceUri )
throw new RuntimeException( 'No source image set' );
# if( function_exists( 'imageantialias' ) )
# imageantialias( $this->target, TRUE );
$this->target = imagerotate( $this->source, $angle, 0 );
if( $this->targetUri )
return $this->saveImage( $type );
return TRUE;
} | php | public function rotate( $angle, $type = NULL )
{
if( !$this->sourceUri )
throw new RuntimeException( 'No source image set' );
# if( function_exists( 'imageantialias' ) )
# imageantialias( $this->target, TRUE );
$this->target = imagerotate( $this->source, $angle, 0 );
if( $this->targetUri )
return $this->saveImage( $type );
return TRUE;
} | [
"public",
"function",
"rotate",
"(",
"$",
"angle",
",",
"$",
"type",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"sourceUri",
")",
"throw",
"new",
"RuntimeException",
"(",
"'No source image set'",
")",
";",
"#\t\tif( function_exists( 'imageantial... | Invertes Source Image.
@access public
@param int $angle Rotation angle in degrees
@param int $type Output format type
@return bool | [
"Invertes",
"Source",
"Image",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/Image/Rotator.php#L50-L62 | train |
CeusMedia/Common | src/UI/Image/Rotator.php | UI_Image_Rotator.rotateImage | public static function rotateImage( $imageUri, $angle, $quality = 100 )
{
$modifier = new UI_Image_Rotator( $imageUri, $imageUri, $quality );
return $modifier->rotate( $angle );
} | php | public static function rotateImage( $imageUri, $angle, $quality = 100 )
{
$modifier = new UI_Image_Rotator( $imageUri, $imageUri, $quality );
return $modifier->rotate( $angle );
} | [
"public",
"static",
"function",
"rotateImage",
"(",
"$",
"imageUri",
",",
"$",
"angle",
",",
"$",
"quality",
"=",
"100",
")",
"{",
"$",
"modifier",
"=",
"new",
"UI_Image_Rotator",
"(",
"$",
"imageUri",
",",
"$",
"imageUri",
",",
"$",
"quality",
")",
";... | Rotates an Image statically.
@access public
@static
@param string $imageUri URI of Image File
@param int $angle Rotation angle in degrees
@param int $quality JPEG Quality in percent | [
"Rotates",
"an",
"Image",
"statically",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/Image/Rotator.php#L72-L76 | train |
CeusMedia/Common | src/FS/File/Log/Tracker/Reader.php | FS_File_Log_Tracker_Reader.callback | protected function callback( $matches )
{
// print_m( $matches );
$data = array(
'timestamp' => $matches[1],
'datetime' => $matches[2],
'remote_addr' => $matches[3],
'request_uri' => $matches[4],
'referer_uri' => $matches[5],
'useragent' => $matches[6],
);
return serialize( $data );
} | php | protected function callback( $matches )
{
// print_m( $matches );
$data = array(
'timestamp' => $matches[1],
'datetime' => $matches[2],
'remote_addr' => $matches[3],
'request_uri' => $matches[4],
'referer_uri' => $matches[5],
'useragent' => $matches[6],
);
return serialize( $data );
} | [
"protected",
"function",
"callback",
"(",
"$",
"matches",
")",
"{",
"//\t\tprint_m( $matches );\r",
"$",
"data",
"=",
"array",
"(",
"'timestamp'",
"=>",
"$",
"matches",
"[",
"1",
"]",
",",
"'datetime'",
"=>",
"$",
"matches",
"[",
"2",
"]",
",",
"'remote_ad... | Callback for Line Parser.
@access protected
@return string | [
"Callback",
"for",
"Line",
"Parser",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Log/Tracker/Reader.php#L72-L84 | train |
CeusMedia/Common | src/FS/File/Log/Tracker/Reader.php | FS_File_Log_Tracker_Reader.getPagesPerVisitor | public function getPagesPerVisitor()
{
$remote_addrs = array();
$visitors = array();
$visitor = 0;
foreach( $this->data as $entry )
{
if( $entry['remote_addr'] != $this->skip )
{
if( isset( $remote_addrs[$entry['remote_addr']] ) )
{
if( $remote_addrs[$entry['remote_addr']] < $entry['timestamp'] - 30 * 60 )
{
$visitor++;
$visitors[$visitor] = 0;
}
$visitors[$visitor] ++;
}
else
{
$visitor++;
$visitors[$visitor] = 1;
$remote_addrs[$entry['remote_addr']] = $entry['timestamp'];
}
}
}
$total = 0;
foreach( $visitors as $visitor => $pages )
$total += $pages;
$pages = round( $total / count( $visitors ), 1 );
return $pages;
} | php | public function getPagesPerVisitor()
{
$remote_addrs = array();
$visitors = array();
$visitor = 0;
foreach( $this->data as $entry )
{
if( $entry['remote_addr'] != $this->skip )
{
if( isset( $remote_addrs[$entry['remote_addr']] ) )
{
if( $remote_addrs[$entry['remote_addr']] < $entry['timestamp'] - 30 * 60 )
{
$visitor++;
$visitors[$visitor] = 0;
}
$visitors[$visitor] ++;
}
else
{
$visitor++;
$visitors[$visitor] = 1;
$remote_addrs[$entry['remote_addr']] = $entry['timestamp'];
}
}
}
$total = 0;
foreach( $visitors as $visitor => $pages )
$total += $pages;
$pages = round( $total / count( $visitors ), 1 );
return $pages;
} | [
"public",
"function",
"getPagesPerVisitor",
"(",
")",
"{",
"$",
"remote_addrs",
"=",
"array",
"(",
")",
";",
"$",
"visitors",
"=",
"array",
"(",
")",
";",
"$",
"visitor",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"entry",
... | Calculates Page View Average of unique Visitors.
@access public
@return float | [
"Calculates",
"Page",
"View",
"Average",
"of",
"unique",
"Visitors",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Log/Tracker/Reader.php#L143-L174 | train |
CeusMedia/Common | src/FS/File/Log/Tracker/Reader.php | FS_File_Log_Tracker_Reader.getReferers | public function getReferers( $skip )
{
$referers = array();
foreach( $this->data as $entry )
{
if( $entry['remote_addr'] != $this->skip )
{
if( $entry['referer_uri'] && !preg_match( "#.*".$skip.".*#si", $entry['referer_uri'] ) )
{
if( isset( $referers[$entry['referer_uri']] ) )
$referers[$entry['referer_uri']] ++;
else
$referers[$entry['referer_uri']] = 1;
}
}
}
arsort( $referers );
foreach( $referers as $referer => $count )
$lines[] = "<tr><td>".$referer."</td><td>".$count."</td></tr>";
$lines = implode( "\n\t", $lines );
$content = "<table>".$lines."</table>";
return $content;
} | php | public function getReferers( $skip )
{
$referers = array();
foreach( $this->data as $entry )
{
if( $entry['remote_addr'] != $this->skip )
{
if( $entry['referer_uri'] && !preg_match( "#.*".$skip.".*#si", $entry['referer_uri'] ) )
{
if( isset( $referers[$entry['referer_uri']] ) )
$referers[$entry['referer_uri']] ++;
else
$referers[$entry['referer_uri']] = 1;
}
}
}
arsort( $referers );
foreach( $referers as $referer => $count )
$lines[] = "<tr><td>".$referer."</td><td>".$count."</td></tr>";
$lines = implode( "\n\t", $lines );
$content = "<table>".$lines."</table>";
return $content;
} | [
"public",
"function",
"getReferers",
"(",
"$",
"skip",
")",
"{",
"$",
"referers",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"$",
"entry",
"[",
"'remote_addr'",
"]",
"!=",
"$",
... | Returns Referers of unique Visitors.
@access public
@return array | [
"Returns",
"Referers",
"of",
"unique",
"Visitors",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Log/Tracker/Reader.php#L181-L203 | train |
CeusMedia/Common | src/XML/DOM/ObjectSerializer.php | XML_DOM_ObjectSerializer.serialize | public static function serialize( $object, $encoding = "utf-8" )
{
$root = new XML_DOM_Node( "object" );
$root->setAttribute( 'class', get_class( $object ) );
$vars = get_object_vars( $object );
self::serializeVarsRec( $vars, $root );
$builder = new XML_DOM_Builder();
$serial = $builder->build( $root, $encoding );
return $serial;
} | php | public static function serialize( $object, $encoding = "utf-8" )
{
$root = new XML_DOM_Node( "object" );
$root->setAttribute( 'class', get_class( $object ) );
$vars = get_object_vars( $object );
self::serializeVarsRec( $vars, $root );
$builder = new XML_DOM_Builder();
$serial = $builder->build( $root, $encoding );
return $serial;
} | [
"public",
"static",
"function",
"serialize",
"(",
"$",
"object",
",",
"$",
"encoding",
"=",
"\"utf-8\"",
")",
"{",
"$",
"root",
"=",
"new",
"XML_DOM_Node",
"(",
"\"object\"",
")",
";",
"$",
"root",
"->",
"setAttribute",
"(",
"'class'",
",",
"get_class",
... | Builds XML String from an Object.
@access public
@static
@param mixed $object Object to serialize
@param string $encoding Encoding Type
@return string | [
"Builds",
"XML",
"String",
"from",
"an",
"Object",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/ObjectSerializer.php#L52-L61 | train |
CeusMedia/Common | src/XML/DOM/ObjectSerializer.php | XML_DOM_ObjectSerializer.serializeVarsRec | protected static function serializeVarsRec( $array, &$node )
{
foreach( $array as $key => $value)
{
switch( gettype( $value ) )
{
case 'NULL':
$child = new XML_DOM_Node( "null" );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'boolean':
$child = new XML_DOM_Node( "boolean", (int) $value );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'string':
$child = new XML_DOM_Node( "string", $value );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'integer':
$child = new XML_DOM_Node( "integer", $value );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'double':
$child = new XML_DOM_Node( "double", $value );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'array':
$child = new XML_DOM_Node( "array" );
$child->setAttribute( "name", $key );
self::serializeVarsRec( $value, $child );
$node->addChild( $child );
break;
case 'object':
$child = new XML_DOM_Node( "object" );
$child->setAttribute( "name", $key );
$child->setAttribute( "class", get_class( $value ) );
$vars = get_object_vars( $value );
self::serializeVarsRec( $vars, $child );
$node->addChild( $child );
break;
}
}
} | php | protected static function serializeVarsRec( $array, &$node )
{
foreach( $array as $key => $value)
{
switch( gettype( $value ) )
{
case 'NULL':
$child = new XML_DOM_Node( "null" );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'boolean':
$child = new XML_DOM_Node( "boolean", (int) $value );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'string':
$child = new XML_DOM_Node( "string", $value );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'integer':
$child = new XML_DOM_Node( "integer", $value );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'double':
$child = new XML_DOM_Node( "double", $value );
$child->setAttribute( "name", $key );
$node->addChild( $child );
break;
case 'array':
$child = new XML_DOM_Node( "array" );
$child->setAttribute( "name", $key );
self::serializeVarsRec( $value, $child );
$node->addChild( $child );
break;
case 'object':
$child = new XML_DOM_Node( "object" );
$child->setAttribute( "name", $key );
$child->setAttribute( "class", get_class( $value ) );
$vars = get_object_vars( $value );
self::serializeVarsRec( $vars, $child );
$node->addChild( $child );
break;
}
}
} | [
"protected",
"static",
"function",
"serializeVarsRec",
"(",
"$",
"array",
",",
"&",
"$",
"node",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"ca... | Adds XML Nodes to a XML Tree by their Type while supporting nested Arrays.
@access protected
@static
@param array $array Array of Vars to add
@param XML_DOM_Node $node current XML Tree Node
@return string | [
"Adds",
"XML",
"Nodes",
"to",
"a",
"XML",
"Tree",
"by",
"their",
"Type",
"while",
"supporting",
"nested",
"Arrays",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/ObjectSerializer.php#L71-L118 | train |
CeusMedia/Common | src/XML/DOM/Parser.php | XML_DOM_Parser.loadXml | protected function loadXml( $xml )
{
$xsv = new XML_DOM_SyntaxValidator;
if( !$xsv->validate( $xml ) )
throw new Exception( "XML Document is not valid:".$xsv->getErrors() );
$this->document = $xsv->getDocument();
$this->clearOptions();
foreach( $this->attributes as $attribute )
if( isset( $this->document->$attribute ) )
$this->setOption( $attribute, $this->document->$attribute );
} | php | protected function loadXml( $xml )
{
$xsv = new XML_DOM_SyntaxValidator;
if( !$xsv->validate( $xml ) )
throw new Exception( "XML Document is not valid:".$xsv->getErrors() );
$this->document = $xsv->getDocument();
$this->clearOptions();
foreach( $this->attributes as $attribute )
if( isset( $this->document->$attribute ) )
$this->setOption( $attribute, $this->document->$attribute );
} | [
"protected",
"function",
"loadXml",
"(",
"$",
"xml",
")",
"{",
"$",
"xsv",
"=",
"new",
"XML_DOM_SyntaxValidator",
";",
"if",
"(",
"!",
"$",
"xsv",
"->",
"validate",
"(",
"$",
"xml",
")",
")",
"throw",
"new",
"Exception",
"(",
"\"XML Document is not valid:\... | Loads XML String into DOM Document Object before parsing.
@access public
@param string $xml XML to be parsed
@return void | [
"Loads",
"XML",
"String",
"into",
"DOM",
"Document",
"Object",
"before",
"parsing",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/Parser.php#L71-L81 | train |
CeusMedia/Common | src/XML/DOM/Parser.php | XML_DOM_Parser.parse | public function parse( $xml )
{
$this->loadXml( $xml );
$root = $this->document->firstChild;
while( $root->nodeType == XML_COMMENT_NODE )
$root = $root->nextSibling;
$tree = new XML_DOM_Node( $root->nodeName );
if( $root->hasAttributes())
{
$attributeNodes = $root->attributes;
foreach( $attributeNodes as $attributeNode )
$tree->setAttribute( $attributeNode->nodeName, $attributeNode->nodeValue );
}
$this->parseRecursive( $root, $tree );
return $tree;
} | php | public function parse( $xml )
{
$this->loadXml( $xml );
$root = $this->document->firstChild;
while( $root->nodeType == XML_COMMENT_NODE )
$root = $root->nextSibling;
$tree = new XML_DOM_Node( $root->nodeName );
if( $root->hasAttributes())
{
$attributeNodes = $root->attributes;
foreach( $attributeNodes as $attributeNode )
$tree->setAttribute( $attributeNode->nodeName, $attributeNode->nodeValue );
}
$this->parseRecursive( $root, $tree );
return $tree;
} | [
"public",
"function",
"parse",
"(",
"$",
"xml",
")",
"{",
"$",
"this",
"->",
"loadXml",
"(",
"$",
"xml",
")",
";",
"$",
"root",
"=",
"$",
"this",
"->",
"document",
"->",
"firstChild",
";",
"while",
"(",
"$",
"root",
"->",
"nodeType",
"==",
"XML_COM... | Parses XML String to XML Tree.
@access public
@param string $xml XML to parse
@return XML_DOM_Node | [
"Parses",
"XML",
"String",
"to",
"XML",
"Tree",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/Parser.php#L89-L105 | train |
CeusMedia/Common | src/XML/DOM/Parser.php | XML_DOM_Parser.parseRecursive | protected function parseRecursive( $root, $tree )
{
$nodes = array();
if( $child = $root->firstChild )
{
while( $child )
{
$attributes = $child->hasAttributes()? $child->attributes : array();
switch( $child->nodeType )
{
case XML_ELEMENT_NODE:
$node = new XML_DOM_Node( $child->nodeName );
if( !$this->parseRecursive( $child, $node ) )
{
# $node->setContent( utf8_decode( $child->textContent ) );
$node->setContent( $child->textContent );
}
foreach( $attributes as $attribute)
$node->setAttribute( $attribute->nodeName, stripslashes( $attribute->nodeValue ) );
$tree->addChild( $node );
break;
case XML_TEXT_NODE:
if( strlen( trim( $content = $child->textContent ) ) )
{
return false;
}
else if( isset( $attributes['type'] ) && preg_match( "/.*ml/i", $attributes['type'] ) )
{
return false;
}
break;
case XML_CDATA_SECTION_NODE:
$tree->setContent( stripslashes( $child->textContent ) );
break;
default:
break;
}
$child = $child->nextSibling;
}
}
return true;
} | php | protected function parseRecursive( $root, $tree )
{
$nodes = array();
if( $child = $root->firstChild )
{
while( $child )
{
$attributes = $child->hasAttributes()? $child->attributes : array();
switch( $child->nodeType )
{
case XML_ELEMENT_NODE:
$node = new XML_DOM_Node( $child->nodeName );
if( !$this->parseRecursive( $child, $node ) )
{
# $node->setContent( utf8_decode( $child->textContent ) );
$node->setContent( $child->textContent );
}
foreach( $attributes as $attribute)
$node->setAttribute( $attribute->nodeName, stripslashes( $attribute->nodeValue ) );
$tree->addChild( $node );
break;
case XML_TEXT_NODE:
if( strlen( trim( $content = $child->textContent ) ) )
{
return false;
}
else if( isset( $attributes['type'] ) && preg_match( "/.*ml/i", $attributes['type'] ) )
{
return false;
}
break;
case XML_CDATA_SECTION_NODE:
$tree->setContent( stripslashes( $child->textContent ) );
break;
default:
break;
}
$child = $child->nextSibling;
}
}
return true;
} | [
"protected",
"function",
"parseRecursive",
"(",
"$",
"root",
",",
"$",
"tree",
")",
"{",
"$",
"nodes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"child",
"=",
"$",
"root",
"->",
"firstChild",
")",
"{",
"while",
"(",
"$",
"child",
")",
"{",
"$"... | Parses XML File to XML Tree recursive.
@access protected
@param DOMElement $root DOM Node Element
@param XML_DOM_Node $tree Parent XML Node
@return bool | [
"Parses",
"XML",
"File",
"to",
"XML",
"Tree",
"recursive",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/DOM/Parser.php#L114-L155 | train |
CeusMedia/Common | src/Net/XMPP/JID.php | Net_XMPP_JID.disassemble | static public function disassemble( $jid ){
if( !self::isValid( $jid ) )
throw new InvalidArgumentException( 'Given JID is not valid.' );
$matches = array();
preg_match_all( self::$regexJid, $jid, $matches );
return array(
'domain' => $matches[2][0],
'node' => $matches[1][0],
'resource' => $matches[3][0]
);
} | php | static public function disassemble( $jid ){
if( !self::isValid( $jid ) )
throw new InvalidArgumentException( 'Given JID is not valid.' );
$matches = array();
preg_match_all( self::$regexJid, $jid, $matches );
return array(
'domain' => $matches[2][0],
'node' => $matches[1][0],
'resource' => $matches[3][0]
);
} | [
"static",
"public",
"function",
"disassemble",
"(",
"$",
"jid",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isValid",
"(",
"$",
"jid",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Given JID is not valid.'",
")",
";",
"$",
"matches",
"=",
"arra... | Spilts JID into parts.
@static
@access public
@return array | [
"Spilts",
"JID",
"into",
"parts",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/JID.php#L68-L78 | train |
CeusMedia/Common | src/Net/XMPP/JID.php | Net_XMPP_JID.getJid | static public function getJid( $domain, $node = NULL, $resource = NULL ){
$jid = $domain;
if( strlen( trim( $node ) ) )
$jid = $node.'@'.$domain;
if( strlen( trim( $resource ) ) )
$jid .= "/".$resource;
return $jid;
} | php | static public function getJid( $domain, $node = NULL, $resource = NULL ){
$jid = $domain;
if( strlen( trim( $node ) ) )
$jid = $node.'@'.$domain;
if( strlen( trim( $resource ) ) )
$jid .= "/".$resource;
return $jid;
} | [
"static",
"public",
"function",
"getJid",
"(",
"$",
"domain",
",",
"$",
"node",
"=",
"NULL",
",",
"$",
"resource",
"=",
"NULL",
")",
"{",
"$",
"jid",
"=",
"$",
"domain",
";",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"node",
")",
")",
")",
"$... | Builds and returns JID from parts.
@static
@access public
@param string $domain Domain name of XMPP server
@param string $node Name of node on XMPP server
@param string $resource Name of client resource
@return string | [
"Builds",
"and",
"returns",
"JID",
"from",
"parts",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/JID.php#L107-L114 | train |
CeusMedia/Common | src/Net/XMPP/JID.php | Net_XMPP_JID.set | public function set( $domain, $node = NULL, $resource = NULL ){
if( !strlen( trim( $domain ) ) )
throw new InvalidArgumentException( 'Domain is missing' );
$this->domain = $domain;
$this->node = $node;
$this->resource = $resource;
} | php | public function set( $domain, $node = NULL, $resource = NULL ){
if( !strlen( trim( $domain ) ) )
throw new InvalidArgumentException( 'Domain is missing' );
$this->domain = $domain;
$this->node = $node;
$this->resource = $resource;
} | [
"public",
"function",
"set",
"(",
"$",
"domain",
",",
"$",
"node",
"=",
"NULL",
",",
"$",
"resource",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"strlen",
"(",
"trim",
"(",
"$",
"domain",
")",
")",
")",
"throw",
"new",
"InvalidArgumentException",
"(",
... | Sets JID by parts.
@access public
@param string $domain Domain name of XMPP server
@param string $node Name of node on XMPP server
@param string $resource Name of client resource
@return void | [
"Sets",
"JID",
"by",
"parts",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/JID.php#L152-L158 | train |
CeusMedia/Common | src/Net/XMPP/JID.php | Net_XMPP_JID.setJid | public function setJid( $jid ){
extract( self::disassemble( $jid ) );
$this->set( $domain, $node, $resource );
} | php | public function setJid( $jid ){
extract( self::disassemble( $jid ) );
$this->set( $domain, $node, $resource );
} | [
"public",
"function",
"setJid",
"(",
"$",
"jid",
")",
"{",
"extract",
"(",
"self",
"::",
"disassemble",
"(",
"$",
"jid",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"$",
"domain",
",",
"$",
"node",
",",
"$",
"resource",
")",
";",
"}"
] | Sets JID.
@access public
@param string $jid JID: domain + optional node and resource
@return void | [
"Sets",
"JID",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/JID.php#L166-L169 | train |
CeusMedia/Common | src/Alg/Search/Interpolation.php | Alg_Search_Interpolation.calculateIndex | protected function calculateIndex( $list, $search, $lowbound, $highbound )
{
$spanIndex = $list[$highbound] - $list[$lowbound];
$spanValues = $highbound - $lowbound;
$spanDiff = $search - $list[$lowbound];
$index = $lowbound + round( $spanValues * ( $spanDiff / $spanIndex ) );
return $index;
} | php | protected function calculateIndex( $list, $search, $lowbound, $highbound )
{
$spanIndex = $list[$highbound] - $list[$lowbound];
$spanValues = $highbound - $lowbound;
$spanDiff = $search - $list[$lowbound];
$index = $lowbound + round( $spanValues * ( $spanDiff / $spanIndex ) );
return $index;
} | [
"protected",
"function",
"calculateIndex",
"(",
"$",
"list",
",",
"$",
"search",
",",
"$",
"lowbound",
",",
"$",
"highbound",
")",
"{",
"$",
"spanIndex",
"=",
"$",
"list",
"[",
"$",
"highbound",
"]",
"-",
"$",
"list",
"[",
"$",
"lowbound",
"]",
";",
... | Calculates next bound index.
@access protected
@param array $ist List to search in
@param mixed $search Element to search
@param int $lowbound Last lower bound
@param int $highbound Last higher bound
@return int | [
"Calculates",
"next",
"bound",
"index",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Search/Interpolation.php#L49-L56 | train |
CeusMedia/Common | src/Alg/Search/Interpolation.php | Alg_Search_Interpolation.search | public function search( $list, $search )
{
$lowbound = 0; // lowbound - untergrenze
$highbound = sizeof( $list ) - 1; // highbound - obergrenze
do
{
$index = $this->calculateIndex( $list, $search, $lowbound, $highbound );
// echo "[".$lowbound."|".$highbound."] search_index: ".$index.": ".$list[$index]."<br>";
if( $index < $lowbound || $index > $highbound )
return -1;
if( $list[$index] == $search )
return $index;
if( $list[$index] < $search )
$lowbound = $index+1;
else
$highbound = $index-1;
}
while( $lowbound < $highbound );
return -1;
} | php | public function search( $list, $search )
{
$lowbound = 0; // lowbound - untergrenze
$highbound = sizeof( $list ) - 1; // highbound - obergrenze
do
{
$index = $this->calculateIndex( $list, $search, $lowbound, $highbound );
// echo "[".$lowbound."|".$highbound."] search_index: ".$index.": ".$list[$index]."<br>";
if( $index < $lowbound || $index > $highbound )
return -1;
if( $list[$index] == $search )
return $index;
if( $list[$index] < $search )
$lowbound = $index+1;
else
$highbound = $index-1;
}
while( $lowbound < $highbound );
return -1;
} | [
"public",
"function",
"search",
"(",
"$",
"list",
",",
"$",
"search",
")",
"{",
"$",
"lowbound",
"=",
"0",
";",
"// lowbound - untergrenze\r",
"$",
"highbound",
"=",
"sizeof",
"(",
"$",
"list",
")",
"-",
"1",
";",
"// highbound - obergrenze\r",
"do",
"{",
... | Searches in List and returns position if found, else -1.
@access public
@param array $ist List to search in
@param mixed $search Element to search
@return int | [
"Searches",
"in",
"List",
"and",
"returns",
"position",
"if",
"found",
"else",
"-",
"1",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Search/Interpolation.php#L64-L83 | train |
CeusMedia/Common | src/Net/HTTP/Reader.php | Net_HTTP_Reader.applyCurlOptions | protected function applyCurlOptions( Net_CURL $curl, $options = array() )
{
foreach( $options as $key => $value )
{
if( is_string( $key ) )
{
if( !( preg_match( "@^CURLOPT_@", $key ) && defined( $key ) ) )
throw new InvalidArgumentException( 'Invalid option constant key "'.$key.'"' );
$key = constant( $key );
}
if( !is_int( $key ) )
throw new InvalidArgumentException( 'Option must be given as integer or string' );
$curl->setOption( $key, $value );
}
} | php | protected function applyCurlOptions( Net_CURL $curl, $options = array() )
{
foreach( $options as $key => $value )
{
if( is_string( $key ) )
{
if( !( preg_match( "@^CURLOPT_@", $key ) && defined( $key ) ) )
throw new InvalidArgumentException( 'Invalid option constant key "'.$key.'"' );
$key = constant( $key );
}
if( !is_int( $key ) )
throw new InvalidArgumentException( 'Option must be given as integer or string' );
$curl->setOption( $key, $value );
}
} | [
"protected",
"function",
"applyCurlOptions",
"(",
"Net_CURL",
"$",
"curl",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",... | Applies cURL Options to a cURL Object.
@access protected
@param Net_CURL $curl cURL Object
@param array $options Map of cURL Options
@return void | [
"Applies",
"cURL",
"Options",
"to",
"a",
"cURL",
"Object",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Reader.php#L72-L86 | train |
CeusMedia/Common | src/Net/HTTP/Reader.php | Net_HTTP_Reader.get | public function get( $url, $headers = array(), $curlOptions = array() )
{
$curl = clone( $this->curl );
$curl->setOption( CURLOPT_URL, $url );
if( $headers )
{
if( $headers instanceof Net_HTTP_Header_Section )
$headers = $headers->toArray();
$curlOptions[CURLOPT_HTTPHEADER] = $headers;
}
$this->applyCurlOptions( $curl, $curlOptions );
$response = $curl->exec( TRUE, FALSE );
$this->curlInfo = $curl->getInfo();
$response = Net_HTTP_Response_Parser::fromString( $response );
/* $encodings = $response->headers->getField( 'content-encoding' );
while( $encoding = array_pop( $encodings ) )
{
$decompressor = new Net_HTTP_Response_Decompressor;
$type = $encoding->getValue();
$body = $decompressor->decompressString( $response->getBody(), $type );
}
$response->setBody( $body );*/
return $response;
} | php | public function get( $url, $headers = array(), $curlOptions = array() )
{
$curl = clone( $this->curl );
$curl->setOption( CURLOPT_URL, $url );
if( $headers )
{
if( $headers instanceof Net_HTTP_Header_Section )
$headers = $headers->toArray();
$curlOptions[CURLOPT_HTTPHEADER] = $headers;
}
$this->applyCurlOptions( $curl, $curlOptions );
$response = $curl->exec( TRUE, FALSE );
$this->curlInfo = $curl->getInfo();
$response = Net_HTTP_Response_Parser::fromString( $response );
/* $encodings = $response->headers->getField( 'content-encoding' );
while( $encoding = array_pop( $encodings ) )
{
$decompressor = new Net_HTTP_Response_Decompressor;
$type = $encoding->getValue();
$body = $decompressor->decompressString( $response->getBody(), $type );
}
$response->setBody( $body );*/
return $response;
} | [
"public",
"function",
"get",
"(",
"$",
"url",
",",
"$",
"headers",
"=",
"array",
"(",
")",
",",
"$",
"curlOptions",
"=",
"array",
"(",
")",
")",
"{",
"$",
"curl",
"=",
"clone",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"$",
"curl",
"->",
"setOp... | Returns Resource Response.
@access public
@param string $url Resource URL
@param array|Net_HTTP_Header_Section $headers Map of HTTP Header Fields or Header Section Object
@param array $curlOptions Map of cURL Options
@return Net_HTTP_Response | [
"Returns",
"Resource",
"Response",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Reader.php#L96-L119 | train |
CeusMedia/Common | src/Net/HTTP/Reader.php | Net_HTTP_Reader.getCurlInfo | public function getCurlInfo( $key = NULL )
{
if( !$this->curlInfo )
throw new RuntimeException( "No Request has been sent, yet." );
if( !$key )
return $this->curlInfo;
if( !array_key_exists( $key, $this->curlInfo ) )
throw new InvalidArgumentException( 'Status Key "'.$key.'" is invalid.' );
return $this->curlInfo[$key];
} | php | public function getCurlInfo( $key = NULL )
{
if( !$this->curlInfo )
throw new RuntimeException( "No Request has been sent, yet." );
if( !$key )
return $this->curlInfo;
if( !array_key_exists( $key, $this->curlInfo ) )
throw new InvalidArgumentException( 'Status Key "'.$key.'" is invalid.' );
return $this->curlInfo[$key];
} | [
"public",
"function",
"getCurlInfo",
"(",
"$",
"key",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"curlInfo",
")",
"throw",
"new",
"RuntimeException",
"(",
"\"No Request has been sent, yet.\"",
")",
";",
"if",
"(",
"!",
"$",
"key",
")",
"re... | Returns Info Array or single Information from last cURL Request.
@access public
@param string $key Information Key
@return mixed | [
"Returns",
"Info",
"Array",
"or",
"single",
"Information",
"from",
"last",
"cURL",
"Request",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Reader.php#L127-L136 | train |
CeusMedia/Common | src/Net/HTTP/Reader.php | Net_HTTP_Reader.post | public function post( $url, $data, $headers = array(), $curlOptions = array() )
{
$curl = clone( $this->curl );
$curl->setOption( CURLOPT_URL, $url );
if( $headers )
{
if( $headers instanceof Net_HTTP_Header_Section )
$headers = $headers->toArray();
$curlOptions[CURLOPT_HTTPHEADER] = $headers;
}
$this->applyCurlOptions( $curl, $curlOptions );
if( is_array( $data ) )
{
foreach( $data as $key => $value ) // cURL hack (file upload identifier)
if( is_string( $value ) && substr( $value, 0, 1 ) == "@" ) // leading @ in field values
$data[$key] = "\\".$value; // need to be escaped
$data = http_build_query( $data, NULL, "&" );
}
$curl->setOption( CURLOPT_POST, TRUE );
$curl->setOption( CURLOPT_POSTFIELDS, (string) $data );
$response = $curl->exec( TRUE, FALSE );
$this->curlInfo = $curl->getInfo();
$response = Net_HTTP_Response_Parser::fromString( $response );
return $response;
} | php | public function post( $url, $data, $headers = array(), $curlOptions = array() )
{
$curl = clone( $this->curl );
$curl->setOption( CURLOPT_URL, $url );
if( $headers )
{
if( $headers instanceof Net_HTTP_Header_Section )
$headers = $headers->toArray();
$curlOptions[CURLOPT_HTTPHEADER] = $headers;
}
$this->applyCurlOptions( $curl, $curlOptions );
if( is_array( $data ) )
{
foreach( $data as $key => $value ) // cURL hack (file upload identifier)
if( is_string( $value ) && substr( $value, 0, 1 ) == "@" ) // leading @ in field values
$data[$key] = "\\".$value; // need to be escaped
$data = http_build_query( $data, NULL, "&" );
}
$curl->setOption( CURLOPT_POST, TRUE );
$curl->setOption( CURLOPT_POSTFIELDS, (string) $data );
$response = $curl->exec( TRUE, FALSE );
$this->curlInfo = $curl->getInfo();
$response = Net_HTTP_Response_Parser::fromString( $response );
return $response;
} | [
"public",
"function",
"post",
"(",
"$",
"url",
",",
"$",
"data",
",",
"$",
"headers",
"=",
"array",
"(",
")",
",",
"$",
"curlOptions",
"=",
"array",
"(",
")",
")",
"{",
"$",
"curl",
"=",
"clone",
"(",
"$",
"this",
"->",
"curl",
")",
";",
"$",
... | Posts Data to Resource and returns Response.
@access public
@param string $url Resource URL
@param array $data Map of POST Data
@param array|Net_HTTP_Header_Section $headers Map of HTTP Header Fields or Header Section Object
@param array $curlOptions Map of cURL Options
@return Net_HTTP_Response | [
"Posts",
"Data",
"to",
"Resource",
"and",
"returns",
"Response",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Reader.php#L147-L173 | train |
CeusMedia/Common | src/Net/HTTP/Reader.php | Net_HTTP_Reader.setBasicAuth | public function setBasicAuth( $username, $password )
{
$this->curl->setOption( CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
$this->curl->setOption( CURLOPT_USERPWD, $username.":".$password );
} | php | public function setBasicAuth( $username, $password )
{
$this->curl->setOption( CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
$this->curl->setOption( CURLOPT_USERPWD, $username.":".$password );
} | [
"public",
"function",
"setBasicAuth",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"this",
"->",
"curl",
"->",
"setOption",
"(",
"CURLOPT_HTTPAUTH",
",",
"CURLAUTH_BASIC",
")",
";",
"$",
"this",
"->",
"curl",
"->",
"setOption",
"(",
"CURLOPT_... | Set Username and Password for Basic Auth.
@access public
@param string $username Basic Auth Username
@param string $password Basic Auth Password
@return void | [
"Set",
"Username",
"and",
"Password",
"for",
"Basic",
"Auth",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Reader.php#L182-L186 | train |
CeusMedia/Common | src/Net/HTTP/Reader.php | Net_HTTP_Reader.setUserAgent | public function setUserAgent( $string )
{
if( empty( $string ) )
throw new InvaligArgumentException( 'Must be set' );
$this->curl->setOption( CURLOPT_USERAGENT, $string );
} | php | public function setUserAgent( $string )
{
if( empty( $string ) )
throw new InvaligArgumentException( 'Must be set' );
$this->curl->setOption( CURLOPT_USERAGENT, $string );
} | [
"public",
"function",
"setUserAgent",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"string",
")",
")",
"throw",
"new",
"InvaligArgumentException",
"(",
"'Must be set'",
")",
";",
"$",
"this",
"->",
"curl",
"->",
"setOption",
"(",
"CURLOPT_US... | Sets User Agent.
@access public
@param string $string User Agent to set
@return void | [
"Sets",
"User",
"Agent",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Reader.php#L236-L241 | train |
CeusMedia/Common | src/Net/HTTP/Reader.php | Net_HTTP_Reader.setVerify | public function setVerify( $host = FALSE, $peer = 0, $caPath = NULL, $caInfo = NULL )
{
$this->curl->setOption( CURLOPT_SSL_VERIFYHOST, $host );
$this->curl->setOption( CURLOPT_SSL_VERIFYPEER, $peer );
$this->curl->setOption( CURLOPT_CAPATH, $caPath );
$this->curl->setOption( CURLOPT_CAINFO, $caInfo );
} | php | public function setVerify( $host = FALSE, $peer = 0, $caPath = NULL, $caInfo = NULL )
{
$this->curl->setOption( CURLOPT_SSL_VERIFYHOST, $host );
$this->curl->setOption( CURLOPT_SSL_VERIFYPEER, $peer );
$this->curl->setOption( CURLOPT_CAPATH, $caPath );
$this->curl->setOption( CURLOPT_CAINFO, $caInfo );
} | [
"public",
"function",
"setVerify",
"(",
"$",
"host",
"=",
"FALSE",
",",
"$",
"peer",
"=",
"0",
",",
"$",
"caPath",
"=",
"NULL",
",",
"$",
"caInfo",
"=",
"NULL",
")",
"{",
"$",
"this",
"->",
"curl",
"->",
"setOption",
"(",
"CURLOPT_SSL_VERIFYHOST",
",... | Sets up SSL Verification.
@access public
@param boolean $host Flag: verify Host
@param integer $peer Flag: verify Peer
@param string $caPath Path to certificates
@param string $caInfo Certificate File Name
@return void | [
"Sets",
"up",
"SSL",
"Verification",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Reader.php#L252-L258 | train |
CeusMedia/Common | src/UI/HTML/Link.php | UI_HTML_Link.render | public function render()
{
$attributes = $this->getAttributes();
if( is_array( $attributes['href'] ) )
$attributes['href'] = ADT_URL_Inference::buildStatic( $attributes['href'] );
$content = $this->renderInner( $this->content );
if( !is_string( $content ) )
throw new InvalidArgumentException( 'Link label is neither rendered nor renderable' );
return UI_HTML_Tag::create( "a", $content, $attributes );
} | php | public function render()
{
$attributes = $this->getAttributes();
if( is_array( $attributes['href'] ) )
$attributes['href'] = ADT_URL_Inference::buildStatic( $attributes['href'] );
$content = $this->renderInner( $this->content );
if( !is_string( $content ) )
throw new InvalidArgumentException( 'Link label is neither rendered nor renderable' );
return UI_HTML_Tag::create( "a", $content, $attributes );
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"attributes",
"[",
"'href'",
"]",
")",
")",
"$",
"attributes",
"[",
"'href'",
"]",
"=",
"ADT_UR... | Returns rendered Link Element
@access public
@return string | [
"Returns",
"rendered",
"Link",
"Element"
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Link.php#L67-L76 | train |
CeusMedia/Common | src/CLI/Fork/Worker/Abstract.php | CLI_Fork_Worker_Abstract.handleSignal | protected function handleSignal( $signalNumber )
{
switch( $signalNumber )
{
case SIGHUP:
$this->handleHangupSignal();
break;
case SIGTERM:
$this->handleTerminationSignal();
break;
default:
$this->handleUnknownSignal();
}
} | php | protected function handleSignal( $signalNumber )
{
switch( $signalNumber )
{
case SIGHUP:
$this->handleHangupSignal();
break;
case SIGTERM:
$this->handleTerminationSignal();
break;
default:
$this->handleUnknownSignal();
}
} | [
"protected",
"function",
"handleSignal",
"(",
"$",
"signalNumber",
")",
"{",
"switch",
"(",
"$",
"signalNumber",
")",
"{",
"case",
"SIGHUP",
":",
"$",
"this",
"->",
"handleHangupSignal",
"(",
")",
";",
"break",
";",
"case",
"SIGTERM",
":",
"$",
"this",
"... | Handle Process Signals.
@access protected
@param int $signalNumber
@return void | [
"Handle",
"Process",
"Signals",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/CLI/Fork/Worker/Abstract.php#L87-L100 | train |
CeusMedia/Common | src/Alg/Object/MethodFactory.php | Alg_Object_MethodFactory.call | public static function call( $mixed, $methodName, $methodParameters = array(), $classParameters = array(), $checkMethod = TRUE, $allowProtected = FALSE )
{
if( is_object( $mixed ) )
return self::callObjectMethod( $mixed, $methodName, $methodParameters, $checkMethod, $allowProtected );
return self::callClassMethod( $mixed, $methodName, $classParameters, $methodParameters, $checkMethod, $allowProtected );
} | php | public static function call( $mixed, $methodName, $methodParameters = array(), $classParameters = array(), $checkMethod = TRUE, $allowProtected = FALSE )
{
if( is_object( $mixed ) )
return self::callObjectMethod( $mixed, $methodName, $methodParameters, $checkMethod, $allowProtected );
return self::callClassMethod( $mixed, $methodName, $classParameters, $methodParameters, $checkMethod, $allowProtected );
} | [
"public",
"static",
"function",
"call",
"(",
"$",
"mixed",
",",
"$",
"methodName",
",",
"$",
"methodParameters",
"=",
"array",
"(",
")",
",",
"$",
"classParameters",
"=",
"array",
"(",
")",
",",
"$",
"checkMethod",
"=",
"TRUE",
",",
"$",
"allowProtected"... | Calls a Method from a Class or Object with Method Parameters and Object Parameters if a Class is given.
@access public
@static
@param string|object $mixed Class Name or Object
@param string $methodName Name of Method to call
@param array $methodParameters List of Parameters for Method Call
@param array $classParameters List of Parameters for Object Construction if Class is given
@param boolean $checkMethod Flag: check if methods exists by default, disable for classes using __call
@param boolean $allowProtected Flag: allow invoking protected and private methods (PHP 5.3.2+), default: no
@return mixed Result of called Method | [
"Calls",
"a",
"Method",
"from",
"a",
"Class",
"or",
"Object",
"with",
"Method",
"Parameters",
"and",
"Object",
"Parameters",
"if",
"a",
"Class",
"is",
"given",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Object/MethodFactory.php#L56-L61 | train |
CeusMedia/Common | src/Alg/Object/MethodFactory.php | Alg_Object_MethodFactory.callObjectMethod | public static function callObjectMethod( $object, $methodName, $parameters = array(), $checkMethod = TRUE, $allowProtected = FALSE )
{
if( !is_object( $object ) )
throw new InvalidArgumentException( 'Invalid object' );
$reflection = new ReflectionObject( $object ); // get Object Reflection
if( $checkMethod && !$reflection->hasMethod( $methodName ) ) // called Method is not existing
{
$message = 'Method '.$reflection->getName().'::'.$methodName.' is not existing'; // prepare Exception Message
throw new BadMethodCallException( $message ); // throw Exception
}
if( $reflection->hasMethod( $methodName ) )
{
$method = $reflection->getMethod( $methodName );
}
else{
$method = $reflection->getMethod( '__call' );
$parameters = array(
$methodName,
$parameters
);
}
if( $allowProtected && version_compare( PHP_VERSION, '5.3.2' ) >= 0 )
$method->setAccessible( TRUE ); // @see http://php.net/manual/de/reflectionmethod.setaccessible.php
if( $parameters ) // if Method Parameters are set
return $method->invokeArgs( $object, $parameters ); // invoke Method with Parameters
return $method->invoke( $object ); // else invoke Method without Parameters
} | php | public static function callObjectMethod( $object, $methodName, $parameters = array(), $checkMethod = TRUE, $allowProtected = FALSE )
{
if( !is_object( $object ) )
throw new InvalidArgumentException( 'Invalid object' );
$reflection = new ReflectionObject( $object ); // get Object Reflection
if( $checkMethod && !$reflection->hasMethod( $methodName ) ) // called Method is not existing
{
$message = 'Method '.$reflection->getName().'::'.$methodName.' is not existing'; // prepare Exception Message
throw new BadMethodCallException( $message ); // throw Exception
}
if( $reflection->hasMethod( $methodName ) )
{
$method = $reflection->getMethod( $methodName );
}
else{
$method = $reflection->getMethod( '__call' );
$parameters = array(
$methodName,
$parameters
);
}
if( $allowProtected && version_compare( PHP_VERSION, '5.3.2' ) >= 0 )
$method->setAccessible( TRUE ); // @see http://php.net/manual/de/reflectionmethod.setaccessible.php
if( $parameters ) // if Method Parameters are set
return $method->invokeArgs( $object, $parameters ); // invoke Method with Parameters
return $method->invoke( $object ); // else invoke Method without Parameters
} | [
"public",
"static",
"function",
"callObjectMethod",
"(",
"$",
"object",
",",
"$",
"methodName",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
",",
"$",
"checkMethod",
"=",
"TRUE",
",",
"$",
"allowProtected",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"i... | Calls Class or Object Method.
@access public
@static
@param object $object Object to call Method of
@param string $methodName Name of Method to call
@param array $parameters List of Parameters for Method Call
@param boolean $checkMethod Flag: check if methods exists by default, disable for classes using __call
@param boolean $allowProtected Flag: allow invoking protected and private methods (PHP 5.3.2+), default: no
@return mixed Result of called Method
@throws InvalidArgumentException if no object is given
@throws BadMethodCallException if an invalid Method is called | [
"Calls",
"Class",
"or",
"Object",
"Method",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Object/MethodFactory.php#L96-L124 | train |
meritoo/common-library | src/Traits/CssSelector/FormCssSelector.php | FormCssSelector.getInputByNameSelector | public static function getInputByNameSelector($formName, $fieldName)
{
$formSelector = static::getFormByNameSelector($formName);
$fieldName = trim($fieldName);
if (empty($formSelector) || empty($fieldName)) {
return '';
}
return sprintf('%s input[name="%s"]', $formSelector, $fieldName);
} | php | public static function getInputByNameSelector($formName, $fieldName)
{
$formSelector = static::getFormByNameSelector($formName);
$fieldName = trim($fieldName);
if (empty($formSelector) || empty($fieldName)) {
return '';
}
return sprintf('%s input[name="%s"]', $formSelector, $fieldName);
} | [
"public",
"static",
"function",
"getInputByNameSelector",
"(",
"$",
"formName",
",",
"$",
"fieldName",
")",
"{",
"$",
"formSelector",
"=",
"static",
"::",
"getFormByNameSelector",
"(",
"$",
"formName",
")",
";",
"$",
"fieldName",
"=",
"trim",
"(",
"$",
"fiel... | Returns selector of the input field based on its name
@param string $formName Name of form (value of the "name" attribute)
@param string $fieldName Name of field (value of the "name" attribute)
@return string | [
"Returns",
"selector",
"of",
"the",
"input",
"field",
"based",
"on",
"its",
"name"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Traits/CssSelector/FormCssSelector.php#L43-L53 | train |
meritoo/common-library | src/Traits/CssSelector/FormCssSelector.php | FormCssSelector.getInputByIdSelector | public static function getInputByIdSelector($formName, $fieldId)
{
$formSelector = static::getFormByNameSelector($formName);
$fieldId = trim($fieldId);
if (empty($formSelector) || empty($fieldId)) {
return '';
}
return sprintf('%s input#%s', $formSelector, $fieldId);
} | php | public static function getInputByIdSelector($formName, $fieldId)
{
$formSelector = static::getFormByNameSelector($formName);
$fieldId = trim($fieldId);
if (empty($formSelector) || empty($fieldId)) {
return '';
}
return sprintf('%s input#%s', $formSelector, $fieldId);
} | [
"public",
"static",
"function",
"getInputByIdSelector",
"(",
"$",
"formName",
",",
"$",
"fieldId",
")",
"{",
"$",
"formSelector",
"=",
"static",
"::",
"getFormByNameSelector",
"(",
"$",
"formName",
")",
";",
"$",
"fieldId",
"=",
"trim",
"(",
"$",
"fieldId",
... | Returns selector of the input field based on its ID
@param string $formName Name of form (value of the "name" attribute)
@param string $fieldId ID of field (value of the "id" attribute)
@return string | [
"Returns",
"selector",
"of",
"the",
"input",
"field",
"based",
"on",
"its",
"ID"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Traits/CssSelector/FormCssSelector.php#L62-L72 | train |
meritoo/common-library | src/Traits/CssSelector/FormCssSelector.php | FormCssSelector.getLabelSelector | public static function getLabelSelector($formName, $fieldId)
{
$formSelector = static::getFormByNameSelector($formName);
$fieldId = trim($fieldId);
if (empty($formSelector) || empty($fieldId)) {
return '';
}
return sprintf('%s label[for="%s"]', $formSelector, $fieldId);
} | php | public static function getLabelSelector($formName, $fieldId)
{
$formSelector = static::getFormByNameSelector($formName);
$fieldId = trim($fieldId);
if (empty($formSelector) || empty($fieldId)) {
return '';
}
return sprintf('%s label[for="%s"]', $formSelector, $fieldId);
} | [
"public",
"static",
"function",
"getLabelSelector",
"(",
"$",
"formName",
",",
"$",
"fieldId",
")",
"{",
"$",
"formSelector",
"=",
"static",
"::",
"getFormByNameSelector",
"(",
"$",
"formName",
")",
";",
"$",
"fieldId",
"=",
"trim",
"(",
"$",
"fieldId",
")... | Returns selector of label
@param string $formName Name of form (value of the "name" attribute)
@param string $fieldId ID of field (value of the "id" attribute)
@return string | [
"Returns",
"selector",
"of",
"label"
] | b166b8b805ae97c15688d27323cae8976bd0f6dc | https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Traits/CssSelector/FormCssSelector.php#L81-L91 | train |
CeusMedia/Common | src/Alg/Math/Algebra/Matrix.php | Alg_Math_Algebra_Matrix.clear | public function clear( $init = 0 )
{
for( $row = 0; $row < $this->getRowNumber(); $row++ )
for( $column = 0; $column < $this->getColumnNumber(); $column++ )
$this->setValue( $row, $column, $init );
} | php | public function clear( $init = 0 )
{
for( $row = 0; $row < $this->getRowNumber(); $row++ )
for( $column = 0; $column < $this->getColumnNumber(); $column++ )
$this->setValue( $row, $column, $init );
} | [
"public",
"function",
"clear",
"(",
"$",
"init",
"=",
"0",
")",
"{",
"for",
"(",
"$",
"row",
"=",
"0",
";",
"$",
"row",
"<",
"$",
"this",
"->",
"getRowNumber",
"(",
")",
";",
"$",
"row",
"++",
")",
"for",
"(",
"$",
"column",
"=",
"0",
";",
... | Clears Matrix by setting initial value.
@access public
@param int $init initial values in Matrix
@return void | [
"Clears",
"Matrix",
"by",
"setting",
"initial",
"value",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Algebra/Matrix.php#L81-L86 | train |
CeusMedia/Common | src/Alg/Math/Algebra/Matrix.php | Alg_Math_Algebra_Matrix.getColumn | public function getColumn( $column )
{
if( $column < 0 || $column >= $this->getColumnNumber() )
throw new OutOfRangeException( 'Column key "'.$column.'" is not valid.' );
$values = array();
for( $row = 0; $row < $this->getRowNumber(); $row++ )
$values[] = $this->getValue( $row, $column );
return new Alg_Math_Algebra_Vector( $values );
} | php | public function getColumn( $column )
{
if( $column < 0 || $column >= $this->getColumnNumber() )
throw new OutOfRangeException( 'Column key "'.$column.'" is not valid.' );
$values = array();
for( $row = 0; $row < $this->getRowNumber(); $row++ )
$values[] = $this->getValue( $row, $column );
return new Alg_Math_Algebra_Vector( $values );
} | [
"public",
"function",
"getColumn",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"$",
"column",
"<",
"0",
"||",
"$",
"column",
">=",
"$",
"this",
"->",
"getColumnNumber",
"(",
")",
")",
"throw",
"new",
"OutOfRangeException",
"(",
"'Column key \"'",
".",
"$",
... | Returns a column as Vector.
@access public
@param int $column Column Index
@return Alg_Math_Algebra_Vector | [
"Returns",
"a",
"column",
"as",
"Vector",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Algebra/Matrix.php#L94-L102 | train |
CeusMedia/Common | src/Alg/Math/Algebra/Matrix.php | Alg_Math_Algebra_Matrix.getRow | public function getRow( $row )
{
if( $row < 0 || $row >= $this->getRowNumber() )
throw new OutOfRangeException( 'Row key "'.$row.'" is not valid.' );
return new Alg_Math_Algebra_Vector( $this->values[$row] );
} | php | public function getRow( $row )
{
if( $row < 0 || $row >= $this->getRowNumber() )
throw new OutOfRangeException( 'Row key "'.$row.'" is not valid.' );
return new Alg_Math_Algebra_Vector( $this->values[$row] );
} | [
"public",
"function",
"getRow",
"(",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"<",
"0",
"||",
"$",
"row",
">=",
"$",
"this",
"->",
"getRowNumber",
"(",
")",
")",
"throw",
"new",
"OutOfRangeException",
"(",
"'Row key \"'",
".",
"$",
"row",
".",
... | Returns a row as Vector.
@access public
@param int $row Row Index
@return Alg_Math_Algebra_Vector | [
"Returns",
"a",
"row",
"as",
"Vector",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Algebra/Matrix.php#L120-L125 | train |
CeusMedia/Common | src/Alg/Math/Algebra/Matrix.php | Alg_Math_Algebra_Matrix.swapColumns | public function swapColumns( $column1, $column2 )
{
if( $column1 < 0 || $column1 >= $this->getColumnNumber() )
throw new OutOfRangeException( 'Column key "'.$column1.'" is not valid.' );
if( $column2 < 0 || $column2 >= $this->getColumnNumber() )
throw new OutOfRangeException( 'Column key "'.$column2.'" is not valid.' );
for( $row = 0; $row < $this->getRowNumber(); $row++ )
{
$buffer = $this->values[$row][$column1];
$this->values[$row][$column1] = $this->values[$row][$column2];
$this->values[$row][$column2] = $buffer;
}
} | php | public function swapColumns( $column1, $column2 )
{
if( $column1 < 0 || $column1 >= $this->getColumnNumber() )
throw new OutOfRangeException( 'Column key "'.$column1.'" is not valid.' );
if( $column2 < 0 || $column2 >= $this->getColumnNumber() )
throw new OutOfRangeException( 'Column key "'.$column2.'" is not valid.' );
for( $row = 0; $row < $this->getRowNumber(); $row++ )
{
$buffer = $this->values[$row][$column1];
$this->values[$row][$column1] = $this->values[$row][$column2];
$this->values[$row][$column2] = $buffer;
}
} | [
"public",
"function",
"swapColumns",
"(",
"$",
"column1",
",",
"$",
"column2",
")",
"{",
"if",
"(",
"$",
"column1",
"<",
"0",
"||",
"$",
"column1",
">=",
"$",
"this",
"->",
"getColumnNumber",
"(",
")",
")",
"throw",
"new",
"OutOfRangeException",
"(",
"... | Swaps 2 Columns within Matrix.
@access public
@param int $column1 Index of Source Column
@param int $column2 Index of Target Column
@return void | [
"Swaps",
"2",
"Columns",
"within",
"Matrix",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Algebra/Matrix.php#L177-L190 | train |
CeusMedia/Common | src/Alg/Math/Algebra/Matrix.php | Alg_Math_Algebra_Matrix.swapRows | public function swapRows( $row1, $row2 )
{
if( $row1 < 0 || $row1 >= $this->getRowNumber() )
throw new OutOfRangeException( 'Source Row key "'.$row1.'" is not valid.' );
if( $row2 < 0 || $row2 >= $this->getRowNumber() )
throw new OutOfRangeException( 'Target Row key "'.$row2.'" is not valid.' );
$buffer = $this->values[$row2];
$this->values[$row2] = $this->values[$row1];
$this->values[$row1] = $buffer;
} | php | public function swapRows( $row1, $row2 )
{
if( $row1 < 0 || $row1 >= $this->getRowNumber() )
throw new OutOfRangeException( 'Source Row key "'.$row1.'" is not valid.' );
if( $row2 < 0 || $row2 >= $this->getRowNumber() )
throw new OutOfRangeException( 'Target Row key "'.$row2.'" is not valid.' );
$buffer = $this->values[$row2];
$this->values[$row2] = $this->values[$row1];
$this->values[$row1] = $buffer;
} | [
"public",
"function",
"swapRows",
"(",
"$",
"row1",
",",
"$",
"row2",
")",
"{",
"if",
"(",
"$",
"row1",
"<",
"0",
"||",
"$",
"row1",
">=",
"$",
"this",
"->",
"getRowNumber",
"(",
")",
")",
"throw",
"new",
"OutOfRangeException",
"(",
"'Source Row key \"... | Swaps 2 Rows within Matrix.
@access public
@param int $row1 Index of Source Row
@param int $row2 Index of Target Row
@return void | [
"Swaps",
"2",
"Rows",
"within",
"Matrix",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Algebra/Matrix.php#L199-L209 | train |
CeusMedia/Common | src/Alg/Math/Algebra/Matrix.php | Alg_Math_Algebra_Matrix.transpose | public function transpose()
{
$array = array();
$rowNumber = $this->getRowNumber();
$columnNumber = $this->getColumnNumber();
for( $row = 0; $row < $rowNumber; $row++ )
for( $column = 0; $column < $columnNumber; $column++ )
$array[$column][$row] = $this->values[$row][$column];
$this->rowNumber = $columnNumber;
$this->columnNumber = $rowNumber;
$this->values = $array;
} | php | public function transpose()
{
$array = array();
$rowNumber = $this->getRowNumber();
$columnNumber = $this->getColumnNumber();
for( $row = 0; $row < $rowNumber; $row++ )
for( $column = 0; $column < $columnNumber; $column++ )
$array[$column][$row] = $this->values[$row][$column];
$this->rowNumber = $columnNumber;
$this->columnNumber = $rowNumber;
$this->values = $array;
} | [
"public",
"function",
"transpose",
"(",
")",
"{",
"$",
"array",
"=",
"array",
"(",
")",
";",
"$",
"rowNumber",
"=",
"$",
"this",
"->",
"getRowNumber",
"(",
")",
";",
"$",
"columnNumber",
"=",
"$",
"this",
"->",
"getColumnNumber",
"(",
")",
";",
"for"... | Returns transposed Matrix.
@access public
@return Alg_Math_Algebra_Matrix | [
"Returns",
"transposed",
"Matrix",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Algebra/Matrix.php#L245-L256 | train |
CeusMedia/Common | src/UI/HTML/Exception/TraceViewer.php | UI_HTML_Exception_TraceViewer.convertArrayToString | protected static function convertArrayToString( $array, $breakMode, $level = 1 )
{
$list = array();
foreach( $array as $key => $value )
{
$string = self::convertArgumentToString( $value, $breakMode, $level+1 );
$list[] = $key.":".$string;
}
$block = implode( ", ", $list );
if( $breakMode == 2 )
{
$level = str_repeat( " ", 3 * $level );
$indent = str_repeat( " ", 3 );
$list = implode( ",<br/>".$level.$indent.$indent.$indent.$indent, $list );
$block = "<br/>".$level.$indent.$indent.$indent.$indent.$list."<br/>".$level.$indent.$indent.$indent;
}
if( $breakMode == 3 )
{
$block = self::blockquote( implode( ',<br/>', $list ) );
}
return '{'.$block.'}';
} | php | protected static function convertArrayToString( $array, $breakMode, $level = 1 )
{
$list = array();
foreach( $array as $key => $value )
{
$string = self::convertArgumentToString( $value, $breakMode, $level+1 );
$list[] = $key.":".$string;
}
$block = implode( ", ", $list );
if( $breakMode == 2 )
{
$level = str_repeat( " ", 3 * $level );
$indent = str_repeat( " ", 3 );
$list = implode( ",<br/>".$level.$indent.$indent.$indent.$indent, $list );
$block = "<br/>".$level.$indent.$indent.$indent.$indent.$list."<br/>".$level.$indent.$indent.$indent;
}
if( $breakMode == 3 )
{
$block = self::blockquote( implode( ',<br/>', $list ) );
}
return '{'.$block.'}';
} | [
"protected",
"static",
"function",
"convertArrayToString",
"(",
"$",
"array",
",",
"$",
"breakMode",
",",
"$",
"level",
"=",
"1",
")",
"{",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
... | Converts Array to String.
@access protected
@static
@param array $array Array to convert to String
@return string | [
"Converts",
"Array",
"to",
"String",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Exception/TraceViewer.php#L208-L229 | train |
CeusMedia/Common | src/Net/Connectivity.php | Net_Connectivity.check | public function check( $method = NULL ){
$method = $this->method;
if( $method && $this->validateMethod( $method ) )
$method = $method;
$currentStatus = $this->status;
switch( $method ){
case self::METHOD_SOCKET:
$this->checkUsingSocket();
break;
case self::METHOD_PING:
$this->checkUsingSystemPing();
break;
}
if( $this->status !== $currentStatus ){
if( $this->callbackOnChange ){
call_user_func_array( $this->callbackOnChange, array( $this->status ) );
}
}
} | php | public function check( $method = NULL ){
$method = $this->method;
if( $method && $this->validateMethod( $method ) )
$method = $method;
$currentStatus = $this->status;
switch( $method ){
case self::METHOD_SOCKET:
$this->checkUsingSocket();
break;
case self::METHOD_PING:
$this->checkUsingSystemPing();
break;
}
if( $this->status !== $currentStatus ){
if( $this->callbackOnChange ){
call_user_func_array( $this->callbackOnChange, array( $this->status ) );
}
}
} | [
"public",
"function",
"check",
"(",
"$",
"method",
"=",
"NULL",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"method",
";",
"if",
"(",
"$",
"method",
"&&",
"$",
"this",
"->",
"validateMethod",
"(",
"$",
"method",
")",
")",
"$",
"method",
"=",
... | ...
Executes callback function by if set and status has changed.
@access public
@param integer $method Method to use for checking
@return void
@throws \RangeException if given method is unsupported | [
"...",
"Executes",
"callback",
"function",
"by",
"if",
"set",
"and",
"status",
"has",
"changed",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/Connectivity.php#L67-L85 | train |
CeusMedia/Common | src/Net/Connectivity.php | Net_Connectivity.checkUsingSocket | public function checkUsingSocket(){
$conn = @fsockopen( 'google.com', 443);
$this->status = $conn ? self::STATUS_ONLINE : self::STATUS_OFFLINE;
fclose( $conn );
} | php | public function checkUsingSocket(){
$conn = @fsockopen( 'google.com', 443);
$this->status = $conn ? self::STATUS_ONLINE : self::STATUS_OFFLINE;
fclose( $conn );
} | [
"public",
"function",
"checkUsingSocket",
"(",
")",
"{",
"$",
"conn",
"=",
"@",
"fsockopen",
"(",
"'google.com'",
",",
"443",
")",
";",
"$",
"this",
"->",
"status",
"=",
"$",
"conn",
"?",
"self",
"::",
"STATUS_ONLINE",
":",
"self",
"::",
"STATUS_OFFLINE"... | Check connectivity using a socket connection.
Sets status depending on result.
@access public
@return void | [
"Check",
"connectivity",
"using",
"a",
"socket",
"connection",
".",
"Sets",
"status",
"depending",
"on",
"result",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/Connectivity.php#L93-L97 | train |
CeusMedia/Common | src/Net/Connectivity.php | Net_Connectivity.checkUsingSystemPing | public function checkUsingSystemPing(){
$response = NULL;
@exec( "ping -c 1 google.com 2>&1 1> /dev/null", $response, $code );
// @system( "ping -c 1 1111google.com &2>1 &1>/dev/null", $code );
if( $code == 0 )
$this->status = self::STATUS_ONLINE;
else
$this->status = self::STATUS_OFFLINE;
} | php | public function checkUsingSystemPing(){
$response = NULL;
@exec( "ping -c 1 google.com 2>&1 1> /dev/null", $response, $code );
// @system( "ping -c 1 1111google.com &2>1 &1>/dev/null", $code );
if( $code == 0 )
$this->status = self::STATUS_ONLINE;
else
$this->status = self::STATUS_OFFLINE;
} | [
"public",
"function",
"checkUsingSystemPing",
"(",
")",
"{",
"$",
"response",
"=",
"NULL",
";",
"@",
"exec",
"(",
"\"ping -c 1 google.com 2>&1 1> /dev/null\"",
",",
"$",
"response",
",",
"$",
"code",
")",
";",
"//\t\t@system( \"ping -c 1 1111google.com &2>1 &1>/dev/null... | Check connectivity using ping via system call.
Sets status depending on result.
@access public
@return void | [
"Check",
"connectivity",
"using",
"ping",
"via",
"system",
"call",
".",
"Sets",
"status",
"depending",
"on",
"result",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/Connectivity.php#L105-L113 | train |
CeusMedia/Common | src/Net/Connectivity.php | Net_Connectivity.validateMethod | protected function validateMethod( $method ){
if( !is_int( $method ) )
throw new \InvalidArgumentException( 'Method must be integer' );
if( !in_array( $method, array( self::METHOD_SOCKET, self::METHOD_PING ) ) )
throw new \RangeException( 'Invalid method' );
return $method;
} | php | protected function validateMethod( $method ){
if( !is_int( $method ) )
throw new \InvalidArgumentException( 'Method must be integer' );
if( !in_array( $method, array( self::METHOD_SOCKET, self::METHOD_PING ) ) )
throw new \RangeException( 'Invalid method' );
return $method;
} | [
"protected",
"function",
"validateMethod",
"(",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"method",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Method must be integer'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"... | Validate given method.
@acess protected
@param integer Method to validate
@return integer Method after validation | [
"Validate",
"given",
"method",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/Connectivity.php#L189-L195 | train |
CeusMedia/Common | src/Alg/Math/Analysis/Integration.php | Alg_Math_Analysis_Integration.getSamplingNodes | public function getSamplingNodes()
{
$nodes = array();
$start = $this->interval->getStart();
$distance = $this->getNodeDistance();
for( $i = 0; $i<$this->getNodes(); $i++ )
{
$x = $start + $i * $distance;
$nodes[] = $x;
}
return $nodes;
} | php | public function getSamplingNodes()
{
$nodes = array();
$start = $this->interval->getStart();
$distance = $this->getNodeDistance();
for( $i = 0; $i<$this->getNodes(); $i++ )
{
$x = $start + $i * $distance;
$nodes[] = $x;
}
return $nodes;
} | [
"public",
"function",
"getSamplingNodes",
"(",
")",
"{",
"$",
"nodes",
"=",
"array",
"(",
")",
";",
"$",
"start",
"=",
"$",
"this",
"->",
"interval",
"->",
"getStart",
"(",
")",
";",
"$",
"distance",
"=",
"$",
"this",
"->",
"getNodeDistance",
"(",
")... | Returns an array of Sampling Nodes.
@access public
@return array | [
"Returns",
"an",
"array",
"of",
"Sampling",
"Nodes",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Math/Analysis/Integration.php#L116-L127 | train |
ncou/Chiron | src/Chiron/Http/Middleware/EncryptCookiesMiddleware.php | EncryptCookiesMiddleware.process | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$request = $this->withDecryptedCookies($request);
$response = $handler->handle($request);
return $this->withEncryptedCookies($response);
} | php | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$request = $this->withDecryptedCookies($request);
$response = $handler->handle($request);
return $this->withEncryptedCookies($response);
} | [
"public",
"function",
"process",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"RequestHandlerInterface",
"$",
"handler",
")",
":",
"ResponseInterface",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"withDecryptedCookies",
"(",
"$",
"request",
")",
";",
"$"... | Start the session, delegate the request processing and add the session cookie to the response.
@param ServerRequestInterface $request
@param RequestHandlerInterface $handler
@return ResponseInterface | [
"Start",
"the",
"session",
"delegate",
"the",
"request",
"processing",
"and",
"add",
"the",
"session",
"cookie",
"to",
"the",
"response",
"."
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Http/Middleware/EncryptCookiesMiddleware.php#L50-L56 | train |
ncou/Chiron | src/Chiron/Http/Middleware/EncryptCookiesMiddleware.php | EncryptCookiesMiddleware.withDecryptedCookies | private function withDecryptedCookies(ServerRequestInterface $request): ServerRequestInterface
{
$cookies = $request->getCookieParams();
$decrypted = [];
foreach ($cookies as $name => $value) {
$decrypted[$name] = in_array($name, $this->bypassed) ? $value : $this->decrypt($value);
}
return $request->withCookieParams($decrypted);
} | php | private function withDecryptedCookies(ServerRequestInterface $request): ServerRequestInterface
{
$cookies = $request->getCookieParams();
$decrypted = [];
foreach ($cookies as $name => $value) {
$decrypted[$name] = in_array($name, $this->bypassed) ? $value : $this->decrypt($value);
}
return $request->withCookieParams($decrypted);
} | [
"private",
"function",
"withDecryptedCookies",
"(",
"ServerRequestInterface",
"$",
"request",
")",
":",
"ServerRequestInterface",
"{",
"$",
"cookies",
"=",
"$",
"request",
"->",
"getCookieParams",
"(",
")",
";",
"$",
"decrypted",
"=",
"[",
"]",
";",
"foreach",
... | Decrypt the non bypassed cookie values attached to the given request and return a new request with those values.
@param ServerRequestInterface $request
@return ServerRequestInterface | [
"Decrypt",
"the",
"non",
"bypassed",
"cookie",
"values",
"attached",
"to",
"the",
"given",
"request",
"and",
"return",
"a",
"new",
"request",
"with",
"those",
"values",
"."
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Http/Middleware/EncryptCookiesMiddleware.php#L65-L75 | train |
ncou/Chiron | src/Chiron/Http/Middleware/EncryptCookiesMiddleware.php | EncryptCookiesMiddleware.withEncryptedCookies | protected function withEncryptedCookies(ResponseInterface $response): ResponseInterface
{
//$cookiesManager = new CookiesManager();
//$cookies = CookiesManager::parseHeaders($response->getHeader('Set-Cookie'));
$cookies = CookiesManager::parseSetCookieHeader($response->getHeader('Set-Cookie'));
// remove all the cookies
$response = $response->withoutHeader('Set-Cookie');
//$header = [];
foreach ($cookies as $name => $cookie) {
if (! in_array($name, $this->bypassed)) {
$cookie['value'] = $this->encrypt($cookie['value']);
}
//$cookiesManager->set($name, $value);
// add again all the cookies (and some are now encrypted)
$response = $response->withAddedHeader('Set-Cookie', CookiesManager::toHeader($name, $cookie));
}
return $response;
} | php | protected function withEncryptedCookies(ResponseInterface $response): ResponseInterface
{
//$cookiesManager = new CookiesManager();
//$cookies = CookiesManager::parseHeaders($response->getHeader('Set-Cookie'));
$cookies = CookiesManager::parseSetCookieHeader($response->getHeader('Set-Cookie'));
// remove all the cookies
$response = $response->withoutHeader('Set-Cookie');
//$header = [];
foreach ($cookies as $name => $cookie) {
if (! in_array($name, $this->bypassed)) {
$cookie['value'] = $this->encrypt($cookie['value']);
}
//$cookiesManager->set($name, $value);
// add again all the cookies (and some are now encrypted)
$response = $response->withAddedHeader('Set-Cookie', CookiesManager::toHeader($name, $cookie));
}
return $response;
} | [
"protected",
"function",
"withEncryptedCookies",
"(",
"ResponseInterface",
"$",
"response",
")",
":",
"ResponseInterface",
"{",
"//$cookiesManager = new CookiesManager();",
"//$cookies = CookiesManager::parseHeaders($response->getHeader('Set-Cookie'));",
"$",
"cookies",
"=",
"Cookies... | Encode cookies from a response's Set-Cookie header.
@param ResponseInterface $response The response to encode cookies in.
@return ResponseInterface Updated response with encoded cookies. | [
"Encode",
"cookies",
"from",
"a",
"response",
"s",
"Set",
"-",
"Cookie",
"header",
"."
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Http/Middleware/EncryptCookiesMiddleware.php#L84-L106 | train |
ncou/Chiron | src/Chiron/Http/Middleware/EncryptCookiesMiddleware.php | EncryptCookiesMiddleware.decrypt | private function decrypt(string $value): string
{
try {
return CryptEngine::decrypt($value, $this->password);
} catch (\Throwable $t) {
// @TODO : Add a silent log message if there is an error in the cookie decrypt function.
return '';
}
} | php | private function decrypt(string $value): string
{
try {
return CryptEngine::decrypt($value, $this->password);
} catch (\Throwable $t) {
// @TODO : Add a silent log message if there is an error in the cookie decrypt function.
return '';
}
} | [
"private",
"function",
"decrypt",
"(",
"string",
"$",
"value",
")",
":",
"string",
"{",
"try",
"{",
"return",
"CryptEngine",
"::",
"decrypt",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"password",
")",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
... | Decrypt the given value using the key.
Return default to blank string when the key is wrong or the cypher text has been modified.
@param string $value
@return string | [
"Decrypt",
"the",
"given",
"value",
"using",
"the",
"key",
".",
"Return",
"default",
"to",
"blank",
"string",
"when",
"the",
"key",
"is",
"wrong",
"or",
"the",
"cypher",
"text",
"has",
"been",
"modified",
"."
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Http/Middleware/EncryptCookiesMiddleware.php#L128-L136 | train |
CeusMedia/Common | src/ADT/Multiplexer.php | ADT_Multiplexer.proceed | public function proceed()
{
if( $this->getType() == 1 )
{
$output = $this->controls[0] ? $this->inputs[1] : $this->inputs[0];
}
else if( $this->getType() == 2 )
{
$mux = new ADT_Multiplexer();
$mux->setControls( $this->controls[0] );
$mux->setInputs( $this->inputs[0], $this->inputs[1] );
$input0 = $mux->proceed();
$mux->setInputs( $this->inputs[2], $this->inputs[3] );
$input1 = $mux->proceed();
$mux->setControls( $this->controls[1] );
$mux->setInputs( $input0, $input1 );
$output = $mux->proceed();
}
else if( $this->getType() == 4)
{
$mux2 = new ADT_Multiplexer( 2 );
$mux2->setControls( $this->controls[0], $this->controls[1] );
$mux2->setInputs( $this->inputs[0], $this->inputs[1], $this->inputs[2], $this->inputs[3] );
$input0 = $mux2->proceed();
$mux2->setInputs( $this->inputs[4], $this->inputs[5], $this->inputs[6], $this->inputs[7] );
$input1 = $mux2->proceed();
$mux2->setInputs( $this->inputs[8], $this->inputs[9], $this->inputs[10], $this->inputs[11] );
$input2 = $mux2->proceed();
$mux2->setInputs( $this->inputs[12], $this->inputs[13], $this->inputs[14], $this->inputs[15] );
$input3 = $mux2->proceed();
$mux2->setControls( $this->controls[2], $this->controls[3] );
$mux2->setInputs( $input0, $input1, $input2, $input3 );
$output = $mux2->proceed();
}
return $output;
} | php | public function proceed()
{
if( $this->getType() == 1 )
{
$output = $this->controls[0] ? $this->inputs[1] : $this->inputs[0];
}
else if( $this->getType() == 2 )
{
$mux = new ADT_Multiplexer();
$mux->setControls( $this->controls[0] );
$mux->setInputs( $this->inputs[0], $this->inputs[1] );
$input0 = $mux->proceed();
$mux->setInputs( $this->inputs[2], $this->inputs[3] );
$input1 = $mux->proceed();
$mux->setControls( $this->controls[1] );
$mux->setInputs( $input0, $input1 );
$output = $mux->proceed();
}
else if( $this->getType() == 4)
{
$mux2 = new ADT_Multiplexer( 2 );
$mux2->setControls( $this->controls[0], $this->controls[1] );
$mux2->setInputs( $this->inputs[0], $this->inputs[1], $this->inputs[2], $this->inputs[3] );
$input0 = $mux2->proceed();
$mux2->setInputs( $this->inputs[4], $this->inputs[5], $this->inputs[6], $this->inputs[7] );
$input1 = $mux2->proceed();
$mux2->setInputs( $this->inputs[8], $this->inputs[9], $this->inputs[10], $this->inputs[11] );
$input2 = $mux2->proceed();
$mux2->setInputs( $this->inputs[12], $this->inputs[13], $this->inputs[14], $this->inputs[15] );
$input3 = $mux2->proceed();
$mux2->setControls( $this->controls[2], $this->controls[3] );
$mux2->setInputs( $input0, $input1, $input2, $input3 );
$output = $mux2->proceed();
}
return $output;
} | [
"public",
"function",
"proceed",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
"==",
"1",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"controls",
"[",
"0",
"]",
"?",
"$",
"this",
"->",
"inputs",
"[",
"1",
"]",
":",
"$... | Runs Multiplexer.
@access public
@return mixed | [
"Runs",
"Multiplexer",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Multiplexer.php#L98-L133 | train |
CeusMedia/Common | src/ADT/Multiplexer.php | ADT_Multiplexer.setControls | public function setControls()
{
$this->controls = array();
$args = func_get_args();
for( $i = 0; $i < $this->type; $i ++ )
if( isset( $args[$i] ) )
$this->controls[$i] = $args[$i];
} | php | public function setControls()
{
$this->controls = array();
$args = func_get_args();
for( $i = 0; $i < $this->type; $i ++ )
if( isset( $args[$i] ) )
$this->controls[$i] = $args[$i];
} | [
"public",
"function",
"setControls",
"(",
")",
"{",
"$",
"this",
"->",
"controls",
"=",
"array",
"(",
")",
";",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"type",
";"... | Sets Controls from Method Arguments.
@access public
@return void | [
"Sets",
"Controls",
"from",
"Method",
"Arguments",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Multiplexer.php#L140-L147 | train |
CeusMedia/Common | src/ADT/Multiplexer.php | ADT_Multiplexer.setInputs | public function setInputs()
{
$this->inputs = array();
$len = pow( 2, $this->type );
$args = func_get_args();
for( $i = 0; $i < $len; $i ++ )
if( isset( $args[$i] ) )
$this->inputs[$i] = $args[$i];
} | php | public function setInputs()
{
$this->inputs = array();
$len = pow( 2, $this->type );
$args = func_get_args();
for( $i = 0; $i < $len; $i ++ )
if( isset( $args[$i] ) )
$this->inputs[$i] = $args[$i];
} | [
"public",
"function",
"setInputs",
"(",
")",
"{",
"$",
"this",
"->",
"inputs",
"=",
"array",
"(",
")",
";",
"$",
"len",
"=",
"pow",
"(",
"2",
",",
"$",
"this",
"->",
"type",
")",
";",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"for",
"("... | Sets Inputs from Method Arguments.
@access public
@return void | [
"Sets",
"Inputs",
"from",
"Method",
"Arguments",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Multiplexer.php#L154-L162 | train |
CeusMedia/Common | src/Exception/Validation.php | Exception_Validation.serialize | public function serialize()
{
return serialize( array( $this->message, $this->code, $this->file, $this->line, $this->errors, $this->form ) );
} | php | public function serialize()
{
return serialize( array( $this->message, $this->code, $this->file, $this->line, $this->errors, $this->form ) );
} | [
"public",
"function",
"serialize",
"(",
")",
"{",
"return",
"serialize",
"(",
"array",
"(",
"$",
"this",
"->",
"message",
",",
"$",
"this",
"->",
"code",
",",
"$",
"this",
"->",
"file",
",",
"$",
"this",
"->",
"line",
",",
"$",
"this",
"->",
"error... | Returns serial of exception.
@access public
@return string | [
"Returns",
"serial",
"of",
"exception",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Exception/Validation.php#L88-L91 | train |
CeusMedia/Common | src/Net/HTTP/Status.php | Net_HTTP_Status.sendHeader | static public function sendHeader( $code, $protocol = "HTTP/1.0" ){
$text = self::getText( $code );
header( $protocol.' '.$code.' '.$text );
} | php | static public function sendHeader( $code, $protocol = "HTTP/1.0" ){
$text = self::getText( $code );
header( $protocol.' '.$code.' '.$text );
} | [
"static",
"public",
"function",
"sendHeader",
"(",
"$",
"code",
",",
"$",
"protocol",
"=",
"\"HTTP/1.0\"",
")",
"{",
"$",
"text",
"=",
"self",
"::",
"getText",
"(",
"$",
"code",
")",
";",
"header",
"(",
"$",
"protocol",
".",
"' '",
".",
"$",
"code",
... | Sends HTTP header with status code and text.
@access public
@param integer $code HTTP status code to send
@param string $protocol HTTP protocol, default: HTTP/1.0
@return void | [
"Sends",
"HTTP",
"header",
"with",
"status",
"code",
"and",
"text",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Status.php#L158-L161 | train |
ncou/Chiron | src/Chiron/Routing/Route.php | Route.validateHttpMethods | private function validateHttpMethods(array $methods): array
{
if (empty($methods)) {
throw new InvalidArgumentException(
'HTTP methods argument was empty; must contain at least one method'
);
}
if (false === array_reduce($methods, function ($valid, $method) {
if (false === $valid) {
return false;
}
if (! is_string($method)) {
return false;
}
//if (! preg_match('/^[!#$%&\'*+.^_`\|~0-9a-z-]+$/i', $method)) {
if (! preg_match("/^[!#$%&'*+.^_`|~0-9a-z-]+$/i", $method)) {
return false;
}
return $valid;
}, true)) {
throw new InvalidArgumentException('One or more HTTP methods were invalid');
}
return array_map('strtoupper', $methods);
} | php | private function validateHttpMethods(array $methods): array
{
if (empty($methods)) {
throw new InvalidArgumentException(
'HTTP methods argument was empty; must contain at least one method'
);
}
if (false === array_reduce($methods, function ($valid, $method) {
if (false === $valid) {
return false;
}
if (! is_string($method)) {
return false;
}
//if (! preg_match('/^[!#$%&\'*+.^_`\|~0-9a-z-]+$/i', $method)) {
if (! preg_match("/^[!#$%&'*+.^_`|~0-9a-z-]+$/i", $method)) {
return false;
}
return $valid;
}, true)) {
throw new InvalidArgumentException('One or more HTTP methods were invalid');
}
return array_map('strtoupper', $methods);
} | [
"private",
"function",
"validateHttpMethods",
"(",
"array",
"$",
"methods",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"methods",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'HTTP methods argument was empty; must contain at least one me... | Validate the provided HTTP method names.
Validates, and then normalizes to upper case.
@param string[] An array of HTTP method names.
@throws Exception InvalidArgumentException for any invalid method names.
@return string[] | [
"Validate",
"the",
"provided",
"HTTP",
"method",
"names",
"."
] | bfb6f85faba0e54005896b09a7c34e456d1a1bed | https://github.com/ncou/Chiron/blob/bfb6f85faba0e54005896b09a7c34e456d1a1bed/src/Chiron/Routing/Route.php#L403-L428 | train |
CeusMedia/Common | src/Loader.php | Loader.registerNew | public static function registerNew( $extensions = NULL, $prefix = NULL, $path = NULL, $logFile = NULL, $verbose = 0 )
{
$loader = new Loader( $extensions, $prefix, $path, $logFile );
$loader->setVerbose( (int) $verbose );
$loader->registerAutoloader();
return $loader;
} | php | public static function registerNew( $extensions = NULL, $prefix = NULL, $path = NULL, $logFile = NULL, $verbose = 0 )
{
$loader = new Loader( $extensions, $prefix, $path, $logFile );
$loader->setVerbose( (int) $verbose );
$loader->registerAutoloader();
return $loader;
} | [
"public",
"static",
"function",
"registerNew",
"(",
"$",
"extensions",
"=",
"NULL",
",",
"$",
"prefix",
"=",
"NULL",
",",
"$",
"path",
"=",
"NULL",
",",
"$",
"logFile",
"=",
"NULL",
",",
"$",
"verbose",
"=",
"0",
")",
"{",
"$",
"loader",
"=",
"new"... | Register new Autoloader statically.
@static
@access public
@param mixed $extensions String or List of supported Class File Extensions
@param string $prefix Prefix of Classes
@param string $path Path to Classes
@param string $logFile Path to autoload log file
@param boolean $verbose Verbosity: 0 - quiet | 1 - show load | 2 - show scan (default: 0 - quiet)
@return Loader
@deprecated not working in PHP 5.2 | [
"Register",
"new",
"Autoloader",
"statically",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Loader.php#L71-L77 | train |
CeusMedia/Common | src/Loader.php | Loader.loadClass | public function loadClass( $className )
{
if( $this->prefix )
{
$prefix = strtolower( substr( $className, 0, strlen( $this->prefix ) ) );
if( $prefix != $this->prefix )
return FALSE;
$className = str_ireplace( $this->prefix, '', $className );
}
$basePath = $this->path ? $this->path : "";
if( $this->lowerPath )
{
$matches = array();
preg_match_all( '/^(.*)([a-z0-9]+)$/iU', $className, $matches );
$fileName = $matches[2][0];
$pathName = str_replace( "_","/", strtolower( $matches[1][0] ) );
$fileName = $pathName.$fileName;
}
else
$fileName = str_replace( "_","/", $className );
foreach( $this->extensions as $extension )
{
$filePath = $basePath.$fileName.".".$extension;
if( $this->verbose > 1 )
echo $this->lineBreak."autoload: ".$filePath;
if( defined( 'LOADER_LOG' ) && LOADER_LOG )
error_log( $filePath."\n", 3, LOADER_LOG );
# if( !@fopen( $filePath, "r", TRUE ) )
if( !file_exists( $filePath ) )
# if( !is_readable( $filePath ) )
continue;
$this->loadFile( $filePath, TRUE );
return TRUE;
}
return FALSE;
} | php | public function loadClass( $className )
{
if( $this->prefix )
{
$prefix = strtolower( substr( $className, 0, strlen( $this->prefix ) ) );
if( $prefix != $this->prefix )
return FALSE;
$className = str_ireplace( $this->prefix, '', $className );
}
$basePath = $this->path ? $this->path : "";
if( $this->lowerPath )
{
$matches = array();
preg_match_all( '/^(.*)([a-z0-9]+)$/iU', $className, $matches );
$fileName = $matches[2][0];
$pathName = str_replace( "_","/", strtolower( $matches[1][0] ) );
$fileName = $pathName.$fileName;
}
else
$fileName = str_replace( "_","/", $className );
foreach( $this->extensions as $extension )
{
$filePath = $basePath.$fileName.".".$extension;
if( $this->verbose > 1 )
echo $this->lineBreak."autoload: ".$filePath;
if( defined( 'LOADER_LOG' ) && LOADER_LOG )
error_log( $filePath."\n", 3, LOADER_LOG );
# if( !@fopen( $filePath, "r", TRUE ) )
if( !file_exists( $filePath ) )
# if( !is_readable( $filePath ) )
continue;
$this->loadFile( $filePath, TRUE );
return TRUE;
}
return FALSE;
} | [
"public",
"function",
"loadClass",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"prefix",
")",
"{",
"$",
"prefix",
"=",
"strtolower",
"(",
"substr",
"(",
"$",
"className",
",",
"0",
",",
"strlen",
"(",
"$",
"this",
"->",
"prefix",
... | Try to load a Class by its Class Name.
@access public
@param string $className Class Name with encoded Path
@return bool | [
"Try",
"to",
"load",
"a",
"Class",
"by",
"its",
"Class",
"Name",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Loader.php#L85-L120 | train |
CeusMedia/Common | src/Loader.php | Loader.loadFile | public function loadFile( $fileName, $once = FALSE )
{
$this->logLoadedFile( $fileName );
if( $once )
include_once $fileName;
else
include $fileName;
if( $this->verbose > 0 )
echo $this->lineBreak."load: ".$fileName;
} | php | public function loadFile( $fileName, $once = FALSE )
{
$this->logLoadedFile( $fileName );
if( $once )
include_once $fileName;
else
include $fileName;
if( $this->verbose > 0 )
echo $this->lineBreak."load: ".$fileName;
} | [
"public",
"function",
"loadFile",
"(",
"$",
"fileName",
",",
"$",
"once",
"=",
"FALSE",
")",
"{",
"$",
"this",
"->",
"logLoadedFile",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"$",
"once",
")",
"include_once",
"$",
"fileName",
";",
"else",
"include",
... | Try to load a File by its File Name.
@access public
@param string $fileName File Name, absolute or relative
@param bool $once Flag: Load once only
@return void | [
"Try",
"to",
"load",
"a",
"File",
"by",
"its",
"File",
"Name",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Loader.php#L129-L138 | train |
CeusMedia/Common | src/Loader.php | Loader.setPath | public function setPath( $path )
{
# if( $path && !file_exists( $path ) )
# throw new RuntimeException( 'Invalid path' );
$path = str_replace( DIRECTORY_SEPARATOR, "/", $path );
$path = preg_replace( "@(.+)/$@", "\\1", $path )."/";
$this->path = $path;
} | php | public function setPath( $path )
{
# if( $path && !file_exists( $path ) )
# throw new RuntimeException( 'Invalid path' );
$path = str_replace( DIRECTORY_SEPARATOR, "/", $path );
$path = preg_replace( "@(.+)/$@", "\\1", $path )."/";
$this->path = $path;
} | [
"public",
"function",
"setPath",
"(",
"$",
"path",
")",
"{",
"#\t\tif( $path && !file_exists( $path ) )",
"#\t\t\tthrow new RuntimeException( 'Invalid path' );",
"$",
"path",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"\"/\"",
",",
"$",
"path",
")",
";",
"$",
... | Sets Path to load Files from to force absolute File Names.
@access public
@param string $path Path to load Files from, empty to remove set Path
@return void
@throws RuntimeException if Path is not existing | [
"Sets",
"Path",
"to",
"load",
"Files",
"from",
"to",
"force",
"absolute",
"File",
"Names",
"."
] | 1138adf9341782a6284c05884989f7497532bcf4 | https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Loader.php#L211-L218 | train |
Assasz/yggdrasil | src/Yggdrasil/Core/Controller/ApiController.php | ApiController.fromBody | protected function fromBody(string $key)
{
$dataCollection = $this->parseBody();
if (!$this->inBody([$key])) {
throw new \InvalidArgumentException('Data with key ' . $key . ' doesn\'t exist in request body.');
}
return $dataCollection[$key];
} | php | protected function fromBody(string $key)
{
$dataCollection = $this->parseBody();
if (!$this->inBody([$key])) {
throw new \InvalidArgumentException('Data with key ' . $key . ' doesn\'t exist in request body.');
}
return $dataCollection[$key];
} | [
"protected",
"function",
"fromBody",
"(",
"string",
"$",
"key",
")",
"{",
"$",
"dataCollection",
"=",
"$",
"this",
"->",
"parseBody",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"inBody",
"(",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"... | Returns request body data specified by key
@param string $key
@return mixed
@throws \InvalidArgumentException if data specified by key doesn't exist | [
"Returns",
"request",
"body",
"data",
"specified",
"by",
"key"
] | bee9bef7713b85799cdd3e9b23dccae33154f3b3 | https://github.com/Assasz/yggdrasil/blob/bee9bef7713b85799cdd3e9b23dccae33154f3b3/src/Yggdrasil/Core/Controller/ApiController.php#L63-L72 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.