id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
9,100 | RhubarbPHP/Module.Patterns | src/Mvp/BoilerPlates/Login/LoginPresenter.php | LoginPresenter.beforeRenderView | protected function beforeRenderView()
{
$login = $this->getLoginProvider();
if (isset($_GET["logout"])) {
$login->logOut();
}
if ( $login->isLoggedIn() ){
$this->onSuccess();
}
} | php | protected function beforeRenderView()
{
$login = $this->getLoginProvider();
if (isset($_GET["logout"])) {
$login->logOut();
}
if ( $login->isLoggedIn() ){
$this->onSuccess();
}
} | [
"protected",
"function",
"beforeRenderView",
"(",
")",
"{",
"$",
"login",
"=",
"$",
"this",
"->",
"getLoginProvider",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"\"logout\"",
"]",
")",
")",
"{",
"$",
"login",
"->",
"logOut",
"(",
")",
";",
"}",
"if",
"(",
"$",
"login",
"->",
"isLoggedIn",
"(",
")",
")",
"{",
"$",
"this",
"->",
"onSuccess",
"(",
")",
";",
"}",
"}"
] | Called just before the view is rendered.
Guaranteed to only be called once during a normal page execution. | [
"Called",
"just",
"before",
"the",
"view",
"is",
"rendered",
"."
] | 118b13b44bce7d35cb8aaa09135c47836098831f | https://github.com/RhubarbPHP/Module.Patterns/blob/118b13b44bce7d35cb8aaa09135c47836098831f/src/Mvp/BoilerPlates/Login/LoginPresenter.php#L106-L117 |
9,101 | Ara95/user | src/Admin/HTMLForm/DeleteAdminForm.php | DeleteAdminForm.getUserDetails | public function getUserDetails($id)
{
$user = new User();
$user->setDb($this->di->get("db"));
$user->find("id", $id);
return $user;
} | php | public function getUserDetails($id)
{
$user = new User();
$user->setDb($this->di->get("db"));
$user->find("id", $id);
return $user;
} | [
"public",
"function",
"getUserDetails",
"(",
"$",
"id",
")",
"{",
"$",
"user",
"=",
"new",
"User",
"(",
")",
";",
"$",
"user",
"->",
"setDb",
"(",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"\"db\"",
")",
")",
";",
"$",
"user",
"->",
"find",
"(",
"\"id\"",
",",
"$",
"id",
")",
";",
"return",
"$",
"user",
";",
"}"
] | Get user details to load form with.
@param string $id get details on item with id.
@return object User details. | [
"Get",
"user",
"details",
"to",
"load",
"form",
"with",
"."
] | 96e15a19906562a689abedf6bcf4818ad8437a3b | https://github.com/Ara95/user/blob/96e15a19906562a689abedf6bcf4818ad8437a3b/src/Admin/HTMLForm/DeleteAdminForm.php#L66-L72 |
9,102 | deasilworks/cms | src/CEF/Domain/Manager/ContentDomainManager.php | ContentDomainManager.getWelcome | public function getWelcome()
{
$stub = $this->getCfgValue('demo.pages.welcome', 'welcome');
$this->getLogger()->addInfo('Got stub: '.$stub);
/** @var PageDataManager $pageMgr */
$pageMgr = $this->getDataManager(PageDataManager::class);
return $pageMgr->getPage($stub)->getTitle();
} | php | public function getWelcome()
{
$stub = $this->getCfgValue('demo.pages.welcome', 'welcome');
$this->getLogger()->addInfo('Got stub: '.$stub);
/** @var PageDataManager $pageMgr */
$pageMgr = $this->getDataManager(PageDataManager::class);
return $pageMgr->getPage($stub)->getTitle();
} | [
"public",
"function",
"getWelcome",
"(",
")",
"{",
"$",
"stub",
"=",
"$",
"this",
"->",
"getCfgValue",
"(",
"'demo.pages.welcome'",
",",
"'welcome'",
")",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"addInfo",
"(",
"'Got stub: '",
".",
"$",
"stub",
")",
";",
"/** @var PageDataManager $pageMgr */",
"$",
"pageMgr",
"=",
"$",
"this",
"->",
"getDataManager",
"(",
"PageDataManager",
"::",
"class",
")",
";",
"return",
"$",
"pageMgr",
"->",
"getPage",
"(",
"$",
"stub",
")",
"->",
"getTitle",
"(",
")",
";",
"}"
] | Get Welcome.
@ApiAction()
@return string | [
"Get",
"Welcome",
"."
] | 759d05a4e79656b62ff26ea55834f64c61fd1fd4 | https://github.com/deasilworks/cms/blob/759d05a4e79656b62ff26ea55834f64c61fd1fd4/src/CEF/Domain/Manager/ContentDomainManager.php#L47-L56 |
9,103 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.flash | public static function flash( $name = '', $message = '', $class = 'success fadeout-message' )
{
//We can only do something if the name isn't empty
if( !empty( $name ) )
{
//No message, create it
if( !empty( $message ) && empty( $_SESSION[$name] ) )
{
if( !empty( $_SESSION[$name] ) )
{
unset( $_SESSION[$name] );
}
if( !empty( $_SESSION[$name.'_class'] ) )
{
unset( $_SESSION[$name.'_class'] );
}
$_SESSION[$name] = $message;
$_SESSION[$name.'_class'] = $class;
}
//Message exists, display it
elseif( !empty( $_SESSION[$name] ) && empty( $message ) )
{
$class = !empty( $_SESSION[$name.'_class'] ) ? $_SESSION[$name.'_class'] : 'success';
$message = $_SESSION[$name];
echo '<div class="ui '.$class.' message">'.$message.'</div>';
unset($_SESSION[$name]);
unset($_SESSION[$name.'_class']);
}
}
} | php | public static function flash( $name = '', $message = '', $class = 'success fadeout-message' )
{
//We can only do something if the name isn't empty
if( !empty( $name ) )
{
//No message, create it
if( !empty( $message ) && empty( $_SESSION[$name] ) )
{
if( !empty( $_SESSION[$name] ) )
{
unset( $_SESSION[$name] );
}
if( !empty( $_SESSION[$name.'_class'] ) )
{
unset( $_SESSION[$name.'_class'] );
}
$_SESSION[$name] = $message;
$_SESSION[$name.'_class'] = $class;
}
//Message exists, display it
elseif( !empty( $_SESSION[$name] ) && empty( $message ) )
{
$class = !empty( $_SESSION[$name.'_class'] ) ? $_SESSION[$name.'_class'] : 'success';
$message = $_SESSION[$name];
echo '<div class="ui '.$class.' message">'.$message.'</div>';
unset($_SESSION[$name]);
unset($_SESSION[$name.'_class']);
}
}
} | [
"public",
"static",
"function",
"flash",
"(",
"$",
"name",
"=",
"''",
",",
"$",
"message",
"=",
"''",
",",
"$",
"class",
"=",
"'success fadeout-message'",
")",
"{",
"//We can only do something if the name isn't empty\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"//No message, create it\r",
"if",
"(",
"!",
"empty",
"(",
"$",
"message",
")",
"&&",
"empty",
"(",
"$",
"_SESSION",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SESSION",
"[",
"$",
"name",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"$",
"name",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SESSION",
"[",
"$",
"name",
".",
"'_class'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"$",
"name",
".",
"'_class'",
"]",
")",
";",
"}",
"$",
"_SESSION",
"[",
"$",
"name",
"]",
"=",
"$",
"message",
";",
"$",
"_SESSION",
"[",
"$",
"name",
".",
"'_class'",
"]",
"=",
"$",
"class",
";",
"}",
"//Message exists, display it\r",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"_SESSION",
"[",
"$",
"name",
"]",
")",
"&&",
"empty",
"(",
"$",
"message",
")",
")",
"{",
"$",
"class",
"=",
"!",
"empty",
"(",
"$",
"_SESSION",
"[",
"$",
"name",
".",
"'_class'",
"]",
")",
"?",
"$",
"_SESSION",
"[",
"$",
"name",
".",
"'_class'",
"]",
":",
"'success'",
";",
"$",
"message",
"=",
"$",
"_SESSION",
"[",
"$",
"name",
"]",
";",
"echo",
"'<div class=\"ui '",
".",
"$",
"class",
".",
"' message\">'",
".",
"$",
"message",
".",
"'</div>'",
";",
"unset",
"(",
"$",
"_SESSION",
"[",
"$",
"name",
"]",
")",
";",
"unset",
"(",
"$",
"_SESSION",
"[",
"$",
"name",
".",
"'_class'",
"]",
")",
";",
"}",
"}",
"}"
] | Function to create and display error and success messages
@access public
@param string session name
@param string message
@param string display class
@return string message | [
"Function",
"to",
"create",
"and",
"display",
"error",
"and",
"success",
"messages"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L52-L82 |
9,104 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.decimalToAlphanumeric | public static function decimalToAlphanumeric($number, $base = 64, $index = false)
{
if (!$base) {
$base = strlen($index);
} elseif (!$index) {
$index = substr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, $base);
}
$out = "";
for ($i = floor(log10($number) / log10($base)); $i >= 0; $i--) {
$no = floor($num/pow($base, $i));
$out = $out.substr($index, $no, 1);
$number = $number - ($no * pow($base, $i));
}
return $out;
} | php | public static function decimalToAlphanumeric($number, $base = 64, $index = false)
{
if (!$base) {
$base = strlen($index);
} elseif (!$index) {
$index = substr("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0, $base);
}
$out = "";
for ($i = floor(log10($number) / log10($base)); $i >= 0; $i--) {
$no = floor($num/pow($base, $i));
$out = $out.substr($index, $no, 1);
$number = $number - ($no * pow($base, $i));
}
return $out;
} | [
"public",
"static",
"function",
"decimalToAlphanumeric",
"(",
"$",
"number",
",",
"$",
"base",
"=",
"64",
",",
"$",
"index",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"base",
")",
"{",
"$",
"base",
"=",
"strlen",
"(",
"$",
"index",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"index",
")",
"{",
"$",
"index",
"=",
"substr",
"(",
"\"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"",
",",
"0",
",",
"$",
"base",
")",
";",
"}",
"$",
"out",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"floor",
"(",
"log10",
"(",
"$",
"number",
")",
"/",
"log10",
"(",
"$",
"base",
")",
")",
";",
"$",
"i",
">=",
"0",
";",
"$",
"i",
"--",
")",
"{",
"$",
"no",
"=",
"floor",
"(",
"$",
"num",
"/",
"pow",
"(",
"$",
"base",
",",
"$",
"i",
")",
")",
";",
"$",
"out",
"=",
"$",
"out",
".",
"substr",
"(",
"$",
"index",
",",
"$",
"no",
",",
"1",
")",
";",
"$",
"number",
"=",
"$",
"number",
"-",
"(",
"$",
"no",
"*",
"pow",
"(",
"$",
"base",
",",
"$",
"i",
")",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Decimal To Alphanumeric
@param Integer
@param Integer
@param Boolean
@return String | [
"Decimal",
"To",
"Alphanumeric"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L256-L272 |
9,105 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.dateRangeArray | public static function dateRangeArray($strDateFrom, $strDateTo, $dateFormat = 'Y-m-d')
{
//Mengambil nilai tanggal dari dua tanggal dengan format YYYY-MM-DD
$arrayRange = array();
$t1 = $this->splitDate($strDateFrom, 'int');
$t2 = $this->splitDate($strDateTo, 'int');
$iDateFrom = mktime(1, 0, 0, $t1['month'], $t1['date'], $t1['year']);
$iDateTo = mktime(1, 0, 0, $t2['month'], $t2['date'], $t2['year']);
if ($iDateTo >= $iDateFrom) {
array_push($arrayRange, date($dateFormat, $iDateFrom)); // first entry
while ($iDateFrom < $iDateTo) {
$iDateFrom += 86400; // add 24 hours
array_push($arrayRange, date($dateFormat, $iDateFrom));
}
}
return $arrayRange;
} | php | public static function dateRangeArray($strDateFrom, $strDateTo, $dateFormat = 'Y-m-d')
{
//Mengambil nilai tanggal dari dua tanggal dengan format YYYY-MM-DD
$arrayRange = array();
$t1 = $this->splitDate($strDateFrom, 'int');
$t2 = $this->splitDate($strDateTo, 'int');
$iDateFrom = mktime(1, 0, 0, $t1['month'], $t1['date'], $t1['year']);
$iDateTo = mktime(1, 0, 0, $t2['month'], $t2['date'], $t2['year']);
if ($iDateTo >= $iDateFrom) {
array_push($arrayRange, date($dateFormat, $iDateFrom)); // first entry
while ($iDateFrom < $iDateTo) {
$iDateFrom += 86400; // add 24 hours
array_push($arrayRange, date($dateFormat, $iDateFrom));
}
}
return $arrayRange;
} | [
"public",
"static",
"function",
"dateRangeArray",
"(",
"$",
"strDateFrom",
",",
"$",
"strDateTo",
",",
"$",
"dateFormat",
"=",
"'Y-m-d'",
")",
"{",
"//Mengambil nilai tanggal dari dua tanggal dengan format YYYY-MM-DD\r",
"$",
"arrayRange",
"=",
"array",
"(",
")",
";",
"$",
"t1",
"=",
"$",
"this",
"->",
"splitDate",
"(",
"$",
"strDateFrom",
",",
"'int'",
")",
";",
"$",
"t2",
"=",
"$",
"this",
"->",
"splitDate",
"(",
"$",
"strDateTo",
",",
"'int'",
")",
";",
"$",
"iDateFrom",
"=",
"mktime",
"(",
"1",
",",
"0",
",",
"0",
",",
"$",
"t1",
"[",
"'month'",
"]",
",",
"$",
"t1",
"[",
"'date'",
"]",
",",
"$",
"t1",
"[",
"'year'",
"]",
")",
";",
"$",
"iDateTo",
"=",
"mktime",
"(",
"1",
",",
"0",
",",
"0",
",",
"$",
"t2",
"[",
"'month'",
"]",
",",
"$",
"t2",
"[",
"'date'",
"]",
",",
"$",
"t2",
"[",
"'year'",
"]",
")",
";",
"if",
"(",
"$",
"iDateTo",
">=",
"$",
"iDateFrom",
")",
"{",
"array_push",
"(",
"$",
"arrayRange",
",",
"date",
"(",
"$",
"dateFormat",
",",
"$",
"iDateFrom",
")",
")",
";",
"// first entry\r",
"while",
"(",
"$",
"iDateFrom",
"<",
"$",
"iDateTo",
")",
"{",
"$",
"iDateFrom",
"+=",
"86400",
";",
"// add 24 hours\r",
"array_push",
"(",
"$",
"arrayRange",
",",
"date",
"(",
"$",
"dateFormat",
",",
"$",
"iDateFrom",
")",
")",
";",
"}",
"}",
"return",
"$",
"arrayRange",
";",
"}"
] | Date Range Array
@param Date
@param Date
@param string
@return Array | [
"Date",
"Range",
"Array"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L579-L599 |
9,106 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.dateToSQL | public static function dateToSQL($tahun, $bulan, $tanggal, $minTahun = "", $maxTahun = "")
{
$tahun = (int)$tahun;
$bulan = (int)$bulan;
$tanggal = (int)$tanggal;
if ($tanggal <= 0 || $tanggal > 31) {
$tanggalX = "01";
} else if ($tanggal < 10) {
$tanggalX = "0" . $tanggal;
} else {
$tanggalX= $tanggal;
}
if ($bulan <= 0 || $bulan > 12) {
$bulanX = "01";
} else if ($bulan < 10) {
$bulanX = "0" . $bulan;
} else {
$bulanX = $bulan;
}
if ($minTahun != "") {
if ($tahun >= $minTahun) {
if ($maxTahun != "") {
if ($tahun <= $maxTahun) {
$tahunX = $tahun;
} else {
$tahunX = date("Y");
}
} else {
$tahunX = $tahun;
}
} else {
$tahunX = date("Y");
}
} else {
if (strlen($tahun) == 4) {
$tahunX = $tahun;
} else {
$tahunX = date("Y");
}
}
$tanggalSql = $tahunX . "-" . $bulanX . "-" . $tanggalX;
return $tanggalSql;
} | php | public static function dateToSQL($tahun, $bulan, $tanggal, $minTahun = "", $maxTahun = "")
{
$tahun = (int)$tahun;
$bulan = (int)$bulan;
$tanggal = (int)$tanggal;
if ($tanggal <= 0 || $tanggal > 31) {
$tanggalX = "01";
} else if ($tanggal < 10) {
$tanggalX = "0" . $tanggal;
} else {
$tanggalX= $tanggal;
}
if ($bulan <= 0 || $bulan > 12) {
$bulanX = "01";
} else if ($bulan < 10) {
$bulanX = "0" . $bulan;
} else {
$bulanX = $bulan;
}
if ($minTahun != "") {
if ($tahun >= $minTahun) {
if ($maxTahun != "") {
if ($tahun <= $maxTahun) {
$tahunX = $tahun;
} else {
$tahunX = date("Y");
}
} else {
$tahunX = $tahun;
}
} else {
$tahunX = date("Y");
}
} else {
if (strlen($tahun) == 4) {
$tahunX = $tahun;
} else {
$tahunX = date("Y");
}
}
$tanggalSql = $tahunX . "-" . $bulanX . "-" . $tanggalX;
return $tanggalSql;
} | [
"public",
"static",
"function",
"dateToSQL",
"(",
"$",
"tahun",
",",
"$",
"bulan",
",",
"$",
"tanggal",
",",
"$",
"minTahun",
"=",
"\"\"",
",",
"$",
"maxTahun",
"=",
"\"\"",
")",
"{",
"$",
"tahun",
"=",
"(",
"int",
")",
"$",
"tahun",
";",
"$",
"bulan",
"=",
"(",
"int",
")",
"$",
"bulan",
";",
"$",
"tanggal",
"=",
"(",
"int",
")",
"$",
"tanggal",
";",
"if",
"(",
"$",
"tanggal",
"<=",
"0",
"||",
"$",
"tanggal",
">",
"31",
")",
"{",
"$",
"tanggalX",
"=",
"\"01\"",
";",
"}",
"else",
"if",
"(",
"$",
"tanggal",
"<",
"10",
")",
"{",
"$",
"tanggalX",
"=",
"\"0\"",
".",
"$",
"tanggal",
";",
"}",
"else",
"{",
"$",
"tanggalX",
"=",
"$",
"tanggal",
";",
"}",
"if",
"(",
"$",
"bulan",
"<=",
"0",
"||",
"$",
"bulan",
">",
"12",
")",
"{",
"$",
"bulanX",
"=",
"\"01\"",
";",
"}",
"else",
"if",
"(",
"$",
"bulan",
"<",
"10",
")",
"{",
"$",
"bulanX",
"=",
"\"0\"",
".",
"$",
"bulan",
";",
"}",
"else",
"{",
"$",
"bulanX",
"=",
"$",
"bulan",
";",
"}",
"if",
"(",
"$",
"minTahun",
"!=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"tahun",
">=",
"$",
"minTahun",
")",
"{",
"if",
"(",
"$",
"maxTahun",
"!=",
"\"\"",
")",
"{",
"if",
"(",
"$",
"tahun",
"<=",
"$",
"maxTahun",
")",
"{",
"$",
"tahunX",
"=",
"$",
"tahun",
";",
"}",
"else",
"{",
"$",
"tahunX",
"=",
"date",
"(",
"\"Y\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"tahunX",
"=",
"$",
"tahun",
";",
"}",
"}",
"else",
"{",
"$",
"tahunX",
"=",
"date",
"(",
"\"Y\"",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"strlen",
"(",
"$",
"tahun",
")",
"==",
"4",
")",
"{",
"$",
"tahunX",
"=",
"$",
"tahun",
";",
"}",
"else",
"{",
"$",
"tahunX",
"=",
"date",
"(",
"\"Y\"",
")",
";",
"}",
"}",
"$",
"tanggalSql",
"=",
"$",
"tahunX",
".",
"\"-\"",
".",
"$",
"bulanX",
".",
"\"-\"",
".",
"$",
"tanggalX",
";",
"return",
"$",
"tanggalSql",
";",
"}"
] | Date To SQL
@param Date - Year
@param Date - Month
@param Date - Day
@param Date - Year
@param Date - Year
@return DateSQL | [
"Date",
"To",
"SQL"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L630-L673 |
9,107 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.displayDateTime | public static function displayDateTime($date)
{
$namaBulan = $this->monthList();
$dateInt = $this->splitDate($date);
$dateString = $this->splitDate($date, 'string');
return $namaBulan[$dateInt['month']] . ' ' . $dateInt['date'] . ', ' . $dateInt['year'] . ' ' . $dateString['hour'] . ':' . $dateString['minute'] . ':' . $dateString['second'];
} | php | public static function displayDateTime($date)
{
$namaBulan = $this->monthList();
$dateInt = $this->splitDate($date);
$dateString = $this->splitDate($date, 'string');
return $namaBulan[$dateInt['month']] . ' ' . $dateInt['date'] . ', ' . $dateInt['year'] . ' ' . $dateString['hour'] . ':' . $dateString['minute'] . ':' . $dateString['second'];
} | [
"public",
"static",
"function",
"displayDateTime",
"(",
"$",
"date",
")",
"{",
"$",
"namaBulan",
"=",
"$",
"this",
"->",
"monthList",
"(",
")",
";",
"$",
"dateInt",
"=",
"$",
"this",
"->",
"splitDate",
"(",
"$",
"date",
")",
";",
"$",
"dateString",
"=",
"$",
"this",
"->",
"splitDate",
"(",
"$",
"date",
",",
"'string'",
")",
";",
"return",
"$",
"namaBulan",
"[",
"$",
"dateInt",
"[",
"'month'",
"]",
"]",
".",
"' '",
".",
"$",
"dateInt",
"[",
"'date'",
"]",
".",
"', '",
".",
"$",
"dateInt",
"[",
"'year'",
"]",
".",
"' '",
".",
"$",
"dateString",
"[",
"'hour'",
"]",
".",
"':'",
".",
"$",
"dateString",
"[",
"'minute'",
"]",
".",
"':'",
".",
"$",
"dateString",
"[",
"'second'",
"]",
";",
"}"
] | Display Date Time
@param Date
@return String | [
"Display",
"Date",
"Time"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L693-L700 |
9,108 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.validDateForm | public static function validDateForm($date)
{
$isOK = true;
if (preg_match("/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})/", $date)) {
list($d, $m, $y) = explode("/", $date);
$month = (int)$m;
$day = (int)$d;
$year = (int)$y;
if (!checkdate($month, $day, $year)) {
$isOK = false;
}
} else {
$isOK = false;
}
if ($isOK == false) {
$date = date('d/m/Y');
}
return $date;
} | php | public static function validDateForm($date)
{
$isOK = true;
if (preg_match("/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{2,4})/", $date)) {
list($d, $m, $y) = explode("/", $date);
$month = (int)$m;
$day = (int)$d;
$year = (int)$y;
if (!checkdate($month, $day, $year)) {
$isOK = false;
}
} else {
$isOK = false;
}
if ($isOK == false) {
$date = date('d/m/Y');
}
return $date;
} | [
"public",
"static",
"function",
"validDateForm",
"(",
"$",
"date",
")",
"{",
"$",
"isOK",
"=",
"true",
";",
"if",
"(",
"preg_match",
"(",
"\"/([0-9]{1,2})\\/([0-9]{1,2})\\/([0-9]{2,4})/\"",
",",
"$",
"date",
")",
")",
"{",
"list",
"(",
"$",
"d",
",",
"$",
"m",
",",
"$",
"y",
")",
"=",
"explode",
"(",
"\"/\"",
",",
"$",
"date",
")",
";",
"$",
"month",
"=",
"(",
"int",
")",
"$",
"m",
";",
"$",
"day",
"=",
"(",
"int",
")",
"$",
"d",
";",
"$",
"year",
"=",
"(",
"int",
")",
"$",
"y",
";",
"if",
"(",
"!",
"checkdate",
"(",
"$",
"month",
",",
"$",
"day",
",",
"$",
"year",
")",
")",
"{",
"$",
"isOK",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"$",
"isOK",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"isOK",
"==",
"false",
")",
"{",
"$",
"date",
"=",
"date",
"(",
"'d/m/Y'",
")",
";",
"}",
"return",
"$",
"date",
";",
"}"
] | Validate Date Form
@param Date
@return Date | [
"Validate",
"Date",
"Form"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L833-L852 |
9,109 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.dateFormToSQL | public static function dateFormToSQL($date)
{
list($d, $m, $y) = @explode("/", $date);
$month = (int)$m;
$day = (int)$d;
$year = (int)$y;
if (checkdate($month, $day, $year)) {
if ($day < 10) {
$day = '0' . $day;
}
if ($month < 10) {
$month = '0' . $month;
}
return $y . '-' . $month . '-' . $day;
} else {
return '';
}
} | php | public static function dateFormToSQL($date)
{
list($d, $m, $y) = @explode("/", $date);
$month = (int)$m;
$day = (int)$d;
$year = (int)$y;
if (checkdate($month, $day, $year)) {
if ($day < 10) {
$day = '0' . $day;
}
if ($month < 10) {
$month = '0' . $month;
}
return $y . '-' . $month . '-' . $day;
} else {
return '';
}
} | [
"public",
"static",
"function",
"dateFormToSQL",
"(",
"$",
"date",
")",
"{",
"list",
"(",
"$",
"d",
",",
"$",
"m",
",",
"$",
"y",
")",
"=",
"@",
"explode",
"(",
"\"/\"",
",",
"$",
"date",
")",
";",
"$",
"month",
"=",
"(",
"int",
")",
"$",
"m",
";",
"$",
"day",
"=",
"(",
"int",
")",
"$",
"d",
";",
"$",
"year",
"=",
"(",
"int",
")",
"$",
"y",
";",
"if",
"(",
"checkdate",
"(",
"$",
"month",
",",
"$",
"day",
",",
"$",
"year",
")",
")",
"{",
"if",
"(",
"$",
"day",
"<",
"10",
")",
"{",
"$",
"day",
"=",
"'0'",
".",
"$",
"day",
";",
"}",
"if",
"(",
"$",
"month",
"<",
"10",
")",
"{",
"$",
"month",
"=",
"'0'",
".",
"$",
"month",
";",
"}",
"return",
"$",
"y",
".",
"'-'",
".",
"$",
"month",
".",
"'-'",
".",
"$",
"day",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] | Date Form To SQL
@param Date
@return DateSQL | [
"Date",
"Form",
"To",
"SQL"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L881-L899 |
9,110 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.dateSQLToForm | public static function dateSQLToForm($date)
{
//if (!empty($date) && $date != "0000-00-00" && $date != "0000-00-00 00:00:00"){
if ($this->isDateSQL($date)) {
$arr = explode('-', $date);
$thn = (int)$arr[0];
$bln = (int)$arr[1];
$tgl = (int)$arr[2];
if ($thn > 2000 AND $bln <= 12 AND $bln >= 1 AND $tgl <= 31 AND $tgl >= 1) {
if ($tgl < 10) $tgl = '0' . $tgl;
if ($bln < 10) $bln = '0' . $bln;
if ($thn < 10) $thn = '0' . $thn;
return $tgl . '/' . $bln . '/' . $thn;
}
}
return '';
} | php | public static function dateSQLToForm($date)
{
//if (!empty($date) && $date != "0000-00-00" && $date != "0000-00-00 00:00:00"){
if ($this->isDateSQL($date)) {
$arr = explode('-', $date);
$thn = (int)$arr[0];
$bln = (int)$arr[1];
$tgl = (int)$arr[2];
if ($thn > 2000 AND $bln <= 12 AND $bln >= 1 AND $tgl <= 31 AND $tgl >= 1) {
if ($tgl < 10) $tgl = '0' . $tgl;
if ($bln < 10) $bln = '0' . $bln;
if ($thn < 10) $thn = '0' . $thn;
return $tgl . '/' . $bln . '/' . $thn;
}
}
return '';
} | [
"public",
"static",
"function",
"dateSQLToForm",
"(",
"$",
"date",
")",
"{",
"//if (!empty($date) && $date != \"0000-00-00\" && $date != \"0000-00-00 00:00:00\"){\r",
"if",
"(",
"$",
"this",
"->",
"isDateSQL",
"(",
"$",
"date",
")",
")",
"{",
"$",
"arr",
"=",
"explode",
"(",
"'-'",
",",
"$",
"date",
")",
";",
"$",
"thn",
"=",
"(",
"int",
")",
"$",
"arr",
"[",
"0",
"]",
";",
"$",
"bln",
"=",
"(",
"int",
")",
"$",
"arr",
"[",
"1",
"]",
";",
"$",
"tgl",
"=",
"(",
"int",
")",
"$",
"arr",
"[",
"2",
"]",
";",
"if",
"(",
"$",
"thn",
">",
"2000",
"AND",
"$",
"bln",
"<=",
"12",
"AND",
"$",
"bln",
">=",
"1",
"AND",
"$",
"tgl",
"<=",
"31",
"AND",
"$",
"tgl",
">=",
"1",
")",
"{",
"if",
"(",
"$",
"tgl",
"<",
"10",
")",
"$",
"tgl",
"=",
"'0'",
".",
"$",
"tgl",
";",
"if",
"(",
"$",
"bln",
"<",
"10",
")",
"$",
"bln",
"=",
"'0'",
".",
"$",
"bln",
";",
"if",
"(",
"$",
"thn",
"<",
"10",
")",
"$",
"thn",
"=",
"'0'",
".",
"$",
"thn",
";",
"return",
"$",
"tgl",
".",
"'/'",
".",
"$",
"bln",
".",
"'/'",
".",
"$",
"thn",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | SQL Date To Date Form
@param Date
@return Date | [
"SQL",
"Date",
"To",
"Date",
"Form"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L906-L925 |
9,111 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.dateRangeInWeek | public static function dateRangeInWeek($week = 0, $year = 0)
{
/*
Fungsi ini untuk mendapatkan nilai tanggal berapa saja dalam minggu tertentu
Tanggal dimulai pada hari senin pada minggu tersebut.
returned type: array
*/
$year = (int)$year;
$week = (int)$week;
if ($year < 1970) { // minimal unix time year 1970
$year = date("Y");
$week = date("W");
}
if ($week <= 0 || $week > 54) {
$week = date("W");
$year = date("Y");
}
//cek apakah tanggal 1 masuk minggu pertama atau minggu terakhir tahun sebelumnya
$mingguTanggalAwalTahun = date("W", mktime(1, 0, 0, 1, 1, $year));
$jumlahDetikDalamSehari = 24 * 60 * 60;
$jumlahDetikDalamSeminggu = $jumlahDetikDalamSehari * 7;
$hariAwalTahun = date("w", mktime(1, 0, 0, 1, 1, $year));
// Hari ke 0/7->minggu 1->Senin 2->Selasa 3->Rabu 4->Kamis 5->Jumat 6->Sabtu
$detikAwalTahun = date("U", mktime(1, 0, 0, 1, 1, $year));
if ($hariAwalTahun == 0) {
$hariAwalTahun = 7; // ISO-8601 numeric representation
}
$jumlahHariPadaMingguPertama = (7 - $hariAwalTahun) + 1; //Long variable name but easily understood :P
$detikTambahan = (($week - 1) * $jumlahDetikDalamSeminggu) + ($jumlahHariPadaMingguPertama * $jumlahDetikDalamSehari);
if ($mingguTanggalAwalTahun == 1) {
$tanggalUnixSenin = $detikAwalTahun + $detikTambahan;
} else {
$tanggalUnixSenin = $detikAwalTahun + $detikTambahan + $jumlahDetikDalamSeminggu;
}
$dateRange = array();
for ($i = 1; $i <= 7; $i++) {
$dateRange[$i] = date("Y-m-d", ($tanggalUnixSenin + (($i - 1) * $jumlahDetikDalamSehari) - $jumlahDetikDalamSeminggu));
}
return $dateRange;
} | php | public static function dateRangeInWeek($week = 0, $year = 0)
{
/*
Fungsi ini untuk mendapatkan nilai tanggal berapa saja dalam minggu tertentu
Tanggal dimulai pada hari senin pada minggu tersebut.
returned type: array
*/
$year = (int)$year;
$week = (int)$week;
if ($year < 1970) { // minimal unix time year 1970
$year = date("Y");
$week = date("W");
}
if ($week <= 0 || $week > 54) {
$week = date("W");
$year = date("Y");
}
//cek apakah tanggal 1 masuk minggu pertama atau minggu terakhir tahun sebelumnya
$mingguTanggalAwalTahun = date("W", mktime(1, 0, 0, 1, 1, $year));
$jumlahDetikDalamSehari = 24 * 60 * 60;
$jumlahDetikDalamSeminggu = $jumlahDetikDalamSehari * 7;
$hariAwalTahun = date("w", mktime(1, 0, 0, 1, 1, $year));
// Hari ke 0/7->minggu 1->Senin 2->Selasa 3->Rabu 4->Kamis 5->Jumat 6->Sabtu
$detikAwalTahun = date("U", mktime(1, 0, 0, 1, 1, $year));
if ($hariAwalTahun == 0) {
$hariAwalTahun = 7; // ISO-8601 numeric representation
}
$jumlahHariPadaMingguPertama = (7 - $hariAwalTahun) + 1; //Long variable name but easily understood :P
$detikTambahan = (($week - 1) * $jumlahDetikDalamSeminggu) + ($jumlahHariPadaMingguPertama * $jumlahDetikDalamSehari);
if ($mingguTanggalAwalTahun == 1) {
$tanggalUnixSenin = $detikAwalTahun + $detikTambahan;
} else {
$tanggalUnixSenin = $detikAwalTahun + $detikTambahan + $jumlahDetikDalamSeminggu;
}
$dateRange = array();
for ($i = 1; $i <= 7; $i++) {
$dateRange[$i] = date("Y-m-d", ($tanggalUnixSenin + (($i - 1) * $jumlahDetikDalamSehari) - $jumlahDetikDalamSeminggu));
}
return $dateRange;
} | [
"public",
"static",
"function",
"dateRangeInWeek",
"(",
"$",
"week",
"=",
"0",
",",
"$",
"year",
"=",
"0",
")",
"{",
"/*\r\n Fungsi ini untuk mendapatkan nilai tanggal berapa saja dalam minggu tertentu\r\n Tanggal dimulai pada hari senin pada minggu tersebut.\r\n returned type: array\r\n */",
"$",
"year",
"=",
"(",
"int",
")",
"$",
"year",
";",
"$",
"week",
"=",
"(",
"int",
")",
"$",
"week",
";",
"if",
"(",
"$",
"year",
"<",
"1970",
")",
"{",
"// minimal unix time year 1970\r",
"$",
"year",
"=",
"date",
"(",
"\"Y\"",
")",
";",
"$",
"week",
"=",
"date",
"(",
"\"W\"",
")",
";",
"}",
"if",
"(",
"$",
"week",
"<=",
"0",
"||",
"$",
"week",
">",
"54",
")",
"{",
"$",
"week",
"=",
"date",
"(",
"\"W\"",
")",
";",
"$",
"year",
"=",
"date",
"(",
"\"Y\"",
")",
";",
"}",
"//cek apakah tanggal 1 masuk minggu pertama atau minggu terakhir tahun sebelumnya\r",
"$",
"mingguTanggalAwalTahun",
"=",
"date",
"(",
"\"W\"",
",",
"mktime",
"(",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"$",
"year",
")",
")",
";",
"$",
"jumlahDetikDalamSehari",
"=",
"24",
"*",
"60",
"*",
"60",
";",
"$",
"jumlahDetikDalamSeminggu",
"=",
"$",
"jumlahDetikDalamSehari",
"*",
"7",
";",
"$",
"hariAwalTahun",
"=",
"date",
"(",
"\"w\"",
",",
"mktime",
"(",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"$",
"year",
")",
")",
";",
"// Hari ke 0/7->minggu 1->Senin 2->Selasa 3->Rabu 4->Kamis 5->Jumat 6->Sabtu\r",
"$",
"detikAwalTahun",
"=",
"date",
"(",
"\"U\"",
",",
"mktime",
"(",
"1",
",",
"0",
",",
"0",
",",
"1",
",",
"1",
",",
"$",
"year",
")",
")",
";",
"if",
"(",
"$",
"hariAwalTahun",
"==",
"0",
")",
"{",
"$",
"hariAwalTahun",
"=",
"7",
";",
"// ISO-8601 numeric representation\r",
"}",
"$",
"jumlahHariPadaMingguPertama",
"=",
"(",
"7",
"-",
"$",
"hariAwalTahun",
")",
"+",
"1",
";",
"//Long variable name but easily understood :P\r",
"$",
"detikTambahan",
"=",
"(",
"(",
"$",
"week",
"-",
"1",
")",
"*",
"$",
"jumlahDetikDalamSeminggu",
")",
"+",
"(",
"$",
"jumlahHariPadaMingguPertama",
"*",
"$",
"jumlahDetikDalamSehari",
")",
";",
"if",
"(",
"$",
"mingguTanggalAwalTahun",
"==",
"1",
")",
"{",
"$",
"tanggalUnixSenin",
"=",
"$",
"detikAwalTahun",
"+",
"$",
"detikTambahan",
";",
"}",
"else",
"{",
"$",
"tanggalUnixSenin",
"=",
"$",
"detikAwalTahun",
"+",
"$",
"detikTambahan",
"+",
"$",
"jumlahDetikDalamSeminggu",
";",
"}",
"$",
"dateRange",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"7",
";",
"$",
"i",
"++",
")",
"{",
"$",
"dateRange",
"[",
"$",
"i",
"]",
"=",
"date",
"(",
"\"Y-m-d\"",
",",
"(",
"$",
"tanggalUnixSenin",
"+",
"(",
"(",
"$",
"i",
"-",
"1",
")",
"*",
"$",
"jumlahDetikDalamSehari",
")",
"-",
"$",
"jumlahDetikDalamSeminggu",
")",
")",
";",
"}",
"return",
"$",
"dateRange",
";",
"}"
] | Date Range In Week
@param integer
@param integer
@return Array | [
"Date",
"Range",
"In",
"Week"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L987-L1027 |
9,112 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.weekRangeInMonth | public static function weekRangeInMonth($month, $year)
{
$year = (int)$year;
$month = (int)$month;
if ($year < 1970) { // minimal unix time year 1970
$month = date("n");
$year = date("Y");
}
if ($month <= 0 || $month > 12) {
$month = date("n");
$year = date("Y");
}
if ($month < 10) {
$month2 = '0' . $month;
} else {
$month2 = $month;
}
$weekAwal = (int)$this->weekNumber($year . '-' . $month2 . '-01');
$weekAkhir = (int)$this->weekNumber($year . '-' . $month2 . '-' . $this->maxDateInMonth($month, $year));
/*
echo $year.'-'.$month2.'-01';
echo '<br />';
echo $weekAwal;
echo '<br />';
echo $year.'-'.$month2.'-'.$this->getMaxDateInMonth($month,$year);
echo '<br />';
echo $weekAkhir;
*/
if ($weekAwal > $weekAkhir) {
$weekAwal = 1;
}
$a = 0;
for ($i = $weekAwal; $i <= $weekAkhir; $i++) {
$a++;
$weekRange[$a] = (int)$i;
}
return $weekRange;
} | php | public static function weekRangeInMonth($month, $year)
{
$year = (int)$year;
$month = (int)$month;
if ($year < 1970) { // minimal unix time year 1970
$month = date("n");
$year = date("Y");
}
if ($month <= 0 || $month > 12) {
$month = date("n");
$year = date("Y");
}
if ($month < 10) {
$month2 = '0' . $month;
} else {
$month2 = $month;
}
$weekAwal = (int)$this->weekNumber($year . '-' . $month2 . '-01');
$weekAkhir = (int)$this->weekNumber($year . '-' . $month2 . '-' . $this->maxDateInMonth($month, $year));
/*
echo $year.'-'.$month2.'-01';
echo '<br />';
echo $weekAwal;
echo '<br />';
echo $year.'-'.$month2.'-'.$this->getMaxDateInMonth($month,$year);
echo '<br />';
echo $weekAkhir;
*/
if ($weekAwal > $weekAkhir) {
$weekAwal = 1;
}
$a = 0;
for ($i = $weekAwal; $i <= $weekAkhir; $i++) {
$a++;
$weekRange[$a] = (int)$i;
}
return $weekRange;
} | [
"public",
"static",
"function",
"weekRangeInMonth",
"(",
"$",
"month",
",",
"$",
"year",
")",
"{",
"$",
"year",
"=",
"(",
"int",
")",
"$",
"year",
";",
"$",
"month",
"=",
"(",
"int",
")",
"$",
"month",
";",
"if",
"(",
"$",
"year",
"<",
"1970",
")",
"{",
"// minimal unix time year 1970\r",
"$",
"month",
"=",
"date",
"(",
"\"n\"",
")",
";",
"$",
"year",
"=",
"date",
"(",
"\"Y\"",
")",
";",
"}",
"if",
"(",
"$",
"month",
"<=",
"0",
"||",
"$",
"month",
">",
"12",
")",
"{",
"$",
"month",
"=",
"date",
"(",
"\"n\"",
")",
";",
"$",
"year",
"=",
"date",
"(",
"\"Y\"",
")",
";",
"}",
"if",
"(",
"$",
"month",
"<",
"10",
")",
"{",
"$",
"month2",
"=",
"'0'",
".",
"$",
"month",
";",
"}",
"else",
"{",
"$",
"month2",
"=",
"$",
"month",
";",
"}",
"$",
"weekAwal",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"weekNumber",
"(",
"$",
"year",
".",
"'-'",
".",
"$",
"month2",
".",
"'-01'",
")",
";",
"$",
"weekAkhir",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"weekNumber",
"(",
"$",
"year",
".",
"'-'",
".",
"$",
"month2",
".",
"'-'",
".",
"$",
"this",
"->",
"maxDateInMonth",
"(",
"$",
"month",
",",
"$",
"year",
")",
")",
";",
"/*\r\n echo $year.'-'.$month2.'-01';\r\n echo '<br />';\r\n echo $weekAwal;\r\n echo '<br />';\r\n echo $year.'-'.$month2.'-'.$this->getMaxDateInMonth($month,$year);\r\n echo '<br />';\r\n echo $weekAkhir;\r\n */",
"if",
"(",
"$",
"weekAwal",
">",
"$",
"weekAkhir",
")",
"{",
"$",
"weekAwal",
"=",
"1",
";",
"}",
"$",
"a",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"weekAwal",
";",
"$",
"i",
"<=",
"$",
"weekAkhir",
";",
"$",
"i",
"++",
")",
"{",
"$",
"a",
"++",
";",
"$",
"weekRange",
"[",
"$",
"a",
"]",
"=",
"(",
"int",
")",
"$",
"i",
";",
"}",
"return",
"$",
"weekRange",
";",
"}"
] | Week Range In Month
@param Date - Month
@param Date - Year
@return Array | [
"Week",
"Range",
"In",
"Month"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L1035-L1074 |
9,113 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.getDateSQLToForm | public static function getDateSQLToForm($datetime)
{
//YYYY-mm-dd
$t = $this->splitDate($datetime, false);
return $t['date'] . '/' . $t['month'] . '/' . $t['year'];
} | php | public static function getDateSQLToForm($datetime)
{
//YYYY-mm-dd
$t = $this->splitDate($datetime, false);
return $t['date'] . '/' . $t['month'] . '/' . $t['year'];
} | [
"public",
"static",
"function",
"getDateSQLToForm",
"(",
"$",
"datetime",
")",
"{",
"//YYYY-mm-dd\r",
"$",
"t",
"=",
"$",
"this",
"->",
"splitDate",
"(",
"$",
"datetime",
",",
"false",
")",
";",
"return",
"$",
"t",
"[",
"'date'",
"]",
".",
"'/'",
".",
"$",
"t",
"[",
"'month'",
"]",
".",
"'/'",
".",
"$",
"t",
"[",
"'year'",
"]",
";",
"}"
] | Date SQL to Form
@param DateTime
@return String | [
"Date",
"SQL",
"to",
"Form"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L1176-L1182 |
9,114 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.timeToSec | public static function timeToSec($time)
{
// hh:mm:ss
$split_time = explode(':', $time);
$hour = $split_time[0] * 3600;
$minutes = $split_time[1] * 60;
$second = $split_time[2] * 1;
$timetosec = (int)($hour + $minutes + $second);
return $timetosec;
} | php | public static function timeToSec($time)
{
// hh:mm:ss
$split_time = explode(':', $time);
$hour = $split_time[0] * 3600;
$minutes = $split_time[1] * 60;
$second = $split_time[2] * 1;
$timetosec = (int)($hour + $minutes + $second);
return $timetosec;
} | [
"public",
"static",
"function",
"timeToSec",
"(",
"$",
"time",
")",
"{",
"// hh:mm:ss\r",
"$",
"split_time",
"=",
"explode",
"(",
"':'",
",",
"$",
"time",
")",
";",
"$",
"hour",
"=",
"$",
"split_time",
"[",
"0",
"]",
"*",
"3600",
";",
"$",
"minutes",
"=",
"$",
"split_time",
"[",
"1",
"]",
"*",
"60",
";",
"$",
"second",
"=",
"$",
"split_time",
"[",
"2",
"]",
"*",
"1",
";",
"$",
"timetosec",
"=",
"(",
"int",
")",
"(",
"$",
"hour",
"+",
"$",
"minutes",
"+",
"$",
"second",
")",
";",
"return",
"$",
"timetosec",
";",
"}"
] | Time To Sec
@param Time
@return String | [
"Time",
"To",
"Sec"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L1189-L1200 |
9,115 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.secToTime | public static function secToTime($sec)
{
// int sec
$hour = (int)floor($sec / 3600);
$minutes = (int)floor(($sec % 3600) / 60);
$second = (int)$sec - (($hour * 3600) + ($minutes * 60));
if ($hour <= 9) {
$hour = '0' . $hour;
}
if ($minutes <= 9) {
$minutes = '0' . $minutes;
}
if ($second <= 9) {
$second = '0' . $second;
}
return $hour . ':' . $minutes . ':' . $second; // return hh:mm:ss
} | php | public static function secToTime($sec)
{
// int sec
$hour = (int)floor($sec / 3600);
$minutes = (int)floor(($sec % 3600) / 60);
$second = (int)$sec - (($hour * 3600) + ($minutes * 60));
if ($hour <= 9) {
$hour = '0' . $hour;
}
if ($minutes <= 9) {
$minutes = '0' . $minutes;
}
if ($second <= 9) {
$second = '0' . $second;
}
return $hour . ':' . $minutes . ':' . $second; // return hh:mm:ss
} | [
"public",
"static",
"function",
"secToTime",
"(",
"$",
"sec",
")",
"{",
"// int sec\r",
"$",
"hour",
"=",
"(",
"int",
")",
"floor",
"(",
"$",
"sec",
"/",
"3600",
")",
";",
"$",
"minutes",
"=",
"(",
"int",
")",
"floor",
"(",
"(",
"$",
"sec",
"%",
"3600",
")",
"/",
"60",
")",
";",
"$",
"second",
"=",
"(",
"int",
")",
"$",
"sec",
"-",
"(",
"(",
"$",
"hour",
"*",
"3600",
")",
"+",
"(",
"$",
"minutes",
"*",
"60",
")",
")",
";",
"if",
"(",
"$",
"hour",
"<=",
"9",
")",
"{",
"$",
"hour",
"=",
"'0'",
".",
"$",
"hour",
";",
"}",
"if",
"(",
"$",
"minutes",
"<=",
"9",
")",
"{",
"$",
"minutes",
"=",
"'0'",
".",
"$",
"minutes",
";",
"}",
"if",
"(",
"$",
"second",
"<=",
"9",
")",
"{",
"$",
"second",
"=",
"'0'",
".",
"$",
"second",
";",
"}",
"return",
"$",
"hour",
".",
"':'",
".",
"$",
"minutes",
".",
"':'",
".",
"$",
"second",
";",
"// return hh:mm:ss\r",
"}"
] | Sec to Time
@param Sec
@return Time | [
"Sec",
"to",
"Time"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L1207-L1225 |
9,116 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.timeToInt | public static function timeToInt($time)
{
$timeHour = substr($time, 0, 2);
if (substr($time, 0, 1) == '0') {
$timeHour = substr($time, 1, 1);
}
$timeMin = substr($time, 3, 5);
$timeHourMin = ((int)$timeHour * 60) + ((int)$timeMin / 1);
$values = $timeHourMin;
return $values;
} | php | public static function timeToInt($time)
{
$timeHour = substr($time, 0, 2);
if (substr($time, 0, 1) == '0') {
$timeHour = substr($time, 1, 1);
}
$timeMin = substr($time, 3, 5);
$timeHourMin = ((int)$timeHour * 60) + ((int)$timeMin / 1);
$values = $timeHourMin;
return $values;
} | [
"public",
"static",
"function",
"timeToInt",
"(",
"$",
"time",
")",
"{",
"$",
"timeHour",
"=",
"substr",
"(",
"$",
"time",
",",
"0",
",",
"2",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"time",
",",
"0",
",",
"1",
")",
"==",
"'0'",
")",
"{",
"$",
"timeHour",
"=",
"substr",
"(",
"$",
"time",
",",
"1",
",",
"1",
")",
";",
"}",
"$",
"timeMin",
"=",
"substr",
"(",
"$",
"time",
",",
"3",
",",
"5",
")",
";",
"$",
"timeHourMin",
"=",
"(",
"(",
"int",
")",
"$",
"timeHour",
"*",
"60",
")",
"+",
"(",
"(",
"int",
")",
"$",
"timeMin",
"/",
"1",
")",
";",
"$",
"values",
"=",
"$",
"timeHourMin",
";",
"return",
"$",
"values",
";",
"}"
] | Time to Integer
@param Time
@return Integer | [
"Time",
"to",
"Integer"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L1232-L1243 |
9,117 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.timeToText | public static function timeToText($time)
{
$timeHour = ceil($time * 60);
$modMinutes = $timeHour % 60;
$hour = floor($time);
return $hour . ' h ' . $modMinutes . ' m';
} | php | public static function timeToText($time)
{
$timeHour = ceil($time * 60);
$modMinutes = $timeHour % 60;
$hour = floor($time);
return $hour . ' h ' . $modMinutes . ' m';
} | [
"public",
"static",
"function",
"timeToText",
"(",
"$",
"time",
")",
"{",
"$",
"timeHour",
"=",
"ceil",
"(",
"$",
"time",
"*",
"60",
")",
";",
"$",
"modMinutes",
"=",
"$",
"timeHour",
"%",
"60",
";",
"$",
"hour",
"=",
"floor",
"(",
"$",
"time",
")",
";",
"return",
"$",
"hour",
".",
"' h '",
".",
"$",
"modMinutes",
".",
"' m'",
";",
"}"
] | Time To Text
@param Time
@return String | [
"Time",
"To",
"Text"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L1250-L1257 |
9,118 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.countMonthBetweenDate | public static function countMonthBetweenDate($startDate, $endDate)
{
$d1 = strtotime($startDate);
$d2 = strtotime($endDate);
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);
$i = 0;
while (($min_date = strtotime("+1 MONTH", $min_date)) <= $max_date) {
$i++;
}
echo $i;
} | php | public static function countMonthBetweenDate($startDate, $endDate)
{
$d1 = strtotime($startDate);
$d2 = strtotime($endDate);
$min_date = min($d1, $d2);
$max_date = max($d1, $d2);
$i = 0;
while (($min_date = strtotime("+1 MONTH", $min_date)) <= $max_date) {
$i++;
}
echo $i;
} | [
"public",
"static",
"function",
"countMonthBetweenDate",
"(",
"$",
"startDate",
",",
"$",
"endDate",
")",
"{",
"$",
"d1",
"=",
"strtotime",
"(",
"$",
"startDate",
")",
";",
"$",
"d2",
"=",
"strtotime",
"(",
"$",
"endDate",
")",
";",
"$",
"min_date",
"=",
"min",
"(",
"$",
"d1",
",",
"$",
"d2",
")",
";",
"$",
"max_date",
"=",
"max",
"(",
"$",
"d1",
",",
"$",
"d2",
")",
";",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"(",
"$",
"min_date",
"=",
"strtotime",
"(",
"\"+1 MONTH\"",
",",
"$",
"min_date",
")",
")",
"<=",
"$",
"max_date",
")",
"{",
"$",
"i",
"++",
";",
"}",
"echo",
"$",
"i",
";",
"}"
] | Count Month Between Date
@param Date
@param Date
@return Integer | [
"Count",
"Month",
"Between",
"Date"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L1397-L1409 |
9,119 | prastowoagungwidodo/utility | src/Transformatika/Utility/Fn.php | Fn.monthListBetweenDate | public static function monthListBetweenDate($startDate, $endDate)
{
$output = [];
$time = strtotime($startDate);
$last = date('m-Y', strtotime($endDate));
do {
$month = date('m-Y', $time);
$total = date('t', $time);
$output[] = [
'month' => $month,
'total' => $total,
];
$time = strtotime('+1 month', $time);
} while ($month != $last);
} | php | public static function monthListBetweenDate($startDate, $endDate)
{
$output = [];
$time = strtotime($startDate);
$last = date('m-Y', strtotime($endDate));
do {
$month = date('m-Y', $time);
$total = date('t', $time);
$output[] = [
'month' => $month,
'total' => $total,
];
$time = strtotime('+1 month', $time);
} while ($month != $last);
} | [
"public",
"static",
"function",
"monthListBetweenDate",
"(",
"$",
"startDate",
",",
"$",
"endDate",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"$",
"time",
"=",
"strtotime",
"(",
"$",
"startDate",
")",
";",
"$",
"last",
"=",
"date",
"(",
"'m-Y'",
",",
"strtotime",
"(",
"$",
"endDate",
")",
")",
";",
"do",
"{",
"$",
"month",
"=",
"date",
"(",
"'m-Y'",
",",
"$",
"time",
")",
";",
"$",
"total",
"=",
"date",
"(",
"'t'",
",",
"$",
"time",
")",
";",
"$",
"output",
"[",
"]",
"=",
"[",
"'month'",
"=>",
"$",
"month",
",",
"'total'",
"=>",
"$",
"total",
",",
"]",
";",
"$",
"time",
"=",
"strtotime",
"(",
"'+1 month'",
",",
"$",
"time",
")",
";",
"}",
"while",
"(",
"$",
"month",
"!=",
"$",
"last",
")",
";",
"}"
] | Get Month List And Month Total
@param Date
@param Date
@return Array | [
"Get",
"Month",
"List",
"And",
"Month",
"Total"
] | bbacc1a8ec15befae83c6a29b60e568fd02d66b7 | https://github.com/prastowoagungwidodo/utility/blob/bbacc1a8ec15befae83c6a29b60e568fd02d66b7/src/Transformatika/Utility/Fn.php#L1417-L1434 |
9,120 | FuturaSoft/Pabana | src/Mvc/Model.php | Model.get | public function get($modelName)
{
$modelNamespace = Configuration::read('mvc.model.namespace');
$modelNamespace = $modelNamespace . '\\' . ucFirst($modelName);
if (!class_exists($modelNamespace)) {
trigger_error('Model "' . $modelNamespace . '" doesn\'t exist.', E_USER_ERROR);
return false;
}
return new $modelNamespace();
} | php | public function get($modelName)
{
$modelNamespace = Configuration::read('mvc.model.namespace');
$modelNamespace = $modelNamespace . '\\' . ucFirst($modelName);
if (!class_exists($modelNamespace)) {
trigger_error('Model "' . $modelNamespace . '" doesn\'t exist.', E_USER_ERROR);
return false;
}
return new $modelNamespace();
} | [
"public",
"function",
"get",
"(",
"$",
"modelName",
")",
"{",
"$",
"modelNamespace",
"=",
"Configuration",
"::",
"read",
"(",
"'mvc.model.namespace'",
")",
";",
"$",
"modelNamespace",
"=",
"$",
"modelNamespace",
".",
"'\\\\'",
".",
"ucFirst",
"(",
"$",
"modelName",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"modelNamespace",
")",
")",
"{",
"trigger_error",
"(",
"'Model \"'",
".",
"$",
"modelNamespace",
".",
"'\" doesn\\'t exist.'",
",",
"E_USER_ERROR",
")",
";",
"return",
"false",
";",
"}",
"return",
"new",
"$",
"modelNamespace",
"(",
")",
";",
"}"
] | Call a model class
@since 1.0
@param string $modelName Model class name
@return object|bool Return model defined in $modelName or false if error | [
"Call",
"a",
"model",
"class"
] | b3a95eeb976042ac2a393cc10755a7adbc164c24 | https://github.com/FuturaSoft/Pabana/blob/b3a95eeb976042ac2a393cc10755a7adbc164c24/src/Mvc/Model.php#L64-L73 |
9,121 | docit/core | src/Project.php | Project.path | public function path($path = null)
{
return is_null($path) ? Path::join($this->path, $this->ref) : Path::join($this->path, $this->ref, $path);
} | php | public function path($path = null)
{
return is_null($path) ? Path::join($this->path, $this->ref) : Path::join($this->path, $this->ref, $path);
} | [
"public",
"function",
"path",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"return",
"is_null",
"(",
"$",
"path",
")",
"?",
"Path",
"::",
"join",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"this",
"->",
"ref",
")",
":",
"Path",
"::",
"join",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"this",
"->",
"ref",
",",
"$",
"path",
")",
";",
"}"
] | Get the absolute path to a file in the project using the current ref
@param null|string $path
@return string | [
"Get",
"the",
"absolute",
"path",
"to",
"a",
"file",
"in",
"the",
"project",
"using",
"the",
"current",
"ref"
] | 448e1cdca18a8ffb6c08430cad8d22162171ac35 | https://github.com/docit/core/blob/448e1cdca18a8ffb6c08430cad8d22162171ac35/src/Project.php#L191-L194 |
9,122 | docit/core | src/Project.php | Project.getDocumentsMenu | public function getDocumentsMenu()
{
$yaml = $this->files->get(Path::join($this->path, $this->ref, 'menu.yml'));
$array = Yaml::parse($yaml);
$this->factory->getMenus()->forget('project_sidebar_menu');
$menu = $this->resolveDocumentsMenu($array[ 'menu' ]);
$menu->setView('docit::menus/project-sidebar');
$this->runHook('project:documents-menu', [ $this, $menu ]);
return $menu;
} | php | public function getDocumentsMenu()
{
$yaml = $this->files->get(Path::join($this->path, $this->ref, 'menu.yml'));
$array = Yaml::parse($yaml);
$this->factory->getMenus()->forget('project_sidebar_menu');
$menu = $this->resolveDocumentsMenu($array[ 'menu' ]);
$menu->setView('docit::menus/project-sidebar');
$this->runHook('project:documents-menu', [ $this, $menu ]);
return $menu;
} | [
"public",
"function",
"getDocumentsMenu",
"(",
")",
"{",
"$",
"yaml",
"=",
"$",
"this",
"->",
"files",
"->",
"get",
"(",
"Path",
"::",
"join",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"this",
"->",
"ref",
",",
"'menu.yml'",
")",
")",
";",
"$",
"array",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"yaml",
")",
";",
"$",
"this",
"->",
"factory",
"->",
"getMenus",
"(",
")",
"->",
"forget",
"(",
"'project_sidebar_menu'",
")",
";",
"$",
"menu",
"=",
"$",
"this",
"->",
"resolveDocumentsMenu",
"(",
"$",
"array",
"[",
"'menu'",
"]",
")",
";",
"$",
"menu",
"->",
"setView",
"(",
"'docit::menus/project-sidebar'",
")",
";",
"$",
"this",
"->",
"runHook",
"(",
"'project:documents-menu'",
",",
"[",
"$",
"this",
",",
"$",
"menu",
"]",
")",
";",
"return",
"$",
"menu",
";",
"}"
] | Returns the menu for this project
@return \Docit\Core\Menus\Menu | [
"Returns",
"the",
"menu",
"for",
"this",
"project"
] | 448e1cdca18a8ffb6c08430cad8d22162171ac35 | https://github.com/docit/core/blob/448e1cdca18a8ffb6c08430cad8d22162171ac35/src/Project.php#L246-L258 |
9,123 | docit/core | src/Project.php | Project.resolveDocumentsMenu | protected function resolveDocumentsMenu($items, $parentId = 'root')
{
/**
* @var Menus\Menu $menu
*/
$menu = $this->factory->getMenus()->add('project_sidebar_menu');
foreach ($items as $item) {
$link = '#';
if (array_key_exists('document', $item)) {
// remove .md extension if present
$path = Str::endsWith($item[ 'document' ], '.md', false) ? Str::remove($item[ 'document' ], '.md') : $item[ 'document' ];
$link = $this->factory->url($this, $this->ref, $path);
} elseif (array_key_exists('href', $item)) {
$link = $item[ 'href' ];
}
$id = md5($item[ 'name' ] . $link);
$node = $menu->add($id, $item[ 'name' ], $parentId);
$node->setAttribute('href', $link);
$node->setAttribute('id', $id);
if (isset($item[ 'icon' ])) {
$node->setMeta('icon', $item[ 'icon' ]);
}
if (isset($item[ 'children' ])) {
$this->resolveDocumentsMenu($item[ 'children' ], $id);
}
}
return $menu;
} | php | protected function resolveDocumentsMenu($items, $parentId = 'root')
{
/**
* @var Menus\Menu $menu
*/
$menu = $this->factory->getMenus()->add('project_sidebar_menu');
foreach ($items as $item) {
$link = '#';
if (array_key_exists('document', $item)) {
// remove .md extension if present
$path = Str::endsWith($item[ 'document' ], '.md', false) ? Str::remove($item[ 'document' ], '.md') : $item[ 'document' ];
$link = $this->factory->url($this, $this->ref, $path);
} elseif (array_key_exists('href', $item)) {
$link = $item[ 'href' ];
}
$id = md5($item[ 'name' ] . $link);
$node = $menu->add($id, $item[ 'name' ], $parentId);
$node->setAttribute('href', $link);
$node->setAttribute('id', $id);
if (isset($item[ 'icon' ])) {
$node->setMeta('icon', $item[ 'icon' ]);
}
if (isset($item[ 'children' ])) {
$this->resolveDocumentsMenu($item[ 'children' ], $id);
}
}
return $menu;
} | [
"protected",
"function",
"resolveDocumentsMenu",
"(",
"$",
"items",
",",
"$",
"parentId",
"=",
"'root'",
")",
"{",
"/**\n * @var Menus\\Menu $menu\n */",
"$",
"menu",
"=",
"$",
"this",
"->",
"factory",
"->",
"getMenus",
"(",
")",
"->",
"add",
"(",
"'project_sidebar_menu'",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"link",
"=",
"'#'",
";",
"if",
"(",
"array_key_exists",
"(",
"'document'",
",",
"$",
"item",
")",
")",
"{",
"// remove .md extension if present",
"$",
"path",
"=",
"Str",
"::",
"endsWith",
"(",
"$",
"item",
"[",
"'document'",
"]",
",",
"'.md'",
",",
"false",
")",
"?",
"Str",
"::",
"remove",
"(",
"$",
"item",
"[",
"'document'",
"]",
",",
"'.md'",
")",
":",
"$",
"item",
"[",
"'document'",
"]",
";",
"$",
"link",
"=",
"$",
"this",
"->",
"factory",
"->",
"url",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"ref",
",",
"$",
"path",
")",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"'href'",
",",
"$",
"item",
")",
")",
"{",
"$",
"link",
"=",
"$",
"item",
"[",
"'href'",
"]",
";",
"}",
"$",
"id",
"=",
"md5",
"(",
"$",
"item",
"[",
"'name'",
"]",
".",
"$",
"link",
")",
";",
"$",
"node",
"=",
"$",
"menu",
"->",
"add",
"(",
"$",
"id",
",",
"$",
"item",
"[",
"'name'",
"]",
",",
"$",
"parentId",
")",
";",
"$",
"node",
"->",
"setAttribute",
"(",
"'href'",
",",
"$",
"link",
")",
";",
"$",
"node",
"->",
"setAttribute",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'icon'",
"]",
")",
")",
"{",
"$",
"node",
"->",
"setMeta",
"(",
"'icon'",
",",
"$",
"item",
"[",
"'icon'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'children'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"resolveDocumentsMenu",
"(",
"$",
"item",
"[",
"'children'",
"]",
",",
"$",
"id",
")",
";",
"}",
"}",
"return",
"$",
"menu",
";",
"}"
] | Resolves and creates the documents menu from the parsed menu.yml
@param array $items The array converted from yaml
@param string $parentId
@return \Docit\Core\Menus\Menu | [
"Resolves",
"and",
"creates",
"the",
"documents",
"menu",
"from",
"the",
"parsed",
"menu",
".",
"yml"
] | 448e1cdca18a8ffb6c08430cad8d22162171ac35 | https://github.com/docit/core/blob/448e1cdca18a8ffb6c08430cad8d22162171ac35/src/Project.php#L267-L300 |
9,124 | docit/core | src/Project.php | Project.getSortedRefs | public function getSortedRefs()
{
$versions = $this->versions;
usort($versions, function (version $v1, version $v2) {
return version::gt($v1, $v2) ? -1 : 1;
});
$versions = array_map(function (version $v) {
return $v->getVersion();
}, $versions);
return array_merge($this->branches, $versions);
} | php | public function getSortedRefs()
{
$versions = $this->versions;
usort($versions, function (version $v1, version $v2) {
return version::gt($v1, $v2) ? -1 : 1;
});
$versions = array_map(function (version $v) {
return $v->getVersion();
}, $versions);
return array_merge($this->branches, $versions);
} | [
"public",
"function",
"getSortedRefs",
"(",
")",
"{",
"$",
"versions",
"=",
"$",
"this",
"->",
"versions",
";",
"usort",
"(",
"$",
"versions",
",",
"function",
"(",
"version",
"$",
"v1",
",",
"version",
"$",
"v2",
")",
"{",
"return",
"version",
"::",
"gt",
"(",
"$",
"v1",
",",
"$",
"v2",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"$",
"versions",
"=",
"array_map",
"(",
"function",
"(",
"version",
"$",
"v",
")",
"{",
"return",
"$",
"v",
"->",
"getVersion",
"(",
")",
";",
"}",
",",
"$",
"versions",
")",
";",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"branches",
",",
"$",
"versions",
")",
";",
"}"
] | Get refs sorted by the configured order.
@return array | [
"Get",
"refs",
"sorted",
"by",
"the",
"configured",
"order",
"."
] | 448e1cdca18a8ffb6c08430cad8d22162171ac35 | https://github.com/docit/core/blob/448e1cdca18a8ffb6c08430cad8d22162171ac35/src/Project.php#L383-L400 |
9,125 | studyportals/Utils | src/Sanitize.php | Sanitize.url | public static function url($url){
$url = static::_nullValue($url);
if(!$url){
return $url;
}
$query = parse_url($url, PHP_URL_QUERY);
if(!$query){
return $url;
}
parse_str($query, $query_parts);
// First urldecode to be sure that we do not re-encode the query parts.
$query_parts = array_map('static::_nested_urldecode', $query_parts);
// http_build_query will take care of the urlencode.
return strtok($url, '?') . '?' . http_build_query($query_parts);
} | php | public static function url($url){
$url = static::_nullValue($url);
if(!$url){
return $url;
}
$query = parse_url($url, PHP_URL_QUERY);
if(!$query){
return $url;
}
parse_str($query, $query_parts);
// First urldecode to be sure that we do not re-encode the query parts.
$query_parts = array_map('static::_nested_urldecode', $query_parts);
// http_build_query will take care of the urlencode.
return strtok($url, '?') . '?' . http_build_query($query_parts);
} | [
"public",
"static",
"function",
"url",
"(",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"static",
"::",
"_nullValue",
"(",
"$",
"url",
")",
";",
"if",
"(",
"!",
"$",
"url",
")",
"{",
"return",
"$",
"url",
";",
"}",
"$",
"query",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_QUERY",
")",
";",
"if",
"(",
"!",
"$",
"query",
")",
"{",
"return",
"$",
"url",
";",
"}",
"parse_str",
"(",
"$",
"query",
",",
"$",
"query_parts",
")",
";",
"// First urldecode to be sure that we do not re-encode the query parts.",
"$",
"query_parts",
"=",
"array_map",
"(",
"'static::_nested_urldecode'",
",",
"$",
"query_parts",
")",
";",
"// http_build_query will take care of the urlencode.",
"return",
"strtok",
"(",
"$",
"url",
",",
"'?'",
")",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"query_parts",
")",
";",
"}"
] | This will rebuild the url with all the query-parts url_encoded.
@param {string} $url
@return string|null | [
"This",
"will",
"rebuild",
"the",
"url",
"with",
"all",
"the",
"query",
"-",
"parts",
"url_encoded",
"."
] | eab69ca10ce3261480164cf8108ae7020459c847 | https://github.com/studyportals/Utils/blob/eab69ca10ce3261480164cf8108ae7020459c847/src/Sanitize.php#L174-L195 |
9,126 | studyportals/Utils | src/Sanitize.php | Sanitize.replaceHttpsUrls | public static function replaceHttpsUrls($value){
// CDN resources
$value = str_ireplace('http://cdn.prtl.eu', '//cdn.prtl.eu', $value);
$value = str_ireplace('http://cdn2.prtl.eu', '//cdn2.prtl.eu', $value);
$value = str_ireplace('http://studyportals-cdn2.imgix.net', '//studyportals-cdn2.imgix.net', $value);
// Portal urls
$value = str_ireplace('http://www.admissiontestportal.com', 'https://www.admissiontestportal.com', $value);
$value = str_ireplace('http://www.preparationcoursesportal.com', 'https://www.preparationcoursesportal.com', $value);
return $value; //NOSONAR
} | php | public static function replaceHttpsUrls($value){
// CDN resources
$value = str_ireplace('http://cdn.prtl.eu', '//cdn.prtl.eu', $value);
$value = str_ireplace('http://cdn2.prtl.eu', '//cdn2.prtl.eu', $value);
$value = str_ireplace('http://studyportals-cdn2.imgix.net', '//studyportals-cdn2.imgix.net', $value);
// Portal urls
$value = str_ireplace('http://www.admissiontestportal.com', 'https://www.admissiontestportal.com', $value);
$value = str_ireplace('http://www.preparationcoursesportal.com', 'https://www.preparationcoursesportal.com', $value);
return $value; //NOSONAR
} | [
"public",
"static",
"function",
"replaceHttpsUrls",
"(",
"$",
"value",
")",
"{",
"// CDN resources",
"$",
"value",
"=",
"str_ireplace",
"(",
"'http://cdn.prtl.eu'",
",",
"'//cdn.prtl.eu'",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"str_ireplace",
"(",
"'http://cdn2.prtl.eu'",
",",
"'//cdn2.prtl.eu'",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"str_ireplace",
"(",
"'http://studyportals-cdn2.imgix.net'",
",",
"'//studyportals-cdn2.imgix.net'",
",",
"$",
"value",
")",
";",
"// Portal urls",
"$",
"value",
"=",
"str_ireplace",
"(",
"'http://www.admissiontestportal.com'",
",",
"'https://www.admissiontestportal.com'",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"str_ireplace",
"(",
"'http://www.preparationcoursesportal.com'",
",",
"'https://www.preparationcoursesportal.com'",
",",
"$",
"value",
")",
";",
"return",
"$",
"value",
";",
"//NOSONAR",
"}"
] | Find en replaces all http urls which should be https.
@param {string} $value
@return string | [
"Find",
"en",
"replaces",
"all",
"http",
"urls",
"which",
"should",
"be",
"https",
"."
] | eab69ca10ce3261480164cf8108ae7020459c847 | https://github.com/studyportals/Utils/blob/eab69ca10ce3261480164cf8108ae7020459c847/src/Sanitize.php#L204-L216 |
9,127 | docit/core | src/Factory.php | Factory.url | public function url($project = null, $ref = null, $doc = null)
{
$uri = $this->config('base_route');
if ( ! is_null($project) )
{
if ( ! $project instanceof Project )
{
$project = $this->getProject($project);
}
$uri .= '/' . $project->getName();
if ( ! is_null($ref) )
{
$uri .= '/' . $ref;
}
else
{
$uri .= '/' . $project->getDefaultRef();
}
if ( ! is_null($doc) )
{
$uri .= '/' . $doc;
}
}
return url($uri);
} | php | public function url($project = null, $ref = null, $doc = null)
{
$uri = $this->config('base_route');
if ( ! is_null($project) )
{
if ( ! $project instanceof Project )
{
$project = $this->getProject($project);
}
$uri .= '/' . $project->getName();
if ( ! is_null($ref) )
{
$uri .= '/' . $ref;
}
else
{
$uri .= '/' . $project->getDefaultRef();
}
if ( ! is_null($doc) )
{
$uri .= '/' . $doc;
}
}
return url($uri);
} | [
"public",
"function",
"url",
"(",
"$",
"project",
"=",
"null",
",",
"$",
"ref",
"=",
"null",
",",
"$",
"doc",
"=",
"null",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"config",
"(",
"'base_route'",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"project",
")",
")",
"{",
"if",
"(",
"!",
"$",
"project",
"instanceof",
"Project",
")",
"{",
"$",
"project",
"=",
"$",
"this",
"->",
"getProject",
"(",
"$",
"project",
")",
";",
"}",
"$",
"uri",
".=",
"'/'",
".",
"$",
"project",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"ref",
")",
")",
"{",
"$",
"uri",
".=",
"'/'",
".",
"$",
"ref",
";",
"}",
"else",
"{",
"$",
"uri",
".=",
"'/'",
".",
"$",
"project",
"->",
"getDefaultRef",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"doc",
")",
")",
"{",
"$",
"uri",
".=",
"'/'",
".",
"$",
"doc",
";",
"}",
"}",
"return",
"url",
"(",
"$",
"uri",
")",
";",
"}"
] | Generate a URL to a project's default page and version.
@param Project|string $project A Project instance or projectName, will auto-resolve
@param null|string $ref
@param null|string $doc
@return string | [
"Generate",
"a",
"URL",
"to",
"a",
"project",
"s",
"default",
"page",
"and",
"version",
"."
] | 448e1cdca18a8ffb6c08430cad8d22162171ac35 | https://github.com/docit/core/blob/448e1cdca18a8ffb6c08430cad8d22162171ac35/src/Factory.php#L239-L269 |
9,128 | bytic/helpers | src/Arrays.php | Nip_Helper_Arrays.without | public function without($array)
{
$values = func_get_args();
unset($values[0]);
if ($values) {
foreach ($values as $value) {
unset($array[array_search($value, $array)]);
}
}
return $array;
} | php | public function without($array)
{
$values = func_get_args();
unset($values[0]);
if ($values) {
foreach ($values as $value) {
unset($array[array_search($value, $array)]);
}
}
return $array;
} | [
"public",
"function",
"without",
"(",
"$",
"array",
")",
"{",
"$",
"values",
"=",
"func_get_args",
"(",
")",
";",
"unset",
"(",
"$",
"values",
"[",
"0",
"]",
")",
";",
"if",
"(",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"unset",
"(",
"$",
"array",
"[",
"array_search",
"(",
"$",
"value",
",",
"$",
"array",
")",
"]",
")",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] | Produces a new version of the array that does not contain any of the specified values
@param array $array
@return array | [
"Produces",
"a",
"new",
"version",
"of",
"the",
"array",
"that",
"does",
"not",
"contain",
"any",
"of",
"the",
"specified",
"values"
] | 6a4f0388ba8653d65058ce63cf7627e38b9df041 | https://github.com/bytic/helpers/blob/6a4f0388ba8653d65058ce63cf7627e38b9df041/src/Arrays.php#L133-L145 |
9,129 | bytic/helpers | src/Arrays.php | Nip_Helper_Arrays.pluck | public function pluck($array, $property, &$return = false)
{
$return = [];
if (count($array) > 0) {
foreach ($array as $item) {
if (is_array($item)) {
$this->pluck($array, $property, $return);
}
$return[] = $item->$property;
}
}
return $return;
} | php | public function pluck($array, $property, &$return = false)
{
$return = [];
if (count($array) > 0) {
foreach ($array as $item) {
if (is_array($item)) {
$this->pluck($array, $property, $return);
}
$return[] = $item->$property;
}
}
return $return;
} | [
"public",
"function",
"pluck",
"(",
"$",
"array",
",",
"$",
"property",
",",
"&",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"array",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"item",
")",
")",
"{",
"$",
"this",
"->",
"pluck",
"(",
"$",
"array",
",",
"$",
"property",
",",
"$",
"return",
")",
";",
"}",
"$",
"return",
"[",
"]",
"=",
"$",
"item",
"->",
"$",
"property",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Fetch the same property for all the elements.
@param Nip\Records\Collections\Collection $array
@param string $property
@param bool|string $return
@return array The property values | [
"Fetch",
"the",
"same",
"property",
"for",
"all",
"the",
"elements",
"."
] | 6a4f0388ba8653d65058ce63cf7627e38b9df041 | https://github.com/bytic/helpers/blob/6a4f0388ba8653d65058ce63cf7627e38b9df041/src/Arrays.php#L195-L210 |
9,130 | bytic/helpers | src/Arrays.php | Nip_Helper_Arrays.toXML | public function toXML($data, $rootNodeName = 'ResultSet', &$xml = null)
{
// turn off compatibility mode as simple xml throws a wobbly if you don't.
if (ini_get('zend.ze1_compatibility_mode') == 1) {
ini_set('zend.ze1_compatibility_mode', 0);
}
if (is_null($xml)) {
$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />");
}
// loop through the data passed in.
foreach ($data as $key => $value) {
// no numeric keys in our xml please!
if (is_numeric($key)) {
$numeric = 1;
$key = $rootNodeName;
}
// delete any char not allowed in XML element names
$key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key);
// if there is another array found recrusively call this function
if (is_array($value)) {
$node = $this->isAssoc($value) || $numeric ? $xml->addChild($key) : $xml;
// recursive call
if ($numeric) {
$key = 'anon';
}
$this->toXML($value, $key, $node);
} else {
// add single node.
$value = htmlentities($value);
// $xml->addChild($key, $value);
$xml->addAttribute($key, $value);
}
}
// pass back as XML
// return $xml->asXML();
// if you want the XML to be formatted, use the below instead to return the XML
$doc = new DOMDocument('1.0');
$doc->preserveWhiteSpace = false;
$doc->loadXML($xml->asXML());
$doc->formatOutput = true;
return $doc->saveXML();
} | php | public function toXML($data, $rootNodeName = 'ResultSet', &$xml = null)
{
// turn off compatibility mode as simple xml throws a wobbly if you don't.
if (ini_get('zend.ze1_compatibility_mode') == 1) {
ini_set('zend.ze1_compatibility_mode', 0);
}
if (is_null($xml)) {
$xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><$rootNodeName />");
}
// loop through the data passed in.
foreach ($data as $key => $value) {
// no numeric keys in our xml please!
if (is_numeric($key)) {
$numeric = 1;
$key = $rootNodeName;
}
// delete any char not allowed in XML element names
$key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key);
// if there is another array found recrusively call this function
if (is_array($value)) {
$node = $this->isAssoc($value) || $numeric ? $xml->addChild($key) : $xml;
// recursive call
if ($numeric) {
$key = 'anon';
}
$this->toXML($value, $key, $node);
} else {
// add single node.
$value = htmlentities($value);
// $xml->addChild($key, $value);
$xml->addAttribute($key, $value);
}
}
// pass back as XML
// return $xml->asXML();
// if you want the XML to be formatted, use the below instead to return the XML
$doc = new DOMDocument('1.0');
$doc->preserveWhiteSpace = false;
$doc->loadXML($xml->asXML());
$doc->formatOutput = true;
return $doc->saveXML();
} | [
"public",
"function",
"toXML",
"(",
"$",
"data",
",",
"$",
"rootNodeName",
"=",
"'ResultSet'",
",",
"&",
"$",
"xml",
"=",
"null",
")",
"{",
"// turn off compatibility mode as simple xml throws a wobbly if you don't.",
"if",
"(",
"ini_get",
"(",
"'zend.ze1_compatibility_mode'",
")",
"==",
"1",
")",
"{",
"ini_set",
"(",
"'zend.ze1_compatibility_mode'",
",",
"0",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"xml",
")",
")",
"{",
"$",
"xml",
"=",
"simplexml_load_string",
"(",
"\"<?xml version='1.0' encoding='utf-8'?><$rootNodeName />\"",
")",
";",
"}",
"// loop through the data passed in.",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// no numeric keys in our xml please!",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"numeric",
"=",
"1",
";",
"$",
"key",
"=",
"$",
"rootNodeName",
";",
"}",
"// delete any char not allowed in XML element names",
"$",
"key",
"=",
"preg_replace",
"(",
"'/[^a-z0-9\\-\\_\\.\\:]/i'",
",",
"''",
",",
"$",
"key",
")",
";",
"// if there is another array found recrusively call this function",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"isAssoc",
"(",
"$",
"value",
")",
"||",
"$",
"numeric",
"?",
"$",
"xml",
"->",
"addChild",
"(",
"$",
"key",
")",
":",
"$",
"xml",
";",
"// recursive call",
"if",
"(",
"$",
"numeric",
")",
"{",
"$",
"key",
"=",
"'anon'",
";",
"}",
"$",
"this",
"->",
"toXML",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"node",
")",
";",
"}",
"else",
"{",
"// add single node.",
"$",
"value",
"=",
"htmlentities",
"(",
"$",
"value",
")",
";",
"// $xml->addChild($key, $value);",
"$",
"xml",
"->",
"addAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"// pass back as XML",
"// return $xml->asXML();",
"// if you want the XML to be formatted, use the below instead to return the XML",
"$",
"doc",
"=",
"new",
"DOMDocument",
"(",
"'1.0'",
")",
";",
"$",
"doc",
"->",
"preserveWhiteSpace",
"=",
"false",
";",
"$",
"doc",
"->",
"loadXML",
"(",
"$",
"xml",
"->",
"asXML",
"(",
")",
")",
";",
"$",
"doc",
"->",
"formatOutput",
"=",
"true",
";",
"return",
"$",
"doc",
"->",
"saveXML",
"(",
")",
";",
"}"
] | Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
@param array $data
@param string $rootNodeName - what you want the root node to be - defaults to data
@param SimpleXMLElement $xml - should only be used recursively
@return string XML | [
"Pass",
"in",
"a",
"multi",
"dimensional",
"array",
"and",
"this",
"recrusively",
"loops",
"through",
"and",
"builds",
"up",
"an",
"XML",
"document",
"."
] | 6a4f0388ba8653d65058ce63cf7627e38b9df041 | https://github.com/bytic/helpers/blob/6a4f0388ba8653d65058ce63cf7627e38b9df041/src/Arrays.php#L316-L363 |
9,131 | fkooman/php-lib-io | src/fkooman/IO/IO.php | IO.getRandom | public function getRandom($byteLength = 16, $rawBytes = false)
{
$randomBytes = random_bytes($byteLength);
if ($rawBytes) {
return $randomBytes;
}
return bin2hex($randomBytes);
} | php | public function getRandom($byteLength = 16, $rawBytes = false)
{
$randomBytes = random_bytes($byteLength);
if ($rawBytes) {
return $randomBytes;
}
return bin2hex($randomBytes);
} | [
"public",
"function",
"getRandom",
"(",
"$",
"byteLength",
"=",
"16",
",",
"$",
"rawBytes",
"=",
"false",
")",
"{",
"$",
"randomBytes",
"=",
"random_bytes",
"(",
"$",
"byteLength",
")",
";",
"if",
"(",
"$",
"rawBytes",
")",
"{",
"return",
"$",
"randomBytes",
";",
"}",
"return",
"bin2hex",
"(",
"$",
"randomBytes",
")",
";",
"}"
] | Get a random byte string.
@param int $byteLength the length of the random string in bytes
@param bool $rawBytes return the raw random string if true or hex
encoded when false (default)
@return string the random string of specified length | [
"Get",
"a",
"random",
"byte",
"string",
"."
] | e478f37798af631ad49c3154420c24c6bbe0484c | https://github.com/fkooman/php-lib-io/blob/e478f37798af631ad49c3154420c24c6bbe0484c/src/fkooman/IO/IO.php#L44-L53 |
9,132 | fkooman/php-lib-io | src/fkooman/IO/IO.php | IO.readFile | public function readFile($filePath)
{
if (false === $fileContent = @file_get_contents($filePath)) {
throw new RuntimeException(
sprintf('unable to read file "%s"', $filePath)
);
}
return $fileContent;
} | php | public function readFile($filePath)
{
if (false === $fileContent = @file_get_contents($filePath)) {
throw new RuntimeException(
sprintf('unable to read file "%s"', $filePath)
);
}
return $fileContent;
} | [
"public",
"function",
"readFile",
"(",
"$",
"filePath",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"fileContent",
"=",
"@",
"file_get_contents",
"(",
"$",
"filePath",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'unable to read file \"%s\"'",
",",
"$",
"filePath",
")",
")",
";",
"}",
"return",
"$",
"fileContent",
";",
"}"
] | Read a file from the file system.
@param string $filePath the path of the file to read
@return string the file contents
@throws RuntimeException if the file could not be read | [
"Read",
"a",
"file",
"from",
"the",
"file",
"system",
"."
] | e478f37798af631ad49c3154420c24c6bbe0484c | https://github.com/fkooman/php-lib-io/blob/e478f37798af631ad49c3154420c24c6bbe0484c/src/fkooman/IO/IO.php#L69-L78 |
9,133 | fkooman/php-lib-io | src/fkooman/IO/IO.php | IO.readFolder | public function readFolder($folderPath, $fileFilter = '*')
{
// make sure folderPath ends with '/'
if ('/' !== substr($folderPath, -1)) {
$folderPath .= '/';
}
$searchPattern = $folderPath.$fileFilter;
$fileList = @glob($searchPattern, GLOB_MARK | GLOB_ERR);
if (false === $fileList) {
return [];
}
return $fileList;
} | php | public function readFolder($folderPath, $fileFilter = '*')
{
// make sure folderPath ends with '/'
if ('/' !== substr($folderPath, -1)) {
$folderPath .= '/';
}
$searchPattern = $folderPath.$fileFilter;
$fileList = @glob($searchPattern, GLOB_MARK | GLOB_ERR);
if (false === $fileList) {
return [];
}
return $fileList;
} | [
"public",
"function",
"readFolder",
"(",
"$",
"folderPath",
",",
"$",
"fileFilter",
"=",
"'*'",
")",
"{",
"// make sure folderPath ends with '/'",
"if",
"(",
"'/'",
"!==",
"substr",
"(",
"$",
"folderPath",
",",
"-",
"1",
")",
")",
"{",
"$",
"folderPath",
".=",
"'/'",
";",
"}",
"$",
"searchPattern",
"=",
"$",
"folderPath",
".",
"$",
"fileFilter",
";",
"$",
"fileList",
"=",
"@",
"glob",
"(",
"$",
"searchPattern",
",",
"GLOB_MARK",
"|",
"GLOB_ERR",
")",
";",
"if",
"(",
"false",
"===",
"$",
"fileList",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"fileList",
";",
"}"
] | Read a folder and return a list of files in that folder.
@param string $folderPath the path to the folder
@param string $fileFilter the filter to apply, defaults to '*'
@return array an array of files and directories in the folder requested,
entries ending in a '/' are folders. If a directory does not exist, is
empty or no there is no permission to read it an empty array is returned. | [
"Read",
"a",
"folder",
"and",
"return",
"a",
"list",
"of",
"files",
"in",
"that",
"folder",
"."
] | e478f37798af631ad49c3154420c24c6bbe0484c | https://github.com/fkooman/php-lib-io/blob/e478f37798af631ad49c3154420c24c6bbe0484c/src/fkooman/IO/IO.php#L90-L103 |
9,134 | fkooman/php-lib-io | src/fkooman/IO/IO.php | IO.writeFile | public function writeFile($filePath, $fileContent, $createParentDir = false, $dirMask = 0750)
{
if ($createParentDir) {
$parentDir = dirname($filePath);
if (false === @file_exists($parentDir)) {
if (false === @mkdir($parentDir, $dirMask, true)) {
throw new RuntimeException(sprintf('unable to create directory "%s"', $parentDir));
}
}
}
if (false === @file_put_contents($filePath, $fileContent)) {
throw new RuntimeException(
sprintf('unable to write file "%s"', $filePath)
);
}
} | php | public function writeFile($filePath, $fileContent, $createParentDir = false, $dirMask = 0750)
{
if ($createParentDir) {
$parentDir = dirname($filePath);
if (false === @file_exists($parentDir)) {
if (false === @mkdir($parentDir, $dirMask, true)) {
throw new RuntimeException(sprintf('unable to create directory "%s"', $parentDir));
}
}
}
if (false === @file_put_contents($filePath, $fileContent)) {
throw new RuntimeException(
sprintf('unable to write file "%s"', $filePath)
);
}
} | [
"public",
"function",
"writeFile",
"(",
"$",
"filePath",
",",
"$",
"fileContent",
",",
"$",
"createParentDir",
"=",
"false",
",",
"$",
"dirMask",
"=",
"0750",
")",
"{",
"if",
"(",
"$",
"createParentDir",
")",
"{",
"$",
"parentDir",
"=",
"dirname",
"(",
"$",
"filePath",
")",
";",
"if",
"(",
"false",
"===",
"@",
"file_exists",
"(",
"$",
"parentDir",
")",
")",
"{",
"if",
"(",
"false",
"===",
"@",
"mkdir",
"(",
"$",
"parentDir",
",",
"$",
"dirMask",
",",
"true",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'unable to create directory \"%s\"'",
",",
"$",
"parentDir",
")",
")",
";",
"}",
"}",
"}",
"if",
"(",
"false",
"===",
"@",
"file_put_contents",
"(",
"$",
"filePath",
",",
"$",
"fileContent",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'unable to write file \"%s\"'",
",",
"$",
"filePath",
")",
")",
";",
"}",
"}"
] | Write a file to the file system.
@param string $filePath the path of the file to write
@param string $fileContent the content to be written to the file
@param bool $createParentDir create the parent directory if it does not exist, defaults to false
@param int $dirMask the mask to use for creating the directory, defaults to 0750
@throws RuntimeException if the file could not be written | [
"Write",
"a",
"file",
"to",
"the",
"file",
"system",
"."
] | e478f37798af631ad49c3154420c24c6bbe0484c | https://github.com/fkooman/php-lib-io/blob/e478f37798af631ad49c3154420c24c6bbe0484c/src/fkooman/IO/IO.php#L115-L131 |
9,135 | ItinerisLtd/preflight-command | src/ConfigCollectionFactory.php | ConfigCollectionFactory.makeFromFiles | public static function makeFromFiles(string ...$paths): ConfigCollection
{
$definitions = array_map(function (string $path): array {
try {
// Toml::parseFile might return void / null.
$definitions = (array) Toml::parseFile($path);
// See: Automattic/VIP-Coding-Standards#144 on Github.
// phpcs:ignore WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable
} catch (ParseException $_parseException) {
// Assume empty config.
$definitions = [];
}
return $definitions;
}, $paths);
$mergedDefinitions = array_reduce($definitions, function (array $merged, array $definition): array {
return self::arrayMergeRecursiveDistinct($merged, $definition);
}, []);
return new ConfigCollection($mergedDefinitions);
} | php | public static function makeFromFiles(string ...$paths): ConfigCollection
{
$definitions = array_map(function (string $path): array {
try {
// Toml::parseFile might return void / null.
$definitions = (array) Toml::parseFile($path);
// See: Automattic/VIP-Coding-Standards#144 on Github.
// phpcs:ignore WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable
} catch (ParseException $_parseException) {
// Assume empty config.
$definitions = [];
}
return $definitions;
}, $paths);
$mergedDefinitions = array_reduce($definitions, function (array $merged, array $definition): array {
return self::arrayMergeRecursiveDistinct($merged, $definition);
}, []);
return new ConfigCollection($mergedDefinitions);
} | [
"public",
"static",
"function",
"makeFromFiles",
"(",
"string",
"...",
"$",
"paths",
")",
":",
"ConfigCollection",
"{",
"$",
"definitions",
"=",
"array_map",
"(",
"function",
"(",
"string",
"$",
"path",
")",
":",
"array",
"{",
"try",
"{",
"// Toml::parseFile might return void / null.",
"$",
"definitions",
"=",
"(",
"array",
")",
"Toml",
"::",
"parseFile",
"(",
"$",
"path",
")",
";",
"// See: Automattic/VIP-Coding-Standards#144 on Github.",
"// phpcs:ignore WordPressVIPMinimum.Variables.VariableAnalysis.UnusedVariable",
"}",
"catch",
"(",
"ParseException",
"$",
"_parseException",
")",
"{",
"// Assume empty config.",
"$",
"definitions",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"definitions",
";",
"}",
",",
"$",
"paths",
")",
";",
"$",
"mergedDefinitions",
"=",
"array_reduce",
"(",
"$",
"definitions",
",",
"function",
"(",
"array",
"$",
"merged",
",",
"array",
"$",
"definition",
")",
":",
"array",
"{",
"return",
"self",
"::",
"arrayMergeRecursiveDistinct",
"(",
"$",
"merged",
",",
"$",
"definition",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"return",
"new",
"ConfigCollection",
"(",
"$",
"mergedDefinitions",
")",
";",
"}"
] | Parses the TOML and returns a config instance.
@param string|string[] ...$paths Paths to TOML files.
@return ConfigCollection | [
"Parses",
"the",
"TOML",
"and",
"returns",
"a",
"config",
"instance",
"."
] | d1c1360ea8d7de0312b5c0c09c9c486949594049 | https://github.com/ItinerisLtd/preflight-command/blob/d1c1360ea8d7de0312b5c0c09c9c486949594049/src/ConfigCollectionFactory.php#L18-L40 |
9,136 | ItinerisLtd/preflight-command | src/ConfigCollectionFactory.php | ConfigCollectionFactory.arrayMergeRecursiveDistinct | private static function arrayMergeRecursiveDistinct(array $merged, array $other): array
{
foreach ($other as $key => $value) {
if (is_array($value) && is_array($merged[$key] ?? [])) {
$merged[$key] = self::arrayMergeRecursiveDistinct($merged[$key] ?? [], $value);
} elseif (is_int($key)) {
// Avoid arrays being overridden.
$merged = array_unique(
array_merge($merged, [$value])
);
} else {
$merged[$key] = $value;
}
}
return $merged;
} | php | private static function arrayMergeRecursiveDistinct(array $merged, array $other): array
{
foreach ($other as $key => $value) {
if (is_array($value) && is_array($merged[$key] ?? [])) {
$merged[$key] = self::arrayMergeRecursiveDistinct($merged[$key] ?? [], $value);
} elseif (is_int($key)) {
// Avoid arrays being overridden.
$merged = array_unique(
array_merge($merged, [$value])
);
} else {
$merged[$key] = $value;
}
}
return $merged;
} | [
"private",
"static",
"function",
"arrayMergeRecursiveDistinct",
"(",
"array",
"$",
"merged",
",",
"array",
"$",
"other",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"other",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"is_array",
"(",
"$",
"merged",
"[",
"$",
"key",
"]",
"??",
"[",
"]",
")",
")",
"{",
"$",
"merged",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"arrayMergeRecursiveDistinct",
"(",
"$",
"merged",
"[",
"$",
"key",
"]",
"??",
"[",
"]",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"// Avoid arrays being overridden.",
"$",
"merged",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"merged",
",",
"[",
"$",
"value",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"merged",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"merged",
";",
"}"
] | This does not change the data types of the values in the arrays. Matching keys' values in the second array
overwrite those in the first array, as is the case with array_merge.
This is modified from an example on php.net.
@see https://secure.php.net/manual/en/function.array-merge-recursive.php#92195
@param array $merged The first array.
@param array $other The second array.
@return array | [
"This",
"does",
"not",
"change",
"the",
"data",
"types",
"of",
"the",
"values",
"in",
"the",
"arrays",
".",
"Matching",
"keys",
"values",
"in",
"the",
"second",
"array",
"overwrite",
"those",
"in",
"the",
"first",
"array",
"as",
"is",
"the",
"case",
"with",
"array_merge",
"."
] | d1c1360ea8d7de0312b5c0c09c9c486949594049 | https://github.com/ItinerisLtd/preflight-command/blob/d1c1360ea8d7de0312b5c0c09c9c486949594049/src/ConfigCollectionFactory.php#L55-L71 |
9,137 | 0x20h/phloppy | src/Stream/DefaultStream.php | DefaultStream.connect | public function connect()
{
$connectTimeout = 1;
$errstr = '';
$errno = 0;
$stream = @stream_socket_client($this->nodeUrl, $errno, $errstr, $connectTimeout);
if (!$stream) {
$this->log->warning('unable to connect to '.$this->nodeUrl.': '.$errstr);
throw new ConnectException('Unable to connect to resource '.$this->nodeUrl.'. '.$errstr, $errno);
}
$this->log->info('connected to '.$this->nodeUrl);
$this->stream = $stream;
return true;
} | php | public function connect()
{
$connectTimeout = 1;
$errstr = '';
$errno = 0;
$stream = @stream_socket_client($this->nodeUrl, $errno, $errstr, $connectTimeout);
if (!$stream) {
$this->log->warning('unable to connect to '.$this->nodeUrl.': '.$errstr);
throw new ConnectException('Unable to connect to resource '.$this->nodeUrl.'. '.$errstr, $errno);
}
$this->log->info('connected to '.$this->nodeUrl);
$this->stream = $stream;
return true;
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"$",
"connectTimeout",
"=",
"1",
";",
"$",
"errstr",
"=",
"''",
";",
"$",
"errno",
"=",
"0",
";",
"$",
"stream",
"=",
"@",
"stream_socket_client",
"(",
"$",
"this",
"->",
"nodeUrl",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"connectTimeout",
")",
";",
"if",
"(",
"!",
"$",
"stream",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'unable to connect to '",
".",
"$",
"this",
"->",
"nodeUrl",
".",
"': '",
".",
"$",
"errstr",
")",
";",
"throw",
"new",
"ConnectException",
"(",
"'Unable to connect to resource '",
".",
"$",
"this",
"->",
"nodeUrl",
".",
"'. '",
".",
"$",
"errstr",
",",
"$",
"errno",
")",
";",
"}",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"'connected to '",
".",
"$",
"this",
"->",
"nodeUrl",
")",
";",
"$",
"this",
"->",
"stream",
"=",
"$",
"stream",
";",
"return",
"true",
";",
"}"
] | Connect the stream.
@return boolean True if connection could be established.
@throws ConnectException | [
"Connect",
"the",
"stream",
"."
] | d917f0578360395899bd583724046d36ac459535 | https://github.com/0x20h/phloppy/blob/d917f0578360395899bd583724046d36ac459535/src/Stream/DefaultStream.php#L48-L64 |
9,138 | 0x20h/phloppy | src/Stream/DefaultStream.php | DefaultStream.readLine | public function readLine()
{
$this->log->debug('going to read a line from the stream');
$line = $this->streamReadLine($this->stream);
if (false === $line) {
$meta = $this->streamMeta($this->stream);
$this->log->warning('fgets returned false', $meta);
throw new StreamException(StreamException::OP_READ, 'stream_get_line returned false');
}
$this->log->debug('readLine()', [$line]);
return $line;
} | php | public function readLine()
{
$this->log->debug('going to read a line from the stream');
$line = $this->streamReadLine($this->stream);
if (false === $line) {
$meta = $this->streamMeta($this->stream);
$this->log->warning('fgets returned false', $meta);
throw new StreamException(StreamException::OP_READ, 'stream_get_line returned false');
}
$this->log->debug('readLine()', [$line]);
return $line;
} | [
"public",
"function",
"readLine",
"(",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'going to read a line from the stream'",
")",
";",
"$",
"line",
"=",
"$",
"this",
"->",
"streamReadLine",
"(",
"$",
"this",
"->",
"stream",
")",
";",
"if",
"(",
"false",
"===",
"$",
"line",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"streamMeta",
"(",
"$",
"this",
"->",
"stream",
")",
";",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'fgets returned false'",
",",
"$",
"meta",
")",
";",
"throw",
"new",
"StreamException",
"(",
"StreamException",
"::",
"OP_READ",
",",
"'stream_get_line returned false'",
")",
";",
"}",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'readLine()'",
",",
"[",
"$",
"line",
"]",
")",
";",
"return",
"$",
"line",
";",
"}"
] | Read a line from the stream.
@return string
@throws StreamException If an error occurs while reading from the stream. | [
"Read",
"a",
"line",
"from",
"the",
"stream",
"."
] | d917f0578360395899bd583724046d36ac459535 | https://github.com/0x20h/phloppy/blob/d917f0578360395899bd583724046d36ac459535/src/Stream/DefaultStream.php#L84-L98 |
9,139 | 0x20h/phloppy | src/Stream/DefaultStream.php | DefaultStream.readBytes | public function readBytes($maxlen = null)
{
$this->log->debug('calling readbytes()', array('maxlen' => $maxlen));
$out = $this->streamReadBytes($this->stream, $maxlen);
$this->log->debug('readBytes()', [$maxlen, $out]);
if (false === $out) {
$meta = $this->streamMeta($this->stream);
$this->log->warning('stream_get_contents returned false', $meta);
throw new StreamException(StreamException::OP_READ, 'stream_get_contents returned false');
}
return $out;
} | php | public function readBytes($maxlen = null)
{
$this->log->debug('calling readbytes()', array('maxlen' => $maxlen));
$out = $this->streamReadBytes($this->stream, $maxlen);
$this->log->debug('readBytes()', [$maxlen, $out]);
if (false === $out) {
$meta = $this->streamMeta($this->stream);
$this->log->warning('stream_get_contents returned false', $meta);
throw new StreamException(StreamException::OP_READ, 'stream_get_contents returned false');
}
return $out;
} | [
"public",
"function",
"readBytes",
"(",
"$",
"maxlen",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'calling readbytes()'",
",",
"array",
"(",
"'maxlen'",
"=>",
"$",
"maxlen",
")",
")",
";",
"$",
"out",
"=",
"$",
"this",
"->",
"streamReadBytes",
"(",
"$",
"this",
"->",
"stream",
",",
"$",
"maxlen",
")",
";",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'readBytes()'",
",",
"[",
"$",
"maxlen",
",",
"$",
"out",
"]",
")",
";",
"if",
"(",
"false",
"===",
"$",
"out",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"streamMeta",
"(",
"$",
"this",
"->",
"stream",
")",
";",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'stream_get_contents returned false'",
",",
"$",
"meta",
")",
";",
"throw",
"new",
"StreamException",
"(",
"StreamException",
"::",
"OP_READ",
",",
"'stream_get_contents returned false'",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Read bytes off from the stream.
@param int|null $maxlen
@return string
@throws StreamException If an error occurs while reading from the stream. | [
"Read",
"bytes",
"off",
"from",
"the",
"stream",
"."
] | d917f0578360395899bd583724046d36ac459535 | https://github.com/0x20h/phloppy/blob/d917f0578360395899bd583724046d36ac459535/src/Stream/DefaultStream.php#L109-L122 |
9,140 | senhungwong/php-loader | src/Loader.php | Loader.load | public static function load(string $dir, int $depth = 6, array $priority = [], array $extensions = ['php'])
{
/* Stop when search to maximum depth */
if ($depth == 0) {
return;
}
/* Load Priority Files */
foreach ($priority as $file) {
self::load($file, 1, [], $extensions);
}
/* Get all files and folders under current directory */
$filesAndFolders = glob($dir . DIRECTORY_SEPARATOR . "*");
/* Go through each item */
foreach ($filesAndFolders as $path) {
/* If is directory, search files under its directory */
if (is_dir($path)) {
self::load($path, $depth - 1, [], $extensions);
}
/* If the file extension is in extensions list; require it */
elseif (in_array(pathinfo($path, PATHINFO_EXTENSION), $extensions)) {
require_once $path;
}
}
} | php | public static function load(string $dir, int $depth = 6, array $priority = [], array $extensions = ['php'])
{
/* Stop when search to maximum depth */
if ($depth == 0) {
return;
}
/* Load Priority Files */
foreach ($priority as $file) {
self::load($file, 1, [], $extensions);
}
/* Get all files and folders under current directory */
$filesAndFolders = glob($dir . DIRECTORY_SEPARATOR . "*");
/* Go through each item */
foreach ($filesAndFolders as $path) {
/* If is directory, search files under its directory */
if (is_dir($path)) {
self::load($path, $depth - 1, [], $extensions);
}
/* If the file extension is in extensions list; require it */
elseif (in_array(pathinfo($path, PATHINFO_EXTENSION), $extensions)) {
require_once $path;
}
}
} | [
"public",
"static",
"function",
"load",
"(",
"string",
"$",
"dir",
",",
"int",
"$",
"depth",
"=",
"6",
",",
"array",
"$",
"priority",
"=",
"[",
"]",
",",
"array",
"$",
"extensions",
"=",
"[",
"'php'",
"]",
")",
"{",
"/* Stop when search to maximum depth */",
"if",
"(",
"$",
"depth",
"==",
"0",
")",
"{",
"return",
";",
"}",
"/* Load Priority Files */",
"foreach",
"(",
"$",
"priority",
"as",
"$",
"file",
")",
"{",
"self",
"::",
"load",
"(",
"$",
"file",
",",
"1",
",",
"[",
"]",
",",
"$",
"extensions",
")",
";",
"}",
"/* Get all files and folders under current directory */",
"$",
"filesAndFolders",
"=",
"glob",
"(",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"\"*\"",
")",
";",
"/* Go through each item */",
"foreach",
"(",
"$",
"filesAndFolders",
"as",
"$",
"path",
")",
"{",
"/* If is directory, search files under its directory */",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"self",
"::",
"load",
"(",
"$",
"path",
",",
"$",
"depth",
"-",
"1",
",",
"[",
"]",
",",
"$",
"extensions",
")",
";",
"}",
"/* If the file extension is in extensions list; require it */",
"elseif",
"(",
"in_array",
"(",
"pathinfo",
"(",
"$",
"path",
",",
"PATHINFO_EXTENSION",
")",
",",
"$",
"extensions",
")",
")",
"{",
"require_once",
"$",
"path",
";",
"}",
"}",
"}"
] | Load files in the given directory and the files under its folders with maximum depth
@param string $dir initial directory to be included
@param int $depth depth of the maximum search
@param array $priority priority files needs to be loaded
@param array $extensions array of file extensions that should be included | [
"Load",
"files",
"in",
"the",
"given",
"directory",
"and",
"the",
"files",
"under",
"its",
"folders",
"with",
"maximum",
"depth"
] | 326a7785ea5771d0e478bd1f898edeafac52f48f | https://github.com/senhungwong/php-loader/blob/326a7785ea5771d0e478bd1f898edeafac52f48f/src/Loader.php#L15-L42 |
9,141 | senhungwong/php-loader | src/Loader.php | Loader.getAllChildClasses | public static function getAllChildClasses($class): array
{
$type = gettype($class);
$className = '';
/* If input an object */
if ($type == 'object') {
$className = get_class($class);
}
/* If input a string */
elseif ($type == 'string') {
$className = $class;
}
$classes = [];
/* Go through all classes */
foreach (get_declared_classes() as $class) {
if (is_subclass_of($class, $className)) {
$classes[] = $class;
}
}
return $classes;
} | php | public static function getAllChildClasses($class): array
{
$type = gettype($class);
$className = '';
/* If input an object */
if ($type == 'object') {
$className = get_class($class);
}
/* If input a string */
elseif ($type == 'string') {
$className = $class;
}
$classes = [];
/* Go through all classes */
foreach (get_declared_classes() as $class) {
if (is_subclass_of($class, $className)) {
$classes[] = $class;
}
}
return $classes;
} | [
"public",
"static",
"function",
"getAllChildClasses",
"(",
"$",
"class",
")",
":",
"array",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"class",
")",
";",
"$",
"className",
"=",
"''",
";",
"/* If input an object */",
"if",
"(",
"$",
"type",
"==",
"'object'",
")",
"{",
"$",
"className",
"=",
"get_class",
"(",
"$",
"class",
")",
";",
"}",
"/* If input a string */",
"elseif",
"(",
"$",
"type",
"==",
"'string'",
")",
"{",
"$",
"className",
"=",
"$",
"class",
";",
"}",
"$",
"classes",
"=",
"[",
"]",
";",
"/* Go through all classes */",
"foreach",
"(",
"get_declared_classes",
"(",
")",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"className",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"$",
"class",
";",
"}",
"}",
"return",
"$",
"classes",
";",
"}"
] | Get all child classes of a class
@param string|object $class
@return array | [
"Get",
"all",
"child",
"classes",
"of",
"a",
"class"
] | 326a7785ea5771d0e478bd1f898edeafac52f48f | https://github.com/senhungwong/php-loader/blob/326a7785ea5771d0e478bd1f898edeafac52f48f/src/Loader.php#L50-L75 |
9,142 | digitas/digex-core | src/Digex/YamlConfigLoader.php | YamlConfigLoader.load | public function load($dir, $env = null, $basename = 'config', $extension = 'yml')
{
$filepath = $dir . '/' . $basename . '.' . $extension;
if (!file_exists($filepath)) {
throw new \Exception(sprintf("Config file \"%s\" does not exist", $filepath));
}
$parameters = Yaml::parse($filepath);
//Override configuration for a specific environment
if ($env) {
$filepath = $dir . '/' . $basename . '_' . $env . '.' . $extension;
if (file_exists($filepath)) {
$envParameters = Yaml::parse($filepath);
if ($envParameters) {
$parameters = $this->deepMerge($parameters, $envParameters);
}
}
}
return $parameters;
} | php | public function load($dir, $env = null, $basename = 'config', $extension = 'yml')
{
$filepath = $dir . '/' . $basename . '.' . $extension;
if (!file_exists($filepath)) {
throw new \Exception(sprintf("Config file \"%s\" does not exist", $filepath));
}
$parameters = Yaml::parse($filepath);
//Override configuration for a specific environment
if ($env) {
$filepath = $dir . '/' . $basename . '_' . $env . '.' . $extension;
if (file_exists($filepath)) {
$envParameters = Yaml::parse($filepath);
if ($envParameters) {
$parameters = $this->deepMerge($parameters, $envParameters);
}
}
}
return $parameters;
} | [
"public",
"function",
"load",
"(",
"$",
"dir",
",",
"$",
"env",
"=",
"null",
",",
"$",
"basename",
"=",
"'config'",
",",
"$",
"extension",
"=",
"'yml'",
")",
"{",
"$",
"filepath",
"=",
"$",
"dir",
".",
"'/'",
".",
"$",
"basename",
".",
"'.'",
".",
"$",
"extension",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filepath",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"\"Config file \\\"%s\\\" does not exist\"",
",",
"$",
"filepath",
")",
")",
";",
"}",
"$",
"parameters",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"filepath",
")",
";",
"//Override configuration for a specific environment",
"if",
"(",
"$",
"env",
")",
"{",
"$",
"filepath",
"=",
"$",
"dir",
".",
"'/'",
".",
"$",
"basename",
".",
"'_'",
".",
"$",
"env",
".",
"'.'",
".",
"$",
"extension",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filepath",
")",
")",
"{",
"$",
"envParameters",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"filepath",
")",
";",
"if",
"(",
"$",
"envParameters",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"deepMerge",
"(",
"$",
"parameters",
",",
"$",
"envParameters",
")",
";",
"}",
"}",
"}",
"return",
"$",
"parameters",
";",
"}"
] | Load the config
@param string $dir
@param string $basename
@param string $extension
@return array | [
"Load",
"the",
"config"
] | 59339a4ad34c1856a5db1bd12097a01de673d2e9 | https://github.com/digitas/digex-core/blob/59339a4ad34c1856a5db1bd12097a01de673d2e9/src/Digex/YamlConfigLoader.php#L22-L44 |
9,143 | digitas/digex-core | src/Digex/YamlConfigLoader.php | YamlConfigLoader.deepMerge | protected function deepMerge($leftSide, $rightSide)
{
if (!is_array($rightSide)) {
return $rightSide;
}
foreach ($rightSide as $k => $v) {
// no conflict
if (!array_key_exists($k, $leftSide)) {
$leftSide[$k] = $v;
continue;
}
$leftSide[$k] = $this->deepMerge($leftSide[$k], $v);
}
return $leftSide;
} | php | protected function deepMerge($leftSide, $rightSide)
{
if (!is_array($rightSide)) {
return $rightSide;
}
foreach ($rightSide as $k => $v) {
// no conflict
if (!array_key_exists($k, $leftSide)) {
$leftSide[$k] = $v;
continue;
}
$leftSide[$k] = $this->deepMerge($leftSide[$k], $v);
}
return $leftSide;
} | [
"protected",
"function",
"deepMerge",
"(",
"$",
"leftSide",
",",
"$",
"rightSide",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"rightSide",
")",
")",
"{",
"return",
"$",
"rightSide",
";",
"}",
"foreach",
"(",
"$",
"rightSide",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"// no conflict",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"k",
",",
"$",
"leftSide",
")",
")",
"{",
"$",
"leftSide",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"continue",
";",
"}",
"$",
"leftSide",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"deepMerge",
"(",
"$",
"leftSide",
"[",
"$",
"k",
"]",
",",
"$",
"v",
")",
";",
"}",
"return",
"$",
"leftSide",
";",
"}"
] | Do a deep merge of two arrays
@param array $leftSide
@param array $rightSide
@return array | [
"Do",
"a",
"deep",
"merge",
"of",
"two",
"arrays"
] | 59339a4ad34c1856a5db1bd12097a01de673d2e9 | https://github.com/digitas/digex-core/blob/59339a4ad34c1856a5db1bd12097a01de673d2e9/src/Digex/YamlConfigLoader.php#L53-L72 |
9,144 | mizmoz/container | src/Resolver.php | Resolver.resolveParameters | private function resolveParameters(string $id, array $parameters, ContainerInterface $container): array
{
$resolved = [];
foreach ($parameters as $parameter) {
$resolved[] = $this->getParameterValue($id, $parameter, $container);
}
return $resolved;
} | php | private function resolveParameters(string $id, array $parameters, ContainerInterface $container): array
{
$resolved = [];
foreach ($parameters as $parameter) {
$resolved[] = $this->getParameterValue($id, $parameter, $container);
}
return $resolved;
} | [
"private",
"function",
"resolveParameters",
"(",
"string",
"$",
"id",
",",
"array",
"$",
"parameters",
",",
"ContainerInterface",
"$",
"container",
")",
":",
"array",
"{",
"$",
"resolved",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"$",
"resolved",
"[",
"]",
"=",
"$",
"this",
"->",
"getParameterValue",
"(",
"$",
"id",
",",
"$",
"parameter",
",",
"$",
"container",
")",
";",
"}",
"return",
"$",
"resolved",
";",
"}"
] | Resolve the parameters
@param string $id
@param ReflectionParameter[] $parameters
@param ContainerInterface $container
@return array | [
"Resolve",
"the",
"parameters"
] | 7ae194189595fbcd392445bb41ac8ddb118b5b7c | https://github.com/mizmoz/container/blob/7ae194189595fbcd392445bb41ac8ddb118b5b7c/src/Resolver.php#L55-L62 |
9,145 | mizmoz/container | src/Resolver.php | Resolver.getParameterValue | private function getParameterValue(string $id, ReflectionParameter $parameter, ContainerInterface $container)
{
if (! ($class = $parameter->getClass())) {
if ($parameter->isDefaultValueAvailable()) {
// a default value is available so use that
return $parameter->getDefaultValue();
}
// no default, eek
throw new FatalNotFoundException("Cannot resolve '" . $parameter->getName() . "' for class '" . $id . "'");
}
try {
// attempt to resolve the value
return $container->get($class->getName());
} catch (NotFoundException $e) {
if ($parameter->isDefaultValueAvailable()) {
// a default value is available so use that
return $parameter->getDefaultValue();
}
throw $e;
}
} | php | private function getParameterValue(string $id, ReflectionParameter $parameter, ContainerInterface $container)
{
if (! ($class = $parameter->getClass())) {
if ($parameter->isDefaultValueAvailable()) {
// a default value is available so use that
return $parameter->getDefaultValue();
}
// no default, eek
throw new FatalNotFoundException("Cannot resolve '" . $parameter->getName() . "' for class '" . $id . "'");
}
try {
// attempt to resolve the value
return $container->get($class->getName());
} catch (NotFoundException $e) {
if ($parameter->isDefaultValueAvailable()) {
// a default value is available so use that
return $parameter->getDefaultValue();
}
throw $e;
}
} | [
"private",
"function",
"getParameterValue",
"(",
"string",
"$",
"id",
",",
"ReflectionParameter",
"$",
"parameter",
",",
"ContainerInterface",
"$",
"container",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"class",
"=",
"$",
"parameter",
"->",
"getClass",
"(",
")",
")",
")",
"{",
"if",
"(",
"$",
"parameter",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"// a default value is available so use that",
"return",
"$",
"parameter",
"->",
"getDefaultValue",
"(",
")",
";",
"}",
"// no default, eek",
"throw",
"new",
"FatalNotFoundException",
"(",
"\"Cannot resolve '\"",
".",
"$",
"parameter",
"->",
"getName",
"(",
")",
".",
"\"' for class '\"",
".",
"$",
"id",
".",
"\"'\"",
")",
";",
"}",
"try",
"{",
"// attempt to resolve the value",
"return",
"$",
"container",
"->",
"get",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"parameter",
"->",
"isDefaultValueAvailable",
"(",
")",
")",
"{",
"// a default value is available so use that",
"return",
"$",
"parameter",
"->",
"getDefaultValue",
"(",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"}"
] | Get the parameter value
@param string $id
@param ReflectionParameter $parameter
@param ContainerInterface $container
@return mixed | [
"Get",
"the",
"parameter",
"value"
] | 7ae194189595fbcd392445bb41ac8ddb118b5b7c | https://github.com/mizmoz/container/blob/7ae194189595fbcd392445bb41ac8ddb118b5b7c/src/Resolver.php#L72-L94 |
9,146 | samurai-fw/samurai | src/Samurai/Component/Response/HttpBody.php | HttpBody.render | public function render($with_headers = false)
{
$contents = array();
// headers
$headers = $this->getHeaders();
if ($with_headers && $headers) {
foreach ($headers as $key => $value) {
$key = join('-', array_map('ucfirst', explode('-', $key)));
$contents[] = sprintf('%s: %s', $key, $value);
}
$contents[] = '';
}
// content
$contents[] = $this->content;
return join("\n", $contents);
} | php | public function render($with_headers = false)
{
$contents = array();
// headers
$headers = $this->getHeaders();
if ($with_headers && $headers) {
foreach ($headers as $key => $value) {
$key = join('-', array_map('ucfirst', explode('-', $key)));
$contents[] = sprintf('%s: %s', $key, $value);
}
$contents[] = '';
}
// content
$contents[] = $this->content;
return join("\n", $contents);
} | [
"public",
"function",
"render",
"(",
"$",
"with_headers",
"=",
"false",
")",
"{",
"$",
"contents",
"=",
"array",
"(",
")",
";",
"// headers",
"$",
"headers",
"=",
"$",
"this",
"->",
"getHeaders",
"(",
")",
";",
"if",
"(",
"$",
"with_headers",
"&&",
"$",
"headers",
")",
"{",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"join",
"(",
"'-'",
",",
"array_map",
"(",
"'ucfirst'",
",",
"explode",
"(",
"'-'",
",",
"$",
"key",
")",
")",
")",
";",
"$",
"contents",
"[",
"]",
"=",
"sprintf",
"(",
"'%s: %s'",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"contents",
"[",
"]",
"=",
"''",
";",
"}",
"// content",
"$",
"contents",
"[",
"]",
"=",
"$",
"this",
"->",
"content",
";",
"return",
"join",
"(",
"\"\\n\"",
",",
"$",
"contents",
")",
";",
"}"
] | build and return content string.
@access public
@return string | [
"build",
"and",
"return",
"content",
"string",
"."
] | 7ca3847b13f86e2847a17ab5e8e4e20893021d5a | https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Response/HttpBody.php#L150-L168 |
9,147 | avoo/FrameworkGeneratorBundle | Generator/Template/Model.php | Model.getEntityGenerator | protected function getEntityGenerator()
{
$entityGenerator = new EntityGenerator();
$entityGenerator->setFieldVisibility(EntityGenerator::FIELD_VISIBLE_PROTECTED);
$entityGenerator->setGenerateAnnotations(false);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(false);
$entityGenerator->setUpdateEntityIfExists(true);
$entityGenerator->setNumSpaces(4);
$entityGenerator->setAnnotationPrefix('ORM\\');
if ($this->configuration['with_interface']) {
$entityGenerator->setClassToInterface($this->configuration['namespace'] . '\\' . $this->model.'Interface');
}
return $entityGenerator;
} | php | protected function getEntityGenerator()
{
$entityGenerator = new EntityGenerator();
$entityGenerator->setFieldVisibility(EntityGenerator::FIELD_VISIBLE_PROTECTED);
$entityGenerator->setGenerateAnnotations(false);
$entityGenerator->setGenerateStubMethods(true);
$entityGenerator->setRegenerateEntityIfExists(false);
$entityGenerator->setUpdateEntityIfExists(true);
$entityGenerator->setNumSpaces(4);
$entityGenerator->setAnnotationPrefix('ORM\\');
if ($this->configuration['with_interface']) {
$entityGenerator->setClassToInterface($this->configuration['namespace'] . '\\' . $this->model.'Interface');
}
return $entityGenerator;
} | [
"protected",
"function",
"getEntityGenerator",
"(",
")",
"{",
"$",
"entityGenerator",
"=",
"new",
"EntityGenerator",
"(",
")",
";",
"$",
"entityGenerator",
"->",
"setFieldVisibility",
"(",
"EntityGenerator",
"::",
"FIELD_VISIBLE_PROTECTED",
")",
";",
"$",
"entityGenerator",
"->",
"setGenerateAnnotations",
"(",
"false",
")",
";",
"$",
"entityGenerator",
"->",
"setGenerateStubMethods",
"(",
"true",
")",
";",
"$",
"entityGenerator",
"->",
"setRegenerateEntityIfExists",
"(",
"false",
")",
";",
"$",
"entityGenerator",
"->",
"setUpdateEntityIfExists",
"(",
"true",
")",
";",
"$",
"entityGenerator",
"->",
"setNumSpaces",
"(",
"4",
")",
";",
"$",
"entityGenerator",
"->",
"setAnnotationPrefix",
"(",
"'ORM\\\\'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'with_interface'",
"]",
")",
"{",
"$",
"entityGenerator",
"->",
"setClassToInterface",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'namespace'",
"]",
".",
"'\\\\'",
".",
"$",
"this",
"->",
"model",
".",
"'Interface'",
")",
";",
"}",
"return",
"$",
"entityGenerator",
";",
"}"
] | get entity generator
@return EntityGenerator | [
"get",
"entity",
"generator"
] | 3178268b9e58e6c60c27e0b9ea976944c1f61a48 | https://github.com/avoo/FrameworkGeneratorBundle/blob/3178268b9e58e6c60c27e0b9ea976944c1f61a48/Generator/Template/Model.php#L137-L153 |
9,148 | kore/CTXParser | src/php/CTXParser/Visitor/Simplified.php | Simplified.visit | public function visit(AccountInfoList $accountList)
{
$list = new Simplified\AccountList();
foreach ($accountList->accountInfo as $accountInfo) {
$list->accounts[] = $this->visitAccount($accountInfo);
}
return $list;
} | php | public function visit(AccountInfoList $accountList)
{
$list = new Simplified\AccountList();
foreach ($accountList->accountInfo as $accountInfo) {
$list->accounts[] = $this->visitAccount($accountInfo);
}
return $list;
} | [
"public",
"function",
"visit",
"(",
"AccountInfoList",
"$",
"accountList",
")",
"{",
"$",
"list",
"=",
"new",
"Simplified",
"\\",
"AccountList",
"(",
")",
";",
"foreach",
"(",
"$",
"accountList",
"->",
"accountInfo",
"as",
"$",
"accountInfo",
")",
"{",
"$",
"list",
"->",
"accounts",
"[",
"]",
"=",
"$",
"this",
"->",
"visitAccount",
"(",
"$",
"accountInfo",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
] | Visit account info list
@param AccountInfoList $account
@return mixed | [
"Visit",
"account",
"info",
"list"
] | 9b11c2311a9de61baee7edafe46d1671dd5833c4 | https://github.com/kore/CTXParser/blob/9b11c2311a9de61baee7edafe46d1671dd5833c4/src/php/CTXParser/Visitor/Simplified.php#L40-L48 |
9,149 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/request/driver.php | Request_Driver.set_options | public function set_options(array $options)
{
foreach ($options as $key => $val)
{
$this->options[$key] = $val;
}
return $this;
} | php | public function set_options(array $options)
{
foreach ($options as $key => $val)
{
$this->options[$key] = $val;
}
return $this;
} | [
"public",
"function",
"set_options",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets options on the driver
@param array $options
@return Request_Driver | [
"Sets",
"options",
"on",
"the",
"driver"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/request/driver.php#L154-L162 |
9,150 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/request/driver.php | Request_Driver.set_header | public function set_header($header, $content = null)
{
if (is_null($content))
{
$this->headers[] = $header;
}
else
{
$this->headers[$header] = $content;
}
return $this;
} | php | public function set_header($header, $content = null)
{
if (is_null($content))
{
$this->headers[] = $header;
}
else
{
$this->headers[$header] = $content;
}
return $this;
} | [
"public",
"function",
"set_header",
"(",
"$",
"header",
",",
"$",
"content",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"content",
")",
")",
"{",
"$",
"this",
"->",
"headers",
"[",
"]",
"=",
"$",
"header",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"headers",
"[",
"$",
"header",
"]",
"=",
"$",
"content",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | set a request http header
@param string $header
@param string $header
@return Request_Driver | [
"set",
"a",
"request",
"http",
"header"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/request/driver.php#L204-L216 |
9,151 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/request/driver.php | Request_Driver.get_headers | public function get_headers()
{
$headers = array();
foreach ($this->headers as $key => $value)
{
$headers[] = is_int($key) ? $value : $key.': '.$value;
}
return $headers;
} | php | public function get_headers()
{
$headers = array();
foreach ($this->headers as $key => $value)
{
$headers[] = is_int($key) ? $value : $key.': '.$value;
}
return $headers;
} | [
"public",
"function",
"get_headers",
"(",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"is_int",
"(",
"$",
"key",
")",
"?",
"$",
"value",
":",
"$",
"key",
".",
"': '",
".",
"$",
"value",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] | Collect all headers and parse into consistent string
@return array | [
"Collect",
"all",
"headers",
"and",
"parse",
"into",
"consistent",
"string"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/request/driver.php#L223-L232 |
9,152 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/request/driver.php | Request_Driver.set_mime_type | public function set_mime_type($mime)
{
if (array_key_exists($mime, static::$supported_formats))
{
$mime = static::$supported_formats[$mime];
}
$this->set_header('Accept', $mime);
return $this;
} | php | public function set_mime_type($mime)
{
if (array_key_exists($mime, static::$supported_formats))
{
$mime = static::$supported_formats[$mime];
}
$this->set_header('Accept', $mime);
return $this;
} | [
"public",
"function",
"set_mime_type",
"(",
"$",
"mime",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"mime",
",",
"static",
"::",
"$",
"supported_formats",
")",
")",
"{",
"$",
"mime",
"=",
"static",
"::",
"$",
"supported_formats",
"[",
"$",
"mime",
"]",
";",
"}",
"$",
"this",
"->",
"set_header",
"(",
"'Accept'",
",",
"$",
"mime",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set mime-type accept header
@param string $mime
@return string Request_Driver | [
"Set",
"mime",
"-",
"type",
"accept",
"header"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/request/driver.php#L240-L249 |
9,153 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/request/driver.php | Request_Driver.set_defaults | protected function set_defaults()
{
$this->options = $this->default_options;
$this->params = $this->default_params;
return $this;
} | php | protected function set_defaults()
{
$this->options = $this->default_options;
$this->params = $this->default_params;
return $this;
} | [
"protected",
"function",
"set_defaults",
"(",
")",
"{",
"$",
"this",
"->",
"options",
"=",
"$",
"this",
"->",
"default_options",
";",
"$",
"this",
"->",
"params",
"=",
"$",
"this",
"->",
"default_params",
";",
"return",
"$",
"this",
";",
"}"
] | Reset before doing another request
@return Request_Driver | [
"Reset",
"before",
"doing",
"another",
"request"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/request/driver.php#L277-L282 |
9,154 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/request/driver.php | Request_Driver.mime_in_header | protected function mime_in_header($mime, $accept_header)
{
// make sure we have input
if (empty($mime) or empty($accept_header))
{
// no header or no mime to check
return true;
}
// process the accept header and get a list of accepted mimes
$accept_mimes = array();
$accept_header = explode(',', $accept_header);
foreach ($accept_header as $accept_def)
{
$accept_def = explode(';', $accept_def);
$accept_def = trim($accept_def[0]);
if ( ! in_array($accept_def, $accept_mimes))
{
$accept_mimes[] = $accept_def;
}
}
// match on generic mime type
if (in_array('*/*', $accept_mimes))
{
return true;
}
// match on full mime type
if (in_array($mime, $accept_mimes))
{
return true;
}
// match on generic mime type
$mime = substr($mime, 0, strpos($mime, '/')).'/*';
if (in_array($mime, $accept_mimes))
{
return true;
}
// no match
return false;
} | php | protected function mime_in_header($mime, $accept_header)
{
// make sure we have input
if (empty($mime) or empty($accept_header))
{
// no header or no mime to check
return true;
}
// process the accept header and get a list of accepted mimes
$accept_mimes = array();
$accept_header = explode(',', $accept_header);
foreach ($accept_header as $accept_def)
{
$accept_def = explode(';', $accept_def);
$accept_def = trim($accept_def[0]);
if ( ! in_array($accept_def, $accept_mimes))
{
$accept_mimes[] = $accept_def;
}
}
// match on generic mime type
if (in_array('*/*', $accept_mimes))
{
return true;
}
// match on full mime type
if (in_array($mime, $accept_mimes))
{
return true;
}
// match on generic mime type
$mime = substr($mime, 0, strpos($mime, '/')).'/*';
if (in_array($mime, $accept_mimes))
{
return true;
}
// no match
return false;
} | [
"protected",
"function",
"mime_in_header",
"(",
"$",
"mime",
",",
"$",
"accept_header",
")",
"{",
"// make sure we have input",
"if",
"(",
"empty",
"(",
"$",
"mime",
")",
"or",
"empty",
"(",
"$",
"accept_header",
")",
")",
"{",
"// no header or no mime to check",
"return",
"true",
";",
"}",
"// process the accept header and get a list of accepted mimes",
"$",
"accept_mimes",
"=",
"array",
"(",
")",
";",
"$",
"accept_header",
"=",
"explode",
"(",
"','",
",",
"$",
"accept_header",
")",
";",
"foreach",
"(",
"$",
"accept_header",
"as",
"$",
"accept_def",
")",
"{",
"$",
"accept_def",
"=",
"explode",
"(",
"';'",
",",
"$",
"accept_def",
")",
";",
"$",
"accept_def",
"=",
"trim",
"(",
"$",
"accept_def",
"[",
"0",
"]",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"accept_def",
",",
"$",
"accept_mimes",
")",
")",
"{",
"$",
"accept_mimes",
"[",
"]",
"=",
"$",
"accept_def",
";",
"}",
"}",
"// match on generic mime type",
"if",
"(",
"in_array",
"(",
"'*/*'",
",",
"$",
"accept_mimes",
")",
")",
"{",
"return",
"true",
";",
"}",
"// match on full mime type",
"if",
"(",
"in_array",
"(",
"$",
"mime",
",",
"$",
"accept_mimes",
")",
")",
"{",
"return",
"true",
";",
"}",
"// match on generic mime type",
"$",
"mime",
"=",
"substr",
"(",
"$",
"mime",
",",
"0",
",",
"strpos",
"(",
"$",
"mime",
",",
"'/'",
")",
")",
".",
"'/*'",
";",
"if",
"(",
"in_array",
"(",
"$",
"mime",
",",
"$",
"accept_mimes",
")",
")",
"{",
"return",
"true",
";",
"}",
"// no match",
"return",
"false",
";",
"}"
] | Validate if a given mime type is accepted according to an accept header
@param string $mime
@param string $accept_header
@return bool | [
"Validate",
"if",
"a",
"given",
"mime",
"type",
"is",
"accepted",
"according",
"to",
"an",
"accept",
"header"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/request/driver.php#L291-L334 |
9,155 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/request/driver.php | Request_Driver.set_response | public function set_response($body, $status, $mime = null, $headers = array(), $accept_header = null)
{
// did we use an accept header? If so, validate the returned mimetype
if ( ! $this->mime_in_header($mime, $accept_header))
{
throw new \OutOfRangeException('The mimetype "'.$mime.'" of the returned response is not acceptable according to the accept header send.');
}
// do we have auto formatting enabled and can we format this mime type?
if ($this->auto_format and array_key_exists($mime, static::$auto_detect_formats))
{
$body = \Format::forge($body, static::$auto_detect_formats[$mime])->to_array();
}
$this->response = \Response::forge($body, $status, $headers);
return $this->response;
} | php | public function set_response($body, $status, $mime = null, $headers = array(), $accept_header = null)
{
// did we use an accept header? If so, validate the returned mimetype
if ( ! $this->mime_in_header($mime, $accept_header))
{
throw new \OutOfRangeException('The mimetype "'.$mime.'" of the returned response is not acceptable according to the accept header send.');
}
// do we have auto formatting enabled and can we format this mime type?
if ($this->auto_format and array_key_exists($mime, static::$auto_detect_formats))
{
$body = \Format::forge($body, static::$auto_detect_formats[$mime])->to_array();
}
$this->response = \Response::forge($body, $status, $headers);
return $this->response;
} | [
"public",
"function",
"set_response",
"(",
"$",
"body",
",",
"$",
"status",
",",
"$",
"mime",
"=",
"null",
",",
"$",
"headers",
"=",
"array",
"(",
")",
",",
"$",
"accept_header",
"=",
"null",
")",
"{",
"// did we use an accept header? If so, validate the returned mimetype",
"if",
"(",
"!",
"$",
"this",
"->",
"mime_in_header",
"(",
"$",
"mime",
",",
"$",
"accept_header",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfRangeException",
"(",
"'The mimetype \"'",
".",
"$",
"mime",
".",
"'\" of the returned response is not acceptable according to the accept header send.'",
")",
";",
"}",
"// do we have auto formatting enabled and can we format this mime type?",
"if",
"(",
"$",
"this",
"->",
"auto_format",
"and",
"array_key_exists",
"(",
"$",
"mime",
",",
"static",
"::",
"$",
"auto_detect_formats",
")",
")",
"{",
"$",
"body",
"=",
"\\",
"Format",
"::",
"forge",
"(",
"$",
"body",
",",
"static",
"::",
"$",
"auto_detect_formats",
"[",
"$",
"mime",
"]",
")",
"->",
"to_array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"response",
"=",
"\\",
"Response",
"::",
"forge",
"(",
"$",
"body",
",",
"$",
"status",
",",
"$",
"headers",
")",
";",
"return",
"$",
"this",
"->",
"response",
";",
"}"
] | Creates the Response and optionally attempts to auto-format the output
@param string $body
@param int $status
@param string $mime
@param array $headers
@param string $accept_header
@return Response
@throws OutOfRangeException if an accept header was specified, but the mime type isn't in it | [
"Creates",
"the",
"Response",
"and",
"optionally",
"attempts",
"to",
"auto",
"-",
"format",
"the",
"output"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/request/driver.php#L349-L366 |
9,156 | indigophp-archive/codeception-fuel-module | fuel/fuel/core/classes/request/driver.php | Request_Driver.response_info | public function response_info($key = null, $default = null)
{
if (func_num_args() == 0)
{
return $this->response_info;
}
return \Arr::get($this->response_info, $key, $default);
} | php | public function response_info($key = null, $default = null)
{
if (func_num_args() == 0)
{
return $this->response_info;
}
return \Arr::get($this->response_info, $key, $default);
} | [
"public",
"function",
"response_info",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"==",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"response_info",
";",
"}",
"return",
"\\",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"response_info",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] | Fetch the response info or a key from it
@param string $key
@param string $default
@return mixed | [
"Fetch",
"the",
"response",
"info",
"or",
"a",
"key",
"from",
"it"
] | 0973b7cbd540a0e89cc5bb7af94627f77f09bf49 | https://github.com/indigophp-archive/codeception-fuel-module/blob/0973b7cbd540a0e89cc5bb7af94627f77f09bf49/fuel/fuel/core/classes/request/driver.php#L385-L393 |
9,157 | osflab/bean | BeanHelper.php | BeanHelper.filterMarkdownContent | public static function filterMarkdownContent(?string $content, bool $compute, bool $fullMarkdown = false): ?string
{
return $compute
? ($fullMarkdown
? self::escapeAndMarkdown($content)
: self::escapeAndMarkdownLight($content)
)
: $content;
} | php | public static function filterMarkdownContent(?string $content, bool $compute, bool $fullMarkdown = false): ?string
{
return $compute
? ($fullMarkdown
? self::escapeAndMarkdown($content)
: self::escapeAndMarkdownLight($content)
)
: $content;
} | [
"public",
"static",
"function",
"filterMarkdownContent",
"(",
"?",
"string",
"$",
"content",
",",
"bool",
"$",
"compute",
",",
"bool",
"$",
"fullMarkdown",
"=",
"false",
")",
":",
"?",
"string",
"{",
"return",
"$",
"compute",
"?",
"(",
"$",
"fullMarkdown",
"?",
"self",
"::",
"escapeAndMarkdown",
"(",
"$",
"content",
")",
":",
"self",
"::",
"escapeAndMarkdownLight",
"(",
"$",
"content",
")",
")",
":",
"$",
"content",
";",
"}"
] | Common filter for markdown content for getters
@param string|null $content
@param bool $compute
@param bool $fullMarkdown
@return string|null | [
"Common",
"filter",
"for",
"markdown",
"content",
"for",
"getters"
] | 1d3e575aaedb6c8bb281dce9c66e8eec5e89a1d7 | https://github.com/osflab/bean/blob/1d3e575aaedb6c8bb281dce9c66e8eec5e89a1d7/BeanHelper.php#L53-L61 |
9,158 | osflab/bean | BeanHelper.php | BeanHelper.filterContent | public static function filterContent(?string $content, bool $escape, bool $nl2br = false): ?string
{
return $escape ? Html::escape($content, $nl2br) : $content;
} | php | public static function filterContent(?string $content, bool $escape, bool $nl2br = false): ?string
{
return $escape ? Html::escape($content, $nl2br) : $content;
} | [
"public",
"static",
"function",
"filterContent",
"(",
"?",
"string",
"$",
"content",
",",
"bool",
"$",
"escape",
",",
"bool",
"$",
"nl2br",
"=",
"false",
")",
":",
"?",
"string",
"{",
"return",
"$",
"escape",
"?",
"Html",
"::",
"escape",
"(",
"$",
"content",
",",
"$",
"nl2br",
")",
":",
"$",
"content",
";",
"}"
] | Common filter for general content for getters
@param string|null $content
@param bool $escape
@return string|null | [
"Common",
"filter",
"for",
"general",
"content",
"for",
"getters"
] | 1d3e575aaedb6c8bb281dce9c66e8eec5e89a1d7 | https://github.com/osflab/bean/blob/1d3e575aaedb6c8bb281dce9c66e8eec5e89a1d7/BeanHelper.php#L69-L72 |
9,159 | matudelatower/ubicacion-bundle | Controller/LocalidadController.php | LocalidadController.showAction | public function showAction(Localidad $localidad)
{
$deleteForm = $this->createDeleteForm($localidad);
return $this->render('UbicacionBundle:localidad:show.html.twig', array(
'localidad' => $localidad,
'delete_form' => $deleteForm->createView(),
));
} | php | public function showAction(Localidad $localidad)
{
$deleteForm = $this->createDeleteForm($localidad);
return $this->render('UbicacionBundle:localidad:show.html.twig', array(
'localidad' => $localidad,
'delete_form' => $deleteForm->createView(),
));
} | [
"public",
"function",
"showAction",
"(",
"Localidad",
"$",
"localidad",
")",
"{",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"localidad",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'UbicacionBundle:localidad:show.html.twig'",
",",
"array",
"(",
"'localidad'",
"=>",
"$",
"localidad",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Finds and displays a Localidad entity. | [
"Finds",
"and",
"displays",
"a",
"Localidad",
"entity",
"."
] | f2daef3f72ae3120386cb9fb8d67fc5fcbb5b5df | https://github.com/matudelatower/ubicacion-bundle/blob/f2daef3f72ae3120386cb9fb8d67fc5fcbb5b5df/Controller/LocalidadController.php#L59-L67 |
9,160 | matudelatower/ubicacion-bundle | Controller/LocalidadController.php | LocalidadController.editAction | public function editAction(Request $request, Localidad $localidad)
{
$deleteForm = $this->createDeleteForm($localidad);
$editForm = $this->createForm('Matudelatower\UbicacionBundle\Form\Type\LocalidadType', $localidad);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($localidad);
$em->flush();
return $this->redirectToRoute('localidad_edit', array('id' => $localidad->getId()));
}
return $this->render('UbicacionBundle:localidad:edit.html.twig', array(
'localidad' => $localidad,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | php | public function editAction(Request $request, Localidad $localidad)
{
$deleteForm = $this->createDeleteForm($localidad);
$editForm = $this->createForm('Matudelatower\UbicacionBundle\Form\Type\LocalidadType', $localidad);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($localidad);
$em->flush();
return $this->redirectToRoute('localidad_edit', array('id' => $localidad->getId()));
}
return $this->render('UbicacionBundle:localidad:edit.html.twig', array(
'localidad' => $localidad,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | [
"public",
"function",
"editAction",
"(",
"Request",
"$",
"request",
",",
"Localidad",
"$",
"localidad",
")",
"{",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"localidad",
")",
";",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"'Matudelatower\\UbicacionBundle\\Form\\Type\\LocalidadType'",
",",
"$",
"localidad",
")",
";",
"$",
"editForm",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"editForm",
"->",
"isSubmitted",
"(",
")",
"&&",
"$",
"editForm",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"localidad",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirectToRoute",
"(",
"'localidad_edit'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"localidad",
"->",
"getId",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'UbicacionBundle:localidad:edit.html.twig'",
",",
"array",
"(",
"'localidad'",
"=>",
"$",
"localidad",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Displays a form to edit an existing Localidad entity. | [
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"Localidad",
"entity",
"."
] | f2daef3f72ae3120386cb9fb8d67fc5fcbb5b5df | https://github.com/matudelatower/ubicacion-bundle/blob/f2daef3f72ae3120386cb9fb8d67fc5fcbb5b5df/Controller/LocalidadController.php#L73-L92 |
9,161 | matudelatower/ubicacion-bundle | Controller/LocalidadController.php | LocalidadController.deleteAction | public function deleteAction(Request $request, Localidad $localidad)
{
$form = $this->createDeleteForm($localidad);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($localidad);
$em->flush();
}
return $this->redirectToRoute('localidad_index');
} | php | public function deleteAction(Request $request, Localidad $localidad)
{
$form = $this->createDeleteForm($localidad);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($localidad);
$em->flush();
}
return $this->redirectToRoute('localidad_index');
} | [
"public",
"function",
"deleteAction",
"(",
"Request",
"$",
"request",
",",
"Localidad",
"$",
"localidad",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"localidad",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isSubmitted",
"(",
")",
"&&",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"remove",
"(",
"$",
"localidad",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirectToRoute",
"(",
"'localidad_index'",
")",
";",
"}"
] | Deletes a Localidad entity. | [
"Deletes",
"a",
"Localidad",
"entity",
"."
] | f2daef3f72ae3120386cb9fb8d67fc5fcbb5b5df | https://github.com/matudelatower/ubicacion-bundle/blob/f2daef3f72ae3120386cb9fb8d67fc5fcbb5b5df/Controller/LocalidadController.php#L98-L110 |
9,162 | matudelatower/ubicacion-bundle | Controller/LocalidadController.php | LocalidadController.createDeleteForm | private function createDeleteForm(Localidad $localidad)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('localidad_delete', array('id' => $localidad->getId())))
->setMethod('DELETE')
->getForm()
;
} | php | private function createDeleteForm(Localidad $localidad)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('localidad_delete', array('id' => $localidad->getId())))
->setMethod('DELETE')
->getForm()
;
} | [
"private",
"function",
"createDeleteForm",
"(",
"Localidad",
"$",
"localidad",
")",
"{",
"return",
"$",
"this",
"->",
"createFormBuilder",
"(",
")",
"->",
"setAction",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'localidad_delete'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"localidad",
"->",
"getId",
"(",
")",
")",
")",
")",
"->",
"setMethod",
"(",
"'DELETE'",
")",
"->",
"getForm",
"(",
")",
";",
"}"
] | Creates a form to delete a Localidad entity.
@param Localidad $localidad The Localidad entity
@return \Symfony\Component\Form\Form The form | [
"Creates",
"a",
"form",
"to",
"delete",
"a",
"Localidad",
"entity",
"."
] | f2daef3f72ae3120386cb9fb8d67fc5fcbb5b5df | https://github.com/matudelatower/ubicacion-bundle/blob/f2daef3f72ae3120386cb9fb8d67fc5fcbb5b5df/Controller/LocalidadController.php#L119-L126 |
9,163 | vutran/wpmvc-core | src/Models/View.php | View.setVars | public function setVars($vars)
{
// If vars is an array
if (is_array($vars) && count($vars)) {
// Iterate and set the var
foreach ($vars as $key => $value) {
$this->setVar($key, $value);
}
}
return $this;
} | php | public function setVars($vars)
{
// If vars is an array
if (is_array($vars) && count($vars)) {
// Iterate and set the var
foreach ($vars as $key => $value) {
$this->setVar($key, $value);
}
}
return $this;
} | [
"public",
"function",
"setVars",
"(",
"$",
"vars",
")",
"{",
"// If vars is an array",
"if",
"(",
"is_array",
"(",
"$",
"vars",
")",
"&&",
"count",
"(",
"$",
"vars",
")",
")",
"{",
"// Iterate and set the var",
"foreach",
"(",
"$",
"vars",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setVar",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets a variable for the view
@access public
@param array $vars
@return self | [
"Sets",
"a",
"variable",
"for",
"the",
"view"
] | 4081be36116ae8e79abfd182d783d28d0fb42219 | https://github.com/vutran/wpmvc-core/blob/4081be36116ae8e79abfd182d783d28d0fb42219/src/Models/View.php#L116-L126 |
9,164 | vutran/wpmvc-core | src/Models/View.php | View.getVar | public function getVar($key)
{
return (array_key_exists($key, $this->vars)) ? $this->vars[$key] : null;
} | php | public function getVar($key)
{
return (array_key_exists($key, $this->vars)) ? $this->vars[$key] : null;
} | [
"public",
"function",
"getVar",
"(",
"$",
"key",
")",
"{",
"return",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"vars",
")",
")",
"?",
"$",
"this",
"->",
"vars",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Retrieves a stored variable
@access public
@param string $key The name of the variable
@return mixed | [
"Retrieves",
"a",
"stored",
"variable"
] | 4081be36116ae8e79abfd182d783d28d0fb42219 | https://github.com/vutran/wpmvc-core/blob/4081be36116ae8e79abfd182d783d28d0fb42219/src/Models/View.php#L161-L164 |
9,165 | vutran/wpmvc-core | src/Models/View.php | View.get | public function get($key)
{
return array_key_exists($key, $this->vars) ? $this->vars[$key] : null;
} | php | public function get($key)
{
return array_key_exists($key, $this->vars) ? $this->vars[$key] : null;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"vars",
")",
"?",
"$",
"this",
"->",
"vars",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Retrieve a view variable
@access public
@param string $key
@return mixed | [
"Retrieve",
"a",
"view",
"variable"
] | 4081be36116ae8e79abfd182d783d28d0fb42219 | https://github.com/vutran/wpmvc-core/blob/4081be36116ae8e79abfd182d783d28d0fb42219/src/Models/View.php#L194-L197 |
9,166 | vutran/wpmvc-core | src/Models/View.php | View.output | public function output()
{
// If the view file exists
if ($this->hasFile()) {
// Extract all view variables
extract($this->getVars());
ob_start();
include($this->getPath() . '/' . $this->getFile(true));
$html = ob_get_contents();
ob_end_clean();
return $html;
} else {
die('Fatal Error: ' . $this->getPath() . '/' . $this->getFile(true) . ' does not exist.');
}
} | php | public function output()
{
// If the view file exists
if ($this->hasFile()) {
// Extract all view variables
extract($this->getVars());
ob_start();
include($this->getPath() . '/' . $this->getFile(true));
$html = ob_get_contents();
ob_end_clean();
return $html;
} else {
die('Fatal Error: ' . $this->getPath() . '/' . $this->getFile(true) . ' does not exist.');
}
} | [
"public",
"function",
"output",
"(",
")",
"{",
"// If the view file exists",
"if",
"(",
"$",
"this",
"->",
"hasFile",
"(",
")",
")",
"{",
"// Extract all view variables",
"extract",
"(",
"$",
"this",
"->",
"getVars",
"(",
")",
")",
";",
"ob_start",
"(",
")",
";",
"include",
"(",
"$",
"this",
"->",
"getPath",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"getFile",
"(",
"true",
")",
")",
";",
"$",
"html",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"return",
"$",
"html",
";",
"}",
"else",
"{",
"die",
"(",
"'Fatal Error: '",
".",
"$",
"this",
"->",
"getPath",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"getFile",
"(",
"true",
")",
".",
"' does not exist.'",
")",
";",
"}",
"}"
] | Retrieve's the view output
@access public
@return string | [
"Retrieve",
"s",
"the",
"view",
"output"
] | 4081be36116ae8e79abfd182d783d28d0fb42219 | https://github.com/vutran/wpmvc-core/blob/4081be36116ae8e79abfd182d783d28d0fb42219/src/Models/View.php#L205-L219 |
9,167 | zepi/turbo-base | Zepi/Core/Language/src/Manager/TranslationManager.php | TranslationManager.translate | public function translate($string, $namespace, $arguments = array())
{
// Load the language file for the given namespace if the language file isn't loaded
if (!isset($this->translatedStrings[$namespace]) || !is_array($this->translatedStrings[$namespace])) {
$this->loadLanguageFileForNamespace($namespace);
}
// If no translation for the original string is available or the string is not translated
// return the original string to the caller.
if (!isset($this->translatedStrings[$namespace][$string]) || $this->translatedStrings[$namespace][$string] == '') {
return $this->replacePlaceholders($string, $arguments);
}
return $this->replacePlaceholders($this->translatedStrings[$namespace][$string], $arguments);
} | php | public function translate($string, $namespace, $arguments = array())
{
// Load the language file for the given namespace if the language file isn't loaded
if (!isset($this->translatedStrings[$namespace]) || !is_array($this->translatedStrings[$namespace])) {
$this->loadLanguageFileForNamespace($namespace);
}
// If no translation for the original string is available or the string is not translated
// return the original string to the caller.
if (!isset($this->translatedStrings[$namespace][$string]) || $this->translatedStrings[$namespace][$string] == '') {
return $this->replacePlaceholders($string, $arguments);
}
return $this->replacePlaceholders($this->translatedStrings[$namespace][$string], $arguments);
} | [
"public",
"function",
"translate",
"(",
"$",
"string",
",",
"$",
"namespace",
",",
"$",
"arguments",
"=",
"array",
"(",
")",
")",
"{",
"// Load the language file for the given namespace if the language file isn't loaded",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"translatedStrings",
"[",
"$",
"namespace",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"translatedStrings",
"[",
"$",
"namespace",
"]",
")",
")",
"{",
"$",
"this",
"->",
"loadLanguageFileForNamespace",
"(",
"$",
"namespace",
")",
";",
"}",
"// If no translation for the original string is available or the string is not translated ",
"// return the original string to the caller.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"translatedStrings",
"[",
"$",
"namespace",
"]",
"[",
"$",
"string",
"]",
")",
"||",
"$",
"this",
"->",
"translatedStrings",
"[",
"$",
"namespace",
"]",
"[",
"$",
"string",
"]",
"==",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"replacePlaceholders",
"(",
"$",
"string",
",",
"$",
"arguments",
")",
";",
"}",
"return",
"$",
"this",
"->",
"replacePlaceholders",
"(",
"$",
"this",
"->",
"translatedStrings",
"[",
"$",
"namespace",
"]",
"[",
"$",
"string",
"]",
",",
"$",
"arguments",
")",
";",
"}"
] | Returns the translated version of the given string. If no
translation is available, the function will return the given
string back.
@access public
@param string $string
@param string $namespace
@param array $arguments
@return string | [
"Returns",
"the",
"translated",
"version",
"of",
"the",
"given",
"string",
".",
"If",
"no",
"translation",
"is",
"available",
"the",
"function",
"will",
"return",
"the",
"given",
"string",
"back",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Core/Language/src/Manager/TranslationManager.php#L96-L110 |
9,168 | zepi/turbo-base | Zepi/Core/Language/src/Manager/TranslationManager.php | TranslationManager.replacePlaceholders | protected function replacePlaceholders($string, $arguments)
{
if (count($arguments) == 0) {
return $string;
}
foreach ($arguments as $key => $value) {
$string = str_replace('%' . $key . '%', $value, $string);
}
return $string;
} | php | protected function replacePlaceholders($string, $arguments)
{
if (count($arguments) == 0) {
return $string;
}
foreach ($arguments as $key => $value) {
$string = str_replace('%' . $key . '%', $value, $string);
}
return $string;
} | [
"protected",
"function",
"replacePlaceholders",
"(",
"$",
"string",
",",
"$",
"arguments",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"arguments",
")",
"==",
"0",
")",
"{",
"return",
"$",
"string",
";",
"}",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"'%'",
".",
"$",
"key",
".",
"'%'",
",",
"$",
"value",
",",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Replaces the placeholders in the string with the correct values
@access protected
@param string $string
@param array $arguments
@return string | [
"Replaces",
"the",
"placeholders",
"in",
"the",
"string",
"with",
"the",
"correct",
"values"
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Core/Language/src/Manager/TranslationManager.php#L120-L131 |
9,169 | zepi/turbo-base | Zepi/Core/Language/src/Manager/TranslationManager.php | TranslationManager.loadLanguageFileForNamespace | protected function loadLanguageFileForNamespace($namespace)
{
$loadedLocale = $this->request->getLocale();
$content = $this->languageFileManager->loadTranslationFileContent($namespace, $loadedLocale);
// If the received content is empty return false
if ($content === false) {
return false;
}
$lines = explode(PHP_EOL, $content);
foreach ($lines as $line) {
$delimiter = strpos($line, ' = ');
if ($delimiter === false) {
continue;
}
$pattern = substr($line, 0, $delimiter);
$replacement = substr($line, $delimiter + 3);
if (!isset($this->translatedStrings[$namespace]) || !is_array($this->translatedStrings[$namespace])) {
$this->translatedStrings[$namespace] = array();
}
$this->translatedStrings[$namespace][$pattern] = $replacement;
}
} | php | protected function loadLanguageFileForNamespace($namespace)
{
$loadedLocale = $this->request->getLocale();
$content = $this->languageFileManager->loadTranslationFileContent($namespace, $loadedLocale);
// If the received content is empty return false
if ($content === false) {
return false;
}
$lines = explode(PHP_EOL, $content);
foreach ($lines as $line) {
$delimiter = strpos($line, ' = ');
if ($delimiter === false) {
continue;
}
$pattern = substr($line, 0, $delimiter);
$replacement = substr($line, $delimiter + 3);
if (!isset($this->translatedStrings[$namespace]) || !is_array($this->translatedStrings[$namespace])) {
$this->translatedStrings[$namespace] = array();
}
$this->translatedStrings[$namespace][$pattern] = $replacement;
}
} | [
"protected",
"function",
"loadLanguageFileForNamespace",
"(",
"$",
"namespace",
")",
"{",
"$",
"loadedLocale",
"=",
"$",
"this",
"->",
"request",
"->",
"getLocale",
"(",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"languageFileManager",
"->",
"loadTranslationFileContent",
"(",
"$",
"namespace",
",",
"$",
"loadedLocale",
")",
";",
"// If the received content is empty return false",
"if",
"(",
"$",
"content",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"lines",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"content",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"delimiter",
"=",
"strpos",
"(",
"$",
"line",
",",
"' = '",
")",
";",
"if",
"(",
"$",
"delimiter",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"$",
"pattern",
"=",
"substr",
"(",
"$",
"line",
",",
"0",
",",
"$",
"delimiter",
")",
";",
"$",
"replacement",
"=",
"substr",
"(",
"$",
"line",
",",
"$",
"delimiter",
"+",
"3",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"translatedStrings",
"[",
"$",
"namespace",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"translatedStrings",
"[",
"$",
"namespace",
"]",
")",
")",
"{",
"$",
"this",
"->",
"translatedStrings",
"[",
"$",
"namespace",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"translatedStrings",
"[",
"$",
"namespace",
"]",
"[",
"$",
"pattern",
"]",
"=",
"$",
"replacement",
";",
"}",
"}"
] | Searches all language files which should be loaded for the
requested locale.
@access protected
@param string $namespace | [
"Searches",
"all",
"language",
"files",
"which",
"should",
"be",
"loaded",
"for",
"the",
"requested",
"locale",
"."
] | 9a36d8c7649317f55f91b2adf386bd1f04ec02a3 | https://github.com/zepi/turbo-base/blob/9a36d8c7649317f55f91b2adf386bd1f04ec02a3/Zepi/Core/Language/src/Manager/TranslationManager.php#L140-L167 |
9,170 | JumpGateio/Database | src/JumpGate/Database/Traits/Collection/Helpers.php | Helpers.explode | public static function explode($delimiter, $string, $limit = null)
{
$array = explode($delimiter, $string);
if (! is_null($limit)) {
$array = explode($delimiter, $string, $limit);
}
return new static($array);
} | php | public static function explode($delimiter, $string, $limit = null)
{
$array = explode($delimiter, $string);
if (! is_null($limit)) {
$array = explode($delimiter, $string, $limit);
}
return new static($array);
} | [
"public",
"static",
"function",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"string",
",",
"$",
"limit",
"=",
"null",
")",
"{",
"$",
"array",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"string",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"limit",
")",
")",
"{",
"$",
"array",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"string",
",",
"$",
"limit",
")",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"array",
")",
";",
"}"
] | Explode a string and return a collection.
@param string $delimiter
@param string $string
@param int $limit
@return $this | [
"Explode",
"a",
"string",
"and",
"return",
"a",
"collection",
"."
] | 0d857a1fa85a66dfe380ab153feaa3b167339822 | https://github.com/JumpGateio/Database/blob/0d857a1fa85a66dfe380ab153feaa3b167339822/src/JumpGate/Database/Traits/Collection/Helpers.php#L36-L45 |
9,171 | JumpGateio/Database | src/JumpGate/Database/Traits/Collection/Helpers.php | Helpers.parseMixed | public static function parseMixed($items, $delimiter = ',')
{
// Convert delimiter separated item strings
// @example: foo,bar,baz => [foo, bar, baz]
if (is_string($items)) {
if (is_string($delimiter)) {
$delimiters = str_split($delimiter);
}
$delimiters[] = $delimiter;
// Removes any ',' that exist at the beginning or the end,
// like in ',1,2,3,4,'
$separator = '|';
$items = str_replace($delimiters, $separator, $items);
$items = explode($separator, trim($items, $separator));
}
// Put single element items in an array
if (! is_array($items)) {
$items = [$items];
}
// Clean up any empty values
$items = array_filter($items, function ($input) {
// Skip blank strings and nulls
$isBlankString = is_string($input) && trim($input) == '';
$isNullString = is_null($input);
return $isNullString || $isBlankString ? false : true;
});
// Return late static binding collection
return new static($items);
} | php | public static function parseMixed($items, $delimiter = ',')
{
// Convert delimiter separated item strings
// @example: foo,bar,baz => [foo, bar, baz]
if (is_string($items)) {
if (is_string($delimiter)) {
$delimiters = str_split($delimiter);
}
$delimiters[] = $delimiter;
// Removes any ',' that exist at the beginning or the end,
// like in ',1,2,3,4,'
$separator = '|';
$items = str_replace($delimiters, $separator, $items);
$items = explode($separator, trim($items, $separator));
}
// Put single element items in an array
if (! is_array($items)) {
$items = [$items];
}
// Clean up any empty values
$items = array_filter($items, function ($input) {
// Skip blank strings and nulls
$isBlankString = is_string($input) && trim($input) == '';
$isNullString = is_null($input);
return $isNullString || $isBlankString ? false : true;
});
// Return late static binding collection
return new static($items);
} | [
"public",
"static",
"function",
"parseMixed",
"(",
"$",
"items",
",",
"$",
"delimiter",
"=",
"','",
")",
"{",
"// Convert delimiter separated item strings",
"// @example: foo,bar,baz => [foo, bar, baz]",
"if",
"(",
"is_string",
"(",
"$",
"items",
")",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"delimiter",
")",
")",
"{",
"$",
"delimiters",
"=",
"str_split",
"(",
"$",
"delimiter",
")",
";",
"}",
"$",
"delimiters",
"[",
"]",
"=",
"$",
"delimiter",
";",
"// Removes any ',' that exist at the beginning or the end,",
"// like in ',1,2,3,4,'",
"$",
"separator",
"=",
"'|'",
";",
"$",
"items",
"=",
"str_replace",
"(",
"$",
"delimiters",
",",
"$",
"separator",
",",
"$",
"items",
")",
";",
"$",
"items",
"=",
"explode",
"(",
"$",
"separator",
",",
"trim",
"(",
"$",
"items",
",",
"$",
"separator",
")",
")",
";",
"}",
"// Put single element items in an array",
"if",
"(",
"!",
"is_array",
"(",
"$",
"items",
")",
")",
"{",
"$",
"items",
"=",
"[",
"$",
"items",
"]",
";",
"}",
"// Clean up any empty values",
"$",
"items",
"=",
"array_filter",
"(",
"$",
"items",
",",
"function",
"(",
"$",
"input",
")",
"{",
"// Skip blank strings and nulls",
"$",
"isBlankString",
"=",
"is_string",
"(",
"$",
"input",
")",
"&&",
"trim",
"(",
"$",
"input",
")",
"==",
"''",
";",
"$",
"isNullString",
"=",
"is_null",
"(",
"$",
"input",
")",
";",
"return",
"$",
"isNullString",
"||",
"$",
"isBlankString",
"?",
"false",
":",
"true",
";",
"}",
")",
";",
"// Return late static binding collection",
"return",
"new",
"static",
"(",
"$",
"items",
")",
";",
"}"
] | Creates a new Collection from a mixed variable.
Strings are assumed to be delimiter separated and are converted to arrays.
@param mixed $items The values to include as items in the collection
@param string|array $delimiter (optional) for array parsing
@return $this | [
"Creates",
"a",
"new",
"Collection",
"from",
"a",
"mixed",
"variable",
".",
"Strings",
"are",
"assumed",
"to",
"be",
"delimiter",
"separated",
"and",
"are",
"converted",
"to",
"arrays",
"."
] | 0d857a1fa85a66dfe380ab153feaa3b167339822 | https://github.com/JumpGateio/Database/blob/0d857a1fa85a66dfe380ab153feaa3b167339822/src/JumpGate/Database/Traits/Collection/Helpers.php#L56-L89 |
9,172 | BR0kEN-/environment-loader | src/EnvironmentLoader.php | EnvironmentLoader.addEnvironmentReader | public function addEnvironmentReader(array $arguments = [])
{
// Full namespace: <EXTENSION_NAMESPACE>\Environment\<EXTENSION_CONFIG_KEY>EnvironmentReader.
// For example we have registered extension at namespace: "Behat\TqExtension". Class, which
// implements extension interface, located at "Behat\TqExtension\ServiceContainer\TqExtension"
// and its method, "getConfigKey()", returns the "tq" string. In this case the full namespace
// of the reader object will be: "Behat\TqExtension\Environment\TqEnvironmentReader" and its
// constructor will have a set of arguments that were passed to this method.
$this->addDefinition(
'Environment',
'Reader',
EnvironmentExtensionReader::class,
EnvironmentExtension::READER_TAG,
array_merge([$this->namespace, $this->path], $arguments)
);
} | php | public function addEnvironmentReader(array $arguments = [])
{
// Full namespace: <EXTENSION_NAMESPACE>\Environment\<EXTENSION_CONFIG_KEY>EnvironmentReader.
// For example we have registered extension at namespace: "Behat\TqExtension". Class, which
// implements extension interface, located at "Behat\TqExtension\ServiceContainer\TqExtension"
// and its method, "getConfigKey()", returns the "tq" string. In this case the full namespace
// of the reader object will be: "Behat\TqExtension\Environment\TqEnvironmentReader" and its
// constructor will have a set of arguments that were passed to this method.
$this->addDefinition(
'Environment',
'Reader',
EnvironmentExtensionReader::class,
EnvironmentExtension::READER_TAG,
array_merge([$this->namespace, $this->path], $arguments)
);
} | [
"public",
"function",
"addEnvironmentReader",
"(",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"// Full namespace: <EXTENSION_NAMESPACE>\\Environment\\<EXTENSION_CONFIG_KEY>EnvironmentReader.",
"// For example we have registered extension at namespace: \"Behat\\TqExtension\". Class, which",
"// implements extension interface, located at \"Behat\\TqExtension\\ServiceContainer\\TqExtension\"",
"// and its method, \"getConfigKey()\", returns the \"tq\" string. In this case the full namespace",
"// of the reader object will be: \"Behat\\TqExtension\\Environment\\TqEnvironmentReader\" and its",
"// constructor will have a set of arguments that were passed to this method.",
"$",
"this",
"->",
"addDefinition",
"(",
"'Environment'",
",",
"'Reader'",
",",
"EnvironmentExtensionReader",
"::",
"class",
",",
"EnvironmentExtension",
"::",
"READER_TAG",
",",
"array_merge",
"(",
"[",
"$",
"this",
"->",
"namespace",
",",
"$",
"this",
"->",
"path",
"]",
",",
"$",
"arguments",
")",
")",
";",
"}"
] | Implement extension's own environment reader.
@param array $arguments | [
"Implement",
"extension",
"s",
"own",
"environment",
"reader",
"."
] | 420b282b34ee4cb4281abb6ac347e6c2ac2ff778 | https://github.com/BR0kEN-/environment-loader/blob/420b282b34ee4cb4281abb6ac347e6c2ac2ff778/src/EnvironmentLoader.php#L112-L127 |
9,173 | BR0kEN-/environment-loader | src/EnvironmentLoader.php | EnvironmentLoader.load | public function load()
{
foreach ($this->definitions as $tag => $definition) {
$this->extendContainer($tag, $definition);
}
} | php | public function load()
{
foreach ($this->definitions as $tag => $definition) {
$this->extendContainer($tag, $definition);
}
} | [
"public",
"function",
"load",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"definitions",
"as",
"$",
"tag",
"=>",
"$",
"definition",
")",
"{",
"$",
"this",
"->",
"extendContainer",
"(",
"$",
"tag",
",",
"$",
"definition",
")",
";",
"}",
"}"
] | Extend DI container by dependencies. | [
"Extend",
"DI",
"container",
"by",
"dependencies",
"."
] | 420b282b34ee4cb4281abb6ac347e6c2ac2ff778 | https://github.com/BR0kEN-/environment-loader/blob/420b282b34ee4cb4281abb6ac347e6c2ac2ff778/src/EnvironmentLoader.php#L132-L137 |
9,174 | BR0kEN-/environment-loader | src/EnvironmentLoader.php | EnvironmentLoader.addDefinition | private function addDefinition($subNamespace, $objectType, $interface, $tag, array $arguments = [])
{
$class = sprintf($this->classPath, $subNamespace) . $subNamespace . $objectType;
if (!class_exists($class)) {
throw new \RuntimeException(sprintf('Class "%s" does not exists!', $class));
}
if (!in_array($interface, class_implements($class))) {
throw new \RuntimeException(sprintf('Class "%s" must implement the "%s" interface!', $class, $interface));
}
$this->definitions[$tag] = new Definition($class, $arguments);
} | php | private function addDefinition($subNamespace, $objectType, $interface, $tag, array $arguments = [])
{
$class = sprintf($this->classPath, $subNamespace) . $subNamespace . $objectType;
if (!class_exists($class)) {
throw new \RuntimeException(sprintf('Class "%s" does not exists!', $class));
}
if (!in_array($interface, class_implements($class))) {
throw new \RuntimeException(sprintf('Class "%s" must implement the "%s" interface!', $class, $interface));
}
$this->definitions[$tag] = new Definition($class, $arguments);
} | [
"private",
"function",
"addDefinition",
"(",
"$",
"subNamespace",
",",
"$",
"objectType",
",",
"$",
"interface",
",",
"$",
"tag",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"$",
"class",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"classPath",
",",
"$",
"subNamespace",
")",
".",
"$",
"subNamespace",
".",
"$",
"objectType",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Class \"%s\" does not exists!'",
",",
"$",
"class",
")",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"interface",
",",
"class_implements",
"(",
"$",
"class",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Class \"%s\" must implement the \"%s\" interface!'",
",",
"$",
"class",
",",
"$",
"interface",
")",
")",
";",
"}",
"$",
"this",
"->",
"definitions",
"[",
"$",
"tag",
"]",
"=",
"new",
"Definition",
"(",
"$",
"class",
",",
"$",
"arguments",
")",
";",
"}"
] | Add dependency definition for DI container.
@param string $subNamespace
@param string $objectType
@param string $interface
@param string $tag
@param array $arguments | [
"Add",
"dependency",
"definition",
"for",
"DI",
"container",
"."
] | 420b282b34ee4cb4281abb6ac347e6c2ac2ff778 | https://github.com/BR0kEN-/environment-loader/blob/420b282b34ee4cb4281abb6ac347e6c2ac2ff778/src/EnvironmentLoader.php#L148-L161 |
9,175 | BR0kEN-/environment-loader | src/EnvironmentLoader.php | EnvironmentLoader.extendContainer | private function extendContainer($tag, Definition $definition, $identifier = '')
{
if ('' !== $identifier) {
$identifier .= '.';
}
$this->container
->setDefinition("$this->configKey.$identifier$tag", $definition)
->addTag($tag);
} | php | private function extendContainer($tag, Definition $definition, $identifier = '')
{
if ('' !== $identifier) {
$identifier .= '.';
}
$this->container
->setDefinition("$this->configKey.$identifier$tag", $definition)
->addTag($tag);
} | [
"private",
"function",
"extendContainer",
"(",
"$",
"tag",
",",
"Definition",
"$",
"definition",
",",
"$",
"identifier",
"=",
"''",
")",
"{",
"if",
"(",
"''",
"!==",
"$",
"identifier",
")",
"{",
"$",
"identifier",
".=",
"'.'",
";",
"}",
"$",
"this",
"->",
"container",
"->",
"setDefinition",
"(",
"\"$this->configKey.$identifier$tag\"",
",",
"$",
"definition",
")",
"->",
"addTag",
"(",
"$",
"tag",
")",
";",
"}"
] | Add dependency to DI container.
@param string $tag
@param Definition $definition
@param string $identifier | [
"Add",
"dependency",
"to",
"DI",
"container",
"."
] | 420b282b34ee4cb4281abb6ac347e6c2ac2ff778 | https://github.com/BR0kEN-/environment-loader/blob/420b282b34ee4cb4281abb6ac347e6c2ac2ff778/src/EnvironmentLoader.php#L170-L179 |
9,176 | studyportals/SQL | src/PostGres.php | PostGres.unserialize | public function unserialize($data)
{
list(
$this->_server,
$this->_username,
$this->_password,
$this->_database,
$this->_port,
) = unserialize($data);
$this->_connect();
} | php | public function unserialize($data)
{
list(
$this->_server,
$this->_username,
$this->_password,
$this->_database,
$this->_port,
) = unserialize($data);
$this->_connect();
} | [
"public",
"function",
"unserialize",
"(",
"$",
"data",
")",
"{",
"list",
"(",
"$",
"this",
"->",
"_server",
",",
"$",
"this",
"->",
"_username",
",",
"$",
"this",
"->",
"_password",
",",
"$",
"this",
"->",
"_database",
",",
"$",
"this",
"->",
"_port",
",",
")",
"=",
"unserialize",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"_connect",
"(",
")",
";",
"}"
] | Function unserialize.
@param string $data
@throws ConnectionException
@return void | [
"Function",
"unserialize",
"."
] | 4f038ced9a3738c1d4ad562f93547812931d9ed4 | https://github.com/studyportals/SQL/blob/4f038ced9a3738c1d4ad562f93547812931d9ed4/src/PostGres.php#L85-L97 |
9,177 | studyportals/SQL | src/PostGres.php | PostGres.query | public function query($query, $return_set = false, $buffered = true)
{
$this->_result = null;
$query = trim($query);
$this->_result = @pg_query($this->_connection, $query);
// Invalid Query
if (!$this->_result) {
$error_message = @\pg_last_error($this->_connection); //NOSONAR
throw new ConnectionException('An error occurred while
attempting to query the PostGres server: ' . $error_message);
} // Valid Query
else {
$num_rows = @\pg_num_rows($this->_result);
$matches = [];
/** @noinspection PhpUnusedLocalVariableInspection */
$match_count = preg_match(
'/^([\w]+)(?:[\W]+|$)/i', $query, $matches);
assert('$match_count === 1');
$query_type = strtoupper($matches[1]);
switch ($query_type) {
case 'SELECT':
case 'SHOW':
case 'EXPLAIN':
case 'DESCRIBE':
if ($return_set && $num_rows >= 1) {
return new PostGresResultSet($this->_result, $buffered);
} elseif ($num_rows == 1) {
return new PostGresResultRow($this->_result);
} elseif ($num_rows > 1) {
return new PostGresResultSet($this->_result, $buffered);
} else {
return false;
}
break;
case 'DELETE':
case 'INSERT':
case 'REPLACE':
case 'UPDATE':
return $this->getAffectedRows();
break;
case 'START':
case 'COMMIT':
case 'ROLLBACK':
case 'SET':
return true;
break;
default:
return false;
}
}
} | php | public function query($query, $return_set = false, $buffered = true)
{
$this->_result = null;
$query = trim($query);
$this->_result = @pg_query($this->_connection, $query);
// Invalid Query
if (!$this->_result) {
$error_message = @\pg_last_error($this->_connection); //NOSONAR
throw new ConnectionException('An error occurred while
attempting to query the PostGres server: ' . $error_message);
} // Valid Query
else {
$num_rows = @\pg_num_rows($this->_result);
$matches = [];
/** @noinspection PhpUnusedLocalVariableInspection */
$match_count = preg_match(
'/^([\w]+)(?:[\W]+|$)/i', $query, $matches);
assert('$match_count === 1');
$query_type = strtoupper($matches[1]);
switch ($query_type) {
case 'SELECT':
case 'SHOW':
case 'EXPLAIN':
case 'DESCRIBE':
if ($return_set && $num_rows >= 1) {
return new PostGresResultSet($this->_result, $buffered);
} elseif ($num_rows == 1) {
return new PostGresResultRow($this->_result);
} elseif ($num_rows > 1) {
return new PostGresResultSet($this->_result, $buffered);
} else {
return false;
}
break;
case 'DELETE':
case 'INSERT':
case 'REPLACE':
case 'UPDATE':
return $this->getAffectedRows();
break;
case 'START':
case 'COMMIT':
case 'ROLLBACK':
case 'SET':
return true;
break;
default:
return false;
}
}
} | [
"public",
"function",
"query",
"(",
"$",
"query",
",",
"$",
"return_set",
"=",
"false",
",",
"$",
"buffered",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"_result",
"=",
"null",
";",
"$",
"query",
"=",
"trim",
"(",
"$",
"query",
")",
";",
"$",
"this",
"->",
"_result",
"=",
"@",
"pg_query",
"(",
"$",
"this",
"->",
"_connection",
",",
"$",
"query",
")",
";",
"// Invalid Query",
"if",
"(",
"!",
"$",
"this",
"->",
"_result",
")",
"{",
"$",
"error_message",
"=",
"@",
"\\",
"pg_last_error",
"(",
"$",
"this",
"->",
"_connection",
")",
";",
"//NOSONAR",
"throw",
"new",
"ConnectionException",
"(",
"'An error occurred while\n\t\t\t\t\tattempting to query the PostGres server: '",
".",
"$",
"error_message",
")",
";",
"}",
"// Valid Query",
"else",
"{",
"$",
"num_rows",
"=",
"@",
"\\",
"pg_num_rows",
"(",
"$",
"this",
"->",
"_result",
")",
";",
"$",
"matches",
"=",
"[",
"]",
";",
"/** @noinspection PhpUnusedLocalVariableInspection */",
"$",
"match_count",
"=",
"preg_match",
"(",
"'/^([\\w]+)(?:[\\W]+|$)/i'",
",",
"$",
"query",
",",
"$",
"matches",
")",
";",
"assert",
"(",
"'$match_count === 1'",
")",
";",
"$",
"query_type",
"=",
"strtoupper",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"switch",
"(",
"$",
"query_type",
")",
"{",
"case",
"'SELECT'",
":",
"case",
"'SHOW'",
":",
"case",
"'EXPLAIN'",
":",
"case",
"'DESCRIBE'",
":",
"if",
"(",
"$",
"return_set",
"&&",
"$",
"num_rows",
">=",
"1",
")",
"{",
"return",
"new",
"PostGresResultSet",
"(",
"$",
"this",
"->",
"_result",
",",
"$",
"buffered",
")",
";",
"}",
"elseif",
"(",
"$",
"num_rows",
"==",
"1",
")",
"{",
"return",
"new",
"PostGresResultRow",
"(",
"$",
"this",
"->",
"_result",
")",
";",
"}",
"elseif",
"(",
"$",
"num_rows",
">",
"1",
")",
"{",
"return",
"new",
"PostGresResultSet",
"(",
"$",
"this",
"->",
"_result",
",",
"$",
"buffered",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"break",
";",
"case",
"'DELETE'",
":",
"case",
"'INSERT'",
":",
"case",
"'REPLACE'",
":",
"case",
"'UPDATE'",
":",
"return",
"$",
"this",
"->",
"getAffectedRows",
"(",
")",
";",
"break",
";",
"case",
"'START'",
":",
"case",
"'COMMIT'",
":",
"case",
"'ROLLBACK'",
":",
"case",
"'SET'",
":",
"return",
"true",
";",
"break",
";",
"default",
":",
"return",
"false",
";",
"}",
"}",
"}"
] | Send a query to the PostGres server.
<p>For <strong>SELECT</strong>-queries: If the query has a result, this
method returns either {@link SQLResultRow} or {@link SQLResultSet}
instance, depending on the number of results. If no results are available
the method returns <em>false</em>.</p>
<p>For all other queries: If the query is successful, the amount of
affected rows is returned, else <em>false</em> is returned.</p>
@param string $query
@param boolean $return_set
@param boolean $buffered
@return SQLResult|integer|boolean
@throws ConnectionException
@see SQL::query() | [
"Send",
"a",
"query",
"to",
"the",
"PostGres",
"server",
"."
] | 4f038ced9a3738c1d4ad562f93547812931d9ed4 | https://github.com/studyportals/SQL/blob/4f038ced9a3738c1d4ad562f93547812931d9ed4/src/PostGres.php#L160-L237 |
9,178 | webriq/core | module/Paragraph/src/Grid/Paragraph/View/Helper/MetaContent.php | MetaContent.renderMetaContent | public function renderMetaContent( $name, $content = '' )
{
$view = $this->getView();
$middle = $this->getMiddleLayoutModel();
$paragraph = $middle->getParagraphModel();
$renderList = $paragraph->findRenderList( $name );
if ( empty( $renderList ) )
{
return $content;
}
$meta = reset( $renderList )[1];
if ( empty( $meta ) )
{
return $content;
}
$appService = $view->plugin( 'appService' );
$serviceManager = $appService();
$allowOverride = $serviceManager->getAllowOverride();
if ( ! $allowOverride )
{
$serviceManager->setAllowOverride( true );
}
$serviceManager->setService( 'RenderedContent', $meta );
if ( ! $allowOverride )
{
$serviceManager->setAllowOverride( false );
}
if ( $meta instanceof LayoutAwareInterface )
{
$view->plugin( 'layout' )
->setMiddleLayout(
$middle->findMiddleParagraphLayoutById(
$meta->getLayoutId()
)
);
}
return $view->render( 'grid/paragraph/render/paragraph', array(
'paragraphRenderList' => $renderList,
'content' => $content,
) );
} | php | public function renderMetaContent( $name, $content = '' )
{
$view = $this->getView();
$middle = $this->getMiddleLayoutModel();
$paragraph = $middle->getParagraphModel();
$renderList = $paragraph->findRenderList( $name );
if ( empty( $renderList ) )
{
return $content;
}
$meta = reset( $renderList )[1];
if ( empty( $meta ) )
{
return $content;
}
$appService = $view->plugin( 'appService' );
$serviceManager = $appService();
$allowOverride = $serviceManager->getAllowOverride();
if ( ! $allowOverride )
{
$serviceManager->setAllowOverride( true );
}
$serviceManager->setService( 'RenderedContent', $meta );
if ( ! $allowOverride )
{
$serviceManager->setAllowOverride( false );
}
if ( $meta instanceof LayoutAwareInterface )
{
$view->plugin( 'layout' )
->setMiddleLayout(
$middle->findMiddleParagraphLayoutById(
$meta->getLayoutId()
)
);
}
return $view->render( 'grid/paragraph/render/paragraph', array(
'paragraphRenderList' => $renderList,
'content' => $content,
) );
} | [
"public",
"function",
"renderMetaContent",
"(",
"$",
"name",
",",
"$",
"content",
"=",
"''",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
";",
"$",
"middle",
"=",
"$",
"this",
"->",
"getMiddleLayoutModel",
"(",
")",
";",
"$",
"paragraph",
"=",
"$",
"middle",
"->",
"getParagraphModel",
"(",
")",
";",
"$",
"renderList",
"=",
"$",
"paragraph",
"->",
"findRenderList",
"(",
"$",
"name",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"renderList",
")",
")",
"{",
"return",
"$",
"content",
";",
"}",
"$",
"meta",
"=",
"reset",
"(",
"$",
"renderList",
")",
"[",
"1",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"meta",
")",
")",
"{",
"return",
"$",
"content",
";",
"}",
"$",
"appService",
"=",
"$",
"view",
"->",
"plugin",
"(",
"'appService'",
")",
";",
"$",
"serviceManager",
"=",
"$",
"appService",
"(",
")",
";",
"$",
"allowOverride",
"=",
"$",
"serviceManager",
"->",
"getAllowOverride",
"(",
")",
";",
"if",
"(",
"!",
"$",
"allowOverride",
")",
"{",
"$",
"serviceManager",
"->",
"setAllowOverride",
"(",
"true",
")",
";",
"}",
"$",
"serviceManager",
"->",
"setService",
"(",
"'RenderedContent'",
",",
"$",
"meta",
")",
";",
"if",
"(",
"!",
"$",
"allowOverride",
")",
"{",
"$",
"serviceManager",
"->",
"setAllowOverride",
"(",
"false",
")",
";",
"}",
"if",
"(",
"$",
"meta",
"instanceof",
"LayoutAwareInterface",
")",
"{",
"$",
"view",
"->",
"plugin",
"(",
"'layout'",
")",
"->",
"setMiddleLayout",
"(",
"$",
"middle",
"->",
"findMiddleParagraphLayoutById",
"(",
"$",
"meta",
"->",
"getLayoutId",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"view",
"->",
"render",
"(",
"'grid/paragraph/render/paragraph'",
",",
"array",
"(",
"'paragraphRenderList'",
"=>",
"$",
"renderList",
",",
"'content'",
"=>",
"$",
"content",
",",
")",
")",
";",
"}"
] | Set meta-content
@param string $name
@param string $content
@return string | [
"Set",
"meta",
"-",
"content"
] | cfeb6e8a4732561c2215ec94e736c07f9b8bc990 | https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Paragraph/src/Grid/Paragraph/View/Helper/MetaContent.php#L78-L127 |
9,179 | novuso/common | src/Domain/EventSourcing/EventSourcedAggregateRoot.php | EventSourcedAggregateRoot.reconstitute | public static function reconstitute(iterable $eventRecords)
{
$reflection = new ReflectionClass(static::class);
/** @var EventSourcedAggregateRoot $aggregate */
$aggregate = $reflection->newInstanceWithoutConstructor();
$lastSequence = null;
/** @var EventRecord $eventRecord */
foreach ($eventRecords as $eventRecord) {
$lastSequence = $eventRecord->sequenceNumber();
/** @var Event $event */
$event = $eventRecord->eventMessage()->payload();
$aggregate->handleRecursively($event);
}
$aggregate->initializeCommittedVersion($lastSequence);
return $aggregate;
} | php | public static function reconstitute(iterable $eventRecords)
{
$reflection = new ReflectionClass(static::class);
/** @var EventSourcedAggregateRoot $aggregate */
$aggregate = $reflection->newInstanceWithoutConstructor();
$lastSequence = null;
/** @var EventRecord $eventRecord */
foreach ($eventRecords as $eventRecord) {
$lastSequence = $eventRecord->sequenceNumber();
/** @var Event $event */
$event = $eventRecord->eventMessage()->payload();
$aggregate->handleRecursively($event);
}
$aggregate->initializeCommittedVersion($lastSequence);
return $aggregate;
} | [
"public",
"static",
"function",
"reconstitute",
"(",
"iterable",
"$",
"eventRecords",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"static",
"::",
"class",
")",
";",
"/** @var EventSourcedAggregateRoot $aggregate */",
"$",
"aggregate",
"=",
"$",
"reflection",
"->",
"newInstanceWithoutConstructor",
"(",
")",
";",
"$",
"lastSequence",
"=",
"null",
";",
"/** @var EventRecord $eventRecord */",
"foreach",
"(",
"$",
"eventRecords",
"as",
"$",
"eventRecord",
")",
"{",
"$",
"lastSequence",
"=",
"$",
"eventRecord",
"->",
"sequenceNumber",
"(",
")",
";",
"/** @var Event $event */",
"$",
"event",
"=",
"$",
"eventRecord",
"->",
"eventMessage",
"(",
")",
"->",
"payload",
"(",
")",
";",
"$",
"aggregate",
"->",
"handleRecursively",
"(",
"$",
"event",
")",
";",
"}",
"$",
"aggregate",
"->",
"initializeCommittedVersion",
"(",
"$",
"lastSequence",
")",
";",
"return",
"$",
"aggregate",
";",
"}"
] | Creates instance from an event stream history
Override to customize instantiation without using reflection.
@param iterable $eventRecords The event records
@return EventSourcedAggregateRoot | [
"Creates",
"instance",
"from",
"an",
"event",
"stream",
"history"
] | 7d0e5a4f4c79c9622e068efc8b7c70815c460863 | https://github.com/novuso/common/blob/7d0e5a4f4c79c9622e068efc8b7c70815c460863/src/Domain/EventSourcing/EventSourcedAggregateRoot.php#L30-L49 |
9,180 | gibboncms/config | src/ConfigRepository.php | ConfigRepository.build | public function build()
{
$files = $this->filesystem->listFiles($this->directory);
$this->cache->clear();
foreach ($files as $file) {
if ($file['extension'] == 'yml' || $file['extension'] == 'yaml') {
$this->cache->put($file['filename'], $this->yaml->parse($this->filesystem->read($file['path'])));
}
}
$this->cache->persist();
$this->updateValues();
} | php | public function build()
{
$files = $this->filesystem->listFiles($this->directory);
$this->cache->clear();
foreach ($files as $file) {
if ($file['extension'] == 'yml' || $file['extension'] == 'yaml') {
$this->cache->put($file['filename'], $this->yaml->parse($this->filesystem->read($file['path'])));
}
}
$this->cache->persist();
$this->updateValues();
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"files",
"=",
"$",
"this",
"->",
"filesystem",
"->",
"listFiles",
"(",
"$",
"this",
"->",
"directory",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"clear",
"(",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"[",
"'extension'",
"]",
"==",
"'yml'",
"||",
"$",
"file",
"[",
"'extension'",
"]",
"==",
"'yaml'",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"put",
"(",
"$",
"file",
"[",
"'filename'",
"]",
",",
"$",
"this",
"->",
"yaml",
"->",
"parse",
"(",
"$",
"this",
"->",
"filesystem",
"->",
"read",
"(",
"$",
"file",
"[",
"'path'",
"]",
")",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"cache",
"->",
"persist",
"(",
")",
";",
"$",
"this",
"->",
"updateValues",
"(",
")",
";",
"}"
] | Parse the config files and save the values in the cache and in memory
@return void | [
"Parse",
"the",
"config",
"files",
"and",
"save",
"the",
"values",
"in",
"the",
"cache",
"and",
"in",
"memory"
] | 05e9a830173004770a1d26e3429b82adf0a52a11 | https://github.com/gibboncms/config/blob/05e9a830173004770a1d26e3429b82adf0a52a11/src/ConfigRepository.php#L106-L120 |
9,181 | superdweebie/exception-module | src/Sds/ExceptionModule/JsonExceptionStrategy.php | JsonExceptionStrategy.prepareExceptionViewModel | public function prepareExceptionViewModel(MvcEvent $e)
{
// Do nothing if no error in the event
if ( ! ($error = $e->getError())) {
return;
}
// Do nothing if the result is a response object
$result = $e->getResult();
if ($result instanceof Response) {
return;
}
if ($error != Application::ERROR_EXCEPTION){
return;
}
if (! $e->getRequest() instanceof Request){
return;
}
$accept = $e->getRequest()->getHeaders()->get('Accept');
if (! ($accept && $accept->match('application/json'))){
return;
}
if (! ($exception = $e->getParam('exception'))){
return;
}
$modelData = $this->serializeException($exception);
$e->setResult(new JsonModel($modelData));
$e->setError(false);
$response = $e->getResponse();
if (!$response) {
$response = new HttpResponse();
$e->setResponse($response);
}
if (isset($modelData['statusCode'])){
$response->setStatusCode($modelData['statusCode']);
} else {
$response->setStatusCode(500);
}
$response->getHeaders()->addHeaders([$accept, ContentType::fromString('Content-type: application/api-problem+json')]);
} | php | public function prepareExceptionViewModel(MvcEvent $e)
{
// Do nothing if no error in the event
if ( ! ($error = $e->getError())) {
return;
}
// Do nothing if the result is a response object
$result = $e->getResult();
if ($result instanceof Response) {
return;
}
if ($error != Application::ERROR_EXCEPTION){
return;
}
if (! $e->getRequest() instanceof Request){
return;
}
$accept = $e->getRequest()->getHeaders()->get('Accept');
if (! ($accept && $accept->match('application/json'))){
return;
}
if (! ($exception = $e->getParam('exception'))){
return;
}
$modelData = $this->serializeException($exception);
$e->setResult(new JsonModel($modelData));
$e->setError(false);
$response = $e->getResponse();
if (!$response) {
$response = new HttpResponse();
$e->setResponse($response);
}
if (isset($modelData['statusCode'])){
$response->setStatusCode($modelData['statusCode']);
} else {
$response->setStatusCode(500);
}
$response->getHeaders()->addHeaders([$accept, ContentType::fromString('Content-type: application/api-problem+json')]);
} | [
"public",
"function",
"prepareExceptionViewModel",
"(",
"MvcEvent",
"$",
"e",
")",
"{",
"// Do nothing if no error in the event",
"if",
"(",
"!",
"(",
"$",
"error",
"=",
"$",
"e",
"->",
"getError",
"(",
")",
")",
")",
"{",
"return",
";",
"}",
"// Do nothing if the result is a response object",
"$",
"result",
"=",
"$",
"e",
"->",
"getResult",
"(",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"Response",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"error",
"!=",
"Application",
"::",
"ERROR_EXCEPTION",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"e",
"->",
"getRequest",
"(",
")",
"instanceof",
"Request",
")",
"{",
"return",
";",
"}",
"$",
"accept",
"=",
"$",
"e",
"->",
"getRequest",
"(",
")",
"->",
"getHeaders",
"(",
")",
"->",
"get",
"(",
"'Accept'",
")",
";",
"if",
"(",
"!",
"(",
"$",
"accept",
"&&",
"$",
"accept",
"->",
"match",
"(",
"'application/json'",
")",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"exception",
"=",
"$",
"e",
"->",
"getParam",
"(",
"'exception'",
")",
")",
")",
"{",
"return",
";",
"}",
"$",
"modelData",
"=",
"$",
"this",
"->",
"serializeException",
"(",
"$",
"exception",
")",
";",
"$",
"e",
"->",
"setResult",
"(",
"new",
"JsonModel",
"(",
"$",
"modelData",
")",
")",
";",
"$",
"e",
"->",
"setError",
"(",
"false",
")",
";",
"$",
"response",
"=",
"$",
"e",
"->",
"getResponse",
"(",
")",
";",
"if",
"(",
"!",
"$",
"response",
")",
"{",
"$",
"response",
"=",
"new",
"HttpResponse",
"(",
")",
";",
"$",
"e",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"modelData",
"[",
"'statusCode'",
"]",
")",
")",
"{",
"$",
"response",
"->",
"setStatusCode",
"(",
"$",
"modelData",
"[",
"'statusCode'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"setStatusCode",
"(",
"500",
")",
";",
"}",
"$",
"response",
"->",
"getHeaders",
"(",
")",
"->",
"addHeaders",
"(",
"[",
"$",
"accept",
",",
"ContentType",
"::",
"fromString",
"(",
"'Content-type: application/api-problem+json'",
")",
"]",
")",
";",
"}"
] | Create an exception json view model, and set the HTTP status code
@todo dispatch.error does not halt dispatch unless a response is
returned. As such, we likely need to trigger rendering as a low
priority dispatch.error event (or goto a render event) to ensure
rendering occurs, and that munging of view models occurs when
expected.
@param MvcEvent $e
@return void | [
"Create",
"an",
"exception",
"json",
"view",
"model",
"and",
"set",
"the",
"HTTP",
"status",
"code"
] | 49a6197a9c34920b84954c8cf04f48b69dd584cd | https://github.com/superdweebie/exception-module/blob/49a6197a9c34920b84954c8cf04f48b69dd584cd/src/Sds/ExceptionModule/JsonExceptionStrategy.php#L64-L110 |
9,182 | SagePHP/Configuration | src/SagePHP/Configuration/HostsFile.php | HostsFile.removeHost | public function removeHost($host)
{
$ips = $this->getIp($host);
unset($this->hosts[$host]);
foreach ($ips as $ip) {
unset($this->ips[$ip][$host]);
}
} | php | public function removeHost($host)
{
$ips = $this->getIp($host);
unset($this->hosts[$host]);
foreach ($ips as $ip) {
unset($this->ips[$ip][$host]);
}
} | [
"public",
"function",
"removeHost",
"(",
"$",
"host",
")",
"{",
"$",
"ips",
"=",
"$",
"this",
"->",
"getIp",
"(",
"$",
"host",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"hosts",
"[",
"$",
"host",
"]",
")",
";",
"foreach",
"(",
"$",
"ips",
"as",
"$",
"ip",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"ips",
"[",
"$",
"ip",
"]",
"[",
"$",
"host",
"]",
")",
";",
"}",
"}"
] | removes an host.
@param string $host | [
"removes",
"an",
"host",
"."
] | d85eaca679df50a424e2ab10ec8234930cb8e4c1 | https://github.com/SagePHP/Configuration/blob/d85eaca679df50a424e2ab10ec8234930cb8e4c1/src/SagePHP/Configuration/HostsFile.php#L173-L180 |
9,183 | SagePHP/Configuration | src/SagePHP/Configuration/HostsFile.php | HostsFile.removeIp | public function removeIp($ip)
{
$hosts = $this->getHosts($ip);
unset($this->ips[$ip]);
foreach ($hosts as $host) {
unset($this->hosts[$host]);
}
} | php | public function removeIp($ip)
{
$hosts = $this->getHosts($ip);
unset($this->ips[$ip]);
foreach ($hosts as $host) {
unset($this->hosts[$host]);
}
} | [
"public",
"function",
"removeIp",
"(",
"$",
"ip",
")",
"{",
"$",
"hosts",
"=",
"$",
"this",
"->",
"getHosts",
"(",
"$",
"ip",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"ips",
"[",
"$",
"ip",
"]",
")",
";",
"foreach",
"(",
"$",
"hosts",
"as",
"$",
"host",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"hosts",
"[",
"$",
"host",
"]",
")",
";",
"}",
"}"
] | removes an ip and all associated hosts
@param [type] $ip [description]
@return [type] [description] | [
"removes",
"an",
"ip",
"and",
"all",
"associated",
"hosts"
] | d85eaca679df50a424e2ab10ec8234930cb8e4c1 | https://github.com/SagePHP/Configuration/blob/d85eaca679df50a424e2ab10ec8234930cb8e4c1/src/SagePHP/Configuration/HostsFile.php#L187-L195 |
9,184 | SagePHP/Configuration | src/SagePHP/Configuration/HostsFile.php | HostsFile.getContent | public function getContent()
{
$this->processFile($this->getFile());
$buffer = array(
'#',
'# Generated by SagePHP HostsFile Component',
'# see https://github.com/SagePHP/',
'#',
'',
);
foreach ($this->ips as $ip => $hosts) {
$buffer[] = sprintf("%s\t%s", $ip, implode($hosts, ' '));
}
return implode($buffer, "\n");
} | php | public function getContent()
{
$this->processFile($this->getFile());
$buffer = array(
'#',
'# Generated by SagePHP HostsFile Component',
'# see https://github.com/SagePHP/',
'#',
'',
);
foreach ($this->ips as $ip => $hosts) {
$buffer[] = sprintf("%s\t%s", $ip, implode($hosts, ' '));
}
return implode($buffer, "\n");
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"$",
"this",
"->",
"processFile",
"(",
"$",
"this",
"->",
"getFile",
"(",
")",
")",
";",
"$",
"buffer",
"=",
"array",
"(",
"'#'",
",",
"'# Generated by SagePHP HostsFile Component'",
",",
"'# see https://github.com/SagePHP/'",
",",
"'#'",
",",
"''",
",",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"ips",
"as",
"$",
"ip",
"=>",
"$",
"hosts",
")",
"{",
"$",
"buffer",
"[",
"]",
"=",
"sprintf",
"(",
"\"%s\\t%s\"",
",",
"$",
"ip",
",",
"implode",
"(",
"$",
"hosts",
",",
"' '",
")",
")",
";",
"}",
"return",
"implode",
"(",
"$",
"buffer",
",",
"\"\\n\"",
")",
";",
"}"
] | Returns the formatted filr contend
@return string | [
"Returns",
"the",
"formatted",
"filr",
"contend"
] | d85eaca679df50a424e2ab10ec8234930cb8e4c1 | https://github.com/SagePHP/Configuration/blob/d85eaca679df50a424e2ab10ec8234930cb8e4c1/src/SagePHP/Configuration/HostsFile.php#L227-L244 |
9,185 | nodes-php/core | src/AbstractServiceProvider.php | AbstractServiceProvider.install | final public function install()
{
// Initiate Flysystem
$this->files = new Filesystem();
// Make sure we have the Console Output style
// before continuing with the install sequence
if (empty($this->getCommand())) {
throw new InstallPackageException('Could not run install sequence. Reason: Missing Console Output reference.');
}
// Run install methods
$this->prepareInstall();
$this->installConfigs();
$this->installFacades();
$this->installScaffolding();
$this->installViews();
$this->installAssets();
$this->installCustom();
$this->installDatabase();
$this->finishInstall();
} | php | final public function install()
{
// Initiate Flysystem
$this->files = new Filesystem();
// Make sure we have the Console Output style
// before continuing with the install sequence
if (empty($this->getCommand())) {
throw new InstallPackageException('Could not run install sequence. Reason: Missing Console Output reference.');
}
// Run install methods
$this->prepareInstall();
$this->installConfigs();
$this->installFacades();
$this->installScaffolding();
$this->installViews();
$this->installAssets();
$this->installCustom();
$this->installDatabase();
$this->finishInstall();
} | [
"final",
"public",
"function",
"install",
"(",
")",
"{",
"// Initiate Flysystem",
"$",
"this",
"->",
"files",
"=",
"new",
"Filesystem",
"(",
")",
";",
"// Make sure we have the Console Output style",
"// before continuing with the install sequence",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"getCommand",
"(",
")",
")",
")",
"{",
"throw",
"new",
"InstallPackageException",
"(",
"'Could not run install sequence. Reason: Missing Console Output reference.'",
")",
";",
"}",
"// Run install methods",
"$",
"this",
"->",
"prepareInstall",
"(",
")",
";",
"$",
"this",
"->",
"installConfigs",
"(",
")",
";",
"$",
"this",
"->",
"installFacades",
"(",
")",
";",
"$",
"this",
"->",
"installScaffolding",
"(",
")",
";",
"$",
"this",
"->",
"installViews",
"(",
")",
";",
"$",
"this",
"->",
"installAssets",
"(",
")",
";",
"$",
"this",
"->",
"installCustom",
"(",
")",
";",
"$",
"this",
"->",
"installDatabase",
"(",
")",
";",
"$",
"this",
"->",
"finishInstall",
"(",
")",
";",
"}"
] | Install service provider.
@author Morten Rugaard <[email protected]>
@final
@throws \Nodes\Exceptions\InstallPackageException
@return void | [
"Install",
"service",
"provider",
"."
] | fc788bb3e9668872573838099f868ab162eb8a96 | https://github.com/nodes-php/core/blob/fc788bb3e9668872573838099f868ab162eb8a96/src/AbstractServiceProvider.php#L145-L166 |
9,186 | nodes-php/core | src/AbstractServiceProvider.php | AbstractServiceProvider.runDatabaseMigrationsAndSeeders | final protected function runDatabaseMigrationsAndSeeders()
{
// Ask to migrate the database,
// if we've copied any migration files to the application.
if (!empty($this->migrations) && $this->getCommand()->confirm('Do you wish to migrate your database?', true)) {
try {
$this->getCommand()->call('migrate');
} catch (Exception $e) {
$this->getCommand()->error(sprintf('Could not migrate your database. Reason: %s', $e->getMessage()));
}
}
// Before we ask user to seed the database
// we need to have look in the $seeders array
// to remove folders from the array
$seeders = [];
foreach ($this->seeders as $seeder) {
if (is_dir(base_path($seeder))) {
continue;
}
$seeders[] = $seeder;
}
// Ask to seed the database,
// if we've copied any migration files to the application.
if (!empty($seeders) && $this->getCommand()->confirm('Do you wish to seed your database?', true)) {
// Load seeders directory so new seeders are available
load_directory($this->getInstaller()->getBasePath('database/seeds/'));
// Run package seeders
foreach ($seeders as $seeder) {
try {
$seederFilename = substr($seeder, strrpos($seeder, '/') + 1);
$this->getCommand()->call('db:seed', [
'--class' => substr($seederFilename, 0, strrpos($seederFilename, '.')),
]);
} catch (Exception $e) {
$this->getCommand()->error(sprintf('Could not seed database. Reason: %s', $e->getMessage()));
}
}
}
} | php | final protected function runDatabaseMigrationsAndSeeders()
{
// Ask to migrate the database,
// if we've copied any migration files to the application.
if (!empty($this->migrations) && $this->getCommand()->confirm('Do you wish to migrate your database?', true)) {
try {
$this->getCommand()->call('migrate');
} catch (Exception $e) {
$this->getCommand()->error(sprintf('Could not migrate your database. Reason: %s', $e->getMessage()));
}
}
// Before we ask user to seed the database
// we need to have look in the $seeders array
// to remove folders from the array
$seeders = [];
foreach ($this->seeders as $seeder) {
if (is_dir(base_path($seeder))) {
continue;
}
$seeders[] = $seeder;
}
// Ask to seed the database,
// if we've copied any migration files to the application.
if (!empty($seeders) && $this->getCommand()->confirm('Do you wish to seed your database?', true)) {
// Load seeders directory so new seeders are available
load_directory($this->getInstaller()->getBasePath('database/seeds/'));
// Run package seeders
foreach ($seeders as $seeder) {
try {
$seederFilename = substr($seeder, strrpos($seeder, '/') + 1);
$this->getCommand()->call('db:seed', [
'--class' => substr($seederFilename, 0, strrpos($seederFilename, '.')),
]);
} catch (Exception $e) {
$this->getCommand()->error(sprintf('Could not seed database. Reason: %s', $e->getMessage()));
}
}
}
} | [
"final",
"protected",
"function",
"runDatabaseMigrationsAndSeeders",
"(",
")",
"{",
"// Ask to migrate the database,",
"// if we've copied any migration files to the application.",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"migrations",
")",
"&&",
"$",
"this",
"->",
"getCommand",
"(",
")",
"->",
"confirm",
"(",
"'Do you wish to migrate your database?'",
",",
"true",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"getCommand",
"(",
")",
"->",
"call",
"(",
"'migrate'",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"getCommand",
"(",
")",
"->",
"error",
"(",
"sprintf",
"(",
"'Could not migrate your database. Reason: %s'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}",
"// Before we ask user to seed the database",
"// we need to have look in the $seeders array",
"// to remove folders from the array",
"$",
"seeders",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"seeders",
"as",
"$",
"seeder",
")",
"{",
"if",
"(",
"is_dir",
"(",
"base_path",
"(",
"$",
"seeder",
")",
")",
")",
"{",
"continue",
";",
"}",
"$",
"seeders",
"[",
"]",
"=",
"$",
"seeder",
";",
"}",
"// Ask to seed the database,",
"// if we've copied any migration files to the application.",
"if",
"(",
"!",
"empty",
"(",
"$",
"seeders",
")",
"&&",
"$",
"this",
"->",
"getCommand",
"(",
")",
"->",
"confirm",
"(",
"'Do you wish to seed your database?'",
",",
"true",
")",
")",
"{",
"// Load seeders directory so new seeders are available",
"load_directory",
"(",
"$",
"this",
"->",
"getInstaller",
"(",
")",
"->",
"getBasePath",
"(",
"'database/seeds/'",
")",
")",
";",
"// Run package seeders",
"foreach",
"(",
"$",
"seeders",
"as",
"$",
"seeder",
")",
"{",
"try",
"{",
"$",
"seederFilename",
"=",
"substr",
"(",
"$",
"seeder",
",",
"strrpos",
"(",
"$",
"seeder",
",",
"'/'",
")",
"+",
"1",
")",
";",
"$",
"this",
"->",
"getCommand",
"(",
")",
"->",
"call",
"(",
"'db:seed'",
",",
"[",
"'--class'",
"=>",
"substr",
"(",
"$",
"seederFilename",
",",
"0",
",",
"strrpos",
"(",
"$",
"seederFilename",
",",
"'.'",
")",
")",
",",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"getCommand",
"(",
")",
"->",
"error",
"(",
"sprintf",
"(",
"'Could not seed database. Reason: %s'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}",
"}",
"}"
] | Run database migrations and seeders.
@author Morten Rugaard <[email protected]>
@return void | [
"Run",
"database",
"migrations",
"and",
"seeders",
"."
] | fc788bb3e9668872573838099f868ab162eb8a96 | https://github.com/nodes-php/core/blob/fc788bb3e9668872573838099f868ab162eb8a96/src/AbstractServiceProvider.php#L339-L380 |
9,187 | nodes-php/core | src/AbstractServiceProvider.php | AbstractServiceProvider.publishFile | final protected function publishFile($from, $to)
{
// If destination directory doesn't exist,
// we'll create before copying the config files
$directoryDestination = dirname($to);
if (!$this->files->isDirectory($directoryDestination)) {
$this->files->makeDirectory($directoryDestination, 0755, true);
}
// Copy file to application
$this->files->copy($from, $to);
// Output status message
$this->getCommand()->line(
sprintf('<info>Copied %s</info> <comment>[%s]</comment> <info>To</info> <comment>[%s]</comment>',
'File', str_replace(base_path(), '', realpath($from)), str_replace(base_path(), '', realpath($to)))
);
} | php | final protected function publishFile($from, $to)
{
// If destination directory doesn't exist,
// we'll create before copying the config files
$directoryDestination = dirname($to);
if (!$this->files->isDirectory($directoryDestination)) {
$this->files->makeDirectory($directoryDestination, 0755, true);
}
// Copy file to application
$this->files->copy($from, $to);
// Output status message
$this->getCommand()->line(
sprintf('<info>Copied %s</info> <comment>[%s]</comment> <info>To</info> <comment>[%s]</comment>',
'File', str_replace(base_path(), '', realpath($from)), str_replace(base_path(), '', realpath($to)))
);
} | [
"final",
"protected",
"function",
"publishFile",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"// If destination directory doesn't exist,",
"// we'll create before copying the config files",
"$",
"directoryDestination",
"=",
"dirname",
"(",
"$",
"to",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"isDirectory",
"(",
"$",
"directoryDestination",
")",
")",
"{",
"$",
"this",
"->",
"files",
"->",
"makeDirectory",
"(",
"$",
"directoryDestination",
",",
"0755",
",",
"true",
")",
";",
"}",
"// Copy file to application",
"$",
"this",
"->",
"files",
"->",
"copy",
"(",
"$",
"from",
",",
"$",
"to",
")",
";",
"// Output status message",
"$",
"this",
"->",
"getCommand",
"(",
")",
"->",
"line",
"(",
"sprintf",
"(",
"'<info>Copied %s</info> <comment>[%s]</comment> <info>To</info> <comment>[%s]</comment>'",
",",
"'File'",
",",
"str_replace",
"(",
"base_path",
"(",
")",
",",
"''",
",",
"realpath",
"(",
"$",
"from",
")",
")",
",",
"str_replace",
"(",
"base_path",
"(",
")",
",",
"''",
",",
"realpath",
"(",
"$",
"to",
")",
")",
")",
")",
";",
"}"
] | Publish file to application.
@author Morten Rugaard <[email protected]>
@param string $from
@param string $to
@return void | [
"Publish",
"file",
"to",
"application",
"."
] | fc788bb3e9668872573838099f868ab162eb8a96 | https://github.com/nodes-php/core/blob/fc788bb3e9668872573838099f868ab162eb8a96/src/AbstractServiceProvider.php#L419-L436 |
9,188 | nodes-php/core | src/AbstractServiceProvider.php | AbstractServiceProvider.publishDirectory | final protected function publishDirectory($from, $to)
{
// Load mount manager
$manager = new MountManager([
'from' => new Flysystem(new LocalAdapter($from)),
'to' => new Flysystem(new LocalAdapter($to)),
]);
// Copy directory to application
foreach ($manager->listContents('from://', true) as $file) {
if ($file['type'] !== 'file') {
continue;
}
$manager->put(sprintf('to://%s', $file['path']), $manager->read(sprintf('from://%s', $file['path'])));
}
// Output status message
$this->getCommand()->line(
sprintf('<info>Copied %s</info> <comment>[%s]</comment> <info>To</info> <comment>[%s]</comment>',
'Directory', str_replace(base_path(), '', realpath($from)), str_replace(base_path(), '', realpath($to)))
);
} | php | final protected function publishDirectory($from, $to)
{
// Load mount manager
$manager = new MountManager([
'from' => new Flysystem(new LocalAdapter($from)),
'to' => new Flysystem(new LocalAdapter($to)),
]);
// Copy directory to application
foreach ($manager->listContents('from://', true) as $file) {
if ($file['type'] !== 'file') {
continue;
}
$manager->put(sprintf('to://%s', $file['path']), $manager->read(sprintf('from://%s', $file['path'])));
}
// Output status message
$this->getCommand()->line(
sprintf('<info>Copied %s</info> <comment>[%s]</comment> <info>To</info> <comment>[%s]</comment>',
'Directory', str_replace(base_path(), '', realpath($from)), str_replace(base_path(), '', realpath($to)))
);
} | [
"final",
"protected",
"function",
"publishDirectory",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"// Load mount manager",
"$",
"manager",
"=",
"new",
"MountManager",
"(",
"[",
"'from'",
"=>",
"new",
"Flysystem",
"(",
"new",
"LocalAdapter",
"(",
"$",
"from",
")",
")",
",",
"'to'",
"=>",
"new",
"Flysystem",
"(",
"new",
"LocalAdapter",
"(",
"$",
"to",
")",
")",
",",
"]",
")",
";",
"// Copy directory to application",
"foreach",
"(",
"$",
"manager",
"->",
"listContents",
"(",
"'from://'",
",",
"true",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"[",
"'type'",
"]",
"!==",
"'file'",
")",
"{",
"continue",
";",
"}",
"$",
"manager",
"->",
"put",
"(",
"sprintf",
"(",
"'to://%s'",
",",
"$",
"file",
"[",
"'path'",
"]",
")",
",",
"$",
"manager",
"->",
"read",
"(",
"sprintf",
"(",
"'from://%s'",
",",
"$",
"file",
"[",
"'path'",
"]",
")",
")",
")",
";",
"}",
"// Output status message",
"$",
"this",
"->",
"getCommand",
"(",
")",
"->",
"line",
"(",
"sprintf",
"(",
"'<info>Copied %s</info> <comment>[%s]</comment> <info>To</info> <comment>[%s]</comment>'",
",",
"'Directory'",
",",
"str_replace",
"(",
"base_path",
"(",
")",
",",
"''",
",",
"realpath",
"(",
"$",
"from",
")",
")",
",",
"str_replace",
"(",
"base_path",
"(",
")",
",",
"''",
",",
"realpath",
"(",
"$",
"to",
")",
")",
")",
")",
";",
"}"
] | Publish directory to application.
@author Morten Rugaard <[email protected]>
@param string $from
@param string $to
@return void | [
"Publish",
"directory",
"to",
"application",
"."
] | fc788bb3e9668872573838099f868ab162eb8a96 | https://github.com/nodes-php/core/blob/fc788bb3e9668872573838099f868ab162eb8a96/src/AbstractServiceProvider.php#L448-L469 |
9,189 | vinala/kernel | src/MVC/Relations/BelongsTo.php | BelongsTo.ini | public function ini($related, $model, $local = null, $remote = null)
{
$this->setCurrent($model);
$this->checkModels($related);
//
if ($this->isOneToOne($related, $model, $local, $remote)) {
return $this->prepare($this->OneToOne($related, $model, $local, $remote));
} elseif ($this->isOneToMany($related, $model, $local, $remote)) {
return $this->prepare($this->OneToMany($related, $model, $local, $remote));
}
} | php | public function ini($related, $model, $local = null, $remote = null)
{
$this->setCurrent($model);
$this->checkModels($related);
//
if ($this->isOneToOne($related, $model, $local, $remote)) {
return $this->prepare($this->OneToOne($related, $model, $local, $remote));
} elseif ($this->isOneToMany($related, $model, $local, $remote)) {
return $this->prepare($this->OneToMany($related, $model, $local, $remote));
}
} | [
"public",
"function",
"ini",
"(",
"$",
"related",
",",
"$",
"model",
",",
"$",
"local",
"=",
"null",
",",
"$",
"remote",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"setCurrent",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"checkModels",
"(",
"$",
"related",
")",
";",
"//",
"if",
"(",
"$",
"this",
"->",
"isOneToOne",
"(",
"$",
"related",
",",
"$",
"model",
",",
"$",
"local",
",",
"$",
"remote",
")",
")",
"{",
"return",
"$",
"this",
"->",
"prepare",
"(",
"$",
"this",
"->",
"OneToOne",
"(",
"$",
"related",
",",
"$",
"model",
",",
"$",
"local",
",",
"$",
"remote",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isOneToMany",
"(",
"$",
"related",
",",
"$",
"model",
",",
"$",
"local",
",",
"$",
"remote",
")",
")",
"{",
"return",
"$",
"this",
"->",
"prepare",
"(",
"$",
"this",
"->",
"OneToMany",
"(",
"$",
"related",
",",
"$",
"model",
",",
"$",
"local",
",",
"$",
"remote",
")",
")",
";",
"}",
"}"
] | The belongs to relation.
@param $model : the model wanted to be related to the
current model
@param $local : if not null would be the local column
of the relation
@param $remote : if not null would be the $remote column
of the relation | [
"The",
"belongs",
"to",
"relation",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/MVC/Relations/BelongsTo.php#L42-L52 |
9,190 | vinala/kernel | src/MVC/Relations/BelongsTo.php | BelongsTo.setCurrent | protected function setCurrent($model)
{
$this->currentModel = get_class($model);
$this->currentTable = $this->getTable($model);
} | php | protected function setCurrent($model)
{
$this->currentModel = get_class($model);
$this->currentTable = $this->getTable($model);
} | [
"protected",
"function",
"setCurrent",
"(",
"$",
"model",
")",
"{",
"$",
"this",
"->",
"currentModel",
"=",
"get_class",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"currentTable",
"=",
"$",
"this",
"->",
"getTable",
"(",
"$",
"model",
")",
";",
"}"
] | set current model name and data table name.
@param $model object | [
"set",
"current",
"model",
"name",
"and",
"data",
"table",
"name",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/MVC/Relations/BelongsTo.php#L111-L115 |
9,191 | vinala/kernel | src/MVC/Relations/BelongsTo.php | BelongsTo.oneRelationValue | protected function oneRelationValue($related, $model, $column = null)
{
$table = $this->checkModelType($model);
//
return $model->{!is_null($column) ? $column : $this->idKey($table)};
} | php | protected function oneRelationValue($related, $model, $column = null)
{
$table = $this->checkModelType($model);
//
return $model->{!is_null($column) ? $column : $this->idKey($table)};
} | [
"protected",
"function",
"oneRelationValue",
"(",
"$",
"related",
",",
"$",
"model",
",",
"$",
"column",
"=",
"null",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"checkModelType",
"(",
"$",
"model",
")",
";",
"//",
"return",
"$",
"model",
"->",
"{",
"!",
"is_null",
"(",
"$",
"column",
")",
"?",
"$",
"column",
":",
"$",
"this",
"->",
"idKey",
"(",
"$",
"table",
")",
"}",
";",
"}"
] | get the value of column of the relation.
@param $column : name of the column
@param $model : name of the model | [
"get",
"the",
"value",
"of",
"column",
"of",
"the",
"relation",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/MVC/Relations/BelongsTo.php#L150-L155 |
9,192 | vinala/kernel | src/MVC/Relations/BelongsTo.php | BelongsTo.checkModelType | protected function checkModelType($model)
{
if (is_string($model)) {
return $this->getTable($model);
} elseif (is_object($model)) {
return $this->getTable(get_class($model));
}
} | php | protected function checkModelType($model)
{
if (is_string($model)) {
return $this->getTable($model);
} elseif (is_object($model)) {
return $this->getTable(get_class($model));
}
} | [
"protected",
"function",
"checkModelType",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"model",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getTable",
"(",
"$",
"model",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"model",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getTable",
"(",
"get_class",
"(",
"$",
"model",
")",
")",
";",
"}",
"}"
] | get database table.
@param $model : mixed | [
"get",
"database",
"table",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/MVC/Relations/BelongsTo.php#L243-L250 |
9,193 | vinala/kernel | src/MVC/Relations/BelongsTo.php | BelongsTo.getType | protected function getType($model, $related, $local, $remote)
{
$modelObject = new $model();
$remoteObject = new $related();
//
$tablemodel = $this->getTable($modelObject);
$tableremote = $this->getTable($remoteObject);
//
if (is_null($local) && is_null($remote)) {
$model = $tablemodel.'_id';
$remote = $tableremote.'_id';
} else {
$model = $remote;
}
//
if (in_array(strtolower($model), $remoteObject->_columns)) {
$this->relation = OneToOneRelation;
}
if (in_array(strtolower($remote), $modelObject->_columns)) {
$this->relation = OneToManyRelation;
}
//
return $this->relation;
} | php | protected function getType($model, $related, $local, $remote)
{
$modelObject = new $model();
$remoteObject = new $related();
//
$tablemodel = $this->getTable($modelObject);
$tableremote = $this->getTable($remoteObject);
//
if (is_null($local) && is_null($remote)) {
$model = $tablemodel.'_id';
$remote = $tableremote.'_id';
} else {
$model = $remote;
}
//
if (in_array(strtolower($model), $remoteObject->_columns)) {
$this->relation = OneToOneRelation;
}
if (in_array(strtolower($remote), $modelObject->_columns)) {
$this->relation = OneToManyRelation;
}
//
return $this->relation;
} | [
"protected",
"function",
"getType",
"(",
"$",
"model",
",",
"$",
"related",
",",
"$",
"local",
",",
"$",
"remote",
")",
"{",
"$",
"modelObject",
"=",
"new",
"$",
"model",
"(",
")",
";",
"$",
"remoteObject",
"=",
"new",
"$",
"related",
"(",
")",
";",
"//",
"$",
"tablemodel",
"=",
"$",
"this",
"->",
"getTable",
"(",
"$",
"modelObject",
")",
";",
"$",
"tableremote",
"=",
"$",
"this",
"->",
"getTable",
"(",
"$",
"remoteObject",
")",
";",
"//",
"if",
"(",
"is_null",
"(",
"$",
"local",
")",
"&&",
"is_null",
"(",
"$",
"remote",
")",
")",
"{",
"$",
"model",
"=",
"$",
"tablemodel",
".",
"'_id'",
";",
"$",
"remote",
"=",
"$",
"tableremote",
".",
"'_id'",
";",
"}",
"else",
"{",
"$",
"model",
"=",
"$",
"remote",
";",
"}",
"//",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"model",
")",
",",
"$",
"remoteObject",
"->",
"_columns",
")",
")",
"{",
"$",
"this",
"->",
"relation",
"=",
"OneToOneRelation",
";",
"}",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"remote",
")",
",",
"$",
"modelObject",
"->",
"_columns",
")",
")",
"{",
"$",
"this",
"->",
"relation",
"=",
"OneToManyRelation",
";",
"}",
"//",
"return",
"$",
"this",
"->",
"relation",
";",
"}"
] | get the type of relation.
@param $model string | [
"get",
"the",
"type",
"of",
"relation",
"."
] | 346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a | https://github.com/vinala/kernel/blob/346c8a4dca48fd1ab88fdc9f7004ecb7bce6a67a/src/MVC/Relations/BelongsTo.php#L267-L290 |
9,194 | cyberspectrum/i18n | src/Configuration/DefinitionBuilder/CopyJobDefinitionBuilder.php | CopyJobDefinitionBuilder.getDictionaryOverrides | private function getDictionaryOverrides(array &$data): array
{
$overrides = [];
foreach (['source_language', 'target_language'] as $key) {
if (array_key_exists($key, $data)) {
$overrides[$key] = $data[$key];
unset($data[$key]);
}
}
return $overrides;
} | php | private function getDictionaryOverrides(array &$data): array
{
$overrides = [];
foreach (['source_language', 'target_language'] as $key) {
if (array_key_exists($key, $data)) {
$overrides[$key] = $data[$key];
unset($data[$key]);
}
}
return $overrides;
} | [
"private",
"function",
"getDictionaryOverrides",
"(",
"array",
"&",
"$",
"data",
")",
":",
"array",
"{",
"$",
"overrides",
"=",
"[",
"]",
";",
"foreach",
"(",
"[",
"'source_language'",
",",
"'target_language'",
"]",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"data",
")",
")",
"{",
"$",
"overrides",
"[",
"$",
"key",
"]",
"=",
"$",
"data",
"[",
"$",
"key",
"]",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"overrides",
";",
"}"
] | Obtain the overrides for a dictionary.
@param array $data The job configuration data.
@return array | [
"Obtain",
"the",
"overrides",
"for",
"a",
"dictionary",
"."
] | 138e81d7119db82c2420bd33967a566e02b1d2f5 | https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Configuration/DefinitionBuilder/CopyJobDefinitionBuilder.php#L67-L78 |
9,195 | cyberspectrum/i18n | src/Configuration/DefinitionBuilder/CopyJobDefinitionBuilder.php | CopyJobDefinitionBuilder.makeDictionary | private function makeDictionary(
Configuration $configuration,
$dictionary,
array $overrides,
string $path
): ExtendedDictionaryDefinition {
$name = $dictionary;
if (is_array($dictionary)) {
if (!isset($dictionary['name'])) {
throw new \InvalidArgumentException('Dictionary "' . $path . '" information is missing key "name".');
}
$name = $dictionary['name'];
$overrides = array_merge($overrides, $dictionary);
unset($overrides['name']);
}
return new ExtendedDictionaryDefinition($name, $configuration, $overrides);
} | php | private function makeDictionary(
Configuration $configuration,
$dictionary,
array $overrides,
string $path
): ExtendedDictionaryDefinition {
$name = $dictionary;
if (is_array($dictionary)) {
if (!isset($dictionary['name'])) {
throw new \InvalidArgumentException('Dictionary "' . $path . '" information is missing key "name".');
}
$name = $dictionary['name'];
$overrides = array_merge($overrides, $dictionary);
unset($overrides['name']);
}
return new ExtendedDictionaryDefinition($name, $configuration, $overrides);
} | [
"private",
"function",
"makeDictionary",
"(",
"Configuration",
"$",
"configuration",
",",
"$",
"dictionary",
",",
"array",
"$",
"overrides",
",",
"string",
"$",
"path",
")",
":",
"ExtendedDictionaryDefinition",
"{",
"$",
"name",
"=",
"$",
"dictionary",
";",
"if",
"(",
"is_array",
"(",
"$",
"dictionary",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"dictionary",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Dictionary \"'",
".",
"$",
"path",
".",
"'\" information is missing key \"name\".'",
")",
";",
"}",
"$",
"name",
"=",
"$",
"dictionary",
"[",
"'name'",
"]",
";",
"$",
"overrides",
"=",
"array_merge",
"(",
"$",
"overrides",
",",
"$",
"dictionary",
")",
";",
"unset",
"(",
"$",
"overrides",
"[",
"'name'",
"]",
")",
";",
"}",
"return",
"new",
"ExtendedDictionaryDefinition",
"(",
"$",
"name",
",",
"$",
"configuration",
",",
"$",
"overrides",
")",
";",
"}"
] | Make the passed value a valid dictionary.
@param Configuration $configuration The configuration.
@param string|array $dictionary The dictionary.
@param array $overrides The values to be overridden.
@param string $path The path for exceptions.
@return ExtendedDictionaryDefinition
@throws \InvalidArgumentException When the name key is missing. | [
"Make",
"the",
"passed",
"value",
"a",
"valid",
"dictionary",
"."
] | 138e81d7119db82c2420bd33967a566e02b1d2f5 | https://github.com/cyberspectrum/i18n/blob/138e81d7119db82c2420bd33967a566e02b1d2f5/src/Configuration/DefinitionBuilder/CopyJobDefinitionBuilder.php#L92-L109 |
9,196 | vspvt/kohana-helpers | classes/Kohana/Helpers/File.php | Kohana_Helpers_File.rmdir | static function rmdir($dir, $deleteRoot = TRUE, $stopOnError = TRUE, &$debug = NULL)
{
if (is_dir($dir)) {
if (NULL === $debug) $debug = [];
try {
foreach (glob($dir . '/*') as $file) {
if (is_dir($file)) {
self::rmdir($file, TRUE, $stopOnError, $debug);
} else {
$debug[] = printf("File: %s", Debug::path($file));
}
unlink($file);
}
if ($deleteRoot) {
$debug[] = printf("Dir: %s", Debug::path($dir));
rmdir($dir);
}
return TRUE;
} catch (Exception $e) {
if ($stopOnError) {
$debug[] = $e->getMessage();
return FALSE;
}
}
}
return FALSE;
} | php | static function rmdir($dir, $deleteRoot = TRUE, $stopOnError = TRUE, &$debug = NULL)
{
if (is_dir($dir)) {
if (NULL === $debug) $debug = [];
try {
foreach (glob($dir . '/*') as $file) {
if (is_dir($file)) {
self::rmdir($file, TRUE, $stopOnError, $debug);
} else {
$debug[] = printf("File: %s", Debug::path($file));
}
unlink($file);
}
if ($deleteRoot) {
$debug[] = printf("Dir: %s", Debug::path($dir));
rmdir($dir);
}
return TRUE;
} catch (Exception $e) {
if ($stopOnError) {
$debug[] = $e->getMessage();
return FALSE;
}
}
}
return FALSE;
} | [
"static",
"function",
"rmdir",
"(",
"$",
"dir",
",",
"$",
"deleteRoot",
"=",
"TRUE",
",",
"$",
"stopOnError",
"=",
"TRUE",
",",
"&",
"$",
"debug",
"=",
"NULL",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"NULL",
"===",
"$",
"debug",
")",
"$",
"debug",
"=",
"[",
"]",
";",
"try",
"{",
"foreach",
"(",
"glob",
"(",
"$",
"dir",
".",
"'/*'",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"file",
")",
")",
"{",
"self",
"::",
"rmdir",
"(",
"$",
"file",
",",
"TRUE",
",",
"$",
"stopOnError",
",",
"$",
"debug",
")",
";",
"}",
"else",
"{",
"$",
"debug",
"[",
"]",
"=",
"printf",
"(",
"\"File: %s\"",
",",
"Debug",
"::",
"path",
"(",
"$",
"file",
")",
")",
";",
"}",
"unlink",
"(",
"$",
"file",
")",
";",
"}",
"if",
"(",
"$",
"deleteRoot",
")",
"{",
"$",
"debug",
"[",
"]",
"=",
"printf",
"(",
"\"Dir: %s\"",
",",
"Debug",
"::",
"path",
"(",
"$",
"dir",
")",
")",
";",
"rmdir",
"(",
"$",
"dir",
")",
";",
"}",
"return",
"TRUE",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"stopOnError",
")",
"{",
"$",
"debug",
"[",
"]",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"return",
"FALSE",
";",
"}",
"}",
"}",
"return",
"FALSE",
";",
"}"
] | Recursive directory delete
@param $dir
@param bool $deleteRoot
@param bool $stopOnError
@param $debug
@return bool | [
"Recursive",
"directory",
"delete"
] | 891c8f4e4efa09c97230162a2842d8ebf3105932 | https://github.com/vspvt/kohana-helpers/blob/891c8f4e4efa09c97230162a2842d8ebf3105932/classes/Kohana/Helpers/File.php#L18-L46 |
9,197 | projek-xyz/ci-common | src/Utils/ErrorHandlerTrait.php | ErrorHandlerTrait.set_error | public function set_error($message, $halt = false)
{
if ($message instanceof Exception) {
$message = $message->getMessage();
}
$this->_errors[] = $message;
log_message('error', $message);
if ($halt) {
show_error($message);
}
} | php | public function set_error($message, $halt = false)
{
if ($message instanceof Exception) {
$message = $message->getMessage();
}
$this->_errors[] = $message;
log_message('error', $message);
if ($halt) {
show_error($message);
}
} | [
"public",
"function",
"set_error",
"(",
"$",
"message",
",",
"$",
"halt",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"message",
"instanceof",
"Exception",
")",
"{",
"$",
"message",
"=",
"$",
"message",
"->",
"getMessage",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"$",
"message",
";",
"log_message",
"(",
"'error'",
",",
"$",
"message",
")",
";",
"if",
"(",
"$",
"halt",
")",
"{",
"show_error",
"(",
"$",
"message",
")",
";",
"}",
"}"
] | Setup error message
@param string $message Error message | [
"Setup",
"error",
"message"
] | 2cd3f507f378e6a871fcaa87efa88c63ce1282c0 | https://github.com/projek-xyz/ci-common/blob/2cd3f507f378e6a871fcaa87efa88c63ce1282c0/src/Utils/ErrorHandlerTrait.php#L18-L30 |
9,198 | eghojansu/nutrition | src/Utils/GroupChecker.php | GroupChecker.getNext | public function getNext()
{
reset($this->groups);
while ($key = key($this->groups)) {
$nextGroup = next($this->groups);
if ($this->groups[$key] === $this->group && $nextGroup) {
return $nextGroup;
}
}
return $this->group;
} | php | public function getNext()
{
reset($this->groups);
while ($key = key($this->groups)) {
$nextGroup = next($this->groups);
if ($this->groups[$key] === $this->group && $nextGroup) {
return $nextGroup;
}
}
return $this->group;
} | [
"public",
"function",
"getNext",
"(",
")",
"{",
"reset",
"(",
"$",
"this",
"->",
"groups",
")",
";",
"while",
"(",
"$",
"key",
"=",
"key",
"(",
"$",
"this",
"->",
"groups",
")",
")",
"{",
"$",
"nextGroup",
"=",
"next",
"(",
"$",
"this",
"->",
"groups",
")",
";",
"if",
"(",
"$",
"this",
"->",
"groups",
"[",
"$",
"key",
"]",
"===",
"$",
"this",
"->",
"group",
"&&",
"$",
"nextGroup",
")",
"{",
"return",
"$",
"nextGroup",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"group",
";",
"}"
] | Get next group
@return string | [
"Get",
"next",
"group"
] | 3941c62aeb6dafda55349a38dd4107d521f8964a | https://github.com/eghojansu/nutrition/blob/3941c62aeb6dafda55349a38dd4107d521f8964a/src/Utils/GroupChecker.php#L87-L99 |
9,199 | eghojansu/nutrition | src/Utils/GroupChecker.php | GroupChecker.getPrev | public function getPrev()
{
end($this->groups);
while ($key = key($this->groups)) {
$prevGroup = prev($this->groups);
if ($this->groups[$key] === $this->group && $prevGroup) {
return $prevGroup;
}
}
return $this->group;
} | php | public function getPrev()
{
end($this->groups);
while ($key = key($this->groups)) {
$prevGroup = prev($this->groups);
if ($this->groups[$key] === $this->group && $prevGroup) {
return $prevGroup;
}
}
return $this->group;
} | [
"public",
"function",
"getPrev",
"(",
")",
"{",
"end",
"(",
"$",
"this",
"->",
"groups",
")",
";",
"while",
"(",
"$",
"key",
"=",
"key",
"(",
"$",
"this",
"->",
"groups",
")",
")",
"{",
"$",
"prevGroup",
"=",
"prev",
"(",
"$",
"this",
"->",
"groups",
")",
";",
"if",
"(",
"$",
"this",
"->",
"groups",
"[",
"$",
"key",
"]",
"===",
"$",
"this",
"->",
"group",
"&&",
"$",
"prevGroup",
")",
"{",
"return",
"$",
"prevGroup",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"group",
";",
"}"
] | Get prev group
@return string | [
"Get",
"prev",
"group"
] | 3941c62aeb6dafda55349a38dd4107d521f8964a | https://github.com/eghojansu/nutrition/blob/3941c62aeb6dafda55349a38dd4107d521f8964a/src/Utils/GroupChecker.php#L105-L117 |
Subsets and Splits