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 |
---|---|---|---|---|---|---|---|---|---|---|---|
koldy/framework | src/Koldy/Session/Adapter/Db.php | Db.getDbData | private function getDbData($sessionid): ?stdClass
{
$r = null;
try {
if ($this->disableLog) {
Log::temporaryDisable('sql');
}
$r = $this->getAdapter()
->select($this->getTableName())
->field('time')
->field('data')
->where('id', $sessionid)
->fetchFirstObj();
} catch (DbException $e) {
throw $e;
} finally {
if ($this->disableLog) {
Log::restoreTemporaryDisablement();
}
}
return $r;
} | php | private function getDbData($sessionid): ?stdClass
{
$r = null;
try {
if ($this->disableLog) {
Log::temporaryDisable('sql');
}
$r = $this->getAdapter()
->select($this->getTableName())
->field('time')
->field('data')
->where('id', $sessionid)
->fetchFirstObj();
} catch (DbException $e) {
throw $e;
} finally {
if ($this->disableLog) {
Log::restoreTemporaryDisablement();
}
}
return $r;
} | [
"private",
"function",
"getDbData",
"(",
"$",
"sessionid",
")",
":",
"?",
"stdClass",
"{",
"$",
"r",
"=",
"null",
";",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"disableLog",
")",
"{",
"Log",
"::",
"temporaryDisable",
"(",
"'sql'",
")",
";",
"}",
"$",
"r",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"select",
"(",
"$",
"this",
"->",
"getTableName",
"(",
")",
")",
"->",
"field",
"(",
"'time'",
")",
"->",
"field",
"(",
"'data'",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"sessionid",
")",
"->",
"fetchFirstObj",
"(",
")",
";",
"}",
"catch",
"(",
"DbException",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"finally",
"{",
"if",
"(",
"$",
"this",
"->",
"disableLog",
")",
"{",
"Log",
"::",
"restoreTemporaryDisablement",
"(",
")",
";",
"}",
"}",
"return",
"$",
"r",
";",
"}"
]
| Get the session data from database
@param string $sessionid
@return null|stdClass if data doesn't exist in database
@throws DbException
@throws \Koldy\Config\Exception
@throws \Koldy\Exception | [
"Get",
"the",
"session",
"data",
"from",
"database"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Session/Adapter/Db.php#L115-L141 | train |
koldy/framework | src/Koldy/Db/Query/Update.php | Update.set | public function set(string $field, $value): Update
{
$this->what[$field] = $value;
return $this;
} | php | public function set(string $field, $value): Update
{
$this->what[$field] = $value;
return $this;
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"field",
",",
"$",
"value",
")",
":",
"Update",
"{",
"$",
"this",
"->",
"what",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
]
| Set field to be updated
@param string $field
@param mixed $value
@return \Koldy\Db\Query\Update | [
"Set",
"field",
"to",
"be",
"updated"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Update.php#L74-L78 | train |
koldy/framework | src/Koldy/Db/Query/Update.php | Update.increment | public function increment(string $field, int $howMuch = 1): Update
{
return $this->set($field, new Expr("{$field} + {$howMuch}"));
} | php | public function increment(string $field, int $howMuch = 1): Update
{
return $this->set($field, new Expr("{$field} + {$howMuch}"));
} | [
"public",
"function",
"increment",
"(",
"string",
"$",
"field",
",",
"int",
"$",
"howMuch",
"=",
"1",
")",
":",
"Update",
"{",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"field",
",",
"new",
"Expr",
"(",
"\"{$field} + {$howMuch}\"",
")",
")",
";",
"}"
]
| Increment numeric field's value in database
@param string $field
@param int $howMuch
@return \Koldy\Db\Query\Update | [
"Increment",
"numeric",
"field",
"s",
"value",
"in",
"database"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Update.php#L140-L143 | train |
koldy/framework | src/Koldy/Db/Query/Update.php | Update.getQuery | public function getQuery(): Query
{
if (count($this->what) == 0) {
throw new Exception('Can not build UPDATE query, SET is not defined');
}
if ($this->table === null) {
throw new Exception('Can not build UPDATE query when table name is not set');
}
$sql = "UPDATE {$this->table}\nSET\n";
foreach ($this->what as $field => $value) {
$sql .= "\t{$field} = ";
if ($value instanceof Expr) {
$sql .= "{$value},\n";
} else {
//$key = $this->bind($field, $value);
$key = $this->getBindings()->makeAndSet($field, $value);
$sql .= ":{$key},\n";
}
}
$sql = substr($sql, 0, -2);
if ($this->hasWhere()) {
$sql .= "\nWHERE{$this->getWhereSql()}";
}
if (count($this->orderBy) > 0) {
$sql .= "\nORDER BY";
foreach ($this->orderBy as $r) {
$sql .= "\n\t{$r['field']} {$r['direction']},";
}
$sql = substr($sql, 0, -1);
}
return new Query($sql, $this->getBindings(), $this->getAdapterConnection());
} | php | public function getQuery(): Query
{
if (count($this->what) == 0) {
throw new Exception('Can not build UPDATE query, SET is not defined');
}
if ($this->table === null) {
throw new Exception('Can not build UPDATE query when table name is not set');
}
$sql = "UPDATE {$this->table}\nSET\n";
foreach ($this->what as $field => $value) {
$sql .= "\t{$field} = ";
if ($value instanceof Expr) {
$sql .= "{$value},\n";
} else {
//$key = $this->bind($field, $value);
$key = $this->getBindings()->makeAndSet($field, $value);
$sql .= ":{$key},\n";
}
}
$sql = substr($sql, 0, -2);
if ($this->hasWhere()) {
$sql .= "\nWHERE{$this->getWhereSql()}";
}
if (count($this->orderBy) > 0) {
$sql .= "\nORDER BY";
foreach ($this->orderBy as $r) {
$sql .= "\n\t{$r['field']} {$r['direction']},";
}
$sql = substr($sql, 0, -1);
}
return new Query($sql, $this->getBindings(), $this->getAdapterConnection());
} | [
"public",
"function",
"getQuery",
"(",
")",
":",
"Query",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"what",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Can not build UPDATE query, SET is not defined'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"table",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Can not build UPDATE query when table name is not set'",
")",
";",
"}",
"$",
"sql",
"=",
"\"UPDATE {$this->table}\\nSET\\n\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"what",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"sql",
".=",
"\"\\t{$field} = \"",
";",
"if",
"(",
"$",
"value",
"instanceof",
"Expr",
")",
"{",
"$",
"sql",
".=",
"\"{$value},\\n\"",
";",
"}",
"else",
"{",
"//$key = $this->bind($field, $value);",
"$",
"key",
"=",
"$",
"this",
"->",
"getBindings",
"(",
")",
"->",
"makeAndSet",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"$",
"sql",
".=",
"\":{$key},\\n\"",
";",
"}",
"}",
"$",
"sql",
"=",
"substr",
"(",
"$",
"sql",
",",
"0",
",",
"-",
"2",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasWhere",
"(",
")",
")",
"{",
"$",
"sql",
".=",
"\"\\nWHERE{$this->getWhereSql()}\"",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"orderBy",
")",
">",
"0",
")",
"{",
"$",
"sql",
".=",
"\"\\nORDER BY\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"orderBy",
"as",
"$",
"r",
")",
"{",
"$",
"sql",
".=",
"\"\\n\\t{$r['field']} {$r['direction']},\"",
";",
"}",
"$",
"sql",
"=",
"substr",
"(",
"$",
"sql",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"return",
"new",
"Query",
"(",
"$",
"sql",
",",
"$",
"this",
"->",
"getBindings",
"(",
")",
",",
"$",
"this",
"->",
"getAdapterConnection",
"(",
")",
")",
";",
"}"
]
| Get the query
@return Query
@throws Exception
@throws \Koldy\Db\Exception | [
"Get",
"the",
"query"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Update.php#L164-L202 | train |
koldy/framework | src/Koldy/Db/Query/Update.php | Update.rowCount | public function rowCount(): int
{
if (!$this->wasExecuted()) {
$this->exec();
}
return $this->getAdapter()->getStatement()->rowCount();
} | php | public function rowCount(): int
{
if (!$this->wasExecuted()) {
$this->exec();
}
return $this->getAdapter()->getStatement()->rowCount();
} | [
"public",
"function",
"rowCount",
"(",
")",
":",
"int",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"wasExecuted",
"(",
")",
")",
"{",
"$",
"this",
"->",
"exec",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"getStatement",
"(",
")",
"->",
"rowCount",
"(",
")",
";",
"}"
]
| Get how many rows was deleted
@return int
@throws Exception
@throws \Koldy\Exception | [
"Get",
"how",
"many",
"rows",
"was",
"deleted"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Update.php#L211-L218 | train |
koldy/framework | src/Koldy/Cookie.php | Cookie.get | public static function get(string $key): ?string
{
if (isset($_COOKIE) && array_key_exists($key, $_COOKIE)) {
return Crypt::decrypt($_COOKIE[$key]);
}
return null;
} | php | public static function get(string $key): ?string
{
if (isset($_COOKIE) && array_key_exists($key, $_COOKIE)) {
return Crypt::decrypt($_COOKIE[$key]);
}
return null;
} | [
"public",
"static",
"function",
"get",
"(",
"string",
"$",
"key",
")",
":",
"?",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"_COOKIE",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"_COOKIE",
")",
")",
"{",
"return",
"Crypt",
"::",
"decrypt",
"(",
"$",
"_COOKIE",
"[",
"$",
"key",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Get the value from encrypted cookie value
@param string $key
@return string or null if cookie value doesn't exist
@throws Config\Exception
@throws Crypt\Exception
@throws Crypt\MalformedException
@throws Exception | [
"Get",
"the",
"value",
"from",
"encrypted",
"cookie",
"value"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cookie.php#L23-L30 | train |
koldy/framework | src/Koldy/Cookie.php | Cookie.rawGet | public static function rawGet(string $key): ?string
{
if (isset($_COOKIE) && array_key_exists($key, $_COOKIE)) {
return $_COOKIE[$key];
}
return null;
} | php | public static function rawGet(string $key): ?string
{
if (isset($_COOKIE) && array_key_exists($key, $_COOKIE)) {
return $_COOKIE[$key];
}
return null;
} | [
"public",
"static",
"function",
"rawGet",
"(",
"string",
"$",
"key",
")",
":",
"?",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"_COOKIE",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"_COOKIE",
")",
")",
"{",
"return",
"$",
"_COOKIE",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Get the raw value from cookie, without decrypting data
@param string $key
@return null|string | [
"Get",
"the",
"raw",
"value",
"from",
"cookie",
"without",
"decrypting",
"data"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cookie.php#L39-L46 | train |
koldy/framework | src/Koldy/Cookie.php | Cookie.set | public static function set(string $name, string $value, ?int $expire = null, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null): string
{
$encryptedValue = Crypt::encrypt($value);
setcookie($name, $encryptedValue, $expire ?? 0, $path ?? '/', $domain ?? '', $secure ?? false, $httpOnly ?? false);
return $encryptedValue;
} | php | public static function set(string $name, string $value, ?int $expire = null, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null): string
{
$encryptedValue = Crypt::encrypt($value);
setcookie($name, $encryptedValue, $expire ?? 0, $path ?? '/', $domain ?? '', $secure ?? false, $httpOnly ?? false);
return $encryptedValue;
} | [
"public",
"static",
"function",
"set",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"value",
",",
"?",
"int",
"$",
"expire",
"=",
"null",
",",
"?",
"string",
"$",
"path",
"=",
"null",
",",
"?",
"string",
"$",
"domain",
"=",
"null",
",",
"?",
"bool",
"$",
"secure",
"=",
"null",
",",
"?",
"bool",
"$",
"httpOnly",
"=",
"null",
")",
":",
"string",
"{",
"$",
"encryptedValue",
"=",
"Crypt",
"::",
"encrypt",
"(",
"$",
"value",
")",
";",
"setcookie",
"(",
"$",
"name",
",",
"$",
"encryptedValue",
",",
"$",
"expire",
"??",
"0",
",",
"$",
"path",
"??",
"'/'",
",",
"$",
"domain",
"??",
"''",
",",
"$",
"secure",
"??",
"false",
",",
"$",
"httpOnly",
"??",
"false",
")",
";",
"return",
"$",
"encryptedValue",
";",
"}"
]
| Set the cookie to encrypted value
@param string $name the cookie name
@param string|number $value the cookie value
@param int $expire [optional] when will cookie expire?
@param string $path [optional] path of the cookie
@param string $domain [optional]
@param boolean $secure [optional]
@param boolean $httpOnly [optional]
@return string
@throws Config\Exception
@throws Crypt\Exception
@throws Exception
@link http://koldy.net/docs/cookies#set
@example Cookie::set('last_visited', date('r')); | [
"Set",
"the",
"cookie",
"to",
"encrypted",
"value"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cookie.php#L66-L71 | train |
koldy/framework | src/Koldy/Cookie.php | Cookie.rawSet | public static function rawSet(string $name, string $value, ?int $expire = null, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null): string
{
setcookie($name, $value, $expire ?? 0, $path ?? '/', $domain ?? '', $secure ?? false, $httpOnly ?? false);
return $value;
} | php | public static function rawSet(string $name, string $value, ?int $expire = null, ?string $path = null, ?string $domain = null, ?bool $secure = null, ?bool $httpOnly = null): string
{
setcookie($name, $value, $expire ?? 0, $path ?? '/', $domain ?? '', $secure ?? false, $httpOnly ?? false);
return $value;
} | [
"public",
"static",
"function",
"rawSet",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"value",
",",
"?",
"int",
"$",
"expire",
"=",
"null",
",",
"?",
"string",
"$",
"path",
"=",
"null",
",",
"?",
"string",
"$",
"domain",
"=",
"null",
",",
"?",
"bool",
"$",
"secure",
"=",
"null",
",",
"?",
"bool",
"$",
"httpOnly",
"=",
"null",
")",
":",
"string",
"{",
"setcookie",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"expire",
"??",
"0",
",",
"$",
"path",
"??",
"'/'",
",",
"$",
"domain",
"??",
"''",
",",
"$",
"secure",
"??",
"false",
",",
"$",
"httpOnly",
"??",
"false",
")",
";",
"return",
"$",
"value",
";",
"}"
]
| Set the raw cookie value, without encryption
@param string $name the cookie name
@param string|number $value the cookie value
@param int $expire [optional] when will cookie expire?
@param string $path [optional] path of the cookie
@param string $domain [optional]
@param boolean $secure [optional]
@param boolean $httpOnly [optional]
@link http://koldy.net/docs/cookies#set
@example Cookie::set('last_visited', date('r'));
@return string | [
"Set",
"the",
"raw",
"cookie",
"value",
"without",
"encryption"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Cookie.php#L88-L92 | train |
koldy/framework | src/Koldy/Db/Where.php | Where.bind | public function bind(string $field, $value, string $prefix = ''): string
{
if ($this->bindings === null) {
$this->bindings = new Bindings();
}
$parameter = $prefix . $field;
$bindName = $this->bindings->makeAndSet($parameter, $value);
return $bindName;
} | php | public function bind(string $field, $value, string $prefix = ''): string
{
if ($this->bindings === null) {
$this->bindings = new Bindings();
}
$parameter = $prefix . $field;
$bindName = $this->bindings->makeAndSet($parameter, $value);
return $bindName;
} | [
"public",
"function",
"bind",
"(",
"string",
"$",
"field",
",",
"$",
"value",
",",
"string",
"$",
"prefix",
"=",
"''",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"bindings",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"bindings",
"=",
"new",
"Bindings",
"(",
")",
";",
"}",
"$",
"parameter",
"=",
"$",
"prefix",
".",
"$",
"field",
";",
"$",
"bindName",
"=",
"$",
"this",
"->",
"bindings",
"->",
"makeAndSet",
"(",
"$",
"parameter",
",",
"$",
"value",
")",
";",
"return",
"$",
"bindName",
";",
"}"
]
| Bind some value for PDO
@param string $field
@param $value
@param string $prefix - optional, use in special cases when there might a field duplicate, usually in clones or sub queries
@return string | [
"Bind",
"some",
"value",
"for",
"PDO"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Where.php#L31-L40 | train |
koldy/framework | src/Koldy/Db/Where.php | Where.addCondition | private function addCondition(string $link, $field, $value, string $operator)
{
$this->where[] = [
'link' => $link,
'field' => $field,
'operator' => $operator,
'value' => $value
];
return $this;
} | php | private function addCondition(string $link, $field, $value, string $operator)
{
$this->where[] = [
'link' => $link,
'field' => $field,
'operator' => $operator,
'value' => $value
];
return $this;
} | [
"private",
"function",
"addCondition",
"(",
"string",
"$",
"link",
",",
"$",
"field",
",",
"$",
"value",
",",
"string",
"$",
"operator",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"[",
"'link'",
"=>",
"$",
"link",
",",
"'field'",
"=>",
"$",
"field",
",",
"'operator'",
"=>",
"$",
"operator",
",",
"'value'",
"=>",
"$",
"value",
"]",
";",
"return",
"$",
"this",
";",
"}"
]
| Add condition to where statements
@param string $link
@param mixed $field
@param mixed $value
@param string $operator
@return $this | [
"Add",
"condition",
"to",
"where",
"statements"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Where.php#L52-L62 | train |
koldy/framework | src/Koldy/Db/Where.php | Where.where | public function where($field, $valueOrOperator = null, $value = null)
{
if (is_string($field) && $valueOrOperator === null) {
throw new \InvalidArgumentException('Invalid second argument; argument must not be null in case when first argument is string');
}
return $this->addCondition('AND', $field, ($value === null) ? $valueOrOperator : $value, ($value === null) ? '=' : $valueOrOperator);
} | php | public function where($field, $valueOrOperator = null, $value = null)
{
if (is_string($field) && $valueOrOperator === null) {
throw new \InvalidArgumentException('Invalid second argument; argument must not be null in case when first argument is string');
}
return $this->addCondition('AND', $field, ($value === null) ? $valueOrOperator : $value, ($value === null) ? '=' : $valueOrOperator);
} | [
"public",
"function",
"where",
"(",
"$",
"field",
",",
"$",
"valueOrOperator",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"field",
")",
"&&",
"$",
"valueOrOperator",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid second argument; argument must not be null in case when first argument is string'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"addCondition",
"(",
"'AND'",
",",
"$",
"field",
",",
"(",
"$",
"value",
"===",
"null",
")",
"?",
"$",
"valueOrOperator",
":",
"$",
"value",
",",
"(",
"$",
"value",
"===",
"null",
")",
"?",
"'='",
":",
"$",
"valueOrOperator",
")",
";",
"}"
]
| Add AND where statement
@param mixed $field
@param mixed $valueOrOperator
@param mixed $value
@return $this
@example where('id', 2) produces WHERE id = 2
@example where('id', '00385') produces WHERE id = '00385'
@example where('id', '>', 5) produces WHERE id > 5
@example where('id', '<=', '0100') produces WHERE id <= '0100' | [
"Add",
"AND",
"where",
"statement"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Where.php#L78-L85 | train |
koldy/framework | src/Koldy/Db/Where.php | Where.whereBetween | public function whereBetween(string $field, $value1, $value2)
{
return $this->addCondition('AND', $field, [$value1, $value2], 'BETWEEN');
} | php | public function whereBetween(string $field, $value1, $value2)
{
return $this->addCondition('AND', $field, [$value1, $value2], 'BETWEEN');
} | [
"public",
"function",
"whereBetween",
"(",
"string",
"$",
"field",
",",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"return",
"$",
"this",
"->",
"addCondition",
"(",
"'AND'",
",",
"$",
"field",
",",
"[",
"$",
"value1",
",",
"$",
"value2",
"]",
",",
"'BETWEEN'",
")",
";",
"}"
]
| Add WHERE field is BETWEEN two values
@param string $field
@param mixed $value1
@param mixed $value2
@return $this | [
"Add",
"WHERE",
"field",
"is",
"BETWEEN",
"two",
"values"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Where.php#L162-L165 | train |
koldy/framework | src/Koldy/Db/Where.php | Where.getWhereSql | protected function getWhereSql(array $whereArray = null, $cnt = 0): string
{
if ($this->bindings === null) {
$this->bindings = new Bindings();
}
$query = '';
if ($whereArray === null) {
$whereArray = $this->where;
}
foreach ($whereArray as $index => $where) {
if ($index > 0) {
$query .= "\t{$where['link']}";
}
$field = $where['field'];
$value = $where['value'];
if (gettype($field) == 'object' && $value === null) {
// function or instance of self is passed, do something
$q = ($field instanceof self) ? clone $field : $field(new self());
if ($q === null) {
throw new DbException('Can not build query, statement\'s where function didn\'t return anything');
}
$whereSql = trim($q->getWhereSql(null, $cnt++));
$whereSql = str_replace("\n", ' ', $whereSql);
$whereSql = str_replace("\t", '', $whereSql);
$query .= " ({$whereSql})\n";
/*
foreach ($q->getBindings() as $k => $v) {
$this->bindings[$k] = $v;
}
*/
$this->bindings->addBindingsFromInstance($q->getBindings());
} else if ($value instanceof Expr) {
$query .= " ({$field} {$where['operator']} {$value})\n";
} else if (is_array($value)) {
switch ($where['operator']) {
case 'BETWEEN':
case 'NOT BETWEEN':
$query .= " ({$field} {$where['operator']} ";
if ($value[0] instanceof Expr) {
$query .= $value[0];
} else {
//$key = $this->bind($field, $value[0]);
$key = $this->bindings->makeAndSet($field, $value[0]);
$query .= ":{$key}";
}
$query .= ' AND ';
if ($value[1] instanceof Expr) {
$query .= $value[1];
} else {
//$key = $this->bind($field, $value[1]);
$key = $this->bindings->makeAndSet($field, $value[1]);
$query .= ":{$key}";
}
$query .= ")\n";
break;
case 'IN':
case 'NOT IN':
$query .= " ({$field} {$where['operator']} (";
foreach ($value as $val) {
//$key = $this->bind($field, $val);
$key = $this->bindings->makeAndSet($field, $val);
$query .= ":{$key},";
}
$query = substr($query, 0, -1);
$query .= "))\n";
break;
// default: nothing by default
}
} else {
//$key = $this->bind($field, $where['value']);
$key = $this->bindings->makeAndSet($field, $where['value']);
$query .= " ({$field} {$where['operator']} :{$key})\n";
}
}
return $query;
} | php | protected function getWhereSql(array $whereArray = null, $cnt = 0): string
{
if ($this->bindings === null) {
$this->bindings = new Bindings();
}
$query = '';
if ($whereArray === null) {
$whereArray = $this->where;
}
foreach ($whereArray as $index => $where) {
if ($index > 0) {
$query .= "\t{$where['link']}";
}
$field = $where['field'];
$value = $where['value'];
if (gettype($field) == 'object' && $value === null) {
// function or instance of self is passed, do something
$q = ($field instanceof self) ? clone $field : $field(new self());
if ($q === null) {
throw new DbException('Can not build query, statement\'s where function didn\'t return anything');
}
$whereSql = trim($q->getWhereSql(null, $cnt++));
$whereSql = str_replace("\n", ' ', $whereSql);
$whereSql = str_replace("\t", '', $whereSql);
$query .= " ({$whereSql})\n";
/*
foreach ($q->getBindings() as $k => $v) {
$this->bindings[$k] = $v;
}
*/
$this->bindings->addBindingsFromInstance($q->getBindings());
} else if ($value instanceof Expr) {
$query .= " ({$field} {$where['operator']} {$value})\n";
} else if (is_array($value)) {
switch ($where['operator']) {
case 'BETWEEN':
case 'NOT BETWEEN':
$query .= " ({$field} {$where['operator']} ";
if ($value[0] instanceof Expr) {
$query .= $value[0];
} else {
//$key = $this->bind($field, $value[0]);
$key = $this->bindings->makeAndSet($field, $value[0]);
$query .= ":{$key}";
}
$query .= ' AND ';
if ($value[1] instanceof Expr) {
$query .= $value[1];
} else {
//$key = $this->bind($field, $value[1]);
$key = $this->bindings->makeAndSet($field, $value[1]);
$query .= ":{$key}";
}
$query .= ")\n";
break;
case 'IN':
case 'NOT IN':
$query .= " ({$field} {$where['operator']} (";
foreach ($value as $val) {
//$key = $this->bind($field, $val);
$key = $this->bindings->makeAndSet($field, $val);
$query .= ":{$key},";
}
$query = substr($query, 0, -1);
$query .= "))\n";
break;
// default: nothing by default
}
} else {
//$key = $this->bind($field, $where['value']);
$key = $this->bindings->makeAndSet($field, $where['value']);
$query .= " ({$field} {$where['operator']} :{$key})\n";
}
}
return $query;
} | [
"protected",
"function",
"getWhereSql",
"(",
"array",
"$",
"whereArray",
"=",
"null",
",",
"$",
"cnt",
"=",
"0",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"bindings",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"bindings",
"=",
"new",
"Bindings",
"(",
")",
";",
"}",
"$",
"query",
"=",
"''",
";",
"if",
"(",
"$",
"whereArray",
"===",
"null",
")",
"{",
"$",
"whereArray",
"=",
"$",
"this",
"->",
"where",
";",
"}",
"foreach",
"(",
"$",
"whereArray",
"as",
"$",
"index",
"=>",
"$",
"where",
")",
"{",
"if",
"(",
"$",
"index",
">",
"0",
")",
"{",
"$",
"query",
".=",
"\"\\t{$where['link']}\"",
";",
"}",
"$",
"field",
"=",
"$",
"where",
"[",
"'field'",
"]",
";",
"$",
"value",
"=",
"$",
"where",
"[",
"'value'",
"]",
";",
"if",
"(",
"gettype",
"(",
"$",
"field",
")",
"==",
"'object'",
"&&",
"$",
"value",
"===",
"null",
")",
"{",
"// function or instance of self is passed, do something",
"$",
"q",
"=",
"(",
"$",
"field",
"instanceof",
"self",
")",
"?",
"clone",
"$",
"field",
":",
"$",
"field",
"(",
"new",
"self",
"(",
")",
")",
";",
"if",
"(",
"$",
"q",
"===",
"null",
")",
"{",
"throw",
"new",
"DbException",
"(",
"'Can not build query, statement\\'s where function didn\\'t return anything'",
")",
";",
"}",
"$",
"whereSql",
"=",
"trim",
"(",
"$",
"q",
"->",
"getWhereSql",
"(",
"null",
",",
"$",
"cnt",
"++",
")",
")",
";",
"$",
"whereSql",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"' '",
",",
"$",
"whereSql",
")",
";",
"$",
"whereSql",
"=",
"str_replace",
"(",
"\"\\t\"",
",",
"''",
",",
"$",
"whereSql",
")",
";",
"$",
"query",
".=",
"\" ({$whereSql})\\n\"",
";",
"/*\n foreach ($q->getBindings() as $k => $v) {\n $this->bindings[$k] = $v;\n }\n */",
"$",
"this",
"->",
"bindings",
"->",
"addBindingsFromInstance",
"(",
"$",
"q",
"->",
"getBindings",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"instanceof",
"Expr",
")",
"{",
"$",
"query",
".=",
"\" ({$field} {$where['operator']} {$value})\\n\"",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"switch",
"(",
"$",
"where",
"[",
"'operator'",
"]",
")",
"{",
"case",
"'BETWEEN'",
":",
"case",
"'NOT BETWEEN'",
":",
"$",
"query",
".=",
"\" ({$field} {$where['operator']} \"",
";",
"if",
"(",
"$",
"value",
"[",
"0",
"]",
"instanceof",
"Expr",
")",
"{",
"$",
"query",
".=",
"$",
"value",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"//$key = $this->bind($field, $value[0]);",
"$",
"key",
"=",
"$",
"this",
"->",
"bindings",
"->",
"makeAndSet",
"(",
"$",
"field",
",",
"$",
"value",
"[",
"0",
"]",
")",
";",
"$",
"query",
".=",
"\":{$key}\"",
";",
"}",
"$",
"query",
".=",
"' AND '",
";",
"if",
"(",
"$",
"value",
"[",
"1",
"]",
"instanceof",
"Expr",
")",
"{",
"$",
"query",
".=",
"$",
"value",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"//$key = $this->bind($field, $value[1]);",
"$",
"key",
"=",
"$",
"this",
"->",
"bindings",
"->",
"makeAndSet",
"(",
"$",
"field",
",",
"$",
"value",
"[",
"1",
"]",
")",
";",
"$",
"query",
".=",
"\":{$key}\"",
";",
"}",
"$",
"query",
".=",
"\")\\n\"",
";",
"break",
";",
"case",
"'IN'",
":",
"case",
"'NOT IN'",
":",
"$",
"query",
".=",
"\" ({$field} {$where['operator']} (\"",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"val",
")",
"{",
"//$key = $this->bind($field, $val);",
"$",
"key",
"=",
"$",
"this",
"->",
"bindings",
"->",
"makeAndSet",
"(",
"$",
"field",
",",
"$",
"val",
")",
";",
"$",
"query",
".=",
"\":{$key},\"",
";",
"}",
"$",
"query",
"=",
"substr",
"(",
"$",
"query",
",",
"0",
",",
"-",
"1",
")",
";",
"$",
"query",
".=",
"\"))\\n\"",
";",
"break",
";",
"// default: nothing by default",
"}",
"}",
"else",
"{",
"//$key = $this->bind($field, $where['value']);",
"$",
"key",
"=",
"$",
"this",
"->",
"bindings",
"->",
"makeAndSet",
"(",
"$",
"field",
",",
"$",
"where",
"[",
"'value'",
"]",
")",
";",
"$",
"query",
".=",
"\" ({$field} {$where['operator']} :{$key})\\n\"",
";",
"}",
"}",
"return",
"$",
"query",
";",
"}"
]
| Get where statement appended to query
@param array $whereArray
@param int $cnt
@throws Exception
@return string | [
"Get",
"where",
"statement",
"appended",
"to",
"query"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Where.php#L362-L462 | train |
koldy/framework | src/Koldy/Http/Request.php | Request.getUrl | public function getUrl(): string
{
$url = $this->url;
if ($this->getMethod() == self::GET) {
if (count($this->params) > 0) {
$params = http_build_query($this->getParams());
if (strpos('?', $url) !== false && substr($url, -1) != '?') {
// just add "&"
$url .= $params;
} else {
$url .= '?' . $params;
}
}
}
return $url;
} | php | public function getUrl(): string
{
$url = $this->url;
if ($this->getMethod() == self::GET) {
if (count($this->params) > 0) {
$params = http_build_query($this->getParams());
if (strpos('?', $url) !== false && substr($url, -1) != '?') {
// just add "&"
$url .= $params;
} else {
$url .= '?' . $params;
}
}
}
return $url;
} | [
"public",
"function",
"getUrl",
"(",
")",
":",
"string",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"url",
";",
"if",
"(",
"$",
"this",
"->",
"getMethod",
"(",
")",
"==",
"self",
"::",
"GET",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"params",
")",
">",
"0",
")",
"{",
"$",
"params",
"=",
"http_build_query",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
";",
"if",
"(",
"strpos",
"(",
"'?'",
",",
"$",
"url",
")",
"!==",
"false",
"&&",
"substr",
"(",
"$",
"url",
",",
"-",
"1",
")",
"!=",
"'?'",
")",
"{",
"// just add \"&\"",
"$",
"url",
".=",
"$",
"params",
";",
"}",
"else",
"{",
"$",
"url",
".=",
"'?'",
".",
"$",
"params",
";",
"}",
"}",
"}",
"return",
"$",
"url",
";",
"}"
]
| Get the URL on which the request will be fired
@return string | [
"Get",
"the",
"URL",
"on",
"which",
"the",
"request",
"will",
"be",
"fired"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Request.php#L68-L85 | train |
koldy/framework | src/Koldy/Http/Request.php | Request.setParam | public function setParam(string $name, $value): Request
{
if (is_object($value)) {
if (property_exists($value, '__toString')) {
$value = $value->__toString();
} else {
$class = get_class($value);
throw new HttpException("Can not set param={$name} when instance of {$class} can't be converted to string");
}
}
$this->params[$name] = $value;
return $this;
} | php | public function setParam(string $name, $value): Request
{
if (is_object($value)) {
if (property_exists($value, '__toString')) {
$value = $value->__toString();
} else {
$class = get_class($value);
throw new HttpException("Can not set param={$name} when instance of {$class} can't be converted to string");
}
}
$this->params[$name] = $value;
return $this;
} | [
"public",
"function",
"setParam",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"Request",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"->",
"__toString",
"(",
")",
";",
"}",
"else",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"value",
")",
";",
"throw",
"new",
"HttpException",
"(",
"\"Can not set param={$name} when instance of {$class} can't be converted to string\"",
")",
";",
"}",
"}",
"$",
"this",
"->",
"params",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the request parameter
@param string $name
@param mixed $value
@return Request
@throws Exception | [
"Set",
"the",
"request",
"parameter"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Request.php#L115-L128 | train |
koldy/framework | src/Koldy/Http/Request.php | Request.getCurlOptions | protected function getCurlOptions(): array
{
$options = [];
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_HEADER] = true;
foreach ($this->getOptions() as $option => $value) {
$options[$option] = $value;
}
switch ($this->getMethod()) {
case self::POST:
if (!$this->hasOption(CURLOPT_CUSTOMREQUEST)) {
$options[CURLOPT_CUSTOMREQUEST] = $this->getMethod();
}
if (!$this->hasOption(CURLOPT_POSTFIELDS)) {
$options[CURLOPT_POSTFIELDS] = count($this->getParams()) > 0 ? http_build_query($this->getParams()) : '';
}
if ($this->hasHeader('Content-Type') && $this->getHeader('Content-Type') == 'application/json') {
$options[CURLOPT_POSTFIELDS] = Json::encode($this->getParams());
}
break;
case self::PUT:
case self::DELETE:
if (!$this->hasOption(CURLOPT_CUSTOMREQUEST)) {
$options[CURLOPT_CUSTOMREQUEST] = $this->getMethod();
}
if (!$this->hasOption(CURLOPT_POSTFIELDS)) {
$options[CURLOPT_POSTFIELDS] = count($this->params) > 0 ? http_build_query($this->params) : '';
}
break;
}
if (count($this->headers) > 0) {
$options[CURLOPT_HTTPHEADER] = $this->getPreparedHeaders();
}
return $options;
} | php | protected function getCurlOptions(): array
{
$options = [];
$options[CURLOPT_RETURNTRANSFER] = true;
$options[CURLOPT_HEADER] = true;
foreach ($this->getOptions() as $option => $value) {
$options[$option] = $value;
}
switch ($this->getMethod()) {
case self::POST:
if (!$this->hasOption(CURLOPT_CUSTOMREQUEST)) {
$options[CURLOPT_CUSTOMREQUEST] = $this->getMethod();
}
if (!$this->hasOption(CURLOPT_POSTFIELDS)) {
$options[CURLOPT_POSTFIELDS] = count($this->getParams()) > 0 ? http_build_query($this->getParams()) : '';
}
if ($this->hasHeader('Content-Type') && $this->getHeader('Content-Type') == 'application/json') {
$options[CURLOPT_POSTFIELDS] = Json::encode($this->getParams());
}
break;
case self::PUT:
case self::DELETE:
if (!$this->hasOption(CURLOPT_CUSTOMREQUEST)) {
$options[CURLOPT_CUSTOMREQUEST] = $this->getMethod();
}
if (!$this->hasOption(CURLOPT_POSTFIELDS)) {
$options[CURLOPT_POSTFIELDS] = count($this->params) > 0 ? http_build_query($this->params) : '';
}
break;
}
if (count($this->headers) > 0) {
$options[CURLOPT_HTTPHEADER] = $this->getPreparedHeaders();
}
return $options;
} | [
"protected",
"function",
"getCurlOptions",
"(",
")",
":",
"array",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"$",
"options",
"[",
"CURLOPT_RETURNTRANSFER",
"]",
"=",
"true",
";",
"$",
"options",
"[",
"CURLOPT_HEADER",
"]",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"$",
"options",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"getMethod",
"(",
")",
")",
"{",
"case",
"self",
"::",
"POST",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOption",
"(",
"CURLOPT_CUSTOMREQUEST",
")",
")",
"{",
"$",
"options",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"$",
"this",
"->",
"getMethod",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOption",
"(",
"CURLOPT_POSTFIELDS",
")",
")",
"{",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"count",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
">",
"0",
"?",
"http_build_query",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
":",
"''",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasHeader",
"(",
"'Content-Type'",
")",
"&&",
"$",
"this",
"->",
"getHeader",
"(",
"'Content-Type'",
")",
"==",
"'application/json'",
")",
"{",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"Json",
"::",
"encode",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
";",
"}",
"break",
";",
"case",
"self",
"::",
"PUT",
":",
"case",
"self",
"::",
"DELETE",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOption",
"(",
"CURLOPT_CUSTOMREQUEST",
")",
")",
"{",
"$",
"options",
"[",
"CURLOPT_CUSTOMREQUEST",
"]",
"=",
"$",
"this",
"->",
"getMethod",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOption",
"(",
"CURLOPT_POSTFIELDS",
")",
")",
"{",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"count",
"(",
"$",
"this",
"->",
"params",
")",
">",
"0",
"?",
"http_build_query",
"(",
"$",
"this",
"->",
"params",
")",
":",
"''",
";",
"}",
"break",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"headers",
")",
">",
"0",
")",
"{",
"$",
"options",
"[",
"CURLOPT_HTTPHEADER",
"]",
"=",
"$",
"this",
"->",
"getPreparedHeaders",
"(",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
]
| Get the prepared curl options for the HTTP request
@return array
@throws Json\Exception | [
"Get",
"the",
"prepared",
"curl",
"options",
"for",
"the",
"HTTP",
"request"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Request.php#L344-L387 | train |
koldy/framework | src/Koldy/Http/Request.php | Request.get | public static function get(string $url, array $params = null, array $headers = null)
{
return static::quickRequest($url, self::GET, $params, $headers);
} | php | public static function get(string $url, array $params = null, array $headers = null)
{
return static::quickRequest($url, self::GET, $params, $headers);
} | [
"public",
"static",
"function",
"get",
"(",
"string",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"null",
",",
"array",
"$",
"headers",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"quickRequest",
"(",
"$",
"url",
",",
"self",
"::",
"GET",
",",
"$",
"params",
",",
"$",
"headers",
")",
";",
"}"
]
| Make quick GET request
@param string $url
@param array|null $params
@param array|null $headers
@return Response
@throws Exception
@throws Json\Exception | [
"Make",
"quick",
"GET",
"request"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Request.php#L456-L459 | train |
koldy/framework | src/Koldy/Http/Request.php | Request.post | public static function post(string $url, array $params = null, array $headers = null)
{
return static::quickRequest($url, self::POST, $params, $headers);
} | php | public static function post(string $url, array $params = null, array $headers = null)
{
return static::quickRequest($url, self::POST, $params, $headers);
} | [
"public",
"static",
"function",
"post",
"(",
"string",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"null",
",",
"array",
"$",
"headers",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"quickRequest",
"(",
"$",
"url",
",",
"self",
"::",
"POST",
",",
"$",
"params",
",",
"$",
"headers",
")",
";",
"}"
]
| Make quick POST request
@param string $url
@param array|null $params
@param array|null $headers
@return Response
@throws Exception
@throws Json\Exception | [
"Make",
"quick",
"POST",
"request"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Request.php#L472-L475 | train |
koldy/framework | src/Koldy/Http/Request.php | Request.put | public static function put(string $url, array $params = null, array $headers = null)
{
return static::quickRequest($url, self::PUT, $params, $headers);
} | php | public static function put(string $url, array $params = null, array $headers = null)
{
return static::quickRequest($url, self::PUT, $params, $headers);
} | [
"public",
"static",
"function",
"put",
"(",
"string",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"null",
",",
"array",
"$",
"headers",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"quickRequest",
"(",
"$",
"url",
",",
"self",
"::",
"PUT",
",",
"$",
"params",
",",
"$",
"headers",
")",
";",
"}"
]
| Make quick PUT request
@param string $url
@param array|null $params
@param array|null $headers
@return Response
@throws Exception
@throws Json\Exception | [
"Make",
"quick",
"PUT",
"request"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Request.php#L488-L491 | train |
koldy/framework | src/Koldy/Http/Request.php | Request.delete | public static function delete(string $url, array $params = null, array $headers = null)
{
return static::quickRequest($url, self::DELETE, $params, $headers);
} | php | public static function delete(string $url, array $params = null, array $headers = null)
{
return static::quickRequest($url, self::DELETE, $params, $headers);
} | [
"public",
"static",
"function",
"delete",
"(",
"string",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"null",
",",
"array",
"$",
"headers",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"quickRequest",
"(",
"$",
"url",
",",
"self",
"::",
"DELETE",
",",
"$",
"params",
",",
"$",
"headers",
")",
";",
"}"
]
| Make quick DELETE request
@param string $url
@param array|null $params
@param array|null $headers
@return Response
@throws Exception
@throws Json\Exception | [
"Make",
"quick",
"DELETE",
"request"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Request.php#L504-L507 | train |
koldy/framework | src/Koldy/Http/Request.php | Request.debug | public function debug()
{
$constants = get_defined_constants(true);
$flipped = array_flip($constants['curl']);
$curlOpts = preg_grep('/^CURLOPT_/', $flipped);
$curlInfo = preg_grep('/^CURLINFO_/', $flipped);
$options = [];
foreach ($this->getCurlOptions() as $const => $value) {
if (isset($curlOpts[$const])) {
$options[$curlOpts[$const]] = $value;
} else if (isset($curlInfo[$const])) {
$options[$curlInfo[$const]] = $value;
} else {
$options[$const] = $value;
}
}
$className = get_class($this);
$msg = "[{$className}] to {$this->getMethod()}={$this->getUrl()}";
if (count($this->params) > 0) {
$params = $this->getParams();
if ($this->getMethod() == self::POST && $this->hasHeader('Content-Type') && $this->getHeader('Content-Type') == 'application/json') {
$params = Json::encode($params);
} else {
$params = http_build_query($params);
}
$msg .= "\nParameters: {$params}";
}
if (count($options) > 0) {
$msg .= 'CURL options: ' . print_r($options, true);
}
return $msg;
} | php | public function debug()
{
$constants = get_defined_constants(true);
$flipped = array_flip($constants['curl']);
$curlOpts = preg_grep('/^CURLOPT_/', $flipped);
$curlInfo = preg_grep('/^CURLINFO_/', $flipped);
$options = [];
foreach ($this->getCurlOptions() as $const => $value) {
if (isset($curlOpts[$const])) {
$options[$curlOpts[$const]] = $value;
} else if (isset($curlInfo[$const])) {
$options[$curlInfo[$const]] = $value;
} else {
$options[$const] = $value;
}
}
$className = get_class($this);
$msg = "[{$className}] to {$this->getMethod()}={$this->getUrl()}";
if (count($this->params) > 0) {
$params = $this->getParams();
if ($this->getMethod() == self::POST && $this->hasHeader('Content-Type') && $this->getHeader('Content-Type') == 'application/json') {
$params = Json::encode($params);
} else {
$params = http_build_query($params);
}
$msg .= "\nParameters: {$params}";
}
if (count($options) > 0) {
$msg .= 'CURL options: ' . print_r($options, true);
}
return $msg;
} | [
"public",
"function",
"debug",
"(",
")",
"{",
"$",
"constants",
"=",
"get_defined_constants",
"(",
"true",
")",
";",
"$",
"flipped",
"=",
"array_flip",
"(",
"$",
"constants",
"[",
"'curl'",
"]",
")",
";",
"$",
"curlOpts",
"=",
"preg_grep",
"(",
"'/^CURLOPT_/'",
",",
"$",
"flipped",
")",
";",
"$",
"curlInfo",
"=",
"preg_grep",
"(",
"'/^CURLINFO_/'",
",",
"$",
"flipped",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getCurlOptions",
"(",
")",
"as",
"$",
"const",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"curlOpts",
"[",
"$",
"const",
"]",
")",
")",
"{",
"$",
"options",
"[",
"$",
"curlOpts",
"[",
"$",
"const",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"curlInfo",
"[",
"$",
"const",
"]",
")",
")",
"{",
"$",
"options",
"[",
"$",
"curlInfo",
"[",
"$",
"const",
"]",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"options",
"[",
"$",
"const",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"className",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"msg",
"=",
"\"[{$className}] to {$this->getMethod()}={$this->getUrl()}\"",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"params",
")",
">",
"0",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParams",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getMethod",
"(",
")",
"==",
"self",
"::",
"POST",
"&&",
"$",
"this",
"->",
"hasHeader",
"(",
"'Content-Type'",
")",
"&&",
"$",
"this",
"->",
"getHeader",
"(",
"'Content-Type'",
")",
"==",
"'application/json'",
")",
"{",
"$",
"params",
"=",
"Json",
"::",
"encode",
"(",
"$",
"params",
")",
";",
"}",
"else",
"{",
"$",
"params",
"=",
"http_build_query",
"(",
"$",
"params",
")",
";",
"}",
"$",
"msg",
".=",
"\"\\nParameters: {$params}\"",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"options",
")",
">",
"0",
")",
"{",
"$",
"msg",
".=",
"'CURL options: '",
".",
"print_r",
"(",
"$",
"options",
",",
"true",
")",
";",
"}",
"return",
"$",
"msg",
";",
"}"
]
| Print settings and all values useful for troubleshooting
@return string
@throws Json\Exception | [
"Print",
"settings",
"and",
"all",
"values",
"useful",
"for",
"troubleshooting"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Http/Request.php#L515-L552 | train |
koldy/framework | src/Koldy/Response/View.php | View.getViewPath | protected function getViewPath(string $view): string
{
if (DS != '/') {
$view = str_replace('/', DS, $view);
}
$pos = strpos($view, ':');
if ($pos === false) {
return $this->viewPath . $view . '.phtml';
} else {
return dirname(substr($this->viewPath, 0, -1)) . DS . 'modules' . DS . substr($view, 0, $pos) . DS . 'views' . DS . substr($view, $pos + 1) . '.phtml';
}
} | php | protected function getViewPath(string $view): string
{
if (DS != '/') {
$view = str_replace('/', DS, $view);
}
$pos = strpos($view, ':');
if ($pos === false) {
return $this->viewPath . $view . '.phtml';
} else {
return dirname(substr($this->viewPath, 0, -1)) . DS . 'modules' . DS . substr($view, 0, $pos) . DS . 'views' . DS . substr($view, $pos + 1) . '.phtml';
}
} | [
"protected",
"function",
"getViewPath",
"(",
"string",
"$",
"view",
")",
":",
"string",
"{",
"if",
"(",
"DS",
"!=",
"'/'",
")",
"{",
"$",
"view",
"=",
"str_replace",
"(",
"'/'",
",",
"DS",
",",
"$",
"view",
")",
";",
"}",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"view",
",",
"':'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"viewPath",
".",
"$",
"view",
".",
"'.phtml'",
";",
"}",
"else",
"{",
"return",
"dirname",
"(",
"substr",
"(",
"$",
"this",
"->",
"viewPath",
",",
"0",
",",
"-",
"1",
")",
")",
".",
"DS",
".",
"'modules'",
".",
"DS",
".",
"substr",
"(",
"$",
"view",
",",
"0",
",",
"$",
"pos",
")",
".",
"DS",
".",
"'views'",
".",
"DS",
".",
"substr",
"(",
"$",
"view",
",",
"$",
"pos",
"+",
"1",
")",
".",
"'.phtml'",
";",
"}",
"}"
]
| Get the path of the view
@param string $view
@return string | [
"Get",
"the",
"path",
"of",
"the",
"view"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/View.php#L83-L95 | train |
koldy/framework | src/Koldy/Response/View.php | View.setViewPath | public function setViewPath(string $basePath): self
{
$this->viewPath = $basePath;
if (substr($this->viewPath, -1) != '/') {
$this->viewPath .= '/';
}
return $this;
} | php | public function setViewPath(string $basePath): self
{
$this->viewPath = $basePath;
if (substr($this->viewPath, -1) != '/') {
$this->viewPath .= '/';
}
return $this;
} | [
"public",
"function",
"setViewPath",
"(",
"string",
"$",
"basePath",
")",
":",
"self",
"{",
"$",
"this",
"->",
"viewPath",
"=",
"$",
"basePath",
";",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"viewPath",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"this",
"->",
"viewPath",
".=",
"'/'",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set custom view path where views are stored. Any additional use within this instance will be relative to the
path given here
@param string $basePath
@return View | [
"Set",
"custom",
"view",
"path",
"where",
"views",
"are",
"stored",
".",
"Any",
"additional",
"use",
"within",
"this",
"instance",
"will",
"be",
"relative",
"to",
"the",
"path",
"given",
"here"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/View.php#L105-L114 | train |
koldy/framework | src/Koldy/Response/View.php | View.exists | public static function exists(string $view): bool
{
$pos = strpos($view, ':');
if ($pos === false) {
$path = Application::getViewPath() . $view . '.phtml';
} else {
$path = dirname(substr(Application::getViewPath(), 0, -1)) . DS . 'modules' . DS . substr($view, 0, $pos) . DS . 'views' . DS . substr($view, $pos + 1) . '.phtml';
}
return is_file($path);
} | php | public static function exists(string $view): bool
{
$pos = strpos($view, ':');
if ($pos === false) {
$path = Application::getViewPath() . $view . '.phtml';
} else {
$path = dirname(substr(Application::getViewPath(), 0, -1)) . DS . 'modules' . DS . substr($view, 0, $pos) . DS . 'views' . DS . substr($view, $pos + 1) . '.phtml';
}
return is_file($path);
} | [
"public",
"static",
"function",
"exists",
"(",
"string",
"$",
"view",
")",
":",
"bool",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"view",
",",
"':'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"$",
"path",
"=",
"Application",
"::",
"getViewPath",
"(",
")",
".",
"$",
"view",
".",
"'.phtml'",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"dirname",
"(",
"substr",
"(",
"Application",
"::",
"getViewPath",
"(",
")",
",",
"0",
",",
"-",
"1",
")",
")",
".",
"DS",
".",
"'modules'",
".",
"DS",
".",
"substr",
"(",
"$",
"view",
",",
"0",
",",
"$",
"pos",
")",
".",
"DS",
".",
"'views'",
".",
"DS",
".",
"substr",
"(",
"$",
"view",
",",
"$",
"pos",
"+",
"1",
")",
".",
"'.phtml'",
";",
"}",
"return",
"is_file",
"(",
"$",
"path",
")",
";",
"}"
]
| Does view exists or not in main view path
@param string $view
@return boolean | [
"Does",
"view",
"exists",
"or",
"not",
"in",
"main",
"view",
"path"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/View.php#L123-L135 | train |
koldy/framework | src/Koldy/Response/View.php | View.render | public function render(string $view, array $with = null): string
{
$path = $this->getViewPath($view);
if (!file_exists($path)) {
throw new ResponseException("View ({$view}) not found on path={$path}");
}
if ($with !== null && count($with) > 0) {
foreach ($with as $variableName => $value) {
if (!is_string($variableName)) {
throw new ResponseException('Invalid argument name, expected string, got ' . gettype($variableName));
}
$$variableName = $value;
}
}
ob_start(null, 0, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE);
require $path;
return ob_get_clean();
} | php | public function render(string $view, array $with = null): string
{
$path = $this->getViewPath($view);
if (!file_exists($path)) {
throw new ResponseException("View ({$view}) not found on path={$path}");
}
if ($with !== null && count($with) > 0) {
foreach ($with as $variableName => $value) {
if (!is_string($variableName)) {
throw new ResponseException('Invalid argument name, expected string, got ' . gettype($variableName));
}
$$variableName = $value;
}
}
ob_start(null, 0, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE);
require $path;
return ob_get_clean();
} | [
"public",
"function",
"render",
"(",
"string",
"$",
"view",
",",
"array",
"$",
"with",
"=",
"null",
")",
":",
"string",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getViewPath",
"(",
"$",
"view",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"ResponseException",
"(",
"\"View ({$view}) not found on path={$path}\"",
")",
";",
"}",
"if",
"(",
"$",
"with",
"!==",
"null",
"&&",
"count",
"(",
"$",
"with",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"with",
"as",
"$",
"variableName",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"variableName",
")",
")",
"{",
"throw",
"new",
"ResponseException",
"(",
"'Invalid argument name, expected string, got '",
".",
"gettype",
"(",
"$",
"variableName",
")",
")",
";",
"}",
"$",
"$",
"variableName",
"=",
"$",
"value",
";",
"}",
"}",
"ob_start",
"(",
"null",
",",
"0",
",",
"PHP_OUTPUT_HANDLER_CLEANABLE",
"|",
"PHP_OUTPUT_HANDLER_FLUSHABLE",
"|",
"PHP_OUTPUT_HANDLER_REMOVABLE",
")",
";",
"require",
"$",
"path",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
]
| Render some other view file inside of parent view file
@param string $view
@param array $with php variables
@throws Exception
@return string | [
"Render",
"some",
"other",
"view",
"file",
"inside",
"of",
"parent",
"view",
"file"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/View.php#L146-L169 | train |
koldy/framework | src/Koldy/Response/View.php | View.renderViewIf | public function renderViewIf(string $view, array $with = null): string
{
if ($this->exists($view)) {
return $this->render($view, $with);
} else {
return '';
}
} | php | public function renderViewIf(string $view, array $with = null): string
{
if ($this->exists($view)) {
return $this->render($view, $with);
} else {
return '';
}
} | [
"public",
"function",
"renderViewIf",
"(",
"string",
"$",
"view",
",",
"array",
"$",
"with",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"view",
")",
")",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"view",
",",
"$",
"with",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
]
| Render view if exists on filesystem - if it doesn't exists, it won't throw any error
@param string $view
@param array $with
@return string
@throws Exception | [
"Render",
"view",
"if",
"exists",
"on",
"filesystem",
"-",
"if",
"it",
"doesn",
"t",
"exists",
"it",
"won",
"t",
"throw",
"any",
"error"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/View.php#L180-L187 | train |
koldy/framework | src/Koldy/Response/View.php | View.renderViewInKeyIf | public function renderViewInKeyIf(string $key, array $with = null): string
{
if (!$this->has($key)) {
return '';
}
$view = $this->$key;
if (static::exists($view)) {
return $this->render($view, $with);
} else {
return '';
}
} | php | public function renderViewInKeyIf(string $key, array $with = null): string
{
if (!$this->has($key)) {
return '';
}
$view = $this->$key;
if (static::exists($view)) {
return $this->render($view, $with);
} else {
return '';
}
} | [
"public",
"function",
"renderViewInKeyIf",
"(",
"string",
"$",
"key",
",",
"array",
"$",
"with",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"view",
"=",
"$",
"this",
"->",
"$",
"key",
";",
"if",
"(",
"static",
"::",
"exists",
"(",
"$",
"view",
")",
")",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"view",
",",
"$",
"with",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
]
| Render view from key variable if exists - if it doesn't exists, it won't throw any error
@param string $key
@param array $with
@return string
@throws Exception | [
"Render",
"view",
"from",
"key",
"variable",
"if",
"exists",
"-",
"if",
"it",
"doesn",
"t",
"exists",
"it",
"won",
"t",
"throw",
"any",
"error"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/View.php#L198-L211 | train |
koldy/framework | src/Koldy/Response/View.php | View.flush | public function flush(): void
{
$this->prepareFlush();
$this->runBeforeFlush();
$path = $this->getViewPath($this->view);
if (!file_exists($path)) {
throw new ResponseException("View ({$this->view}) not found on path={$path}");
}
ob_start(null, 0, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE);
require $path;
$statusCode = $this->statusCode;
$statusCodeIs1XX = $statusCode >= 100 && $statusCode <= 199;
if (!$statusCodeIs1XX && $statusCode !== 204) {
$size = ob_get_length();
$this->setHeader('Content-Length', $size);
}
$this->flushBuffer();
$this->runAfterFlush();
} | php | public function flush(): void
{
$this->prepareFlush();
$this->runBeforeFlush();
$path = $this->getViewPath($this->view);
if (!file_exists($path)) {
throw new ResponseException("View ({$this->view}) not found on path={$path}");
}
ob_start(null, 0, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE);
require $path;
$statusCode = $this->statusCode;
$statusCodeIs1XX = $statusCode >= 100 && $statusCode <= 199;
if (!$statusCodeIs1XX && $statusCode !== 204) {
$size = ob_get_length();
$this->setHeader('Content-Length', $size);
}
$this->flushBuffer();
$this->runAfterFlush();
} | [
"public",
"function",
"flush",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"prepareFlush",
"(",
")",
";",
"$",
"this",
"->",
"runBeforeFlush",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getViewPath",
"(",
"$",
"this",
"->",
"view",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"ResponseException",
"(",
"\"View ({$this->view}) not found on path={$path}\"",
")",
";",
"}",
"ob_start",
"(",
"null",
",",
"0",
",",
"PHP_OUTPUT_HANDLER_CLEANABLE",
"|",
"PHP_OUTPUT_HANDLER_FLUSHABLE",
"|",
"PHP_OUTPUT_HANDLER_REMOVABLE",
")",
";",
"require",
"$",
"path",
";",
"$",
"statusCode",
"=",
"$",
"this",
"->",
"statusCode",
";",
"$",
"statusCodeIs1XX",
"=",
"$",
"statusCode",
">=",
"100",
"&&",
"$",
"statusCode",
"<=",
"199",
";",
"if",
"(",
"!",
"$",
"statusCodeIs1XX",
"&&",
"$",
"statusCode",
"!==",
"204",
")",
"{",
"$",
"size",
"=",
"ob_get_length",
"(",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Content-Length'",
",",
"$",
"size",
")",
";",
"}",
"$",
"this",
"->",
"flushBuffer",
"(",
")",
";",
"$",
"this",
"->",
"runAfterFlush",
"(",
")",
";",
"}"
]
| This method is called by framework, but in some cases, you'll want to call it by yourself.
@throws Exception
@throws \Koldy\Exception | [
"This",
"method",
"is",
"called",
"by",
"framework",
"but",
"in",
"some",
"cases",
"you",
"ll",
"want",
"to",
"call",
"it",
"by",
"yourself",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/View.php#L242-L268 | train |
koldy/framework | src/Koldy/Response/View.php | View.getOutput | public function getOutput(): string
{
$this->prepareFlush();
$path = $this->getViewPath($this->view);
if (!file_exists($path)) {
throw new ResponseException("View ({$this->view}) not found on path={$path}");
}
ob_start(null, 0, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE);
require $path;
return ob_get_clean();
} | php | public function getOutput(): string
{
$this->prepareFlush();
$path = $this->getViewPath($this->view);
if (!file_exists($path)) {
throw new ResponseException("View ({$this->view}) not found on path={$path}");
}
ob_start(null, 0, PHP_OUTPUT_HANDLER_CLEANABLE | PHP_OUTPUT_HANDLER_FLUSHABLE | PHP_OUTPUT_HANDLER_REMOVABLE);
require $path;
return ob_get_clean();
} | [
"public",
"function",
"getOutput",
"(",
")",
":",
"string",
"{",
"$",
"this",
"->",
"prepareFlush",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getViewPath",
"(",
"$",
"this",
"->",
"view",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"ResponseException",
"(",
"\"View ({$this->view}) not found on path={$path}\"",
")",
";",
"}",
"ob_start",
"(",
"null",
",",
"0",
",",
"PHP_OUTPUT_HANDLER_CLEANABLE",
"|",
"PHP_OUTPUT_HANDLER_FLUSHABLE",
"|",
"PHP_OUTPUT_HANDLER_REMOVABLE",
")",
";",
"require",
"$",
"path",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
]
| Get the rendered view code.
@throws Exception
@return string
@link http://koldy.net/docs/view#get-output | [
"Get",
"the",
"rendered",
"view",
"code",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/View.php#L277-L291 | train |
dewsign/maxfactor-laravel-support | src/Maxfactor.php | Maxfactor.bake | public static function bake($seed = [], bool $timetravel = true)
{
$future = false;
$bread = collect($seed)->map(function ($crumb) use (&$future, $timetravel) {
if (!$crumb) {
return;
}
$status = $future && !$timetravel ? 'disabled' : 'enabled';
$future = ($currentCrumb = (url()->full() === array_get($crumb, 'url')) ? 'current' : '') || $future;
$crumb['status'] = $currentCrumb ? : $status;
return $crumb;
});
return $bread;
} | php | public static function bake($seed = [], bool $timetravel = true)
{
$future = false;
$bread = collect($seed)->map(function ($crumb) use (&$future, $timetravel) {
if (!$crumb) {
return;
}
$status = $future && !$timetravel ? 'disabled' : 'enabled';
$future = ($currentCrumb = (url()->full() === array_get($crumb, 'url')) ? 'current' : '') || $future;
$crumb['status'] = $currentCrumb ? : $status;
return $crumb;
});
return $bread;
} | [
"public",
"static",
"function",
"bake",
"(",
"$",
"seed",
"=",
"[",
"]",
",",
"bool",
"$",
"timetravel",
"=",
"true",
")",
"{",
"$",
"future",
"=",
"false",
";",
"$",
"bread",
"=",
"collect",
"(",
"$",
"seed",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"crumb",
")",
"use",
"(",
"&",
"$",
"future",
",",
"$",
"timetravel",
")",
"{",
"if",
"(",
"!",
"$",
"crumb",
")",
"{",
"return",
";",
"}",
"$",
"status",
"=",
"$",
"future",
"&&",
"!",
"$",
"timetravel",
"?",
"'disabled'",
":",
"'enabled'",
";",
"$",
"future",
"=",
"(",
"$",
"currentCrumb",
"=",
"(",
"url",
"(",
")",
"->",
"full",
"(",
")",
"===",
"array_get",
"(",
"$",
"crumb",
",",
"'url'",
")",
")",
"?",
"'current'",
":",
"''",
")",
"||",
"$",
"future",
";",
"$",
"crumb",
"[",
"'status'",
"]",
"=",
"$",
"currentCrumb",
"?",
":",
"$",
"status",
";",
"return",
"$",
"crumb",
";",
"}",
")",
";",
"return",
"$",
"bread",
";",
"}"
]
| Generate a Breadcrumb navigation trail. Set time travel to false to disable
forward navigation. Useful in Checkout for example.
@param boolean $timetravel
@return Array|Collection | [
"Generate",
"a",
"Breadcrumb",
"navigation",
"trail",
".",
"Set",
"time",
"travel",
"to",
"false",
"to",
"disable",
"forward",
"navigation",
".",
"Useful",
"in",
"Checkout",
"for",
"example",
"."
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Maxfactor.php#L27-L45 | train |
dewsign/maxfactor-laravel-support | src/Maxfactor.php | Maxfactor.urlWithQuerystring | public function urlWithQuerystring(string $url, string $allowedParameters = null) : string
{
if (!$allowedParameters) {
return $url;
}
$allowedParameters = str_start($allowedParameters, '/');
$allowedParameters = str_finish($allowedParameters, '/');
$currentQuery = collect(request()->query())->filter(function ($value, $parameter) use ($allowedParameters) {
return preg_match($allowedParameters, sprintf('%s=%s', $parameter, $value));
});
if (!$newQuery = http_build_query($currentQuery->all())) {
return $url;
};
return sprintf('%s?%s', $url, $newQuery);
} | php | public function urlWithQuerystring(string $url, string $allowedParameters = null) : string
{
if (!$allowedParameters) {
return $url;
}
$allowedParameters = str_start($allowedParameters, '/');
$allowedParameters = str_finish($allowedParameters, '/');
$currentQuery = collect(request()->query())->filter(function ($value, $parameter) use ($allowedParameters) {
return preg_match($allowedParameters, sprintf('%s=%s', $parameter, $value));
});
if (!$newQuery = http_build_query($currentQuery->all())) {
return $url;
};
return sprintf('%s?%s', $url, $newQuery);
} | [
"public",
"function",
"urlWithQuerystring",
"(",
"string",
"$",
"url",
",",
"string",
"$",
"allowedParameters",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"allowedParameters",
")",
"{",
"return",
"$",
"url",
";",
"}",
"$",
"allowedParameters",
"=",
"str_start",
"(",
"$",
"allowedParameters",
",",
"'/'",
")",
";",
"$",
"allowedParameters",
"=",
"str_finish",
"(",
"$",
"allowedParameters",
",",
"'/'",
")",
";",
"$",
"currentQuery",
"=",
"collect",
"(",
"request",
"(",
")",
"->",
"query",
"(",
")",
")",
"->",
"filter",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"parameter",
")",
"use",
"(",
"$",
"allowedParameters",
")",
"{",
"return",
"preg_match",
"(",
"$",
"allowedParameters",
",",
"sprintf",
"(",
"'%s=%s'",
",",
"$",
"parameter",
",",
"$",
"value",
")",
")",
";",
"}",
")",
";",
"if",
"(",
"!",
"$",
"newQuery",
"=",
"http_build_query",
"(",
"$",
"currentQuery",
"->",
"all",
"(",
")",
")",
")",
"{",
"return",
"$",
"url",
";",
"}",
";",
"return",
"sprintf",
"(",
"'%s?%s'",
",",
"$",
"url",
",",
"$",
"newQuery",
")",
";",
"}"
]
| Returns a url with query string where the final querystring is a filtered
version of the current querystring.
@param string $url
@param string $allowedParameters Accepts a string or regular expression
@return string | [
"Returns",
"a",
"url",
"with",
"query",
"string",
"where",
"the",
"final",
"querystring",
"is",
"a",
"filtered",
"version",
"of",
"the",
"current",
"querystring",
"."
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Maxfactor.php#L55-L73 | train |
dewsign/maxfactor-laravel-support | src/MaxfactorServiceProvider.php | MaxfactorServiceProvider.registerBlueprints | private function registerBlueprints()
{
Blueprint::macro('active', function ($name = 'active', $default = false) {
return $this->boolean($name)->default($default);
});
Blueprint::macro('featured', function ($name = 'featured', $default = false) {
return $this->boolean($name)->default($default);
});
Blueprint::macro('sortable', function ($name = 'sort_order', $default = false) {
return $this->integer($name)->default(1);
});
Blueprint::macro('meta', function ($name = 'meta_attributes') {
return $this->json($name)->nullable();
});
Blueprint::macro('priority', function ($name = 'priority', $default = 50) {
return $this->integer($name)->default($default);
});
Blueprint::macro('slug', function ($name = 'slug') {
return $this->string($name)->unique()->index();
});
} | php | private function registerBlueprints()
{
Blueprint::macro('active', function ($name = 'active', $default = false) {
return $this->boolean($name)->default($default);
});
Blueprint::macro('featured', function ($name = 'featured', $default = false) {
return $this->boolean($name)->default($default);
});
Blueprint::macro('sortable', function ($name = 'sort_order', $default = false) {
return $this->integer($name)->default(1);
});
Blueprint::macro('meta', function ($name = 'meta_attributes') {
return $this->json($name)->nullable();
});
Blueprint::macro('priority', function ($name = 'priority', $default = 50) {
return $this->integer($name)->default($default);
});
Blueprint::macro('slug', function ($name = 'slug') {
return $this->string($name)->unique()->index();
});
} | [
"private",
"function",
"registerBlueprints",
"(",
")",
"{",
"Blueprint",
"::",
"macro",
"(",
"'active'",
",",
"function",
"(",
"$",
"name",
"=",
"'active'",
",",
"$",
"default",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"boolean",
"(",
"$",
"name",
")",
"->",
"default",
"(",
"$",
"default",
")",
";",
"}",
")",
";",
"Blueprint",
"::",
"macro",
"(",
"'featured'",
",",
"function",
"(",
"$",
"name",
"=",
"'featured'",
",",
"$",
"default",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"boolean",
"(",
"$",
"name",
")",
"->",
"default",
"(",
"$",
"default",
")",
";",
"}",
")",
";",
"Blueprint",
"::",
"macro",
"(",
"'sortable'",
",",
"function",
"(",
"$",
"name",
"=",
"'sort_order'",
",",
"$",
"default",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"integer",
"(",
"$",
"name",
")",
"->",
"default",
"(",
"1",
")",
";",
"}",
")",
";",
"Blueprint",
"::",
"macro",
"(",
"'meta'",
",",
"function",
"(",
"$",
"name",
"=",
"'meta_attributes'",
")",
"{",
"return",
"$",
"this",
"->",
"json",
"(",
"$",
"name",
")",
"->",
"nullable",
"(",
")",
";",
"}",
")",
";",
"Blueprint",
"::",
"macro",
"(",
"'priority'",
",",
"function",
"(",
"$",
"name",
"=",
"'priority'",
",",
"$",
"default",
"=",
"50",
")",
"{",
"return",
"$",
"this",
"->",
"integer",
"(",
"$",
"name",
")",
"->",
"default",
"(",
"$",
"default",
")",
";",
"}",
")",
";",
"Blueprint",
"::",
"macro",
"(",
"'slug'",
",",
"function",
"(",
"$",
"name",
"=",
"'slug'",
")",
"{",
"return",
"$",
"this",
"->",
"string",
"(",
"$",
"name",
")",
"->",
"unique",
"(",
")",
"->",
"index",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Register additional table blueprints for use in database migrations
@return void | [
"Register",
"additional",
"table",
"blueprints",
"for",
"use",
"in",
"database",
"migrations"
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/MaxfactorServiceProvider.php#L78-L103 | train |
koldy/framework | src/Koldy/Request.php | Request.host | public static function host(): ?string
{
$ip = self::ip();
if (isset(static::$hosts[$ip])) {
return static::$hosts[$ip];
}
$host = gethostbyaddr($ip);
static::$hosts[$ip] = ($host === '') ? null : $host;
return static::$hosts[$ip];
} | php | public static function host(): ?string
{
$ip = self::ip();
if (isset(static::$hosts[$ip])) {
return static::$hosts[$ip];
}
$host = gethostbyaddr($ip);
static::$hosts[$ip] = ($host === '') ? null : $host;
return static::$hosts[$ip];
} | [
"public",
"static",
"function",
"host",
"(",
")",
":",
"?",
"string",
"{",
"$",
"ip",
"=",
"self",
"::",
"ip",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"hosts",
"[",
"$",
"ip",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"hosts",
"[",
"$",
"ip",
"]",
";",
"}",
"$",
"host",
"=",
"gethostbyaddr",
"(",
"$",
"ip",
")",
";",
"static",
"::",
"$",
"hosts",
"[",
"$",
"ip",
"]",
"=",
"(",
"$",
"host",
"===",
"''",
")",
"?",
"null",
":",
"$",
"host",
";",
"return",
"static",
"::",
"$",
"hosts",
"[",
"$",
"ip",
"]",
";",
"}"
]
| Get the host name of remote user. This will use gethostbyaddr function or its "cached" version
@return string|null
@throws Exception
@link http://php.net/manual/en/function.gethostbyaddr.php | [
"Get",
"the",
"host",
"name",
"of",
"remote",
"user",
".",
"This",
"will",
"use",
"gethostbyaddr",
"function",
"or",
"its",
"cached",
"version"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L104-L115 | train |
koldy/framework | src/Koldy/Request.php | Request.ipWithProxy | public static function ipWithProxy($delimiter = ','): string
{
$ip = self::ip();
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $ip != $_SERVER['HTTP_X_FORWARDED_FOR']) {
$ip .= "{$delimiter}{$_SERVER['HTTP_X_FORWARDED_FOR']}";
}
return $ip;
} | php | public static function ipWithProxy($delimiter = ','): string
{
$ip = self::ip();
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $ip != $_SERVER['HTTP_X_FORWARDED_FOR']) {
$ip .= "{$delimiter}{$_SERVER['HTTP_X_FORWARDED_FOR']}";
}
return $ip;
} | [
"public",
"static",
"function",
"ipWithProxy",
"(",
"$",
"delimiter",
"=",
"','",
")",
":",
"string",
"{",
"$",
"ip",
"=",
"self",
"::",
"ip",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
")",
"&&",
"$",
"ip",
"!=",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
")",
"{",
"$",
"ip",
".=",
"\"{$delimiter}{$_SERVER['HTTP_X_FORWARDED_FOR']}\"",
";",
"}",
"return",
"$",
"ip",
";",
"}"
]
| Get remote IP address with additional IP sent over proxy if exists
@param string $delimiter
@return string
@throws Exception
@example 89.205.104.23,10.100.10.190 | [
"Get",
"remote",
"IP",
"address",
"with",
"additional",
"IP",
"sent",
"over",
"proxy",
"if",
"exists"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L166-L175 | train |
koldy/framework | src/Koldy/Request.php | Request.getRawData | public static function getRawData(): string
{
if (static::$rawData === null) {
static::$rawData = file_get_contents('php://input');
if (static::$rawData === false) {
throw new RequestException('Unable to read raw data from request');
}
}
return static::$rawData;
} | php | public static function getRawData(): string
{
if (static::$rawData === null) {
static::$rawData = file_get_contents('php://input');
if (static::$rawData === false) {
throw new RequestException('Unable to read raw data from request');
}
}
return static::$rawData;
} | [
"public",
"static",
"function",
"getRawData",
"(",
")",
":",
"string",
"{",
"if",
"(",
"static",
"::",
"$",
"rawData",
"===",
"null",
")",
"{",
"static",
"::",
"$",
"rawData",
"=",
"file_get_contents",
"(",
"'php://input'",
")",
";",
"if",
"(",
"static",
"::",
"$",
"rawData",
"===",
"false",
")",
"{",
"throw",
"new",
"RequestException",
"(",
"'Unable to read raw data from request'",
")",
";",
"}",
"}",
"return",
"static",
"::",
"$",
"rawData",
";",
"}"
]
| Get raw data of the request
@return string
@throws RequestException | [
"Get",
"raw",
"data",
"of",
"the",
"request"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L321-L332 | train |
koldy/framework | src/Koldy/Request.php | Request.get | private static function get(string $resourceName, string $name, string $default = null, array $allowedValues = null)
{
switch ($resourceName) {
case 'GET':
$resource = $_GET;
break;
case 'POST':
if (!isset($_POST)) {
return $default;
}
$resource = $_POST;
break;
case 'PUT':
if ($_SERVER['REQUEST_METHOD'] !== 'PUT') {
return $default;
}
$resource = static::getInputVars();
break;
case 'DELETE':
if ($_SERVER['REQUEST_METHOD'] !== 'DELETE') {
return $default;
}
$resource = static::getInputVars();
break;
default:
throw new RequestException("Invalid resource name={$resourceName}");
break;
}
if (array_key_exists($name, $resource)) {
if (is_array($resource[$name])) {
return $resource[$name];
}
$value = trim($resource[$name]);
if ($value == '') {
return $default;
}
if ($allowedValues !== null) {
return (in_array($value, $allowedValues)) ? $value : $default;
}
return $value;
} else {
return $default;
}
} | php | private static function get(string $resourceName, string $name, string $default = null, array $allowedValues = null)
{
switch ($resourceName) {
case 'GET':
$resource = $_GET;
break;
case 'POST':
if (!isset($_POST)) {
return $default;
}
$resource = $_POST;
break;
case 'PUT':
if ($_SERVER['REQUEST_METHOD'] !== 'PUT') {
return $default;
}
$resource = static::getInputVars();
break;
case 'DELETE':
if ($_SERVER['REQUEST_METHOD'] !== 'DELETE') {
return $default;
}
$resource = static::getInputVars();
break;
default:
throw new RequestException("Invalid resource name={$resourceName}");
break;
}
if (array_key_exists($name, $resource)) {
if (is_array($resource[$name])) {
return $resource[$name];
}
$value = trim($resource[$name]);
if ($value == '') {
return $default;
}
if ($allowedValues !== null) {
return (in_array($value, $allowedValues)) ? $value : $default;
}
return $value;
} else {
return $default;
}
} | [
"private",
"static",
"function",
"get",
"(",
"string",
"$",
"resourceName",
",",
"string",
"$",
"name",
",",
"string",
"$",
"default",
"=",
"null",
",",
"array",
"$",
"allowedValues",
"=",
"null",
")",
"{",
"switch",
"(",
"$",
"resourceName",
")",
"{",
"case",
"'GET'",
":",
"$",
"resource",
"=",
"$",
"_GET",
";",
"break",
";",
"case",
"'POST'",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"$",
"resource",
"=",
"$",
"_POST",
";",
"break",
";",
"case",
"'PUT'",
":",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"!==",
"'PUT'",
")",
"{",
"return",
"$",
"default",
";",
"}",
"$",
"resource",
"=",
"static",
"::",
"getInputVars",
"(",
")",
";",
"break",
";",
"case",
"'DELETE'",
":",
"if",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
"!==",
"'DELETE'",
")",
"{",
"return",
"$",
"default",
";",
"}",
"$",
"resource",
"=",
"static",
"::",
"getInputVars",
"(",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"RequestException",
"(",
"\"Invalid resource name={$resourceName}\"",
")",
";",
"break",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"resource",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"resource",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"resource",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"$",
"resource",
"[",
"$",
"name",
"]",
")",
";",
"if",
"(",
"$",
"value",
"==",
"''",
")",
"{",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"$",
"allowedValues",
"!==",
"null",
")",
"{",
"return",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"allowedValues",
")",
")",
"?",
"$",
"value",
":",
"$",
"default",
";",
"}",
"return",
"$",
"value",
";",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}"
]
| Fetch the value from the resource
@param string $resourceName
@param string $name parameter name
@param string $default [optional] default value if parameter doesn't exists
@param array $allowedValues [optional] allowed values; if resource value doesn't contain one of values in this array, default is returned
@return string
@throws Exception | [
"Fetch",
"the",
"value",
"from",
"the",
"resource"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L374-L430 | train |
koldy/framework | src/Koldy/Request.php | Request.getGetParameter | public static function getGetParameter(string $name, string $default = null, array $allowed = null): string
{
return self::get('GET', $name, $default, $allowed);
} | php | public static function getGetParameter(string $name, string $default = null, array $allowed = null): string
{
return self::get('GET', $name, $default, $allowed);
} | [
"public",
"static",
"function",
"getGetParameter",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"default",
"=",
"null",
",",
"array",
"$",
"allowed",
"=",
"null",
")",
":",
"string",
"{",
"return",
"self",
"::",
"get",
"(",
"'GET'",
",",
"$",
"name",
",",
"$",
"default",
",",
"$",
"allowed",
")",
";",
"}"
]
| Returns the GET parameter
@param string $name
@param string $default [optional]
@param array $allowed [optional]
@return string
@throws Exception
@link http://koldy.net/docs/input#get | [
"Returns",
"the",
"GET",
"parameter"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L456-L459 | train |
koldy/framework | src/Koldy/Request.php | Request.getPostParameter | public static function getPostParameter(string $name, string $default = null, array $allowed = null): string
{
return self::get('POST', $name, $default, $allowed);
} | php | public static function getPostParameter(string $name, string $default = null, array $allowed = null): string
{
return self::get('POST', $name, $default, $allowed);
} | [
"public",
"static",
"function",
"getPostParameter",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"default",
"=",
"null",
",",
"array",
"$",
"allowed",
"=",
"null",
")",
":",
"string",
"{",
"return",
"self",
"::",
"get",
"(",
"'POST'",
",",
"$",
"name",
",",
"$",
"default",
",",
"$",
"allowed",
")",
";",
"}"
]
| Returns the POST parameter
@param string $name
@param string $default [optional] default NULL
@param array $allowed [optional]
@return string
@throws Exception
@link http://koldy.net/docs/input#post | [
"Returns",
"the",
"POST",
"parameter"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L495-L498 | train |
koldy/framework | src/Koldy/Request.php | Request.getPutParameter | public static function getPutParameter(string $name, string $default = null, array $allowed = null): string
{
return self::get('PUT', $name, $default, $allowed);
} | php | public static function getPutParameter(string $name, string $default = null, array $allowed = null): string
{
return self::get('PUT', $name, $default, $allowed);
} | [
"public",
"static",
"function",
"getPutParameter",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"default",
"=",
"null",
",",
"array",
"$",
"allowed",
"=",
"null",
")",
":",
"string",
"{",
"return",
"self",
"::",
"get",
"(",
"'PUT'",
",",
"$",
"name",
",",
"$",
"default",
",",
"$",
"allowed",
")",
";",
"}"
]
| Returns the PUT parameter
@param string $name
@param string $default [optional]
@param array $allowed [optional]
@return string
@throws Exception
@link http://koldy.net/docs/input#put | [
"Returns",
"the",
"PUT",
"parameter"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L539-L542 | train |
koldy/framework | src/Koldy/Request.php | Request.getDeleteParameter | public static function getDeleteParameter(string $name, $default = null, array $allowed = null): string
{
return self::get('DELETE', $name, $default, $allowed);
} | php | public static function getDeleteParameter(string $name, $default = null, array $allowed = null): string
{
return self::get('DELETE', $name, $default, $allowed);
} | [
"public",
"static",
"function",
"getDeleteParameter",
"(",
"string",
"$",
"name",
",",
"$",
"default",
"=",
"null",
",",
"array",
"$",
"allowed",
"=",
"null",
")",
":",
"string",
"{",
"return",
"self",
"::",
"get",
"(",
"'DELETE'",
",",
"$",
"name",
",",
"$",
"default",
",",
"$",
"allowed",
")",
";",
"}"
]
| Returns the DELETE parameter
@param string $name
@param string $default [optional]
@param array $allowed [optional]
@return string
@throws Exception
@link http://koldy.net/docs/input#delete | [
"Returns",
"the",
"DELETE",
"parameter"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L582-L585 | train |
koldy/framework | src/Koldy/Request.php | Request.requireParams | public static function requireParams(string ...$requiredParameters): array
{
if (KOLDY_CLI) {
throw new ApplicationException('Unable to require parameters in CLI mode. Check \Koldy\Cli for that');
}
switch ($_SERVER['REQUEST_METHOD']) {
default:
$parameters = static::getInputVars();
break;
case 'GET':
$parameters = $_GET;
break;
case 'POST':
$parameters = $_POST;
break;
}
$extractedParams = [];
$missing = [];
foreach ($requiredParameters as $param) {
if (array_key_exists($param, $parameters)) {
$extractedParams[$param] = $parameters[$param];
} else {
$missing[] = $param;
}
}
if (count($missing) > 0) {
$missingParameters = implode(', ', $missing);
$passedParams = implode(', ', $requiredParameters);
throw new BadRequestException("Missing {$_SERVER['REQUEST_METHOD']} parameter(s) '{$missingParameters}', only got " . (count($requiredParameters) > 0 ? $passedParams : '[nothing]'));
}
return $extractedParams;
} | php | public static function requireParams(string ...$requiredParameters): array
{
if (KOLDY_CLI) {
throw new ApplicationException('Unable to require parameters in CLI mode. Check \Koldy\Cli for that');
}
switch ($_SERVER['REQUEST_METHOD']) {
default:
$parameters = static::getInputVars();
break;
case 'GET':
$parameters = $_GET;
break;
case 'POST':
$parameters = $_POST;
break;
}
$extractedParams = [];
$missing = [];
foreach ($requiredParameters as $param) {
if (array_key_exists($param, $parameters)) {
$extractedParams[$param] = $parameters[$param];
} else {
$missing[] = $param;
}
}
if (count($missing) > 0) {
$missingParameters = implode(', ', $missing);
$passedParams = implode(', ', $requiredParameters);
throw new BadRequestException("Missing {$_SERVER['REQUEST_METHOD']} parameter(s) '{$missingParameters}', only got " . (count($requiredParameters) > 0 ? $passedParams : '[nothing]'));
}
return $extractedParams;
} | [
"public",
"static",
"function",
"requireParams",
"(",
"string",
"...",
"$",
"requiredParameters",
")",
":",
"array",
"{",
"if",
"(",
"KOLDY_CLI",
")",
"{",
"throw",
"new",
"ApplicationException",
"(",
"'Unable to require parameters in CLI mode. Check \\Koldy\\Cli for that'",
")",
";",
"}",
"switch",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
"{",
"default",
":",
"$",
"parameters",
"=",
"static",
"::",
"getInputVars",
"(",
")",
";",
"break",
";",
"case",
"'GET'",
":",
"$",
"parameters",
"=",
"$",
"_GET",
";",
"break",
";",
"case",
"'POST'",
":",
"$",
"parameters",
"=",
"$",
"_POST",
";",
"break",
";",
"}",
"$",
"extractedParams",
"=",
"[",
"]",
";",
"$",
"missing",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"requiredParameters",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"param",
",",
"$",
"parameters",
")",
")",
"{",
"$",
"extractedParams",
"[",
"$",
"param",
"]",
"=",
"$",
"parameters",
"[",
"$",
"param",
"]",
";",
"}",
"else",
"{",
"$",
"missing",
"[",
"]",
"=",
"$",
"param",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"missing",
")",
">",
"0",
")",
"{",
"$",
"missingParameters",
"=",
"implode",
"(",
"', '",
",",
"$",
"missing",
")",
";",
"$",
"passedParams",
"=",
"implode",
"(",
"', '",
",",
"$",
"requiredParameters",
")",
";",
"throw",
"new",
"BadRequestException",
"(",
"\"Missing {$_SERVER['REQUEST_METHOD']} parameter(s) '{$missingParameters}', only got \"",
".",
"(",
"count",
"(",
"$",
"requiredParameters",
")",
">",
"0",
"?",
"$",
"passedParams",
":",
"'[nothing]'",
")",
")",
";",
"}",
"return",
"$",
"extractedParams",
";",
"}"
]
| Get the required parameters. Return bad request if any of them is missing.
@param string[] ...$requiredParameters
@return array
@throws BadRequestException
@throws Exception
@link http://koldy.net/docs/input#require
@example
$params = Input::requireParams('id', 'email');
echo $params->email; | [
"Get",
"the",
"required",
"parameters",
".",
"Return",
"bad",
"request",
"if",
"any",
"of",
"them",
"is",
"missing",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L601-L637 | train |
koldy/framework | src/Koldy/Request.php | Request.requireParamsObj | public static function requireParamsObj(string ...$requiredParameters): stdClass
{
$class = new stdClass();
foreach (static::requireParams(...$requiredParameters) as $param => $value) {
$class->$param = $value;
}
return $class;
} | php | public static function requireParamsObj(string ...$requiredParameters): stdClass
{
$class = new stdClass();
foreach (static::requireParams(...$requiredParameters) as $param => $value) {
$class->$param = $value;
}
return $class;
} | [
"public",
"static",
"function",
"requireParamsObj",
"(",
"string",
"...",
"$",
"requiredParameters",
")",
":",
"stdClass",
"{",
"$",
"class",
"=",
"new",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"static",
"::",
"requireParams",
"(",
"...",
"$",
"requiredParameters",
")",
"as",
"$",
"param",
"=>",
"$",
"value",
")",
"{",
"$",
"class",
"->",
"$",
"param",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"class",
";",
"}"
]
| Get required parameters as object
@param string ...$requiredParameters
@return stdClass
@throws BadRequestException
@throws Exception | [
"Get",
"required",
"parameters",
"as",
"object"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L648-L657 | train |
koldy/framework | src/Koldy/Request.php | Request.getAllParametersObj | public static function getAllParametersObj(): stdClass
{
$values = new stdClass();
foreach (static::getAllParameters() as $name => $value) {
$values->$name = $value;
}
return $values;
} | php | public static function getAllParametersObj(): stdClass
{
$values = new stdClass();
foreach (static::getAllParameters() as $name => $value) {
$values->$name = $value;
}
return $values;
} | [
"public",
"static",
"function",
"getAllParametersObj",
"(",
")",
":",
"stdClass",
"{",
"$",
"values",
"=",
"new",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"static",
"::",
"getAllParameters",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"values",
"->",
"$",
"name",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"values",
";",
"}"
]
| Get all parameters in stdClass
@return stdClass
@throws Exception | [
"Get",
"all",
"parameters",
"in",
"stdClass"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L694-L703 | train |
koldy/framework | src/Koldy/Request.php | Request.only | public static function only(...$params): bool
{
if (static::parametersCount() != count(is_array($params[0]) ? $params[0] : $params)) {
return false;
}
return static::containsParams(...$params);
} | php | public static function only(...$params): bool
{
if (static::parametersCount() != count(is_array($params[0]) ? $params[0] : $params)) {
return false;
}
return static::containsParams(...$params);
} | [
"public",
"static",
"function",
"only",
"(",
"...",
"$",
"params",
")",
":",
"bool",
"{",
"if",
"(",
"static",
"::",
"parametersCount",
"(",
")",
"!=",
"count",
"(",
"is_array",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"?",
"$",
"params",
"[",
"0",
"]",
":",
"$",
"params",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"static",
"::",
"containsParams",
"(",
"...",
"$",
"params",
")",
";",
"}"
]
| Return true if request contains only parameters from method argument. If there are more parameters then defined,
method will return false.
@param mixed ...$params
@return bool
@throws Exception | [
"Return",
"true",
"if",
"request",
"contains",
"only",
"parameters",
"from",
"method",
"argument",
".",
"If",
"there",
"are",
"more",
"parameters",
"then",
"defined",
"method",
"will",
"return",
"false",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L725-L732 | train |
koldy/framework | src/Koldy/Request.php | Request.containsParams | public static function containsParams(...$params): bool
{
$params = array_flip(is_array($params[0]) ? $params[0] : $params);
foreach (static::getAllParameters() as $name => $value) {
if (array_key_exists($name, $params)) {
unset($params[$name]);
}
}
return count($params) == 0;
} | php | public static function containsParams(...$params): bool
{
$params = array_flip(is_array($params[0]) ? $params[0] : $params);
foreach (static::getAllParameters() as $name => $value) {
if (array_key_exists($name, $params)) {
unset($params[$name]);
}
}
return count($params) == 0;
} | [
"public",
"static",
"function",
"containsParams",
"(",
"...",
"$",
"params",
")",
":",
"bool",
"{",
"$",
"params",
"=",
"array_flip",
"(",
"is_array",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"?",
"$",
"params",
"[",
"0",
"]",
":",
"$",
"params",
")",
";",
"foreach",
"(",
"static",
"::",
"getAllParameters",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"params",
")",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"return",
"count",
"(",
"$",
"params",
")",
"==",
"0",
";",
"}"
]
| Return true if request contains all of the parameters from method argument. If there are more parameters then
params passed to methods, method will still return true.
@param mixed ...$params
@return bool
@throws Exception | [
"Return",
"true",
"if",
"request",
"contains",
"all",
"of",
"the",
"parameters",
"from",
"method",
"argument",
".",
"If",
"there",
"are",
"more",
"parameters",
"then",
"params",
"passed",
"to",
"methods",
"method",
"will",
"still",
"return",
"true",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L743-L754 | train |
koldy/framework | src/Koldy/Request.php | Request.doesntContainParams | public static function doesntContainParams(...$params): bool
{
if (is_array($params[0])) {
$params = $params[0];
}
$targetCount = count($params);
$params = array_flip($params);
foreach (static::getAllParameters() as $name => $value) {
if (array_key_exists($name, $params)) {
unset($params[$name]);
}
}
return count($params) == $targetCount;
} | php | public static function doesntContainParams(...$params): bool
{
if (is_array($params[0])) {
$params = $params[0];
}
$targetCount = count($params);
$params = array_flip($params);
foreach (static::getAllParameters() as $name => $value) {
if (array_key_exists($name, $params)) {
unset($params[$name]);
}
}
return count($params) == $targetCount;
} | [
"public",
"static",
"function",
"doesntContainParams",
"(",
"...",
"$",
"params",
")",
":",
"bool",
"{",
"if",
"(",
"is_array",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"params",
"=",
"$",
"params",
"[",
"0",
"]",
";",
"}",
"$",
"targetCount",
"=",
"count",
"(",
"$",
"params",
")",
";",
"$",
"params",
"=",
"array_flip",
"(",
"$",
"params",
")",
";",
"foreach",
"(",
"static",
"::",
"getAllParameters",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"params",
")",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"return",
"count",
"(",
"$",
"params",
")",
"==",
"$",
"targetCount",
";",
"}"
]
| Return true only if request doesn't have any of the params from method argument.
@param array $params
@return bool
@throws Exception | [
"Return",
"true",
"only",
"if",
"request",
"doesn",
"t",
"have",
"any",
"of",
"the",
"params",
"from",
"method",
"argument",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Request.php#L764-L780 | train |
koldy/framework | src/Koldy/Json.php | Json.encode | public static function encode($data): string
{
$json = json_encode($data);
if ($json === false) {
$errNo = json_last_error();
$msg = json_last_error_msg();
throw new Exception("Unable to encode data to JSON, error ({$errNo}): {$msg}", $errNo);
}
return $json;
} | php | public static function encode($data): string
{
$json = json_encode($data);
if ($json === false) {
$errNo = json_last_error();
$msg = json_last_error_msg();
throw new Exception("Unable to encode data to JSON, error ({$errNo}): {$msg}", $errNo);
}
return $json;
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"data",
")",
":",
"string",
"{",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"json",
"===",
"false",
")",
"{",
"$",
"errNo",
"=",
"json_last_error",
"(",
")",
";",
"$",
"msg",
"=",
"json_last_error_msg",
"(",
")",
";",
"throw",
"new",
"Exception",
"(",
"\"Unable to encode data to JSON, error ({$errNo}): {$msg}\"",
",",
"$",
"errNo",
")",
";",
"}",
"return",
"$",
"json",
";",
"}"
]
| JSON helper to quickly encode some data
@param mixed $data
@return mixed in JSON format
@throws Exception
@link https://koldy.net/framework/docs/2.0/json.md | [
"JSON",
"helper",
"to",
"quickly",
"encode",
"some",
"data"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Json.php#L22-L33 | train |
koldy/framework | src/Koldy/Convert.php | Convert.getMeasure | private static function getMeasure(int $size, int $count = 0, int $round = 0): string
{
if ($size >= 1024) {
return self::getMeasure((int)round($size / 1024), ++$count, $round);
} else {
return round($size, $round) . ' ' . self::$measure[$count];
}
} | php | private static function getMeasure(int $size, int $count = 0, int $round = 0): string
{
if ($size >= 1024) {
return self::getMeasure((int)round($size / 1024), ++$count, $round);
} else {
return round($size, $round) . ' ' . self::$measure[$count];
}
} | [
"private",
"static",
"function",
"getMeasure",
"(",
"int",
"$",
"size",
",",
"int",
"$",
"count",
"=",
"0",
",",
"int",
"$",
"round",
"=",
"0",
")",
":",
"string",
"{",
"if",
"(",
"$",
"size",
">=",
"1024",
")",
"{",
"return",
"self",
"::",
"getMeasure",
"(",
"(",
"int",
")",
"round",
"(",
"$",
"size",
"/",
"1024",
")",
",",
"++",
"$",
"count",
",",
"$",
"round",
")",
";",
"}",
"else",
"{",
"return",
"round",
"(",
"$",
"size",
",",
"$",
"round",
")",
".",
"' '",
".",
"self",
"::",
"$",
"measure",
"[",
"$",
"count",
"]",
";",
"}",
"}"
]
| Get file's measure
@param int $size
@param int $count
@param int $round
@return string | [
"Get",
"file",
"s",
"measure"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Convert.php#L31-L38 | train |
koldy/framework | src/Koldy/Convert.php | Convert.bytesToString | public static function bytesToString(int $bytes, int $round = 0): string
{
return self::getMeasure($bytes, 0, $round);
} | php | public static function bytesToString(int $bytes, int $round = 0): string
{
return self::getMeasure($bytes, 0, $round);
} | [
"public",
"static",
"function",
"bytesToString",
"(",
"int",
"$",
"bytes",
",",
"int",
"$",
"round",
"=",
"0",
")",
":",
"string",
"{",
"return",
"self",
"::",
"getMeasure",
"(",
"$",
"bytes",
",",
"0",
",",
"$",
"round",
")",
";",
"}"
]
| Get bytes size as string
@param int $bytes
@param int $round round to how many decimals
@return string
@example 2048 will return 2 KB
@link https://koldy.net/framework/docs/2.0/converters.md#bytestostring | [
"Get",
"bytes",
"size",
"as",
"string"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Convert.php#L51-L54 | train |
koldy/framework | src/Koldy/Convert.php | Convert.stringToBytes | public static function stringToBytes(string $string): int
{
$original = trim($string);
$number = (int)$original;
if ($number === $original || $number === 0) {
return $number;
} else {
$char = strtoupper(substr($original, -1, 1));
switch ($char) {
case 'K': // KILO
return $number * 1024;
break;
case 'M': // MEGA
return $number * pow(1024, 2);
break;
case 'G': // GIGA
return $number * pow(1024, 3);
break;
case 'T': // TERA
return $number * pow(1024, 4);
break;
case 'P': // PETA
return $number * pow(1024, 5);
break;
case 'E': // EXA
return $number * pow(1024, 6);
break;
default:
throw new ConvertException('Not implemented sizes greater than exabytes');
break;
}
}
} | php | public static function stringToBytes(string $string): int
{
$original = trim($string);
$number = (int)$original;
if ($number === $original || $number === 0) {
return $number;
} else {
$char = strtoupper(substr($original, -1, 1));
switch ($char) {
case 'K': // KILO
return $number * 1024;
break;
case 'M': // MEGA
return $number * pow(1024, 2);
break;
case 'G': // GIGA
return $number * pow(1024, 3);
break;
case 'T': // TERA
return $number * pow(1024, 4);
break;
case 'P': // PETA
return $number * pow(1024, 5);
break;
case 'E': // EXA
return $number * pow(1024, 6);
break;
default:
throw new ConvertException('Not implemented sizes greater than exabytes');
break;
}
}
} | [
"public",
"static",
"function",
"stringToBytes",
"(",
"string",
"$",
"string",
")",
":",
"int",
"{",
"$",
"original",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"$",
"number",
"=",
"(",
"int",
")",
"$",
"original",
";",
"if",
"(",
"$",
"number",
"===",
"$",
"original",
"||",
"$",
"number",
"===",
"0",
")",
"{",
"return",
"$",
"number",
";",
"}",
"else",
"{",
"$",
"char",
"=",
"strtoupper",
"(",
"substr",
"(",
"$",
"original",
",",
"-",
"1",
",",
"1",
")",
")",
";",
"switch",
"(",
"$",
"char",
")",
"{",
"case",
"'K'",
":",
"// KILO",
"return",
"$",
"number",
"*",
"1024",
";",
"break",
";",
"case",
"'M'",
":",
"// MEGA",
"return",
"$",
"number",
"*",
"pow",
"(",
"1024",
",",
"2",
")",
";",
"break",
";",
"case",
"'G'",
":",
"// GIGA",
"return",
"$",
"number",
"*",
"pow",
"(",
"1024",
",",
"3",
")",
";",
"break",
";",
"case",
"'T'",
":",
"// TERA",
"return",
"$",
"number",
"*",
"pow",
"(",
"1024",
",",
"4",
")",
";",
"break",
";",
"case",
"'P'",
":",
"// PETA",
"return",
"$",
"number",
"*",
"pow",
"(",
"1024",
",",
"5",
")",
";",
"break",
";",
"case",
"'E'",
":",
"// EXA",
"return",
"$",
"number",
"*",
"pow",
"(",
"1024",
",",
"6",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"ConvertException",
"(",
"'Not implemented sizes greater than exabytes'",
")",
";",
"break",
";",
"}",
"}",
"}"
]
| Get the number of bytes from string
@param string $string
@return int
@throws ConvertException
@example 1M will return 1048576
@link https://koldy.net/framework/docs/2.0/converters.md#stringtobytes | [
"Get",
"the",
"number",
"of",
"bytes",
"from",
"string"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Convert.php#L67-L106 | train |
koldy/framework | src/Koldy/Convert.php | Convert.stringToUtf8 | public static function stringToUtf8(string $string): string
{
if (!mb_check_encoding($string, 'UTF-8') || !($string === mb_convert_encoding(mb_convert_encoding($string, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32'))) {
$string = mb_convert_encoding($string, 'UTF-8');
if (!mb_check_encoding($string, 'UTF-8')) {
throw new ConvertException('Can not convert given string to UTF-8');
}
}
return $string;
} | php | public static function stringToUtf8(string $string): string
{
if (!mb_check_encoding($string, 'UTF-8') || !($string === mb_convert_encoding(mb_convert_encoding($string, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32'))) {
$string = mb_convert_encoding($string, 'UTF-8');
if (!mb_check_encoding($string, 'UTF-8')) {
throw new ConvertException('Can not convert given string to UTF-8');
}
}
return $string;
} | [
"public",
"static",
"function",
"stringToUtf8",
"(",
"string",
"$",
"string",
")",
":",
"string",
"{",
"if",
"(",
"!",
"mb_check_encoding",
"(",
"$",
"string",
",",
"'UTF-8'",
")",
"||",
"!",
"(",
"$",
"string",
"===",
"mb_convert_encoding",
"(",
"mb_convert_encoding",
"(",
"$",
"string",
",",
"'UTF-32'",
",",
"'UTF-8'",
")",
",",
"'UTF-8'",
",",
"'UTF-32'",
")",
")",
")",
"{",
"$",
"string",
"=",
"mb_convert_encoding",
"(",
"$",
"string",
",",
"'UTF-8'",
")",
";",
"if",
"(",
"!",
"mb_check_encoding",
"(",
"$",
"string",
",",
"'UTF-8'",
")",
")",
"{",
"throw",
"new",
"ConvertException",
"(",
"'Can not convert given string to UTF-8'",
")",
";",
"}",
"}",
"return",
"$",
"string",
";",
"}"
]
| Convert given string into proper UTF-8 string
@param string $string
@return string
@throws ConvertException
@author Simon Brüchner (@powtac)
@link https://koldy.net/framework/docs/2.0/converters.md#stringtoutf8
@link http://php.net/manual/en/function.utf8-encode.php#102382 | [
"Convert",
"given",
"string",
"into",
"proper",
"UTF",
"-",
"8",
"string"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Convert.php#L120-L132 | train |
koldy/framework | src/Koldy/Log/Adapter/Out.php | Out.logMessage | public function logMessage(Message $message): void
{
if (in_array($message->getLevel(), $this->config['log'])) {
if ($this->getMessageFunction !== null) {
$line = call_user_func($this->getMessageFunction, $message);
} else {
$time = $message->getTime()->format('y-m-d H:i:s.v');
$level = strtoupper($message->getLevel());
$space = str_repeat(' ', 10 - strlen($level));
$who = $message->getWho() ?? Log::getWho();
$line = "{$time} {$level}{$space}{$who}\t{$message->getMessage()}\n";
}
if (is_string($line)) {
print $line;
}
}
} | php | public function logMessage(Message $message): void
{
if (in_array($message->getLevel(), $this->config['log'])) {
if ($this->getMessageFunction !== null) {
$line = call_user_func($this->getMessageFunction, $message);
} else {
$time = $message->getTime()->format('y-m-d H:i:s.v');
$level = strtoupper($message->getLevel());
$space = str_repeat(' ', 10 - strlen($level));
$who = $message->getWho() ?? Log::getWho();
$line = "{$time} {$level}{$space}{$who}\t{$message->getMessage()}\n";
}
if (is_string($line)) {
print $line;
}
}
} | [
"public",
"function",
"logMessage",
"(",
"Message",
"$",
"message",
")",
":",
"void",
"{",
"if",
"(",
"in_array",
"(",
"$",
"message",
"->",
"getLevel",
"(",
")",
",",
"$",
"this",
"->",
"config",
"[",
"'log'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getMessageFunction",
"!==",
"null",
")",
"{",
"$",
"line",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"getMessageFunction",
",",
"$",
"message",
")",
";",
"}",
"else",
"{",
"$",
"time",
"=",
"$",
"message",
"->",
"getTime",
"(",
")",
"->",
"format",
"(",
"'y-m-d H:i:s.v'",
")",
";",
"$",
"level",
"=",
"strtoupper",
"(",
"$",
"message",
"->",
"getLevel",
"(",
")",
")",
";",
"$",
"space",
"=",
"str_repeat",
"(",
"' '",
",",
"10",
"-",
"strlen",
"(",
"$",
"level",
")",
")",
";",
"$",
"who",
"=",
"$",
"message",
"->",
"getWho",
"(",
")",
"??",
"Log",
"::",
"getWho",
"(",
")",
";",
"$",
"line",
"=",
"\"{$time} {$level}{$space}{$who}\\t{$message->getMessage()}\\n\"",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"line",
")",
")",
"{",
"print",
"$",
"line",
";",
"}",
"}",
"}"
]
| Actually print message out
@param Message $message | [
"Actually",
"print",
"message",
"out"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Adapter/Out.php#L75-L92 | train |
koldy/framework | src/Koldy/Route/DefaultRoute.php | DefaultRoute.getVar | public function getVar($whatVar, $default = null)
{
if (is_numeric($whatVar)) {
$whatVar = (int)$whatVar + 1;
if (isset($this->uri[$whatVar])) {
$value = trim($this->uri[$whatVar]);
return ($value != '') ? $value : $default;
} else {
return $default;
}
} else {
// if variable is string, then treat it like GET parameter
if (isset($_GET[$whatVar])) {
$value = trim($_GET[$whatVar]);
return ($value != '') ? $value : $default;
} else {
return $default;
}
}
} | php | public function getVar($whatVar, $default = null)
{
if (is_numeric($whatVar)) {
$whatVar = (int)$whatVar + 1;
if (isset($this->uri[$whatVar])) {
$value = trim($this->uri[$whatVar]);
return ($value != '') ? $value : $default;
} else {
return $default;
}
} else {
// if variable is string, then treat it like GET parameter
if (isset($_GET[$whatVar])) {
$value = trim($_GET[$whatVar]);
return ($value != '') ? $value : $default;
} else {
return $default;
}
}
} | [
"public",
"function",
"getVar",
"(",
"$",
"whatVar",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"whatVar",
")",
")",
"{",
"$",
"whatVar",
"=",
"(",
"int",
")",
"$",
"whatVar",
"+",
"1",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"uri",
"[",
"$",
"whatVar",
"]",
")",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"this",
"->",
"uri",
"[",
"$",
"whatVar",
"]",
")",
";",
"return",
"(",
"$",
"value",
"!=",
"''",
")",
"?",
"$",
"value",
":",
"$",
"default",
";",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}",
"else",
"{",
"// if variable is string, then treat it like GET parameter",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"$",
"whatVar",
"]",
")",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"_GET",
"[",
"$",
"whatVar",
"]",
")",
";",
"return",
"(",
"$",
"value",
"!=",
"''",
")",
"?",
"$",
"value",
":",
"$",
"default",
";",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}",
"}"
]
| Get the variable value from parameters
@param string $whatVar
@param string $default
@return mixed|null|string | [
"Get",
"the",
"variable",
"value",
"from",
"parameters"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Route/DefaultRoute.php#L287-L307 | train |
koldy/framework | src/Koldy/Route/DefaultRoute.php | DefaultRoute.handleException | public function handleException(Throwable $e): void
{
$exceptionHandlerPath = null;
if (($module = Application::getCurrentModule()) !== null) {
$exceptionHandlerPath = Application::getModulePath($module) . 'controllers/ExceptionHandler.php';
if (!is_file($exceptionHandlerPath)) {
$exceptionHandlerPath = Application::getApplicationPath('controllers/ExceptionHandler.php');
}
} else {
$exceptionHandlerPath = Application::getApplicationPath('controllers/ExceptionHandler.php');
}
if (is_file($exceptionHandlerPath)) {
require_once $exceptionHandlerPath;
$exceptionHandler = new \ExceptionHandler($e);
if ($exceptionHandler instanceof ResponseExceptionHandler) {
$exceptionHandler->exec();
} else {
$routeException = new ServerException('Your ExceptionHandler is not instance of ResponseExceptionHandler, can not continue');
Log::emergency($routeException);
Application::terminateWithError('Your ExceptionHandler is not instance of ResponseExceptionHandler, can not continue');
}
} else {
$exceptionHandler = new ResponseExceptionHandler($e);
$exceptionHandler->exec();
}
} | php | public function handleException(Throwable $e): void
{
$exceptionHandlerPath = null;
if (($module = Application::getCurrentModule()) !== null) {
$exceptionHandlerPath = Application::getModulePath($module) . 'controllers/ExceptionHandler.php';
if (!is_file($exceptionHandlerPath)) {
$exceptionHandlerPath = Application::getApplicationPath('controllers/ExceptionHandler.php');
}
} else {
$exceptionHandlerPath = Application::getApplicationPath('controllers/ExceptionHandler.php');
}
if (is_file($exceptionHandlerPath)) {
require_once $exceptionHandlerPath;
$exceptionHandler = new \ExceptionHandler($e);
if ($exceptionHandler instanceof ResponseExceptionHandler) {
$exceptionHandler->exec();
} else {
$routeException = new ServerException('Your ExceptionHandler is not instance of ResponseExceptionHandler, can not continue');
Log::emergency($routeException);
Application::terminateWithError('Your ExceptionHandler is not instance of ResponseExceptionHandler, can not continue');
}
} else {
$exceptionHandler = new ResponseExceptionHandler($e);
$exceptionHandler->exec();
}
} | [
"public",
"function",
"handleException",
"(",
"Throwable",
"$",
"e",
")",
":",
"void",
"{",
"$",
"exceptionHandlerPath",
"=",
"null",
";",
"if",
"(",
"(",
"$",
"module",
"=",
"Application",
"::",
"getCurrentModule",
"(",
")",
")",
"!==",
"null",
")",
"{",
"$",
"exceptionHandlerPath",
"=",
"Application",
"::",
"getModulePath",
"(",
"$",
"module",
")",
".",
"'controllers/ExceptionHandler.php'",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"exceptionHandlerPath",
")",
")",
"{",
"$",
"exceptionHandlerPath",
"=",
"Application",
"::",
"getApplicationPath",
"(",
"'controllers/ExceptionHandler.php'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"exceptionHandlerPath",
"=",
"Application",
"::",
"getApplicationPath",
"(",
"'controllers/ExceptionHandler.php'",
")",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"exceptionHandlerPath",
")",
")",
"{",
"require_once",
"$",
"exceptionHandlerPath",
";",
"$",
"exceptionHandler",
"=",
"new",
"\\",
"ExceptionHandler",
"(",
"$",
"e",
")",
";",
"if",
"(",
"$",
"exceptionHandler",
"instanceof",
"ResponseExceptionHandler",
")",
"{",
"$",
"exceptionHandler",
"->",
"exec",
"(",
")",
";",
"}",
"else",
"{",
"$",
"routeException",
"=",
"new",
"ServerException",
"(",
"'Your ExceptionHandler is not instance of ResponseExceptionHandler, can not continue'",
")",
";",
"Log",
"::",
"emergency",
"(",
"$",
"routeException",
")",
";",
"Application",
"::",
"terminateWithError",
"(",
"'Your ExceptionHandler is not instance of ResponseExceptionHandler, can not continue'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"exceptionHandler",
"=",
"new",
"ResponseExceptionHandler",
"(",
"$",
"e",
")",
";",
"$",
"exceptionHandler",
"->",
"exec",
"(",
")",
";",
"}",
"}"
]
| If your app throws any kind of exception, it will end up here, so, handle it!
@param Throwable $e | [
"If",
"your",
"app",
"throws",
"any",
"kind",
"of",
"exception",
"it",
"will",
"end",
"up",
"here",
"so",
"handle",
"it!"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Route/DefaultRoute.php#L474-L502 | train |
koldy/framework | src/Koldy/Db/Migration/Manager.php | Manager.createMigration | public static function createMigration(string $name): void
{
$directory = Application::getApplicationPath('migrations');
if (!is_dir($directory)) {
Directory::mkdir($directory, 0755);
}
$timestamp = time();
$className = Util::camelCase($name, null, false);
$phpClassName = "Migration_{$timestamp}_{$className}";
$fileName = "{$timestamp}_{$className}.php";
$fullPath = Application::getApplicationPath("migrations/{$fileName}");
$migrationFileContent = file_get_contents(__DIR__ . '/MigrationTemplate.php');
$migrationFileContent = str_replace('templateClassName', $phpClassName, $migrationFileContent);
$migrationFileContent = str_replace('templateClassGenerated', date('r'), $migrationFileContent);
if (file_put_contents($fullPath, $migrationFileContent) === false) {
throw new Application\Exception("Unable to write to migration file on path={$fullPath}");
}
Log::info("Created DB migration with name: {$name}");
Log::info("You may now open application/migrations/{$fileName} and add your migration code");
} | php | public static function createMigration(string $name): void
{
$directory = Application::getApplicationPath('migrations');
if (!is_dir($directory)) {
Directory::mkdir($directory, 0755);
}
$timestamp = time();
$className = Util::camelCase($name, null, false);
$phpClassName = "Migration_{$timestamp}_{$className}";
$fileName = "{$timestamp}_{$className}.php";
$fullPath = Application::getApplicationPath("migrations/{$fileName}");
$migrationFileContent = file_get_contents(__DIR__ . '/MigrationTemplate.php');
$migrationFileContent = str_replace('templateClassName', $phpClassName, $migrationFileContent);
$migrationFileContent = str_replace('templateClassGenerated', date('r'), $migrationFileContent);
if (file_put_contents($fullPath, $migrationFileContent) === false) {
throw new Application\Exception("Unable to write to migration file on path={$fullPath}");
}
Log::info("Created DB migration with name: {$name}");
Log::info("You may now open application/migrations/{$fileName} and add your migration code");
} | [
"public",
"static",
"function",
"createMigration",
"(",
"string",
"$",
"name",
")",
":",
"void",
"{",
"$",
"directory",
"=",
"Application",
"::",
"getApplicationPath",
"(",
"'migrations'",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"Directory",
"::",
"mkdir",
"(",
"$",
"directory",
",",
"0755",
")",
";",
"}",
"$",
"timestamp",
"=",
"time",
"(",
")",
";",
"$",
"className",
"=",
"Util",
"::",
"camelCase",
"(",
"$",
"name",
",",
"null",
",",
"false",
")",
";",
"$",
"phpClassName",
"=",
"\"Migration_{$timestamp}_{$className}\"",
";",
"$",
"fileName",
"=",
"\"{$timestamp}_{$className}.php\"",
";",
"$",
"fullPath",
"=",
"Application",
"::",
"getApplicationPath",
"(",
"\"migrations/{$fileName}\"",
")",
";",
"$",
"migrationFileContent",
"=",
"file_get_contents",
"(",
"__DIR__",
".",
"'/MigrationTemplate.php'",
")",
";",
"$",
"migrationFileContent",
"=",
"str_replace",
"(",
"'templateClassName'",
",",
"$",
"phpClassName",
",",
"$",
"migrationFileContent",
")",
";",
"$",
"migrationFileContent",
"=",
"str_replace",
"(",
"'templateClassGenerated'",
",",
"date",
"(",
"'r'",
")",
",",
"$",
"migrationFileContent",
")",
";",
"if",
"(",
"file_put_contents",
"(",
"$",
"fullPath",
",",
"$",
"migrationFileContent",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Application",
"\\",
"Exception",
"(",
"\"Unable to write to migration file on path={$fullPath}\"",
")",
";",
"}",
"Log",
"::",
"info",
"(",
"\"Created DB migration with name: {$name}\"",
")",
";",
"Log",
"::",
"info",
"(",
"\"You may now open application/migrations/{$fileName} and add your migration code\"",
")",
";",
"}"
]
| Create migration with given name
@param string $name
@throws Application\Exception
@throws \Koldy\Config\Exception
@throws \Koldy\Exception
@throws \Koldy\Filesystem\Exception | [
"Create",
"migration",
"with",
"given",
"name"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Migration/Manager.php#L30-L54 | train |
koldy/framework | src/Koldy/Db/Query/Delete.php | Delete.getQuery | public function getQuery(): Query
{
if ($this->table === null) {
throw new Exception('Unable to build DELETE query when table name is not set');
}
$sql = "DELETE FROM {$this->table}";
if ($this->hasWhere()) {
$sql .= "\nWHERE{$this->getWhereSql()}";
}
return new Query($sql, $this->getBindings(), $this->getAdapterConnection());
} | php | public function getQuery(): Query
{
if ($this->table === null) {
throw new Exception('Unable to build DELETE query when table name is not set');
}
$sql = "DELETE FROM {$this->table}";
if ($this->hasWhere()) {
$sql .= "\nWHERE{$this->getWhereSql()}";
}
return new Query($sql, $this->getBindings(), $this->getAdapterConnection());
} | [
"public",
"function",
"getQuery",
"(",
")",
":",
"Query",
"{",
"if",
"(",
"$",
"this",
"->",
"table",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to build DELETE query when table name is not set'",
")",
";",
"}",
"$",
"sql",
"=",
"\"DELETE FROM {$this->table}\"",
";",
"if",
"(",
"$",
"this",
"->",
"hasWhere",
"(",
")",
")",
"{",
"$",
"sql",
".=",
"\"\\nWHERE{$this->getWhereSql()}\"",
";",
"}",
"return",
"new",
"Query",
"(",
"$",
"sql",
",",
"$",
"this",
"->",
"getBindings",
"(",
")",
",",
"$",
"this",
"->",
"getAdapterConnection",
"(",
")",
")",
";",
"}"
]
| Get the query that will be executed
@return Query
@throws Exception
@throws \Koldy\Db\Exception | [
"Get",
"the",
"query",
"that",
"will",
"be",
"executed"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Delete.php#L59-L72 | train |
koldy/framework | src/Koldy/Response/Redirect.php | Redirect.link | public static function link(string $path, string $assetSite = null): Redirect
{
return self::temporary(Application::route()->asset($path, $assetSite));
} | php | public static function link(string $path, string $assetSite = null): Redirect
{
return self::temporary(Application::route()->asset($path, $assetSite));
} | [
"public",
"static",
"function",
"link",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"assetSite",
"=",
"null",
")",
":",
"Redirect",
"{",
"return",
"self",
"::",
"temporary",
"(",
"Application",
"::",
"route",
"(",
")",
"->",
"asset",
"(",
"$",
"path",
",",
"$",
"assetSite",
")",
")",
";",
"}"
]
| Redirect client the the given link under the same domain.
@param string $path
@param string|null $assetSite
@return Redirect
@deprecated use asset() method instead of this mthod | [
"Redirect",
"client",
"the",
"the",
"given",
"link",
"under",
"the",
"same",
"domain",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/Redirect.php#L97-L100 | train |
koldy/framework | src/Koldy/Log/Message.php | Message.addPHPErrorMessage | public function addPHPErrorMessage(string $message, string $file, int $number, int $line): self
{
$this->messages[] = [
'type' => self::TYPE_PHP,
'message' => $message,
'file' => $file,
'number' => $number,
'line' => $line
];
return $this;
} | php | public function addPHPErrorMessage(string $message, string $file, int $number, int $line): self
{
$this->messages[] = [
'type' => self::TYPE_PHP,
'message' => $message,
'file' => $file,
'number' => $number,
'line' => $line
];
return $this;
} | [
"public",
"function",
"addPHPErrorMessage",
"(",
"string",
"$",
"message",
",",
"string",
"$",
"file",
",",
"int",
"$",
"number",
",",
"int",
"$",
"line",
")",
":",
"self",
"{",
"$",
"this",
"->",
"messages",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"self",
"::",
"TYPE_PHP",
",",
"'message'",
"=>",
"$",
"message",
",",
"'file'",
"=>",
"$",
"file",
",",
"'number'",
"=>",
"$",
"number",
",",
"'line'",
"=>",
"$",
"line",
"]",
";",
"return",
"$",
"this",
";",
"}"
]
| Add standard PHP error message. This is usually for framework's internal use.
@param string $message
@param string $file
@param int $number
@param int $line
@return Message | [
"Add",
"standard",
"PHP",
"error",
"message",
".",
"This",
"is",
"usually",
"for",
"framework",
"s",
"internal",
"use",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Message.php#L114-L125 | train |
koldy/framework | src/Koldy/Log/Message.php | Message.getMessage | public function getMessage(string $delimiter = ' '): string
{
$messages = $this->getMessages();
$return = [];
foreach ($messages as $part) {
if (is_array($part)) {
$type = $part['type'] ?? '';
if (!in_array($type, [self::TYPE_PHP])) {
$return[] = print_r($part, true);
} else {
$return[] = "PHP [{$part['number']}] {$part['message']} in file {$part['file']}:{$part['line']}";
}
} else if (is_object($part) && $part instanceof Throwable) {
$isCli = defined('KOLDY_CLI') && KOLDY_CLI === true;
if ($isCli) {
$on = '';
} else {
$on = ' on ' . Application::getCurrentURL();
}
$className = get_class($part);
$return[] = "[{$className}] {$part->getMessage()}{$on} in {$part->getFile()}:{$part->getLine()}\n\n{$part->getTraceAsString()}";
} else if (is_object($part) && method_exists($part, '__toString')) {
$return[] = $part->__toString();
} else if (is_object($part)) {
$return[] = print_r($part, true);
} else {
$return[] = $part;
}
}
return implode($delimiter, $return);
} | php | public function getMessage(string $delimiter = ' '): string
{
$messages = $this->getMessages();
$return = [];
foreach ($messages as $part) {
if (is_array($part)) {
$type = $part['type'] ?? '';
if (!in_array($type, [self::TYPE_PHP])) {
$return[] = print_r($part, true);
} else {
$return[] = "PHP [{$part['number']}] {$part['message']} in file {$part['file']}:{$part['line']}";
}
} else if (is_object($part) && $part instanceof Throwable) {
$isCli = defined('KOLDY_CLI') && KOLDY_CLI === true;
if ($isCli) {
$on = '';
} else {
$on = ' on ' . Application::getCurrentURL();
}
$className = get_class($part);
$return[] = "[{$className}] {$part->getMessage()}{$on} in {$part->getFile()}:{$part->getLine()}\n\n{$part->getTraceAsString()}";
} else if (is_object($part) && method_exists($part, '__toString')) {
$return[] = $part->__toString();
} else if (is_object($part)) {
$return[] = print_r($part, true);
} else {
$return[] = $part;
}
}
return implode($delimiter, $return);
} | [
"public",
"function",
"getMessage",
"(",
"string",
"$",
"delimiter",
"=",
"' '",
")",
":",
"string",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"getMessages",
"(",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"part",
")",
")",
"{",
"$",
"type",
"=",
"$",
"part",
"[",
"'type'",
"]",
"??",
"''",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"type",
",",
"[",
"self",
"::",
"TYPE_PHP",
"]",
")",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"print_r",
"(",
"$",
"part",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"return",
"[",
"]",
"=",
"\"PHP [{$part['number']}] {$part['message']} in file {$part['file']}:{$part['line']}\"",
";",
"}",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"part",
")",
"&&",
"$",
"part",
"instanceof",
"Throwable",
")",
"{",
"$",
"isCli",
"=",
"defined",
"(",
"'KOLDY_CLI'",
")",
"&&",
"KOLDY_CLI",
"===",
"true",
";",
"if",
"(",
"$",
"isCli",
")",
"{",
"$",
"on",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"on",
"=",
"' on '",
".",
"Application",
"::",
"getCurrentURL",
"(",
")",
";",
"}",
"$",
"className",
"=",
"get_class",
"(",
"$",
"part",
")",
";",
"$",
"return",
"[",
"]",
"=",
"\"[{$className}] {$part->getMessage()}{$on} in {$part->getFile()}:{$part->getLine()}\\n\\n{$part->getTraceAsString()}\"",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"part",
")",
"&&",
"method_exists",
"(",
"$",
"part",
",",
"'__toString'",
")",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"$",
"part",
"->",
"__toString",
"(",
")",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"part",
")",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"print_r",
"(",
"$",
"part",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"return",
"[",
"]",
"=",
"$",
"part",
";",
"}",
"}",
"return",
"implode",
"(",
"$",
"delimiter",
",",
"$",
"return",
")",
";",
"}"
]
| Get the actual message only, depending on data we have. It's like "get the message line"
@param string $delimiter
@return string
@throws \Koldy\Exception | [
"Get",
"the",
"actual",
"message",
"only",
"depending",
"on",
"data",
"we",
"have",
".",
"It",
"s",
"like",
"get",
"the",
"message",
"line"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Message.php#L159-L199 | train |
koldy/framework | src/Koldy/Log/Message.php | Message.getDefaultLine | public function getDefaultLine(): string
{
$messages = $this->getMessages();
if (count($messages) == 0) {
return '';
}
$who = $this->getWho() ?? Log::getWho();
return "{$this->getTimeFormatted()}\t{$who}\t{$this->getLevel()}\t{$this->getMessage()}";
} | php | public function getDefaultLine(): string
{
$messages = $this->getMessages();
if (count($messages) == 0) {
return '';
}
$who = $this->getWho() ?? Log::getWho();
return "{$this->getTimeFormatted()}\t{$who}\t{$this->getLevel()}\t{$this->getMessage()}";
} | [
"public",
"function",
"getDefaultLine",
"(",
")",
":",
"string",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"getMessages",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"messages",
")",
"==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"who",
"=",
"$",
"this",
"->",
"getWho",
"(",
")",
"??",
"Log",
"::",
"getWho",
"(",
")",
";",
"return",
"\"{$this->getTimeFormatted()}\\t{$who}\\t{$this->getLevel()}\\t{$this->getMessage()}\"",
";",
"}"
]
| Get the default "message line" that includes time, level, who triggered it and the information
@return string
@throws \Koldy\Exception | [
"Get",
"the",
"default",
"message",
"line",
"that",
"includes",
"time",
"level",
"who",
"triggered",
"it",
"and",
"the",
"information"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Message.php#L253-L263 | train |
koldy/framework | src/Koldy/Crypt.php | Crypt.encrypt | final public static function encrypt(string $plainText, string $key = null, string $method = null): string
{
if ($method === null) {
$method = static::getMethod();
if (!in_array($method, openssl_get_cipher_methods())) {
throw new CryptException("OpenSSL method={$method} defined in application config is not available");
}
} else {
if (!in_array($method, openssl_get_cipher_methods())) {
throw new CryptException("Passed OpenSSL method={$method} is not available");
}
}
$key = Util::str2hex($key ?? Application::getKey());
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
$encrypted = @openssl_encrypt($plainText, $method, $key, 0, $iv);
if ($encrypted === false) {
throw new CryptException('Unable to encrypt your plain text; check your openssl_default_method in application config');
}
return $encrypted . ':' . bin2hex($iv);
} | php | final public static function encrypt(string $plainText, string $key = null, string $method = null): string
{
if ($method === null) {
$method = static::getMethod();
if (!in_array($method, openssl_get_cipher_methods())) {
throw new CryptException("OpenSSL method={$method} defined in application config is not available");
}
} else {
if (!in_array($method, openssl_get_cipher_methods())) {
throw new CryptException("Passed OpenSSL method={$method} is not available");
}
}
$key = Util::str2hex($key ?? Application::getKey());
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
$encrypted = @openssl_encrypt($plainText, $method, $key, 0, $iv);
if ($encrypted === false) {
throw new CryptException('Unable to encrypt your plain text; check your openssl_default_method in application config');
}
return $encrypted . ':' . bin2hex($iv);
} | [
"final",
"public",
"static",
"function",
"encrypt",
"(",
"string",
"$",
"plainText",
",",
"string",
"$",
"key",
"=",
"null",
",",
"string",
"$",
"method",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"method",
"===",
"null",
")",
"{",
"$",
"method",
"=",
"static",
"::",
"getMethod",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"method",
",",
"openssl_get_cipher_methods",
"(",
")",
")",
")",
"{",
"throw",
"new",
"CryptException",
"(",
"\"OpenSSL method={$method} defined in application config is not available\"",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"method",
",",
"openssl_get_cipher_methods",
"(",
")",
")",
")",
"{",
"throw",
"new",
"CryptException",
"(",
"\"Passed OpenSSL method={$method} is not available\"",
")",
";",
"}",
"}",
"$",
"key",
"=",
"Util",
"::",
"str2hex",
"(",
"$",
"key",
"??",
"Application",
"::",
"getKey",
"(",
")",
")",
";",
"$",
"iv",
"=",
"openssl_random_pseudo_bytes",
"(",
"openssl_cipher_iv_length",
"(",
"$",
"method",
")",
")",
";",
"$",
"encrypted",
"=",
"@",
"openssl_encrypt",
"(",
"$",
"plainText",
",",
"$",
"method",
",",
"$",
"key",
",",
"0",
",",
"$",
"iv",
")",
";",
"if",
"(",
"$",
"encrypted",
"===",
"false",
")",
"{",
"throw",
"new",
"CryptException",
"(",
"'Unable to encrypt your plain text; check your openssl_default_method in application config'",
")",
";",
"}",
"return",
"$",
"encrypted",
".",
"':'",
".",
"bin2hex",
"(",
"$",
"iv",
")",
";",
"}"
]
| Encrypt given texts. If method is not provided, default will be used
@param string $plainText
@param string|null $key
@param string|null $method
@return string
@throws Config\Exception
@throws CryptException
@throws Exception | [
"Encrypt",
"given",
"texts",
".",
"If",
"method",
"is",
"not",
"provided",
"default",
"will",
"be",
"used"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Crypt.php#L39-L63 | train |
koldy/framework | src/Koldy/Config.php | Config.loadFrom | public function loadFrom(string $path): void
{
$this->path = $path;
if (is_file($path)) {
$this->data = require $path;
if (!is_array($this->data)) {
throw new ConfigException("Config loaded from path={$path} is not an array");
}
$this->loadedAt = time();
} else {
throw new ConfigException('Unable to load config from path=' . $path);
}
} | php | public function loadFrom(string $path): void
{
$this->path = $path;
if (is_file($path)) {
$this->data = require $path;
if (!is_array($this->data)) {
throw new ConfigException("Config loaded from path={$path} is not an array");
}
$this->loadedAt = time();
} else {
throw new ConfigException('Unable to load config from path=' . $path);
}
} | [
"public",
"function",
"loadFrom",
"(",
"string",
"$",
"path",
")",
":",
"void",
"{",
"$",
"this",
"->",
"path",
"=",
"$",
"path",
";",
"if",
"(",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"require",
"$",
"path",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"Config loaded from path={$path} is not an array\"",
")",
";",
"}",
"$",
"this",
"->",
"loadedAt",
"=",
"time",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Unable to load config from path='",
".",
"$",
"path",
")",
";",
"}",
"}"
]
| After config instance is constructed, you should load configuration from file by using this method. Otherwise,
configuration should be set by using set or setData methods.
@param string $path
@throws ConfigException | [
"After",
"config",
"instance",
"is",
"constructed",
"you",
"should",
"load",
"configuration",
"from",
"file",
"by",
"using",
"this",
"method",
".",
"Otherwise",
"configuration",
"should",
"be",
"set",
"by",
"using",
"set",
"or",
"setData",
"methods",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Config.php#L84-L99 | train |
koldy/framework | src/Koldy/Config.php | Config.isOlderThen | public function isOlderThen(int $numberOfSeconds): bool
{
if ($this->loadedAt == null) {
throw new ConfigException('Can not know how old is config when config is not set nor loaded yet; Please load config first for config name=' . $this->name);
}
return time() - $numberOfSeconds > $this->loadedAt;
} | php | public function isOlderThen(int $numberOfSeconds): bool
{
if ($this->loadedAt == null) {
throw new ConfigException('Can not know how old is config when config is not set nor loaded yet; Please load config first for config name=' . $this->name);
}
return time() - $numberOfSeconds > $this->loadedAt;
} | [
"public",
"function",
"isOlderThen",
"(",
"int",
"$",
"numberOfSeconds",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"loadedAt",
"==",
"null",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Can not know how old is config when config is not set nor loaded yet; Please load config first for config name='",
".",
"$",
"this",
"->",
"name",
")",
";",
"}",
"return",
"time",
"(",
")",
"-",
"$",
"numberOfSeconds",
">",
"$",
"this",
"->",
"loadedAt",
";",
"}"
]
| Returns true if loaded configuration is older then the seconds passed as first argument, `false` otherwise.
This is useful if your CLI script is running for the long time and there's possibility that config
was updated in meantime.
@param int $numberOfSeconds
@return bool
@throws ConfigException | [
"Returns",
"true",
"if",
"loaded",
"configuration",
"is",
"older",
"then",
"the",
"seconds",
"passed",
"as",
"first",
"argument",
"false",
"otherwise",
".",
"This",
"is",
"useful",
"if",
"your",
"CLI",
"script",
"is",
"running",
"for",
"the",
"long",
"time",
"and",
"there",
"s",
"possibility",
"that",
"config",
"was",
"updated",
"in",
"meantime",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Config.php#L169-L176 | train |
koldy/framework | src/Koldy/Config.php | Config.has | public function has(string $key): bool
{
if (!is_array($this->data)) {
throw new ConfigException('Unable to get config data when config wasn\'t loaded for config name=' . $this->name);
}
return array_key_exists($key, $this->data);
} | php | public function has(string $key): bool
{
if (!is_array($this->data)) {
throw new ConfigException('Unable to get config data when config wasn\'t loaded for config name=' . $this->name);
}
return array_key_exists($key, $this->data);
} | [
"public",
"function",
"has",
"(",
"string",
"$",
"key",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Unable to get config data when config wasn\\'t loaded for config name='",
".",
"$",
"this",
"->",
"name",
")",
";",
"}",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"data",
")",
";",
"}"
]
| Returns true if requested key exists in current configuration, false otherwise.
@param string $key
@return bool
@throws ConfigException | [
"Returns",
"true",
"if",
"requested",
"key",
"exists",
"in",
"current",
"configuration",
"false",
"otherwise",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Config.php#L202-L209 | train |
koldy/framework | src/Koldy/Config.php | Config.get | public function get(string $key, $defaultValue = null)
{
if (!is_array($this->data)) {
throw new ConfigException('Unable to get config data when config wasn\'t loaded for config name=' . $this->name);
}
if (!array_key_exists($key, $this->data)) {
return $defaultValue;
}
if (!$this->isPointerConfig()) {
return $this->data[$key];
} else {
// this is pointer config, let's examine what we have
$counter = 0;
do {
if (!isset($this->data[$key])) {
throw new ConfigException("Trying to get non-existing config key={$key} in config name={$this->name()} after {$counter} 'redirects'");
}
$config = $this->data[$key];
if (!is_string($config)) {
return $config;
} else {
$key = $config;
}
} while ($counter++ < 10);
}
// if you get to this line, then something is wrong
throw new ConfigException("{$this} has too many \"redirects\"");
} | php | public function get(string $key, $defaultValue = null)
{
if (!is_array($this->data)) {
throw new ConfigException('Unable to get config data when config wasn\'t loaded for config name=' . $this->name);
}
if (!array_key_exists($key, $this->data)) {
return $defaultValue;
}
if (!$this->isPointerConfig()) {
return $this->data[$key];
} else {
// this is pointer config, let's examine what we have
$counter = 0;
do {
if (!isset($this->data[$key])) {
throw new ConfigException("Trying to get non-existing config key={$key} in config name={$this->name()} after {$counter} 'redirects'");
}
$config = $this->data[$key];
if (!is_string($config)) {
return $config;
} else {
$key = $config;
}
} while ($counter++ < 10);
}
// if you get to this line, then something is wrong
throw new ConfigException("{$this} has too many \"redirects\"");
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"key",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Unable to get config data when config wasn\\'t loaded for config name='",
".",
"$",
"this",
"->",
"name",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"return",
"$",
"defaultValue",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isPointerConfig",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"// this is pointer config, let's examine what we have",
"$",
"counter",
"=",
"0",
";",
"do",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"Trying to get non-existing config key={$key} in config name={$this->name()} after {$counter} 'redirects'\"",
")",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"config",
")",
")",
"{",
"return",
"$",
"config",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"$",
"config",
";",
"}",
"}",
"while",
"(",
"$",
"counter",
"++",
"<",
"10",
")",
";",
"}",
"// if you get to this line, then something is wrong",
"throw",
"new",
"ConfigException",
"(",
"\"{$this} has too many \\\"redirects\\\"\"",
")",
";",
"}"
]
| Gets the value on requested key. First argument is key's name, second argument is default value you want
to get if key is not set.
@param string $key
@param mixed $defaultValue
@return mixed
@throws ConfigException | [
"Gets",
"the",
"value",
"on",
"requested",
"key",
".",
"First",
"argument",
"is",
"key",
"s",
"name",
"second",
"argument",
"is",
"default",
"value",
"you",
"want",
"to",
"get",
"if",
"key",
"is",
"not",
"set",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Config.php#L221-L254 | train |
koldy/framework | src/Koldy/Config.php | Config.delete | public function delete(string $key): void
{
if (array_key_exists($key, $this->data)) {
unset($this->data[$key]);
}
} | php | public function delete(string $key): void
{
if (array_key_exists($key, $this->data)) {
unset($this->data[$key]);
}
} | [
"public",
"function",
"delete",
"(",
"string",
"$",
"key",
")",
":",
"void",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
]
| When config is loaded or set, you can delete the presence of key by providing its name as first argument.
This is advanced usage and should be avoided as much as possible. If configuration was loaded from file, this
won't alter the file on file system.
@param string $key | [
"When",
"config",
"is",
"loaded",
"or",
"set",
"you",
"can",
"delete",
"the",
"presence",
"of",
"key",
"by",
"providing",
"its",
"name",
"as",
"first",
"argument",
".",
"This",
"is",
"advanced",
"usage",
"and",
"should",
"be",
"avoided",
"as",
"much",
"as",
"possible",
".",
"If",
"configuration",
"was",
"loaded",
"from",
"file",
"this",
"won",
"t",
"alter",
"the",
"file",
"on",
"file",
"system",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Config.php#L263-L268 | train |
koldy/framework | src/Koldy/Config.php | Config.getArrayItem | public function getArrayItem(string $key, string $subKey, $defaultValue = null)
{
$expectedArray = $this->get($key, []);
if (!is_array($expectedArray)) {
$type = gettype($expectedArray);
throw new ConfigException("Trying to fetch array from config={$this->name()} under key={$key}, but got '{$type}' instead");
}
return array_key_exists($subKey, $expectedArray) ? $expectedArray[$subKey] : $defaultValue;
} | php | public function getArrayItem(string $key, string $subKey, $defaultValue = null)
{
$expectedArray = $this->get($key, []);
if (!is_array($expectedArray)) {
$type = gettype($expectedArray);
throw new ConfigException("Trying to fetch array from config={$this->name()} under key={$key}, but got '{$type}' instead");
}
return array_key_exists($subKey, $expectedArray) ? $expectedArray[$subKey] : $defaultValue;
} | [
"public",
"function",
"getArrayItem",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"subKey",
",",
"$",
"defaultValue",
"=",
"null",
")",
"{",
"$",
"expectedArray",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
",",
"[",
"]",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"expectedArray",
")",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"expectedArray",
")",
";",
"throw",
"new",
"ConfigException",
"(",
"\"Trying to fetch array from config={$this->name()} under key={$key}, but got '{$type}' instead\"",
")",
";",
"}",
"return",
"array_key_exists",
"(",
"$",
"subKey",
",",
"$",
"expectedArray",
")",
"?",
"$",
"expectedArray",
"[",
"$",
"subKey",
"]",
":",
"$",
"defaultValue",
";",
"}"
]
| If targeted key in first level is array, then you can use this to fetch the key from that array
@param string $key
@param string $subKey
@param mixed|null $defaultValue
@return mixed
@throws ConfigException
@throws Exception | [
"If",
"targeted",
"key",
"in",
"first",
"level",
"is",
"array",
"then",
"you",
"can",
"use",
"this",
"to",
"fetch",
"the",
"key",
"from",
"that",
"array"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Config.php#L281-L291 | train |
koldy/framework | src/Koldy/Config.php | Config.getFirstKey | public function getFirstKey(): string
{
$config = $this->data;
if (count($config) == 0) {
throw new ConfigException('Unable to get first config key when config is empty');
}
$key = array_keys($config)[0];
if ($this->isPointerConfig()) {
$counter = 0;
while (is_string($key) && $counter++ < 50) {
if (isset($this->data[$key])) {
$value = $this->data[$key];
} else {
throw new ConfigException("{$this} found invalid config pointer named={$key}");
}
if (is_string($value)) {
$key = $value;
}
}
if ($counter == 50) {
throw new ConfigException('Unable to get first key in config after 50 "redirects"');
}
}
return $key;
} | php | public function getFirstKey(): string
{
$config = $this->data;
if (count($config) == 0) {
throw new ConfigException('Unable to get first config key when config is empty');
}
$key = array_keys($config)[0];
if ($this->isPointerConfig()) {
$counter = 0;
while (is_string($key) && $counter++ < 50) {
if (isset($this->data[$key])) {
$value = $this->data[$key];
} else {
throw new ConfigException("{$this} found invalid config pointer named={$key}");
}
if (is_string($value)) {
$key = $value;
}
}
if ($counter == 50) {
throw new ConfigException('Unable to get first key in config after 50 "redirects"');
}
}
return $key;
} | [
"public",
"function",
"getFirstKey",
"(",
")",
":",
"string",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"data",
";",
"if",
"(",
"count",
"(",
"$",
"config",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Unable to get first config key when config is empty'",
")",
";",
"}",
"$",
"key",
"=",
"array_keys",
"(",
"$",
"config",
")",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"isPointerConfig",
"(",
")",
")",
"{",
"$",
"counter",
"=",
"0",
";",
"while",
"(",
"is_string",
"(",
"$",
"key",
")",
"&&",
"$",
"counter",
"++",
"<",
"50",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"{$this} found invalid config pointer named={$key}\"",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"$",
"counter",
"==",
"50",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'Unable to get first key in config after 50 \"redirects\"'",
")",
";",
"}",
"}",
"return",
"$",
"key",
";",
"}"
]
| Get the first key in config. Useful for pointer configs.
@return string
@throws ConfigException | [
"Get",
"the",
"first",
"key",
"in",
"config",
".",
"Useful",
"for",
"pointer",
"configs",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Config.php#L299-L329 | train |
koldy/framework | src/Koldy/Config.php | Config.checkPresence | public function checkPresence(array $keys, bool $throwException = true): array
{
$missingKeys = [];
foreach ($keys as $key) {
if (!array_key_exists($key, $this->data)) {
$missingKeys[] = $key;
}
}
if ($throwException && count($missingKeys) > 0) {
$missingKeys = implode(', ', $missingKeys);
throw new ConfigException("Following keys are missing in {$this}: {$missingKeys}");
}
return $missingKeys;
} | php | public function checkPresence(array $keys, bool $throwException = true): array
{
$missingKeys = [];
foreach ($keys as $key) {
if (!array_key_exists($key, $this->data)) {
$missingKeys[] = $key;
}
}
if ($throwException && count($missingKeys) > 0) {
$missingKeys = implode(', ', $missingKeys);
throw new ConfigException("Following keys are missing in {$this}: {$missingKeys}");
}
return $missingKeys;
} | [
"public",
"function",
"checkPresence",
"(",
"array",
"$",
"keys",
",",
"bool",
"$",
"throwException",
"=",
"true",
")",
":",
"array",
"{",
"$",
"missingKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"missingKeys",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"if",
"(",
"$",
"throwException",
"&&",
"count",
"(",
"$",
"missingKeys",
")",
">",
"0",
")",
"{",
"$",
"missingKeys",
"=",
"implode",
"(",
"', '",
",",
"$",
"missingKeys",
")",
";",
"throw",
"new",
"ConfigException",
"(",
"\"Following keys are missing in {$this}: {$missingKeys}\"",
")",
";",
"}",
"return",
"$",
"missingKeys",
";",
"}"
]
| Checks the presence of given config keys; if any of required keys is missing, exception will be thrown. If you
want to know which keys are missing, then pass false as second argument and you'll get the array of missing keys.
@param array $keys
@param bool $throwException
@return array
@throws ConfigException | [
"Checks",
"the",
"presence",
"of",
"given",
"config",
"keys",
";",
"if",
"any",
"of",
"required",
"keys",
"is",
"missing",
"exception",
"will",
"be",
"thrown",
".",
"If",
"you",
"want",
"to",
"know",
"which",
"keys",
"are",
"missing",
"then",
"pass",
"false",
"as",
"second",
"argument",
"and",
"you",
"ll",
"get",
"the",
"array",
"of",
"missing",
"keys",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Config.php#L341-L357 | train |
koldy/framework | src/Koldy/Mail/Adapter/AbstractMailAdapter.php | AbstractMailAdapter.removeHeader | public function removeHeader(string $name)
{
if (array_key_exists($name, $this->headers)) {
unset($this->headers[$name]);
}
return $this;
} | php | public function removeHeader(string $name)
{
if (array_key_exists($name, $this->headers)) {
unset($this->headers[$name]);
}
return $this;
} | [
"public",
"function",
"removeHeader",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"headers",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Remove the header
@param string $name
@return $this | [
"Remove",
"the",
"header"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Mail/Adapter/AbstractMailAdapter.php#L166-L173 | train |
koldy/framework | src/Koldy/Mail/Adapter/AbstractMailAdapter.php | AbstractMailAdapter.getAddressValue | protected function getAddressValue(string $email, string $name = null)
{
if ($name === null || $name == '') {
return $email;
} else {
return "{$name} <{$email}>";
}
} | php | protected function getAddressValue(string $email, string $name = null)
{
if ($name === null || $name == '') {
return $email;
} else {
return "{$name} <{$email}>";
}
} | [
"protected",
"function",
"getAddressValue",
"(",
"string",
"$",
"email",
",",
"string",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"null",
"||",
"$",
"name",
"==",
"''",
")",
"{",
"return",
"$",
"email",
";",
"}",
"else",
"{",
"return",
"\"{$name} <{$email}>\"",
";",
"}",
"}"
]
| Internal helper to get the proper address header value
@param string $email
@param string|null $name
@return string | [
"Internal",
"helper",
"to",
"get",
"the",
"proper",
"address",
"header",
"value"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Mail/Adapter/AbstractMailAdapter.php#L219-L226 | train |
koldy/framework | src/Koldy/Mail/Adapter/CommonMailAdapter.php | CommonMailAdapter.attachFile | public function attachFile(string $filePath, string $name = null)
{
$this->attachedFiles[] = [
'path' => $filePath,
'name' => $name
];
return $this;
} | php | public function attachFile(string $filePath, string $name = null)
{
$this->attachedFiles[] = [
'path' => $filePath,
'name' => $name
];
return $this;
} | [
"public",
"function",
"attachFile",
"(",
"string",
"$",
"filePath",
",",
"string",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"attachedFiles",
"[",
"]",
"=",
"[",
"'path'",
"=>",
"$",
"filePath",
",",
"'name'",
"=>",
"$",
"name",
"]",
";",
"return",
"$",
"this",
";",
"}"
]
| Attach file to e-mail
@param string $filePath
@param string $name [optional]
@return $this | [
"Attach",
"file",
"to",
"e",
"-",
"mail"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Mail/Adapter/CommonMailAdapter.php#L195-L203 | train |
koldy/framework | src/Koldy/Route.php | Route.is | public static function is(string $controller, string $action): bool
{
return $controller == Application::route()->getControllerUrl() && $action == Application::route()->getActionUrl();
} | php | public static function is(string $controller, string $action): bool
{
return $controller == Application::route()->getControllerUrl() && $action == Application::route()->getActionUrl();
} | [
"public",
"static",
"function",
"is",
"(",
"string",
"$",
"controller",
",",
"string",
"$",
"action",
")",
":",
"bool",
"{",
"return",
"$",
"controller",
"==",
"Application",
"::",
"route",
"(",
")",
"->",
"getControllerUrl",
"(",
")",
"&&",
"$",
"action",
"==",
"Application",
"::",
"route",
"(",
")",
"->",
"getActionUrl",
"(",
")",
";",
"}"
]
| Are given controller and action current working controller and action?
@param string $controller in the url format
@param string $action in the url format
@return bool
@throws Exception | [
"Are",
"given",
"controller",
"and",
"action",
"current",
"working",
"controller",
"and",
"action?"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Route.php#L102-L105 | train |
koldy/framework | src/Koldy/Route.php | Route.isModule | public static function isModule(string $module, string $controller = null, string $action = null): bool
{
$route = Application::route();
if ($module === $route->getModuleUrl()) {
if ($controller === null) {
return true;
} else {
if ($controller === $route->getControllerUrl()) {
// now we have matched module and controller
if ($action === null) {
return true;
} else {
return ($action === $route->getActionUrl());
}
} else {
return false;
}
}
} else {
return false;
}
} | php | public static function isModule(string $module, string $controller = null, string $action = null): bool
{
$route = Application::route();
if ($module === $route->getModuleUrl()) {
if ($controller === null) {
return true;
} else {
if ($controller === $route->getControllerUrl()) {
// now we have matched module and controller
if ($action === null) {
return true;
} else {
return ($action === $route->getActionUrl());
}
} else {
return false;
}
}
} else {
return false;
}
} | [
"public",
"static",
"function",
"isModule",
"(",
"string",
"$",
"module",
",",
"string",
"$",
"controller",
"=",
"null",
",",
"string",
"$",
"action",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"route",
"=",
"Application",
"::",
"route",
"(",
")",
";",
"if",
"(",
"$",
"module",
"===",
"$",
"route",
"->",
"getModuleUrl",
"(",
")",
")",
"{",
"if",
"(",
"$",
"controller",
"===",
"null",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"controller",
"===",
"$",
"route",
"->",
"getControllerUrl",
"(",
")",
")",
"{",
"// now we have matched module and controller",
"if",
"(",
"$",
"action",
"===",
"null",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"(",
"$",
"action",
"===",
"$",
"route",
"->",
"getActionUrl",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Is this the matching module, controller and action?
@param string $module
@param string $controller
@param string $action
@return bool
@throws Exception | [
"Is",
"this",
"the",
"matching",
"module",
"controller",
"and",
"action?"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Route.php#L117-L138 | train |
dewsign/maxfactor-laravel-support | src/Webpage/Middleware/EnvironmentAuth.php | EnvironmentAuth.handle | public function handle($request, Closure $next, $guard = null, $field = null)
{
if (!App::environment(config('auth.environments', ['staging']))) {
return $next($request);
}
return parent::handle($request, $next, $guard);
} | php | public function handle($request, Closure $next, $guard = null, $field = null)
{
if (!App::environment(config('auth.environments', ['staging']))) {
return $next($request);
}
return parent::handle($request, $next, $guard);
} | [
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
",",
"$",
"guard",
"=",
"null",
",",
"$",
"field",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"App",
"::",
"environment",
"(",
"config",
"(",
"'auth.environments'",
",",
"[",
"'staging'",
"]",
")",
")",
")",
"{",
"return",
"$",
"next",
"(",
"$",
"request",
")",
";",
"}",
"return",
"parent",
"::",
"handle",
"(",
"$",
"request",
",",
"$",
"next",
",",
"$",
"guard",
")",
";",
"}"
]
| Only allow authenticated users on environments specified in the auth config.
@param \Illuminate\Http\Request $request
@param \Closure $next
@param string|null $guard
@return mixed | [
"Only",
"allow",
"authenticated",
"users",
"on",
"environments",
"specified",
"in",
"the",
"auth",
"config",
"."
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Webpage/Middleware/EnvironmentAuth.php#L19-L26 | train |
koldy/framework | src/Koldy/Application.php | Application.terminateWithError | public static function terminateWithError(string $message, int $errorCode = 503): void
{
http_response_code($errorCode);
header('Retry-After: 300'); // 300 seconds / 5 minutes
print $message;
exit(1);
} | php | public static function terminateWithError(string $message, int $errorCode = 503): void
{
http_response_code($errorCode);
header('Retry-After: 300'); // 300 seconds / 5 minutes
print $message;
exit(1);
} | [
"public",
"static",
"function",
"terminateWithError",
"(",
"string",
"$",
"message",
",",
"int",
"$",
"errorCode",
"=",
"503",
")",
":",
"void",
"{",
"http_response_code",
"(",
"$",
"errorCode",
")",
";",
"header",
"(",
"'Retry-After: 300'",
")",
";",
"// 300 seconds / 5 minutes",
"print",
"$",
"message",
";",
"exit",
"(",
"1",
")",
";",
"}"
]
| Terminate execution immediately - use it when there's no other way of recovering from error, usually
in boot procedure, when exceptions are not loaded yet and etc.
Some parts of framework use this method, that's why it's public. You should never get into case when
using this method would be recommended.
@param string $message
@param int $errorCode | [
"Terminate",
"execution",
"immediately",
"-",
"use",
"it",
"when",
"there",
"s",
"no",
"other",
"way",
"of",
"recovering",
"from",
"error",
"usually",
"in",
"boot",
"procedure",
"when",
"exceptions",
"are",
"not",
"loaded",
"yet",
"and",
"etc",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L185-L191 | train |
koldy/framework | src/Koldy/Application.php | Application.getApplicationPath | public static function getApplicationPath(string $append = null): string
{
if ($append === null) {
return static::$applicationPath;
} else {
return str_replace(DS . DS, DS, static::$applicationPath . $append);
}
} | php | public static function getApplicationPath(string $append = null): string
{
if ($append === null) {
return static::$applicationPath;
} else {
return str_replace(DS . DS, DS, static::$applicationPath . $append);
}
} | [
"public",
"static",
"function",
"getApplicationPath",
"(",
"string",
"$",
"append",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"append",
"===",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"applicationPath",
";",
"}",
"else",
"{",
"return",
"str_replace",
"(",
"DS",
".",
"DS",
",",
"DS",
",",
"static",
"::",
"$",
"applicationPath",
".",
"$",
"append",
")",
";",
"}",
"}"
]
| Get the path to application folder with ending slash
@param string $append [optional] append anything you want to application path
@return string
@example /var/www/your.site/com/application/ | [
"Get",
"the",
"path",
"to",
"application",
"folder",
"with",
"ending",
"slash"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L450-L457 | train |
koldy/framework | src/Koldy/Application.php | Application.getStoragePath | public static function getStoragePath(string $append = null): string
{
if ($append === null) {
return static::$storagePath;
} else {
return str_replace(DS . DS, DS, static::$storagePath . $append);
}
} | php | public static function getStoragePath(string $append = null): string
{
if ($append === null) {
return static::$storagePath;
} else {
return str_replace(DS . DS, DS, static::$storagePath . $append);
}
} | [
"public",
"static",
"function",
"getStoragePath",
"(",
"string",
"$",
"append",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"append",
"===",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"storagePath",
";",
"}",
"else",
"{",
"return",
"str_replace",
"(",
"DS",
".",
"DS",
",",
"DS",
",",
"static",
"::",
"$",
"storagePath",
".",
"$",
"append",
")",
";",
"}",
"}"
]
| Get the path to storage folder with ending slash
@param string $append [optional] append anything you want to application path
@return string
@example /var/www/your.site/com/storage/ | [
"Get",
"the",
"path",
"to",
"storage",
"folder",
"with",
"ending",
"slash"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L467-L474 | train |
koldy/framework | src/Koldy/Application.php | Application.getPublicPath | public static function getPublicPath(string $append = null): string
{
if ($append === null) {
return static::$publicPath;
} else {
return str_replace(DS . DS, DS, static::$publicPath . $append);
}
} | php | public static function getPublicPath(string $append = null): string
{
if ($append === null) {
return static::$publicPath;
} else {
return str_replace(DS . DS, DS, static::$publicPath . $append);
}
} | [
"public",
"static",
"function",
"getPublicPath",
"(",
"string",
"$",
"append",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"append",
"===",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"publicPath",
";",
"}",
"else",
"{",
"return",
"str_replace",
"(",
"DS",
".",
"DS",
",",
"DS",
",",
"static",
"::",
"$",
"publicPath",
".",
"$",
"append",
")",
";",
"}",
"}"
]
| Get the path to the public folder with ending slash
@param string $append [optional] append anything you want to application path
@return string
@example /var/www/your.site/com/public/ | [
"Get",
"the",
"path",
"to",
"the",
"public",
"folder",
"with",
"ending",
"slash"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L484-L491 | train |
koldy/framework | src/Koldy/Application.php | Application.getViewPath | public static function getViewPath(string $append = null): string
{
if ($append === null) {
return static::$viewPath;
} else {
return str_replace(DS . DS, DS, static::$viewPath . $append);
}
} | php | public static function getViewPath(string $append = null): string
{
if ($append === null) {
return static::$viewPath;
} else {
return str_replace(DS . DS, DS, static::$viewPath . $append);
}
} | [
"public",
"static",
"function",
"getViewPath",
"(",
"string",
"$",
"append",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"append",
"===",
"null",
")",
"{",
"return",
"static",
"::",
"$",
"viewPath",
";",
"}",
"else",
"{",
"return",
"str_replace",
"(",
"DS",
".",
"DS",
",",
"DS",
",",
"static",
"::",
"$",
"viewPath",
".",
"$",
"append",
")",
";",
"}",
"}"
]
| Get the path to directory with views
@param string|null $append
@return string | [
"Get",
"the",
"path",
"to",
"directory",
"with",
"views"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L500-L507 | train |
koldy/framework | src/Koldy/Application.php | Application.getConfig | public static function getConfig(string $name, bool $isPointerConfig = false): Config
{
if (isset(static::$configs[$name])) {
return static::$configs[$name];
}
// otherwise, lookup for config on file system
$applicationConfig = static::$configs['application'] ?? null;
if ($applicationConfig === null) {
throw new ConfigException('The main "application" config is NOT passed to the web app so framework can\'t load other configs because it doesn\'t know where they are');
}
$configFiles = $applicationConfig->get('config', []);
$config = new Config($name, $isPointerConfig);
if (array_key_exists($name, $configFiles)) {
$path = stream_resolve_include_path($configFiles[$name]);
} else {
$path = static::$configsPath . $name . '.php';
}
$config->loadFrom($path);
static::$configs[$name] = $config;
return $config;
} | php | public static function getConfig(string $name, bool $isPointerConfig = false): Config
{
if (isset(static::$configs[$name])) {
return static::$configs[$name];
}
// otherwise, lookup for config on file system
$applicationConfig = static::$configs['application'] ?? null;
if ($applicationConfig === null) {
throw new ConfigException('The main "application" config is NOT passed to the web app so framework can\'t load other configs because it doesn\'t know where they are');
}
$configFiles = $applicationConfig->get('config', []);
$config = new Config($name, $isPointerConfig);
if (array_key_exists($name, $configFiles)) {
$path = stream_resolve_include_path($configFiles[$name]);
} else {
$path = static::$configsPath . $name . '.php';
}
$config->loadFrom($path);
static::$configs[$name] = $config;
return $config;
} | [
"public",
"static",
"function",
"getConfig",
"(",
"string",
"$",
"name",
",",
"bool",
"$",
"isPointerConfig",
"=",
"false",
")",
":",
"Config",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"configs",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"configs",
"[",
"$",
"name",
"]",
";",
"}",
"// otherwise, lookup for config on file system",
"$",
"applicationConfig",
"=",
"static",
"::",
"$",
"configs",
"[",
"'application'",
"]",
"??",
"null",
";",
"if",
"(",
"$",
"applicationConfig",
"===",
"null",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"'The main \"application\" config is NOT passed to the web app so framework can\\'t load other configs because it doesn\\'t know where they are'",
")",
";",
"}",
"$",
"configFiles",
"=",
"$",
"applicationConfig",
"->",
"get",
"(",
"'config'",
",",
"[",
"]",
")",
";",
"$",
"config",
"=",
"new",
"Config",
"(",
"$",
"name",
",",
"$",
"isPointerConfig",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"configFiles",
")",
")",
"{",
"$",
"path",
"=",
"stream_resolve_include_path",
"(",
"$",
"configFiles",
"[",
"$",
"name",
"]",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"static",
"::",
"$",
"configsPath",
".",
"$",
"name",
".",
"'.php'",
";",
"}",
"$",
"config",
"->",
"loadFrom",
"(",
"$",
"path",
")",
";",
"static",
"::",
"$",
"configs",
"[",
"$",
"name",
"]",
"=",
"$",
"config",
";",
"return",
"$",
"config",
";",
"}"
]
| Get the configs from any config file, fetched by config name. Config name is the name on file system,
so you can fetch Koldy's config files or your own configs.
@param string $name
@param bool $isPointerConfig
@return Config
@throws Exception | [
"Get",
"the",
"configs",
"from",
"any",
"config",
"file",
"fetched",
"by",
"config",
"name",
".",
"Config",
"name",
"is",
"the",
"name",
"on",
"file",
"system",
"so",
"you",
"can",
"fetch",
"Koldy",
"s",
"config",
"files",
"or",
"your",
"own",
"configs",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L559-L585 | train |
koldy/framework | src/Koldy/Application.php | Application.getCurrentURL | public static function getCurrentURL(): Url
{
if (static::$currentUrl instanceof Url) {
return static::$currentUrl;
}
if (Application::isCli()) {
throw new ApplicationException('Can not get current URL while running in CLI mode; URL doesn\'t exist in CLI mode');
}
static::$currentUrl = new Url(static::getDomainWithSchema() . static::getUri());
return static::$currentUrl;
} | php | public static function getCurrentURL(): Url
{
if (static::$currentUrl instanceof Url) {
return static::$currentUrl;
}
if (Application::isCli()) {
throw new ApplicationException('Can not get current URL while running in CLI mode; URL doesn\'t exist in CLI mode');
}
static::$currentUrl = new Url(static::getDomainWithSchema() . static::getUri());
return static::$currentUrl;
} | [
"public",
"static",
"function",
"getCurrentURL",
"(",
")",
":",
"Url",
"{",
"if",
"(",
"static",
"::",
"$",
"currentUrl",
"instanceof",
"Url",
")",
"{",
"return",
"static",
"::",
"$",
"currentUrl",
";",
"}",
"if",
"(",
"Application",
"::",
"isCli",
"(",
")",
")",
"{",
"throw",
"new",
"ApplicationException",
"(",
"'Can not get current URL while running in CLI mode; URL doesn\\'t exist in CLI mode'",
")",
";",
"}",
"static",
"::",
"$",
"currentUrl",
"=",
"new",
"Url",
"(",
"static",
"::",
"getDomainWithSchema",
"(",
")",
".",
"static",
"::",
"getUri",
"(",
")",
")",
";",
"return",
"static",
"::",
"$",
"currentUrl",
";",
"}"
]
| Get full current URL, with schema
@return Url
@throws Exception | [
"Get",
"full",
"current",
"URL",
"with",
"schema"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L699-L711 | train |
koldy/framework | src/Koldy/Application.php | Application.route | public static function route(): AbstractRoute
{
if (static::$routing === null) {
$config = static::getConfig('application');
$routingClassName = $config->get('routing_class');
$routeOptions = $config->get('routing_options') ?? [];
if ($routingClassName == null) {
static::terminateWithError('Can not init routing class when routing_class is not set in application config');
}
static::$routing = new $routingClassName($routeOptions);
}
return static::$routing;
} | php | public static function route(): AbstractRoute
{
if (static::$routing === null) {
$config = static::getConfig('application');
$routingClassName = $config->get('routing_class');
$routeOptions = $config->get('routing_options') ?? [];
if ($routingClassName == null) {
static::terminateWithError('Can not init routing class when routing_class is not set in application config');
}
static::$routing = new $routingClassName($routeOptions);
}
return static::$routing;
} | [
"public",
"static",
"function",
"route",
"(",
")",
":",
"AbstractRoute",
"{",
"if",
"(",
"static",
"::",
"$",
"routing",
"===",
"null",
")",
"{",
"$",
"config",
"=",
"static",
"::",
"getConfig",
"(",
"'application'",
")",
";",
"$",
"routingClassName",
"=",
"$",
"config",
"->",
"get",
"(",
"'routing_class'",
")",
";",
"$",
"routeOptions",
"=",
"$",
"config",
"->",
"get",
"(",
"'routing_options'",
")",
"??",
"[",
"]",
";",
"if",
"(",
"$",
"routingClassName",
"==",
"null",
")",
"{",
"static",
"::",
"terminateWithError",
"(",
"'Can not init routing class when routing_class is not set in application config'",
")",
";",
"}",
"static",
"::",
"$",
"routing",
"=",
"new",
"$",
"routingClassName",
"(",
"$",
"routeOptions",
")",
";",
"}",
"return",
"static",
"::",
"$",
"routing",
";",
"}"
]
| Get the initialized routing class
@return \Koldy\Route\AbstractRoute
@throws Exception | [
"Get",
"the",
"initialized",
"routing",
"class"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L719-L734 | train |
koldy/framework | src/Koldy/Application.php | Application.registerModule | public static function registerModule(string $name): void
{
if (!isset(static::$registeredModules[$name])) {
$modulePath = static::getModulePath($name);
static::prependIncludePath($modulePath . 'controllers', $modulePath . 'library');
static::$registeredModules[$name] = true;
$initPath = $modulePath . 'init.php';
if (is_file($initPath)) {
require $initPath;
}
}
} | php | public static function registerModule(string $name): void
{
if (!isset(static::$registeredModules[$name])) {
$modulePath = static::getModulePath($name);
static::prependIncludePath($modulePath . 'controllers', $modulePath . 'library');
static::$registeredModules[$name] = true;
$initPath = $modulePath . 'init.php';
if (is_file($initPath)) {
require $initPath;
}
}
} | [
"public",
"static",
"function",
"registerModule",
"(",
"string",
"$",
"name",
")",
":",
"void",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"registeredModules",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"modulePath",
"=",
"static",
"::",
"getModulePath",
"(",
"$",
"name",
")",
";",
"static",
"::",
"prependIncludePath",
"(",
"$",
"modulePath",
".",
"'controllers'",
",",
"$",
"modulePath",
".",
"'library'",
")",
";",
"static",
"::",
"$",
"registeredModules",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"$",
"initPath",
"=",
"$",
"modulePath",
".",
"'init.php'",
";",
"if",
"(",
"is_file",
"(",
"$",
"initPath",
")",
")",
"{",
"require",
"$",
"initPath",
";",
"}",
"}",
"}"
]
| Register module by registering include path and by running init.php in module root folder
@param string $name
@example if your module is located on "/application/modules/invoices", then pass "invoices" | [
"Register",
"module",
"by",
"registering",
"include",
"path",
"and",
"by",
"running",
"init",
".",
"php",
"in",
"module",
"root",
"folder"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L783-L796 | train |
koldy/framework | src/Koldy/Application.php | Application.getModulePath | public static function getModulePath($name): string
{
$modulePath = static::$modulePath;
return str_replace(DS . DS, DS, $modulePath . DS . $name . DS);
} | php | public static function getModulePath($name): string
{
$modulePath = static::$modulePath;
return str_replace(DS . DS, DS, $modulePath . DS . $name . DS);
} | [
"public",
"static",
"function",
"getModulePath",
"(",
"$",
"name",
")",
":",
"string",
"{",
"$",
"modulePath",
"=",
"static",
"::",
"$",
"modulePath",
";",
"return",
"str_replace",
"(",
"DS",
".",
"DS",
",",
"DS",
",",
"$",
"modulePath",
".",
"DS",
".",
"$",
"name",
".",
"DS",
")",
";",
"}"
]
| Get the path on file system to the module WITH ending slash
@param string $name
@return string | [
"Get",
"the",
"path",
"on",
"file",
"system",
"to",
"the",
"module",
"WITH",
"ending",
"slash"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L842-L846 | train |
koldy/framework | src/Koldy/Application.php | Application.getKey | public static function getKey(): string
{
$key = static::getConfig('application')->get('key');
if ($key === null || $key === '') {
throw new ApplicationException('The key \'key\' in application config is invalid; please set non-empty string there');
}
if ($key == '_____ENTERSomeRandomKeyHere_____') {
throw new ApplicationException('Please configure key \'key\' in main application config, it can\'t be _____ENTERSomeRandomKeyHere_____');
}
if (strlen($key) > 32) {
throw new ApplicationException('Please make sure your application key in application config is not longer then 32 chars');
}
return $key;
} | php | public static function getKey(): string
{
$key = static::getConfig('application')->get('key');
if ($key === null || $key === '') {
throw new ApplicationException('The key \'key\' in application config is invalid; please set non-empty string there');
}
if ($key == '_____ENTERSomeRandomKeyHere_____') {
throw new ApplicationException('Please configure key \'key\' in main application config, it can\'t be _____ENTERSomeRandomKeyHere_____');
}
if (strlen($key) > 32) {
throw new ApplicationException('Please make sure your application key in application config is not longer then 32 chars');
}
return $key;
} | [
"public",
"static",
"function",
"getKey",
"(",
")",
":",
"string",
"{",
"$",
"key",
"=",
"static",
"::",
"getConfig",
"(",
"'application'",
")",
"->",
"get",
"(",
"'key'",
")",
";",
"if",
"(",
"$",
"key",
"===",
"null",
"||",
"$",
"key",
"===",
"''",
")",
"{",
"throw",
"new",
"ApplicationException",
"(",
"'The key \\'key\\' in application config is invalid; please set non-empty string there'",
")",
";",
"}",
"if",
"(",
"$",
"key",
"==",
"'_____ENTERSomeRandomKeyHere_____'",
")",
"{",
"throw",
"new",
"ApplicationException",
"(",
"'Please configure key \\'key\\' in main application config, it can\\'t be _____ENTERSomeRandomKeyHere_____'",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"key",
")",
">",
"32",
")",
"{",
"throw",
"new",
"ApplicationException",
"(",
"'Please make sure your application key in application config is not longer then 32 chars'",
")",
";",
"}",
"return",
"$",
"key",
";",
"}"
]
| Get the key defined in application config
@return string
@throws Exception | [
"Get",
"the",
"key",
"defined",
"in",
"application",
"config"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Application.php#L876-L893 | train |
koldy/framework | src/Koldy/Db/ModelTraits/DeletedAt.php | DeletedAt.setDeletedAtDateTime | public function setDeletedAtDateTime(?DateTime $deletedAt): void
{
$this->deleted_at = $deletedAt === null ? null : $deletedAt->format('Y-m-d H:i:s');
} | php | public function setDeletedAtDateTime(?DateTime $deletedAt): void
{
$this->deleted_at = $deletedAt === null ? null : $deletedAt->format('Y-m-d H:i:s');
} | [
"public",
"function",
"setDeletedAtDateTime",
"(",
"?",
"DateTime",
"$",
"deletedAt",
")",
":",
"void",
"{",
"$",
"this",
"->",
"deleted_at",
"=",
"$",
"deletedAt",
"===",
"null",
"?",
"null",
":",
"$",
"deletedAt",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"}"
]
| Set the deleted at date time by passing instance of deletedAt
@param DateTime|null $deletedAt | [
"Set",
"the",
"deleted",
"at",
"date",
"time",
"by",
"passing",
"instance",
"of",
"deletedAt"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/ModelTraits/DeletedAt.php#L89-L92 | train |
koldy/framework | src/Koldy/Db/Query/Bindings.php | Bindings.make | public static function make(string $parameter): string
{
$parameter = str_replace('.', '_', $parameter);
$parameter = str_replace(',', '_', $parameter);
$parameter = str_replace(' ', '_', $parameter);
$parameter = str_replace('-', '_', $parameter);
$parameter = str_replace('(', '', $parameter);
$parameter = str_replace(')', '', $parameter);
$parameter = str_replace('*', '', $parameter);
$parameter = str_replace('>', '_', $parameter);
$parameter = str_replace('<', '_', $parameter);
$parameter = str_replace('\'', '', $parameter);
$parameter = str_replace('"', '', $parameter);
$parameter = str_replace('__', '_', $parameter);
$parameter = str_replace(':', '_', $parameter);
return strtolower($parameter) . static::getNextIndex();
} | php | public static function make(string $parameter): string
{
$parameter = str_replace('.', '_', $parameter);
$parameter = str_replace(',', '_', $parameter);
$parameter = str_replace(' ', '_', $parameter);
$parameter = str_replace('-', '_', $parameter);
$parameter = str_replace('(', '', $parameter);
$parameter = str_replace(')', '', $parameter);
$parameter = str_replace('*', '', $parameter);
$parameter = str_replace('>', '_', $parameter);
$parameter = str_replace('<', '_', $parameter);
$parameter = str_replace('\'', '', $parameter);
$parameter = str_replace('"', '', $parameter);
$parameter = str_replace('__', '_', $parameter);
$parameter = str_replace(':', '_', $parameter);
return strtolower($parameter) . static::getNextIndex();
} | [
"public",
"static",
"function",
"make",
"(",
"string",
"$",
"parameter",
")",
":",
"string",
"{",
"$",
"parameter",
"=",
"str_replace",
"(",
"'.'",
",",
"'_'",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"','",
",",
"'_'",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"' '",
",",
"'_'",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"'-'",
",",
"'_'",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"'('",
",",
"''",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"')'",
",",
"''",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"'*'",
",",
"''",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"'>'",
",",
"'_'",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"'<'",
",",
"'_'",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"'\\''",
",",
"''",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"'\"'",
",",
"''",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"'__'",
",",
"'_'",
",",
"$",
"parameter",
")",
";",
"$",
"parameter",
"=",
"str_replace",
"(",
"':'",
",",
"'_'",
",",
"$",
"parameter",
")",
";",
"return",
"strtolower",
"(",
"$",
"parameter",
")",
".",
"static",
"::",
"getNextIndex",
"(",
")",
";",
"}"
]
| Make unique bind name according to given parameter name
@param string $parameter
@return string | [
"Make",
"unique",
"bind",
"name",
"according",
"to",
"given",
"parameter",
"name"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Bindings.php#L68-L85 | train |
koldy/framework | src/Koldy/Db/Query/Bindings.php | Bindings.get | public function get(string $parameter): Bind
{
if (!$this->has($parameter)) {
throw new Exception("Bind name \"{$parameter}\" does not exists");
}
return $this->bindings[$parameter];
} | php | public function get(string $parameter): Bind
{
if (!$this->has($parameter)) {
throw new Exception("Bind name \"{$parameter}\" does not exists");
}
return $this->bindings[$parameter];
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"parameter",
")",
":",
"Bind",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"parameter",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Bind name \\\"{$parameter}\\\" does not exists\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"bindings",
"[",
"$",
"parameter",
"]",
";",
"}"
]
| Get already binded parameter
@param string $parameter
@return Bind
@throws Exception | [
"Get",
"already",
"binded",
"parameter"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Bindings.php#L119-L126 | train |
koldy/framework | src/Koldy/Db/Query/Bindings.php | Bindings.getAsArray | public function getAsArray(): array
{
$data = [];
foreach ($this->getBindings() as $bind) {
$data[$bind->getParameter()] = $bind->getValue();
}
return $data;
} | php | public function getAsArray(): array
{
$data = [];
foreach ($this->getBindings() as $bind) {
$data[$bind->getParameter()] = $bind->getValue();
}
return $data;
} | [
"public",
"function",
"getAsArray",
"(",
")",
":",
"array",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getBindings",
"(",
")",
"as",
"$",
"bind",
")",
"{",
"$",
"data",
"[",
"$",
"bind",
"->",
"getParameter",
"(",
")",
"]",
"=",
"$",
"bind",
"->",
"getValue",
"(",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Gets all bindings as key value assoc array where key is parameter and value is its value.
@return array | [
"Gets",
"all",
"bindings",
"as",
"key",
"value",
"assoc",
"array",
"where",
"key",
"is",
"parameter",
"and",
"value",
"is",
"its",
"value",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Bindings.php#L166-L175 | train |
koldy/framework | src/Koldy/Db/Query/Bindings.php | Bindings.setFromArray | public function setFromArray(array $data): void
{
foreach ($data as $parameter => $value) {
$this->bindings[$parameter] = new Bind($parameter, $value);
}
} | php | public function setFromArray(array $data): void
{
foreach ($data as $parameter => $value) {
$this->bindings[$parameter] = new Bind($parameter, $value);
}
} | [
"public",
"function",
"setFromArray",
"(",
"array",
"$",
"data",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"parameter",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"bindings",
"[",
"$",
"parameter",
"]",
"=",
"new",
"Bind",
"(",
"$",
"parameter",
",",
"$",
"value",
")",
";",
"}",
"}"
]
| Set the bindings by providing assoc array of parameter => value
@param array $data | [
"Set",
"the",
"bindings",
"by",
"providing",
"assoc",
"array",
"of",
"parameter",
"=",
">",
"value"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Query/Bindings.php#L182-L187 | train |
koldy/framework | src/Koldy/Convert/NumericNotation.php | NumericNotation.dec2big | public static function dec2big(string $number): string
{
static::checkExtensionOrFail();
$alphabet = static::NUMBERS;
$number = trim((string)$number);
if (strlen($number) == 0) {
throw new Exception('Got empty number for dec2big, can not proceed');
}
$mod = (string)count($alphabet);
$s = '';
do {
$x = bcdiv($number, $mod, 0);
$left = bcmod($number, $mod);
$char = $alphabet[$left];
$s = $char . $s;
$number = $x;
} while ($x != '0');
return $s;
} | php | public static function dec2big(string $number): string
{
static::checkExtensionOrFail();
$alphabet = static::NUMBERS;
$number = trim((string)$number);
if (strlen($number) == 0) {
throw new Exception('Got empty number for dec2big, can not proceed');
}
$mod = (string)count($alphabet);
$s = '';
do {
$x = bcdiv($number, $mod, 0);
$left = bcmod($number, $mod);
$char = $alphabet[$left];
$s = $char . $s;
$number = $x;
} while ($x != '0');
return $s;
} | [
"public",
"static",
"function",
"dec2big",
"(",
"string",
"$",
"number",
")",
":",
"string",
"{",
"static",
"::",
"checkExtensionOrFail",
"(",
")",
";",
"$",
"alphabet",
"=",
"static",
"::",
"NUMBERS",
";",
"$",
"number",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"number",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"number",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Got empty number for dec2big, can not proceed'",
")",
";",
"}",
"$",
"mod",
"=",
"(",
"string",
")",
"count",
"(",
"$",
"alphabet",
")",
";",
"$",
"s",
"=",
"''",
";",
"do",
"{",
"$",
"x",
"=",
"bcdiv",
"(",
"$",
"number",
",",
"$",
"mod",
",",
"0",
")",
";",
"$",
"left",
"=",
"bcmod",
"(",
"$",
"number",
",",
"$",
"mod",
")",
";",
"$",
"char",
"=",
"$",
"alphabet",
"[",
"$",
"left",
"]",
";",
"$",
"s",
"=",
"$",
"char",
".",
"$",
"s",
";",
"$",
"number",
"=",
"$",
"x",
";",
"}",
"while",
"(",
"$",
"x",
"!=",
"'0'",
")",
";",
"return",
"$",
"s",
";",
"}"
]
| Convert decimal number into your numeric system
@param string $number
@return string
@throws Exception
@throws ExtensionException
@example 40487 is ax1 | [
"Convert",
"decimal",
"number",
"into",
"your",
"numeric",
"system"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Convert/NumericNotation.php#L109-L133 | train |
koldy/framework | src/Koldy/Convert/NumericNotation.php | NumericNotation.big2dec | public static function big2dec(string $alpha): string
{
static::checkExtensionOrFail();
if (strlen($alpha) <= 0) {
throw new Exception('Got empty string in big2dec, can not proceed');
}
$alphabet = array_flip(static::NUMBERS);
$mod = (string)count($alphabet);
$x = '0';
for ($i = 0, $j = strlen($alpha) - 1; $i < strlen($alpha); $i++, $j--) {
$char = substr($alpha, $j, 1);
$val = $alphabet[$char];
$x = bcadd($x, bcmul((string)$val, bcpow($mod, (string)$i)));
}
return $x;
} | php | public static function big2dec(string $alpha): string
{
static::checkExtensionOrFail();
if (strlen($alpha) <= 0) {
throw new Exception('Got empty string in big2dec, can not proceed');
}
$alphabet = array_flip(static::NUMBERS);
$mod = (string)count($alphabet);
$x = '0';
for ($i = 0, $j = strlen($alpha) - 1; $i < strlen($alpha); $i++, $j--) {
$char = substr($alpha, $j, 1);
$val = $alphabet[$char];
$x = bcadd($x, bcmul((string)$val, bcpow($mod, (string)$i)));
}
return $x;
} | [
"public",
"static",
"function",
"big2dec",
"(",
"string",
"$",
"alpha",
")",
":",
"string",
"{",
"static",
"::",
"checkExtensionOrFail",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"alpha",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Got empty string in big2dec, can not proceed'",
")",
";",
"}",
"$",
"alphabet",
"=",
"array_flip",
"(",
"static",
"::",
"NUMBERS",
")",
";",
"$",
"mod",
"=",
"(",
"string",
")",
"count",
"(",
"$",
"alphabet",
")",
";",
"$",
"x",
"=",
"'0'",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"j",
"=",
"strlen",
"(",
"$",
"alpha",
")",
"-",
"1",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"alpha",
")",
";",
"$",
"i",
"++",
",",
"$",
"j",
"--",
")",
"{",
"$",
"char",
"=",
"substr",
"(",
"$",
"alpha",
",",
"$",
"j",
",",
"1",
")",
";",
"$",
"val",
"=",
"$",
"alphabet",
"[",
"$",
"char",
"]",
";",
"$",
"x",
"=",
"bcadd",
"(",
"$",
"x",
",",
"bcmul",
"(",
"(",
"string",
")",
"$",
"val",
",",
"bcpow",
"(",
"$",
"mod",
",",
"(",
"string",
")",
"$",
"i",
")",
")",
")",
";",
"}",
"return",
"$",
"x",
";",
"}"
]
| The reverse procedure, convert number from your numeric system into decimal number
@param string $alpha
@return string because real number can reach the MAX_INT
@throws Exception
@throws ExtensionException
@example ax1 is 40487 | [
"The",
"reverse",
"procedure",
"convert",
"number",
"from",
"your",
"numeric",
"system",
"into",
"decimal",
"number"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Convert/NumericNotation.php#L145-L165 | train |
koldy/framework | src/Koldy/Response/FileDownload.php | FileDownload.create | public static function create(string $path, string $asName = null, string $contentType = null): FileDownload
{
$self = new static(new File($path));
if ($asName !== null) {
$self->setAsName($asName);
}
if ($contentType !== null) {
$self->setContentType($contentType);
}
return $self;
} | php | public static function create(string $path, string $asName = null, string $contentType = null): FileDownload
{
$self = new static(new File($path));
if ($asName !== null) {
$self->setAsName($asName);
}
if ($contentType !== null) {
$self->setContentType($contentType);
}
return $self;
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"asName",
"=",
"null",
",",
"string",
"$",
"contentType",
"=",
"null",
")",
":",
"FileDownload",
"{",
"$",
"self",
"=",
"new",
"static",
"(",
"new",
"File",
"(",
"$",
"path",
")",
")",
";",
"if",
"(",
"$",
"asName",
"!==",
"null",
")",
"{",
"$",
"self",
"->",
"setAsName",
"(",
"$",
"asName",
")",
";",
"}",
"if",
"(",
"$",
"contentType",
"!==",
"null",
")",
"{",
"$",
"self",
"->",
"setContentType",
"(",
"$",
"contentType",
")",
";",
"}",
"return",
"$",
"self",
";",
"}"
]
| Return file download
@param string $path
@param string $asName [optional]
@param string $contentType [optional]
@throws Exception
@return FileDownload | [
"Return",
"file",
"download"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/FileDownload.php#L83-L96 | train |
koldy/framework | src/Koldy/Response/ResponseExceptionHandler.php | ResponseExceptionHandler.exec | public function exec(): void
{
if (Application::route()->isAjax()) {
// if is ajax
$this->handleExceptionInAjax($this->e);
} else {
// normal request
$this->handleExceptionInNormalRequest($this->e);
}
} | php | public function exec(): void
{
if (Application::route()->isAjax()) {
// if is ajax
$this->handleExceptionInAjax($this->e);
} else {
// normal request
$this->handleExceptionInNormalRequest($this->e);
}
} | [
"public",
"function",
"exec",
"(",
")",
":",
"void",
"{",
"if",
"(",
"Application",
"::",
"route",
"(",
")",
"->",
"isAjax",
"(",
")",
")",
"{",
"// if is ajax",
"$",
"this",
"->",
"handleExceptionInAjax",
"(",
"$",
"this",
"->",
"e",
")",
";",
"}",
"else",
"{",
"// normal request",
"$",
"this",
"->",
"handleExceptionInNormalRequest",
"(",
"$",
"this",
"->",
"e",
")",
";",
"}",
"}"
]
| Execute exception handler
@throws Exception
@throws Json\Exception | [
"Execute",
"exception",
"handler"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Response/ResponseExceptionHandler.php#L138-L147 | train |
koldy/framework | src/Koldy/Db/Adapter/AbstractAdapter.php | AbstractAdapter.query | public function query(string $query, array $bindings = null): Query
{
$this->lastQuery = new Query($query, $bindings, $this->configKey);
return $this->lastQuery;
} | php | public function query(string $query, array $bindings = null): Query
{
$this->lastQuery = new Query($query, $bindings, $this->configKey);
return $this->lastQuery;
} | [
"public",
"function",
"query",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"bindings",
"=",
"null",
")",
":",
"Query",
"{",
"$",
"this",
"->",
"lastQuery",
"=",
"new",
"Query",
"(",
"$",
"query",
",",
"$",
"bindings",
",",
"$",
"this",
"->",
"configKey",
")",
";",
"return",
"$",
"this",
"->",
"lastQuery",
";",
"}"
]
| Get new query
@param string $query
@param array|null $bindings
@return Query | [
"Get",
"new",
"query"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Db/Adapter/AbstractAdapter.php#L207-L211 | train |
dewsign/maxfactor-laravel-support | src/Webpage/Traits/MustHaveCanonical.php | MustHaveCanonical.getCanonicalAttribute | public function getCanonicalAttribute()
{
if ($canonical = $this->canonicalUrl) {
return $canonical;
}
if (method_exists($this, 'baseCanonical')) {
return $this->baseCanonical();
}
return url()->current();
} | php | public function getCanonicalAttribute()
{
if ($canonical = $this->canonicalUrl) {
return $canonical;
}
if (method_exists($this, 'baseCanonical')) {
return $this->baseCanonical();
}
return url()->current();
} | [
"public",
"function",
"getCanonicalAttribute",
"(",
")",
"{",
"if",
"(",
"$",
"canonical",
"=",
"$",
"this",
"->",
"canonicalUrl",
")",
"{",
"return",
"$",
"canonical",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'baseCanonical'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"baseCanonical",
"(",
")",
";",
"}",
"return",
"url",
"(",
")",
"->",
"current",
"(",
")",
";",
"}"
]
| Return the canonical URL to be rendered in the browser
@return string | [
"Return",
"the",
"canonical",
"URL",
"to",
"be",
"rendered",
"in",
"the",
"browser"
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Webpage/Traits/MustHaveCanonical.php#L44-L55 | train |
koldy/framework | src/Koldy/Log/Adapter/Email.php | Email.getEmail | protected function getEmail(): AbstractMailAdapter
{
if (isset($this->config[self::FN_CONFIG_KEY])) {
$mail = call_user_func($this->config[self::FN_CONFIG_KEY], $this->messages);
if (!($mail instanceof AbstractMailAdapter)) {
throw new Exception('Function defined in mail config under ' . self::FN_CONFIG_KEY . ' must return instance of \Koldy\Mail\Adapter\AbstractMailAdapter; ' . gettype($mail) . ' given');
}
return $mail;
}
if (count($this->messages) == 0) {
throw new Exception('Can not prepare e-mail instance when there\'s no log messages added from before; try not to call getEmail() if messages array is empty');
}
$mail = Mail::create($this->config['adapter']);
$allMessages = [];
$firstMessage = $this->messages[0];
foreach ($this->messages as $msg) {
$allMessages[] = $msg->getDefaultLine();
}
$body = implode("\n", $allMessages);
$level = strtoupper($firstMessage->getLevel());
$subject = "[{$level}] {$firstMessage->getMessage()}";
$body .= "\n\n----------\n";
$body .= Server::signature();
$subject = Util::truncate($subject, 140);
$domain = Application::getDomain();
$mail->from('alert@' . $domain, $domain)->subject($subject)->body($body);
$to = $this->config['to'];
if (!is_array($this->config['to']) && strpos($this->config['to'], ',') !== false) {
$to = explode(',', $this->config['to']);
}
if (is_array($to)) {
foreach ($to as $toEmail) {
$mail->to(trim($toEmail));
}
} else if (is_string($to)) {
$mail->to(trim($to));
} else {
throw new Exception('Unable to prepare log via email, expected array or string for \'to\', got ' . gettype($to));
}
return $mail;
} | php | protected function getEmail(): AbstractMailAdapter
{
if (isset($this->config[self::FN_CONFIG_KEY])) {
$mail = call_user_func($this->config[self::FN_CONFIG_KEY], $this->messages);
if (!($mail instanceof AbstractMailAdapter)) {
throw new Exception('Function defined in mail config under ' . self::FN_CONFIG_KEY . ' must return instance of \Koldy\Mail\Adapter\AbstractMailAdapter; ' . gettype($mail) . ' given');
}
return $mail;
}
if (count($this->messages) == 0) {
throw new Exception('Can not prepare e-mail instance when there\'s no log messages added from before; try not to call getEmail() if messages array is empty');
}
$mail = Mail::create($this->config['adapter']);
$allMessages = [];
$firstMessage = $this->messages[0];
foreach ($this->messages as $msg) {
$allMessages[] = $msg->getDefaultLine();
}
$body = implode("\n", $allMessages);
$level = strtoupper($firstMessage->getLevel());
$subject = "[{$level}] {$firstMessage->getMessage()}";
$body .= "\n\n----------\n";
$body .= Server::signature();
$subject = Util::truncate($subject, 140);
$domain = Application::getDomain();
$mail->from('alert@' . $domain, $domain)->subject($subject)->body($body);
$to = $this->config['to'];
if (!is_array($this->config['to']) && strpos($this->config['to'], ',') !== false) {
$to = explode(',', $this->config['to']);
}
if (is_array($to)) {
foreach ($to as $toEmail) {
$mail->to(trim($toEmail));
}
} else if (is_string($to)) {
$mail->to(trim($to));
} else {
throw new Exception('Unable to prepare log via email, expected array or string for \'to\', got ' . gettype($to));
}
return $mail;
} | [
"protected",
"function",
"getEmail",
"(",
")",
":",
"AbstractMailAdapter",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"self",
"::",
"FN_CONFIG_KEY",
"]",
")",
")",
"{",
"$",
"mail",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"config",
"[",
"self",
"::",
"FN_CONFIG_KEY",
"]",
",",
"$",
"this",
"->",
"messages",
")",
";",
"if",
"(",
"!",
"(",
"$",
"mail",
"instanceof",
"AbstractMailAdapter",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Function defined in mail config under '",
".",
"self",
"::",
"FN_CONFIG_KEY",
".",
"' must return instance of \\Koldy\\Mail\\Adapter\\AbstractMailAdapter; '",
".",
"gettype",
"(",
"$",
"mail",
")",
".",
"' given'",
")",
";",
"}",
"return",
"$",
"mail",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"messages",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Can not prepare e-mail instance when there\\'s no log messages added from before; try not to call getEmail() if messages array is empty'",
")",
";",
"}",
"$",
"mail",
"=",
"Mail",
"::",
"create",
"(",
"$",
"this",
"->",
"config",
"[",
"'adapter'",
"]",
")",
";",
"$",
"allMessages",
"=",
"[",
"]",
";",
"$",
"firstMessage",
"=",
"$",
"this",
"->",
"messages",
"[",
"0",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"messages",
"as",
"$",
"msg",
")",
"{",
"$",
"allMessages",
"[",
"]",
"=",
"$",
"msg",
"->",
"getDefaultLine",
"(",
")",
";",
"}",
"$",
"body",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"allMessages",
")",
";",
"$",
"level",
"=",
"strtoupper",
"(",
"$",
"firstMessage",
"->",
"getLevel",
"(",
")",
")",
";",
"$",
"subject",
"=",
"\"[{$level}] {$firstMessage->getMessage()}\"",
";",
"$",
"body",
".=",
"\"\\n\\n----------\\n\"",
";",
"$",
"body",
".=",
"Server",
"::",
"signature",
"(",
")",
";",
"$",
"subject",
"=",
"Util",
"::",
"truncate",
"(",
"$",
"subject",
",",
"140",
")",
";",
"$",
"domain",
"=",
"Application",
"::",
"getDomain",
"(",
")",
";",
"$",
"mail",
"->",
"from",
"(",
"'alert@'",
".",
"$",
"domain",
",",
"$",
"domain",
")",
"->",
"subject",
"(",
"$",
"subject",
")",
"->",
"body",
"(",
"$",
"body",
")",
";",
"$",
"to",
"=",
"$",
"this",
"->",
"config",
"[",
"'to'",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"config",
"[",
"'to'",
"]",
")",
"&&",
"strpos",
"(",
"$",
"this",
"->",
"config",
"[",
"'to'",
"]",
",",
"','",
")",
"!==",
"false",
")",
"{",
"$",
"to",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"config",
"[",
"'to'",
"]",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"to",
")",
")",
"{",
"foreach",
"(",
"$",
"to",
"as",
"$",
"toEmail",
")",
"{",
"$",
"mail",
"->",
"to",
"(",
"trim",
"(",
"$",
"toEmail",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"to",
")",
")",
"{",
"$",
"mail",
"->",
"to",
"(",
"trim",
"(",
"$",
"to",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Unable to prepare log via email, expected array or string for \\'to\\', got '",
".",
"gettype",
"(",
"$",
"to",
")",
")",
";",
"}",
"return",
"$",
"mail",
";",
"}"
]
| Get the Mail instance ready
@return AbstractMailAdapter
@throws Exception
@throws \Koldy\Exception | [
"Get",
"the",
"Mail",
"instance",
"ready"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Adapter/Email.php#L74-L126 | train |
koldy/framework | src/Koldy/Log/Adapter/Email.php | Email.sendEmail | protected function sendEmail(): void
{
if (!$this->emailing) {
$mail = $this->getEmail();
try {
$this->emailing = true;
$mail->send();
$this->messages = [];
$this->emailing = false;
} catch (Mail\Exception $e) {
Log::alert('Can not send log message(s) with e-mail logger', $e);
}
}
} | php | protected function sendEmail(): void
{
if (!$this->emailing) {
$mail = $this->getEmail();
try {
$this->emailing = true;
$mail->send();
$this->messages = [];
$this->emailing = false;
} catch (Mail\Exception $e) {
Log::alert('Can not send log message(s) with e-mail logger', $e);
}
}
} | [
"protected",
"function",
"sendEmail",
"(",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"emailing",
")",
"{",
"$",
"mail",
"=",
"$",
"this",
"->",
"getEmail",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"emailing",
"=",
"true",
";",
"$",
"mail",
"->",
"send",
"(",
")",
";",
"$",
"this",
"->",
"messages",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"emailing",
"=",
"false",
";",
"}",
"catch",
"(",
"Mail",
"\\",
"Exception",
"$",
"e",
")",
"{",
"Log",
"::",
"alert",
"(",
"'Can not send log message(s) with e-mail logger'",
",",
"$",
"e",
")",
";",
"}",
"}",
"}"
]
| Send e-mail report if system detected that e-mail should be sent
@throws Exception
@throws \Koldy\Exception | [
"Send",
"e",
"-",
"mail",
"report",
"if",
"system",
"detected",
"that",
"e",
"-",
"mail",
"should",
"be",
"sent"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Log/Adapter/Email.php#L168-L182 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.