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
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
ARCANESOFT/Media | src/Entities/FileCollection.php | FileCollection.exclude | public function exclude(array $patterns)
{
return $this->reject(function ($file) use ($patterns) {
foreach ($patterns as $pattern) {
if (Str::is($pattern, $file['name'])) return true;
}
return false;
});
} | php | public function exclude(array $patterns)
{
return $this->reject(function ($file) use ($patterns) {
foreach ($patterns as $pattern) {
if (Str::is($pattern, $file['name'])) return true;
}
return false;
});
} | [
"public",
"function",
"exclude",
"(",
"array",
"$",
"patterns",
")",
"{",
"return",
"$",
"this",
"->",
"reject",
"(",
"function",
"(",
"$",
"file",
")",
"use",
"(",
"$",
"patterns",
")",
"{",
"foreach",
"(",
"$",
"patterns",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"Str",
"::",
"is",
"(",
"$",
"pattern",
",",
"$",
"file",
"[",
"'name'",
"]",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"}"
] | ExcludePattern files with the given patterns.
@param array $patterns
@return self | [
"ExcludePattern",
"files",
"with",
"the",
"given",
"patterns",
"."
] | e98aad52f94e6587fcbf79c56f7bf7072929bfc9 | https://github.com/ARCANESOFT/Media/blob/e98aad52f94e6587fcbf79c56f7bf7072929bfc9/src/Entities/FileCollection.php#L26-L35 | train |
danielgp/common-lib | source/CommonViews.php | CommonViews.setField | private function setField($tableSource, $dtl, $features, $fieldLabel)
{
if ($dtl['COLUMN_NAME'] == 'host') {
$inVl = gethostbyaddr($this->tCmnRequest->server->get('REMOTE_ADDR'));
return [
'label' => '<label for="' . $dtl['COLUMN_NAME'] . '">Numele calculatorului</label>',
'input' => '<input type="text" name="host" size="15" readonly value="' . $inVl . '" />',
];
}
$result = $this->setFieldInput($tableSource, $dtl, $features);
return ['label' => $this->setFieldLabel($dtl, $features, $fieldLabel), 'input' => $result];
} | php | private function setField($tableSource, $dtl, $features, $fieldLabel)
{
if ($dtl['COLUMN_NAME'] == 'host') {
$inVl = gethostbyaddr($this->tCmnRequest->server->get('REMOTE_ADDR'));
return [
'label' => '<label for="' . $dtl['COLUMN_NAME'] . '">Numele calculatorului</label>',
'input' => '<input type="text" name="host" size="15" readonly value="' . $inVl . '" />',
];
}
$result = $this->setFieldInput($tableSource, $dtl, $features);
return ['label' => $this->setFieldLabel($dtl, $features, $fieldLabel), 'input' => $result];
} | [
"private",
"function",
"setField",
"(",
"$",
"tableSource",
",",
"$",
"dtl",
",",
"$",
"features",
",",
"$",
"fieldLabel",
")",
"{",
"if",
"(",
"$",
"dtl",
"[",
"'COLUMN_NAME'",
"]",
"==",
"'host'",
")",
"{",
"$",
"inVl",
"=",
"gethostbyaddr",
"(",
"$",
"this",
"->",
"tCmnRequest",
"->",
"server",
"->",
"get",
"(",
"'REMOTE_ADDR'",
")",
")",
";",
"return",
"[",
"'label'",
"=>",
"'<label for=\"'",
".",
"$",
"dtl",
"[",
"'COLUMN_NAME'",
"]",
".",
"'\">Numele calculatorului</label>'",
",",
"'input'",
"=>",
"'<input type=\"text\" name=\"host\" size=\"15\" readonly value=\"'",
".",
"$",
"inVl",
".",
"'\" />'",
",",
"]",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"setFieldInput",
"(",
"$",
"tableSource",
",",
"$",
"dtl",
",",
"$",
"features",
")",
";",
"return",
"[",
"'label'",
"=>",
"$",
"this",
"->",
"setFieldLabel",
"(",
"$",
"dtl",
",",
"$",
"features",
",",
"$",
"fieldLabel",
")",
",",
"'input'",
"=>",
"$",
"result",
"]",
";",
"}"
] | Builds field output w. special column name
@param string $tableSource
@param array $dtl
@param array $features
@param string $fieldLabel
@return array | [
"Builds",
"field",
"output",
"w",
".",
"special",
"column",
"name"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonViews.php#L50-L61 | train |
danielgp/common-lib | source/CommonViews.php | CommonViews.setFieldInput | private function setFieldInput($tableSource, $dtl, $features)
{
if ($dtl['COLUMN_NAME'] == 'ChoiceId') {
return '<input type="text" name="ChoiceId" value="'
. $this->tCmnRequest->request->get($dtl['COLUMN_NAME']) . '" />';
}
return $this->setNeededFieldByType($tableSource, $dtl, $features);
} | php | private function setFieldInput($tableSource, $dtl, $features)
{
if ($dtl['COLUMN_NAME'] == 'ChoiceId') {
return '<input type="text" name="ChoiceId" value="'
. $this->tCmnRequest->request->get($dtl['COLUMN_NAME']) . '" />';
}
return $this->setNeededFieldByType($tableSource, $dtl, $features);
} | [
"private",
"function",
"setFieldInput",
"(",
"$",
"tableSource",
",",
"$",
"dtl",
",",
"$",
"features",
")",
"{",
"if",
"(",
"$",
"dtl",
"[",
"'COLUMN_NAME'",
"]",
"==",
"'ChoiceId'",
")",
"{",
"return",
"'<input type=\"text\" name=\"ChoiceId\" value=\"'",
".",
"$",
"this",
"->",
"tCmnRequest",
"->",
"request",
"->",
"get",
"(",
"$",
"dtl",
"[",
"'COLUMN_NAME'",
"]",
")",
".",
"'\" />'",
";",
"}",
"return",
"$",
"this",
"->",
"setNeededFieldByType",
"(",
"$",
"tableSource",
",",
"$",
"dtl",
",",
"$",
"features",
")",
";",
"}"
] | Builds field output w. another special column name
@param string $tableSource
@param array $dtl
@param array $features
@return string | [
"Builds",
"field",
"output",
"w",
".",
"another",
"special",
"column",
"name"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonViews.php#L71-L78 | train |
danielgp/common-lib | source/CommonViews.php | CommonViews.setFormGenericSingleRecord | protected function setFormGenericSingleRecord($tblSrc, $feat, $hdnInf = [])
{
echo $this->setStringIntoTag('', 'div', ['id' => 'loading']);
$this->setTableCache($tblSrc);
if (strpos($tblSrc, '.') !== false) {
$tblSrc = explode('.', str_replace('`', '', $tblSrc))[1];
}
$sReturn = [];
if (count($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc]) != 0) {
foreach ($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc] as $value) {
$sReturn[] = $this->setNeededField($tblSrc, $value, $feat);
}
}
$frmFtrs = ['id' => $feat['id'], 'action' => $feat['action'], 'method' => $feat['method']];
return $this->setStringIntoTag(implode('', $sReturn) . $this->setFormButtons($feat, $hdnInf), 'form', $frmFtrs)
. $this->setFormJavascriptFinal($feat['id']);
} | php | protected function setFormGenericSingleRecord($tblSrc, $feat, $hdnInf = [])
{
echo $this->setStringIntoTag('', 'div', ['id' => 'loading']);
$this->setTableCache($tblSrc);
if (strpos($tblSrc, '.') !== false) {
$tblSrc = explode('.', str_replace('`', '', $tblSrc))[1];
}
$sReturn = [];
if (count($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc]) != 0) {
foreach ($this->advCache['tableStructureCache'][$this->advCache['workingDatabase']][$tblSrc] as $value) {
$sReturn[] = $this->setNeededField($tblSrc, $value, $feat);
}
}
$frmFtrs = ['id' => $feat['id'], 'action' => $feat['action'], 'method' => $feat['method']];
return $this->setStringIntoTag(implode('', $sReturn) . $this->setFormButtons($feat, $hdnInf), 'form', $frmFtrs)
. $this->setFormJavascriptFinal($feat['id']);
} | [
"protected",
"function",
"setFormGenericSingleRecord",
"(",
"$",
"tblSrc",
",",
"$",
"feat",
",",
"$",
"hdnInf",
"=",
"[",
"]",
")",
"{",
"echo",
"$",
"this",
"->",
"setStringIntoTag",
"(",
"''",
",",
"'div'",
",",
"[",
"'id'",
"=>",
"'loading'",
"]",
")",
";",
"$",
"this",
"->",
"setTableCache",
"(",
"$",
"tblSrc",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"tblSrc",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"tblSrc",
"=",
"explode",
"(",
"'.'",
",",
"str_replace",
"(",
"'`'",
",",
"''",
",",
"$",
"tblSrc",
")",
")",
"[",
"1",
"]",
";",
"}",
"$",
"sReturn",
"=",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"advCache",
"[",
"'tableStructureCache'",
"]",
"[",
"$",
"this",
"->",
"advCache",
"[",
"'workingDatabase'",
"]",
"]",
"[",
"$",
"tblSrc",
"]",
")",
"!=",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"advCache",
"[",
"'tableStructureCache'",
"]",
"[",
"$",
"this",
"->",
"advCache",
"[",
"'workingDatabase'",
"]",
"]",
"[",
"$",
"tblSrc",
"]",
"as",
"$",
"value",
")",
"{",
"$",
"sReturn",
"[",
"]",
"=",
"$",
"this",
"->",
"setNeededField",
"(",
"$",
"tblSrc",
",",
"$",
"value",
",",
"$",
"feat",
")",
";",
"}",
"}",
"$",
"frmFtrs",
"=",
"[",
"'id'",
"=>",
"$",
"feat",
"[",
"'id'",
"]",
",",
"'action'",
"=>",
"$",
"feat",
"[",
"'action'",
"]",
",",
"'method'",
"=>",
"$",
"feat",
"[",
"'method'",
"]",
"]",
";",
"return",
"$",
"this",
"->",
"setStringIntoTag",
"(",
"implode",
"(",
"''",
",",
"$",
"sReturn",
")",
".",
"$",
"this",
"->",
"setFormButtons",
"(",
"$",
"feat",
",",
"$",
"hdnInf",
")",
",",
"'form'",
",",
"$",
"frmFtrs",
")",
".",
"$",
"this",
"->",
"setFormJavascriptFinal",
"(",
"$",
"feat",
"[",
"'id'",
"]",
")",
";",
"}"
] | Returns a generic form based on a given table
@param string $tblSrc
@param array $feat
@param array $hdnInf
@return string Form to add/modify detail for a single row within a table | [
"Returns",
"a",
"generic",
"form",
"based",
"on",
"a",
"given",
"table"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonViews.php#L89-L105 | train |
danielgp/common-lib | source/CommonViews.php | CommonViews.setNeededField | private function setNeededField($tableSource, $details, $features)
{
if (isset($features['hidden'])) {
if (in_array($details['COLUMN_NAME'], $features['hidden'])) {
return null;
}
}
$fieldLabel = $this->getFieldNameForDisplay($details);
if ($fieldLabel == 'hidden') {
return null;
}
return $this->setNeededFieldFinal($tableSource, $details, $features, $fieldLabel);
} | php | private function setNeededField($tableSource, $details, $features)
{
if (isset($features['hidden'])) {
if (in_array($details['COLUMN_NAME'], $features['hidden'])) {
return null;
}
}
$fieldLabel = $this->getFieldNameForDisplay($details);
if ($fieldLabel == 'hidden') {
return null;
}
return $this->setNeededFieldFinal($tableSource, $details, $features, $fieldLabel);
} | [
"private",
"function",
"setNeededField",
"(",
"$",
"tableSource",
",",
"$",
"details",
",",
"$",
"features",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"features",
"[",
"'hidden'",
"]",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"details",
"[",
"'COLUMN_NAME'",
"]",
",",
"$",
"features",
"[",
"'hidden'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"}",
"$",
"fieldLabel",
"=",
"$",
"this",
"->",
"getFieldNameForDisplay",
"(",
"$",
"details",
")",
";",
"if",
"(",
"$",
"fieldLabel",
"==",
"'hidden'",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"setNeededFieldFinal",
"(",
"$",
"tableSource",
",",
"$",
"details",
",",
"$",
"features",
",",
"$",
"fieldLabel",
")",
";",
"}"
] | Analyse the field and returns the proper line 2 use in forms
@param string $tableSource
@param array $details
@param array $features
@return string|array | [
"Analyse",
"the",
"field",
"and",
"returns",
"the",
"proper",
"line",
"2",
"use",
"in",
"forms"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonViews.php#L115-L127 | train |
danielgp/common-lib | source/CommonViews.php | CommonViews.setNeededFieldByType | private function setNeededFieldByType($tblName, $dtls, $features)
{
if (isset($features['special']) && isset($features['special'][$dtls['COLUMN_NAME']])) {
$sOpt = $this->setMySQLquery2Server($features['special'][$dtls['COLUMN_NAME']], 'array_key_value');
return $this->setArrayToSelect($sOpt, $this->getFieldValue($dtls), $dtls['COLUMN_NAME'], ['size' => 1]);
}
return $this->setNeededFieldKnown($tblName, $dtls, $features);
} | php | private function setNeededFieldByType($tblName, $dtls, $features)
{
if (isset($features['special']) && isset($features['special'][$dtls['COLUMN_NAME']])) {
$sOpt = $this->setMySQLquery2Server($features['special'][$dtls['COLUMN_NAME']], 'array_key_value');
return $this->setArrayToSelect($sOpt, $this->getFieldValue($dtls), $dtls['COLUMN_NAME'], ['size' => 1]);
}
return $this->setNeededFieldKnown($tblName, $dtls, $features);
} | [
"private",
"function",
"setNeededFieldByType",
"(",
"$",
"tblName",
",",
"$",
"dtls",
",",
"$",
"features",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"features",
"[",
"'special'",
"]",
")",
"&&",
"isset",
"(",
"$",
"features",
"[",
"'special'",
"]",
"[",
"$",
"dtls",
"[",
"'COLUMN_NAME'",
"]",
"]",
")",
")",
"{",
"$",
"sOpt",
"=",
"$",
"this",
"->",
"setMySQLquery2Server",
"(",
"$",
"features",
"[",
"'special'",
"]",
"[",
"$",
"dtls",
"[",
"'COLUMN_NAME'",
"]",
"]",
",",
"'array_key_value'",
")",
";",
"return",
"$",
"this",
"->",
"setArrayToSelect",
"(",
"$",
"sOpt",
",",
"$",
"this",
"->",
"getFieldValue",
"(",
"$",
"dtls",
")",
",",
"$",
"dtls",
"[",
"'COLUMN_NAME'",
"]",
",",
"[",
"'size'",
"=>",
"1",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setNeededFieldKnown",
"(",
"$",
"tblName",
",",
"$",
"dtls",
",",
"$",
"features",
")",
";",
"}"
] | Analyse the field type and returns the proper lines 2 use in forms
@param string $tblName
@param array $dtls
@param array $features
@return string|array | [
"Analyse",
"the",
"field",
"type",
"and",
"returns",
"the",
"proper",
"lines",
"2",
"use",
"in",
"forms"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonViews.php#L137-L144 | train |
danielgp/common-lib | source/CommonViews.php | CommonViews.setViewModernDelete | protected function setViewModernDelete($tbl, $idn)
{
$tMsg = $this->setViewDeleteFeedbacks();
if ($tbl == '') {
$sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Impossible']);
} else {
$this->initializeSprGlbAndSession();
$idFldVal = $this->tCmnSuperGlobals->query->get($idn);
$this->setMySQLquery2Server($this->sQueryToDeleteSingleIdentifier([$tbl, $idn, $idFldVal]));
$sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Failed'])
. '(' . $this->mySQLconnection->error . ')';
if ($this->mySQLconnection->affected_rows > 0) {
$sReturn = $this->setFeedbackModern('check', $tMsg['Confirmation'], $tMsg['Success']);
}
}
return $this->setViewDeletePackedFinal($sReturn);
} | php | protected function setViewModernDelete($tbl, $idn)
{
$tMsg = $this->setViewDeleteFeedbacks();
if ($tbl == '') {
$sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Impossible']);
} else {
$this->initializeSprGlbAndSession();
$idFldVal = $this->tCmnSuperGlobals->query->get($idn);
$this->setMySQLquery2Server($this->sQueryToDeleteSingleIdentifier([$tbl, $idn, $idFldVal]));
$sReturn = $this->setFeedbackModern('error', $tMsg['Confirmation'], $tMsg['Failed'])
. '(' . $this->mySQLconnection->error . ')';
if ($this->mySQLconnection->affected_rows > 0) {
$sReturn = $this->setFeedbackModern('check', $tMsg['Confirmation'], $tMsg['Success']);
}
}
return $this->setViewDeletePackedFinal($sReturn);
} | [
"protected",
"function",
"setViewModernDelete",
"(",
"$",
"tbl",
",",
"$",
"idn",
")",
"{",
"$",
"tMsg",
"=",
"$",
"this",
"->",
"setViewDeleteFeedbacks",
"(",
")",
";",
"if",
"(",
"$",
"tbl",
"==",
"''",
")",
"{",
"$",
"sReturn",
"=",
"$",
"this",
"->",
"setFeedbackModern",
"(",
"'error'",
",",
"$",
"tMsg",
"[",
"'Confirmation'",
"]",
",",
"$",
"tMsg",
"[",
"'Impossible'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"initializeSprGlbAndSession",
"(",
")",
";",
"$",
"idFldVal",
"=",
"$",
"this",
"->",
"tCmnSuperGlobals",
"->",
"query",
"->",
"get",
"(",
"$",
"idn",
")",
";",
"$",
"this",
"->",
"setMySQLquery2Server",
"(",
"$",
"this",
"->",
"sQueryToDeleteSingleIdentifier",
"(",
"[",
"$",
"tbl",
",",
"$",
"idn",
",",
"$",
"idFldVal",
"]",
")",
")",
";",
"$",
"sReturn",
"=",
"$",
"this",
"->",
"setFeedbackModern",
"(",
"'error'",
",",
"$",
"tMsg",
"[",
"'Confirmation'",
"]",
",",
"$",
"tMsg",
"[",
"'Failed'",
"]",
")",
".",
"'('",
".",
"$",
"this",
"->",
"mySQLconnection",
"->",
"error",
".",
"')'",
";",
"if",
"(",
"$",
"this",
"->",
"mySQLconnection",
"->",
"affected_rows",
">",
"0",
")",
"{",
"$",
"sReturn",
"=",
"$",
"this",
"->",
"setFeedbackModern",
"(",
"'check'",
",",
"$",
"tMsg",
"[",
"'Confirmation'",
"]",
",",
"$",
"tMsg",
"[",
"'Success'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"setViewDeletePackedFinal",
"(",
"$",
"sReturn",
")",
";",
"}"
] | Automatic handler for Record deletion
@param string $tbl
@param string $idn
@return string | [
"Automatic",
"handler",
"for",
"Record",
"deletion"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonViews.php#L189-L205 | train |
LpFactory/NestedSetRoutingBundle | Configuration/PageRouteConfigurationChain.php | PageRouteConfigurationChain.findConfiguration | protected function findConfiguration($value, \Closure $func)
{
/** @var AbstractPageRouteConfiguration $configuration */
foreach ($this->all() as $configuration) {
if ($func($configuration, $value)) {
return $configuration;
}
}
return null;
} | php | protected function findConfiguration($value, \Closure $func)
{
/** @var AbstractPageRouteConfiguration $configuration */
foreach ($this->all() as $configuration) {
if ($func($configuration, $value)) {
return $configuration;
}
}
return null;
} | [
"protected",
"function",
"findConfiguration",
"(",
"$",
"value",
",",
"\\",
"Closure",
"$",
"func",
")",
"{",
"/** @var AbstractPageRouteConfiguration $configuration */",
"foreach",
"(",
"$",
"this",
"->",
"all",
"(",
")",
"as",
"$",
"configuration",
")",
"{",
"if",
"(",
"$",
"func",
"(",
"$",
"configuration",
",",
"$",
"value",
")",
")",
"{",
"return",
"$",
"configuration",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Find a configuration matching custom criteria
@param string $value
@param callable $func
@return null|AbstractPageRouteConfiguration | [
"Find",
"a",
"configuration",
"matching",
"custom",
"criteria"
] | dc07227a6764e657b7b321827a18127ec18ba214 | https://github.com/LpFactory/NestedSetRoutingBundle/blob/dc07227a6764e657b7b321827a18127ec18ba214/Configuration/PageRouteConfigurationChain.php#L116-L126 | train |
bytic/debugbar | src/DebugBar.php | DebugBar.injectDebugBar | public function injectDebugBar(ResponseInterface $response)
{
$content = $response->getContent();
$renderer = $this->getJavascriptRenderer();
$renderedContent = $this->generateAssetsContent().$renderer->render();
$pos = strripos($content, '</body>');
if (false !== $pos) {
$content = substr($content, 0, $pos).$renderedContent.substr($content, $pos);
} else {
$content = '<body>'.$content.'</body>'.$renderedContent;
}
// Update the new content and reset the content length
$response->setContent($content);
$response->headers->remove('Content-Length');
} | php | public function injectDebugBar(ResponseInterface $response)
{
$content = $response->getContent();
$renderer = $this->getJavascriptRenderer();
$renderedContent = $this->generateAssetsContent().$renderer->render();
$pos = strripos($content, '</body>');
if (false !== $pos) {
$content = substr($content, 0, $pos).$renderedContent.substr($content, $pos);
} else {
$content = '<body>'.$content.'</body>'.$renderedContent;
}
// Update the new content and reset the content length
$response->setContent($content);
$response->headers->remove('Content-Length');
} | [
"public",
"function",
"injectDebugBar",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"content",
"=",
"$",
"response",
"->",
"getContent",
"(",
")",
";",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getJavascriptRenderer",
"(",
")",
";",
"$",
"renderedContent",
"=",
"$",
"this",
"->",
"generateAssetsContent",
"(",
")",
".",
"$",
"renderer",
"->",
"render",
"(",
")",
";",
"$",
"pos",
"=",
"strripos",
"(",
"$",
"content",
",",
"'</body>'",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"pos",
")",
"{",
"$",
"content",
"=",
"substr",
"(",
"$",
"content",
",",
"0",
",",
"$",
"pos",
")",
".",
"$",
"renderedContent",
".",
"substr",
"(",
"$",
"content",
",",
"$",
"pos",
")",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"'<body>'",
".",
"$",
"content",
".",
"'</body>'",
".",
"$",
"renderedContent",
";",
"}",
"// Update the new content and reset the content length",
"$",
"response",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"remove",
"(",
"'Content-Length'",
")",
";",
"}"
] | Injects the web debug toolbar
@param Response $response | [
"Injects",
"the",
"web",
"debug",
"toolbar"
] | 3199ade9a8fff866bffc39712bdf78d2dd214e4b | https://github.com/bytic/debugbar/blob/3199ade9a8fff866bffc39712bdf78d2dd214e4b/src/DebugBar.php#L116-L132 | train |
spoom-php/core | src/extension/Application.php | Application.environment | public static function environment( int $severity, array $configuration = [] ) {
// setup error reporting in PHP
$reporting = ~E_ALL;
foreach( self::SEVERITY as $key => $value ) {
if( $key <= $severity ) $reporting |= $value;
}
error_reporting( $reporting );
// setup locale
if( isset( $configuration[ 'locale' ] ) ) {
setlocale( LC_ALL, $configuration[ 'locale' ] );
}
// setup encoding
if( isset( $configuration[ 'encoding' ] ) ) {
mb_internal_encoding( $configuration[ 'encoding' ] );
mb_http_output( $configuration[ 'encoding' ] );
}
// setup timezones
if( isset( $configuration[ 'timezone' ] ) ) {
date_default_timezone_set( $configuration[ 'timezone' ] );
}
} | php | public static function environment( int $severity, array $configuration = [] ) {
// setup error reporting in PHP
$reporting = ~E_ALL;
foreach( self::SEVERITY as $key => $value ) {
if( $key <= $severity ) $reporting |= $value;
}
error_reporting( $reporting );
// setup locale
if( isset( $configuration[ 'locale' ] ) ) {
setlocale( LC_ALL, $configuration[ 'locale' ] );
}
// setup encoding
if( isset( $configuration[ 'encoding' ] ) ) {
mb_internal_encoding( $configuration[ 'encoding' ] );
mb_http_output( $configuration[ 'encoding' ] );
}
// setup timezones
if( isset( $configuration[ 'timezone' ] ) ) {
date_default_timezone_set( $configuration[ 'timezone' ] );
}
} | [
"public",
"static",
"function",
"environment",
"(",
"int",
"$",
"severity",
",",
"array",
"$",
"configuration",
"=",
"[",
"]",
")",
"{",
"// setup error reporting in PHP",
"$",
"reporting",
"=",
"~",
"E_ALL",
";",
"foreach",
"(",
"self",
"::",
"SEVERITY",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"<=",
"$",
"severity",
")",
"$",
"reporting",
"|=",
"$",
"value",
";",
"}",
"error_reporting",
"(",
"$",
"reporting",
")",
";",
"// setup locale",
"if",
"(",
"isset",
"(",
"$",
"configuration",
"[",
"'locale'",
"]",
")",
")",
"{",
"setlocale",
"(",
"LC_ALL",
",",
"$",
"configuration",
"[",
"'locale'",
"]",
")",
";",
"}",
"// setup encoding",
"if",
"(",
"isset",
"(",
"$",
"configuration",
"[",
"'encoding'",
"]",
")",
")",
"{",
"mb_internal_encoding",
"(",
"$",
"configuration",
"[",
"'encoding'",
"]",
")",
";",
"mb_http_output",
"(",
"$",
"configuration",
"[",
"'encoding'",
"]",
")",
";",
"}",
"// setup timezones",
"if",
"(",
"isset",
"(",
"$",
"configuration",
"[",
"'timezone'",
"]",
")",
")",
"{",
"date_default_timezone_set",
"(",
"$",
"configuration",
"[",
"'timezone'",
"]",
")",
";",
"}",
"}"
] | Global setup of the PHP environment
This SHOULD be done before the application...or anything else in the PHP code
@param int $severity Maximum severity level tht should be reported
@param array $configuration | [
"Global",
"setup",
"of",
"the",
"PHP",
"environment"
] | ea7184213352fa2fad7636927a019e5798734e04 | https://github.com/spoom-php/core/blob/ea7184213352fa2fad7636927a019e5798734e04/src/extension/Application.php#L260-L284 | train |
jenskooij/cloudcontrol | src/storage/storage/ImageSetStorage.php | ImageSetStorage.getImageSetBySlug | public function getImageSetBySlug($slug)
{
$imageSet = $this->getImageSet();
foreach ($imageSet as $set) {
if ($set->slug == $slug) {
return $set;
}
}
return null;
} | php | public function getImageSetBySlug($slug)
{
$imageSet = $this->getImageSet();
foreach ($imageSet as $set) {
if ($set->slug == $slug) {
return $set;
}
}
return null;
} | [
"public",
"function",
"getImageSetBySlug",
"(",
"$",
"slug",
")",
"{",
"$",
"imageSet",
"=",
"$",
"this",
"->",
"getImageSet",
"(",
")",
";",
"foreach",
"(",
"$",
"imageSet",
"as",
"$",
"set",
")",
"{",
"if",
"(",
"$",
"set",
"->",
"slug",
"==",
"$",
"slug",
")",
"{",
"return",
"$",
"set",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Get Image by slug
@param $slug
@return \stdClass | [
"Get",
"Image",
"by",
"slug"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/ImageSetStorage.php#L29-L39 | train |
jenskooij/cloudcontrol | src/storage/storage/ImageSetStorage.php | ImageSetStorage.addImageSet | public function addImageSet($postValues)
{
$imageSetObject = ImageSetFactory::createImageSetFromPostValues($postValues);
$imageSet = $this->repository->imageSet;
$imageSet[] = $imageSetObject;
$this->repository->imageSet = $imageSet;
$this->save();
} | php | public function addImageSet($postValues)
{
$imageSetObject = ImageSetFactory::createImageSetFromPostValues($postValues);
$imageSet = $this->repository->imageSet;
$imageSet[] = $imageSetObject;
$this->repository->imageSet = $imageSet;
$this->save();
} | [
"public",
"function",
"addImageSet",
"(",
"$",
"postValues",
")",
"{",
"$",
"imageSetObject",
"=",
"ImageSetFactory",
"::",
"createImageSetFromPostValues",
"(",
"$",
"postValues",
")",
";",
"$",
"imageSet",
"=",
"$",
"this",
"->",
"repository",
"->",
"imageSet",
";",
"$",
"imageSet",
"[",
"]",
"=",
"$",
"imageSetObject",
";",
"$",
"this",
"->",
"repository",
"->",
"imageSet",
"=",
"$",
"imageSet",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Add image set
@param $postValues
@throws \Exception | [
"Add",
"image",
"set"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/ImageSetStorage.php#L48-L57 | train |
jenskooij/cloudcontrol | src/storage/storage/ImageSetStorage.php | ImageSetStorage.saveImageSet | public function saveImageSet($slug, $postValues)
{
$imageSetObject = ImageSetFactory::createImageSetFromPostValues($postValues);
$imageSet = $this->repository->imageSet;
foreach ($imageSet as $key => $set) {
if ($set->slug == $slug) {
$imageSet[$key] = $imageSetObject;
}
}
$this->repository->imageSet = $imageSet;
$this->save();
} | php | public function saveImageSet($slug, $postValues)
{
$imageSetObject = ImageSetFactory::createImageSetFromPostValues($postValues);
$imageSet = $this->repository->imageSet;
foreach ($imageSet as $key => $set) {
if ($set->slug == $slug) {
$imageSet[$key] = $imageSetObject;
}
}
$this->repository->imageSet = $imageSet;
$this->save();
} | [
"public",
"function",
"saveImageSet",
"(",
"$",
"slug",
",",
"$",
"postValues",
")",
"{",
"$",
"imageSetObject",
"=",
"ImageSetFactory",
"::",
"createImageSetFromPostValues",
"(",
"$",
"postValues",
")",
";",
"$",
"imageSet",
"=",
"$",
"this",
"->",
"repository",
"->",
"imageSet",
";",
"foreach",
"(",
"$",
"imageSet",
"as",
"$",
"key",
"=>",
"$",
"set",
")",
"{",
"if",
"(",
"$",
"set",
"->",
"slug",
"==",
"$",
"slug",
")",
"{",
"$",
"imageSet",
"[",
"$",
"key",
"]",
"=",
"$",
"imageSetObject",
";",
"}",
"}",
"$",
"this",
"->",
"repository",
"->",
"imageSet",
"=",
"$",
"imageSet",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Save Image Set by it's slug
@param $slug
@param $postValues
@throws \Exception | [
"Save",
"Image",
"Set",
"by",
"it",
"s",
"slug"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/ImageSetStorage.php#L67-L79 | train |
jenskooij/cloudcontrol | src/storage/storage/ImageSetStorage.php | ImageSetStorage.deleteImageSetBySlug | public function deleteImageSetBySlug($slug)
{
$imageSet = $this->getImageSet();
foreach ($imageSet as $key => $set) {
if ($set->slug == $slug) {
unset($imageSet[$key]);
}
}
$imageSet = array_values($imageSet);
$this->repository->imageSet = $imageSet;
$this->save();
} | php | public function deleteImageSetBySlug($slug)
{
$imageSet = $this->getImageSet();
foreach ($imageSet as $key => $set) {
if ($set->slug == $slug) {
unset($imageSet[$key]);
}
}
$imageSet = array_values($imageSet);
$this->repository->imageSet = $imageSet;
$this->save();
} | [
"public",
"function",
"deleteImageSetBySlug",
"(",
"$",
"slug",
")",
"{",
"$",
"imageSet",
"=",
"$",
"this",
"->",
"getImageSet",
"(",
")",
";",
"foreach",
"(",
"$",
"imageSet",
"as",
"$",
"key",
"=>",
"$",
"set",
")",
"{",
"if",
"(",
"$",
"set",
"->",
"slug",
"==",
"$",
"slug",
")",
"{",
"unset",
"(",
"$",
"imageSet",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"imageSet",
"=",
"array_values",
"(",
"$",
"imageSet",
")",
";",
"$",
"this",
"->",
"repository",
"->",
"imageSet",
"=",
"$",
"imageSet",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}"
] | Delete Image Set by its slug
@param $slug
@throws \Exception | [
"Delete",
"Image",
"Set",
"by",
"its",
"slug"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/ImageSetStorage.php#L88-L100 | train |
jenskooij/cloudcontrol | src/storage/storage/ImageSetStorage.php | ImageSetStorage.getSmallestImageSet | public function getSmallestImageSet()
{
$imageSet = $this->getImageSet();
$returnSize = PHP_INT_MAX;
$returnSet = null;
foreach ($imageSet as $set) {
$size = $set->width * $set->height;
if ($size < $returnSize) {
$returnSize = $size;
$returnSet = $set;
}
}
if ($returnSet === null) {
$returnSet = new \stdClass();
$returnSet->slug = 'original';
}
return $returnSet;
} | php | public function getSmallestImageSet()
{
$imageSet = $this->getImageSet();
$returnSize = PHP_INT_MAX;
$returnSet = null;
foreach ($imageSet as $set) {
$size = $set->width * $set->height;
if ($size < $returnSize) {
$returnSize = $size;
$returnSet = $set;
}
}
if ($returnSet === null) {
$returnSet = new \stdClass();
$returnSet->slug = 'original';
}
return $returnSet;
} | [
"public",
"function",
"getSmallestImageSet",
"(",
")",
"{",
"$",
"imageSet",
"=",
"$",
"this",
"->",
"getImageSet",
"(",
")",
";",
"$",
"returnSize",
"=",
"PHP_INT_MAX",
";",
"$",
"returnSet",
"=",
"null",
";",
"foreach",
"(",
"$",
"imageSet",
"as",
"$",
"set",
")",
"{",
"$",
"size",
"=",
"$",
"set",
"->",
"width",
"*",
"$",
"set",
"->",
"height",
";",
"if",
"(",
"$",
"size",
"<",
"$",
"returnSize",
")",
"{",
"$",
"returnSize",
"=",
"$",
"size",
";",
"$",
"returnSet",
"=",
"$",
"set",
";",
"}",
"}",
"if",
"(",
"$",
"returnSet",
"===",
"null",
")",
"{",
"$",
"returnSet",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"returnSet",
"->",
"slug",
"=",
"'original'",
";",
"}",
"return",
"$",
"returnSet",
";",
"}"
] | Get the image set with the smallest size
@return \stdClass | [
"Get",
"the",
"image",
"set",
"with",
"the",
"smallest",
"size"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/storage/ImageSetStorage.php#L107-L128 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Message.php | Message.setError | public static function setError($prefix = null, $field, $error) {
if(null !== $prefix && false === is_string($prefix)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($prefix)), E_USER_ERROR);
}
if(false === is_string($field)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($field)), E_USER_ERROR);
}
if(false === is_string($error)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($error)), E_USER_ERROR);
}
if(false === isset(static :: $errors['short'][$field])) {
static :: $errors['short'][$field] = $error;
}
if(false === isset(static :: $errors['full'][$field])) {
if(null !== $prefix) {
static :: $errors['full'][$prefix . '[' . $field . ']'] = $error;
}
else {
static :: $errors['full'][$field] = $error;
}
}
return static :: Instance();
} | php | public static function setError($prefix = null, $field, $error) {
if(null !== $prefix && false === is_string($prefix)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($prefix)), E_USER_ERROR);
}
if(false === is_string($field)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($field)), E_USER_ERROR);
}
if(false === is_string($error)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($error)), E_USER_ERROR);
}
if(false === isset(static :: $errors['short'][$field])) {
static :: $errors['short'][$field] = $error;
}
if(false === isset(static :: $errors['full'][$field])) {
if(null !== $prefix) {
static :: $errors['full'][$prefix . '[' . $field . ']'] = $error;
}
else {
static :: $errors['full'][$field] = $error;
}
}
return static :: Instance();
} | [
"public",
"static",
"function",
"setError",
"(",
"$",
"prefix",
"=",
"null",
",",
"$",
"field",
",",
"$",
"error",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"prefix",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"prefix",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"prefix",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"field",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"field",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"error",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 3 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"error",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"static",
"::",
"$",
"errors",
"[",
"'short'",
"]",
"[",
"$",
"field",
"]",
")",
")",
"{",
"static",
"::",
"$",
"errors",
"[",
"'short'",
"]",
"[",
"$",
"field",
"]",
"=",
"$",
"error",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"static",
"::",
"$",
"errors",
"[",
"'full'",
"]",
"[",
"$",
"field",
"]",
")",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"prefix",
")",
"{",
"static",
"::",
"$",
"errors",
"[",
"'full'",
"]",
"[",
"$",
"prefix",
".",
"'['",
".",
"$",
"field",
".",
"']'",
"]",
"=",
"$",
"error",
";",
"}",
"else",
"{",
"static",
"::",
"$",
"errors",
"[",
"'full'",
"]",
"[",
"$",
"field",
"]",
"=",
"$",
"error",
";",
"}",
"}",
"return",
"static",
"::",
"Instance",
"(",
")",
";",
"}"
] | Sets an error for the current field
@param string $prefix
@param string $field
@param string $error
@return sFire\Validator\Message | [
"Sets",
"an",
"error",
"for",
"the",
"current",
"field"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Message.php#L121-L150 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Message.php | Message.getMessage | public static function getMessage($field, $rule) {
if(false === is_string($field)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($field)), E_USER_ERROR);
}
if(false === is_string($rule)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($rule)), E_USER_ERROR);
}
if(true === isset(static :: $messages[$field][$rule])) {
return static :: $messages[$field][$rule];
}
} | php | public static function getMessage($field, $rule) {
if(false === is_string($field)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($field)), E_USER_ERROR);
}
if(false === is_string($rule)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($rule)), E_USER_ERROR);
}
if(true === isset(static :: $messages[$field][$rule])) {
return static :: $messages[$field][$rule];
}
} | [
"public",
"static",
"function",
"getMessage",
"(",
"$",
"field",
",",
"$",
"rule",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"field",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"field",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"rule",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"rule",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"true",
"===",
"isset",
"(",
"static",
"::",
"$",
"messages",
"[",
"$",
"field",
"]",
"[",
"$",
"rule",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"messages",
"[",
"$",
"field",
"]",
"[",
"$",
"rule",
"]",
";",
"}",
"}"
] | Returns message by field and rule
@param string $field
@param string $rule
@return string | [
"Returns",
"message",
"by",
"field",
"and",
"rule"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Message.php#L159-L172 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Message.php | Message.loadCustom | public static function loadCustom($classname, $namespace, $name) {
if(false === is_string($classname)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($classname)), E_USER_ERROR);
}
if(false === is_string($namespace)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($namespace)), E_USER_ERROR);
}
if(false === is_string($name)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
static :: $custom[$name] = $namespace;
return static :: Instance();
} | php | public static function loadCustom($classname, $namespace, $name) {
if(false === is_string($classname)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($classname)), E_USER_ERROR);
}
if(false === is_string($namespace)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($namespace)), E_USER_ERROR);
}
if(false === is_string($name)) {
return trigger_error(sprintf('Argument 3 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
static :: $custom[$name] = $namespace;
return static :: Instance();
} | [
"public",
"static",
"function",
"loadCustom",
"(",
"$",
"classname",
",",
"$",
"namespace",
",",
"$",
"name",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"classname",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"classname",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"namespace",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"namespace",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 3 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"name",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"static",
"::",
"$",
"custom",
"[",
"$",
"name",
"]",
"=",
"$",
"namespace",
";",
"return",
"static",
"::",
"Instance",
"(",
")",
";",
"}"
] | Loads a custom validator class
@param string $classname
@param string $namespace
@param string $name
@return sFire\Validator\Message | [
"Loads",
"a",
"custom",
"validator",
"class"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Message.php#L191-L208 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Message.php | Message.getErrors | public static function getErrors($fullnames = false) {
if(false === is_bool($fullnames)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($fullnames)), E_USER_ERROR);
}
if(true === $fullnames) {
return static :: $errors['full'];
}
return static :: $errors['short'];
} | php | public static function getErrors($fullnames = false) {
if(false === is_bool($fullnames)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type boolean, "%s" given', __METHOD__, gettype($fullnames)), E_USER_ERROR);
}
if(true === $fullnames) {
return static :: $errors['full'];
}
return static :: $errors['short'];
} | [
"public",
"static",
"function",
"getErrors",
"(",
"$",
"fullnames",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"is_bool",
"(",
"$",
"fullnames",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type boolean, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"fullnames",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"true",
"===",
"$",
"fullnames",
")",
"{",
"return",
"static",
"::",
"$",
"errors",
"[",
"'full'",
"]",
";",
"}",
"return",
"static",
"::",
"$",
"errors",
"[",
"'short'",
"]",
";",
"}"
] | Returns all errors
@param boolean $fullnames
@return array | [
"Returns",
"all",
"errors"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Message.php#L216-L227 | train |
Kris-Kuiper/sFire-Framework | src/Validator/Message.php | Message.addMessage | private static function addMessage($rule, $params) {
if(false === is_string($rule)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($rule)), E_USER_ERROR);
}
if(false === is_array($params)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
}
if(false === isset($params[0])) {
return trigger_error(sprintf('Params passed to %s() are not well formed', __METHOD__), E_USER_ERROR);
}
foreach(static :: $fieldnames as $fieldname) {
if(false === isset(static :: $messages[$fieldname][$rule])) {
static :: $messages[$fieldname][$rule] = [];
}
static :: $messages[$fieldname][$rule] = $params[0];
}
} | php | private static function addMessage($rule, $params) {
if(false === is_string($rule)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($rule)), E_USER_ERROR);
}
if(false === is_array($params)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
}
if(false === isset($params[0])) {
return trigger_error(sprintf('Params passed to %s() are not well formed', __METHOD__), E_USER_ERROR);
}
foreach(static :: $fieldnames as $fieldname) {
if(false === isset(static :: $messages[$fieldname][$rule])) {
static :: $messages[$fieldname][$rule] = [];
}
static :: $messages[$fieldname][$rule] = $params[0];
}
} | [
"private",
"static",
"function",
"addMessage",
"(",
"$",
"rule",
",",
"$",
"params",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"rule",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"rule",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"params",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Params passed to %s() are not well formed'",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"foreach",
"(",
"static",
"::",
"$",
"fieldnames",
"as",
"$",
"fieldname",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"static",
"::",
"$",
"messages",
"[",
"$",
"fieldname",
"]",
"[",
"$",
"rule",
"]",
")",
")",
"{",
"static",
"::",
"$",
"messages",
"[",
"$",
"fieldname",
"]",
"[",
"$",
"rule",
"]",
"=",
"[",
"]",
";",
"}",
"static",
"::",
"$",
"messages",
"[",
"$",
"fieldname",
"]",
"[",
"$",
"rule",
"]",
"=",
"$",
"params",
"[",
"0",
"]",
";",
"}",
"}"
] | Adds a new custom message to current fieldname
@param string $rule
@param array $params | [
"Adds",
"a",
"new",
"custom",
"message",
"to",
"current",
"fieldname"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Message.php#L235-L257 | train |
koolkode/lexer | src/AbstractTokenBuffer.php | AbstractTokenBuffer.append | public function append($data)
{
if($data instanceof AbstractToken)
{
$this->tokens[] = $data;
}
elseif($data instanceof AbstractTokenContainer)
{
$this->tokens = array_merge($this->tokens, $data->toArray());
}
elseif($data instanceof AbstractTokenCursor)
{
while($data->valid())
{
$this->tokens[] = $data->current();
$data->next();
}
}
else
{
throw new \InvalidArgumentException('Cannot append data to token buffer: ' . gettype($data));
}
return $this;
} | php | public function append($data)
{
if($data instanceof AbstractToken)
{
$this->tokens[] = $data;
}
elseif($data instanceof AbstractTokenContainer)
{
$this->tokens = array_merge($this->tokens, $data->toArray());
}
elseif($data instanceof AbstractTokenCursor)
{
while($data->valid())
{
$this->tokens[] = $data->current();
$data->next();
}
}
else
{
throw new \InvalidArgumentException('Cannot append data to token buffer: ' . gettype($data));
}
return $this;
} | [
"public",
"function",
"append",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"instanceof",
"AbstractToken",
")",
"{",
"$",
"this",
"->",
"tokens",
"[",
"]",
"=",
"$",
"data",
";",
"}",
"elseif",
"(",
"$",
"data",
"instanceof",
"AbstractTokenContainer",
")",
"{",
"$",
"this",
"->",
"tokens",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"tokens",
",",
"$",
"data",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"data",
"instanceof",
"AbstractTokenCursor",
")",
"{",
"while",
"(",
"$",
"data",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"tokens",
"[",
"]",
"=",
"$",
"data",
"->",
"current",
"(",
")",
";",
"$",
"data",
"->",
"next",
"(",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Cannot append data to token buffer: '",
".",
"gettype",
"(",
"$",
"data",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Append the given token or token container to the TokenBuffer.
@param mixed $data
@return AbstractTokenBuffer
@throws \InvalidArgumentException | [
"Append",
"the",
"given",
"token",
"or",
"token",
"container",
"to",
"the",
"TokenBuffer",
"."
] | 1f33fb4e95bf3b6b21c63187e503bbe612a1646c | https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractTokenBuffer.php#L37-L62 | train |
RhubarbPHP/Module.ImageProcessing | src/ImageMetrics.php | ImageMetrics.commit | public function commit()
{
$this->sourceWidth = $this->frameWidth;
$this->sourceHeight = $this->frameHeight;
$this->offsetX = 0;
$this->offsetY = 0;
$this->scaleWidth = $this->frameWidth;
$this->scaleHeight = $this->frameHeight;
$this->getFocalPoint();
} | php | public function commit()
{
$this->sourceWidth = $this->frameWidth;
$this->sourceHeight = $this->frameHeight;
$this->offsetX = 0;
$this->offsetY = 0;
$this->scaleWidth = $this->frameWidth;
$this->scaleHeight = $this->frameHeight;
$this->getFocalPoint();
} | [
"public",
"function",
"commit",
"(",
")",
"{",
"$",
"this",
"->",
"sourceWidth",
"=",
"$",
"this",
"->",
"frameWidth",
";",
"$",
"this",
"->",
"sourceHeight",
"=",
"$",
"this",
"->",
"frameHeight",
";",
"$",
"this",
"->",
"offsetX",
"=",
"0",
";",
"$",
"this",
"->",
"offsetY",
"=",
"0",
";",
"$",
"this",
"->",
"scaleWidth",
"=",
"$",
"this",
"->",
"frameWidth",
";",
"$",
"this",
"->",
"scaleHeight",
"=",
"$",
"this",
"->",
"frameHeight",
";",
"$",
"this",
"->",
"getFocalPoint",
"(",
")",
";",
"}"
] | Resets the image metrics so as to reflect the image should the current settings be applied. | [
"Resets",
"the",
"image",
"metrics",
"so",
"as",
"to",
"reflect",
"the",
"image",
"should",
"the",
"current",
"settings",
"be",
"applied",
"."
] | e980ae6b524ce60f550064257eb7318dce331c1a | https://github.com/RhubarbPHP/Module.ImageProcessing/blob/e980ae6b524ce60f550064257eb7318dce331c1a/src/ImageMetrics.php#L46-L56 | train |
RhubarbPHP/Module.ImageProcessing | src/ImageMetrics.php | ImageMetrics.getFocalPoint | public function getFocalPoint()
{
$scale = $this->sourceWidth / $this->scaleWidth;
$focalX = ( ( $this->frameWidth / 2 ) - $this->offsetX ) * $scale;
$focalY = ( ( $this->frameHeight / 2 ) - $this->offsetY ) * $scale;
return array( $focalX, $focalY );
} | php | public function getFocalPoint()
{
$scale = $this->sourceWidth / $this->scaleWidth;
$focalX = ( ( $this->frameWidth / 2 ) - $this->offsetX ) * $scale;
$focalY = ( ( $this->frameHeight / 2 ) - $this->offsetY ) * $scale;
return array( $focalX, $focalY );
} | [
"public",
"function",
"getFocalPoint",
"(",
")",
"{",
"$",
"scale",
"=",
"$",
"this",
"->",
"sourceWidth",
"/",
"$",
"this",
"->",
"scaleWidth",
";",
"$",
"focalX",
"=",
"(",
"(",
"$",
"this",
"->",
"frameWidth",
"/",
"2",
")",
"-",
"$",
"this",
"->",
"offsetX",
")",
"*",
"$",
"scale",
";",
"$",
"focalY",
"=",
"(",
"(",
"$",
"this",
"->",
"frameHeight",
"/",
"2",
")",
"-",
"$",
"this",
"->",
"offsetY",
")",
"*",
"$",
"scale",
";",
"return",
"array",
"(",
"$",
"focalX",
",",
"$",
"focalY",
")",
";",
"}"
] | Returns an array with the X, Y co-ords of the focal point of the current crop.
The measurement is relative to the original source image. | [
"Returns",
"an",
"array",
"with",
"the",
"X",
"Y",
"co",
"-",
"ords",
"of",
"the",
"focal",
"point",
"of",
"the",
"current",
"crop",
"."
] | e980ae6b524ce60f550064257eb7318dce331c1a | https://github.com/RhubarbPHP/Module.ImageProcessing/blob/e980ae6b524ce60f550064257eb7318dce331c1a/src/ImageMetrics.php#L64-L72 | train |
RhubarbPHP/Module.ImageProcessing | src/ImageMetrics.php | ImageMetrics.setSourceDetails | public function setSourceDetails()
{
if ( !file_exists( $this->sourcePath ) )
{
throw new FileNotFoundException( $this->sourcePath );
}
if ( is_dir( $this->sourcePath ) )
{
throw new FileNotFoundException( $this->sourcePath );
}
$imageDetails = getimagesize( $this->sourcePath );
$this->sourceWidth = $imageDetails[0];
$this->sourceHeight = $imageDetails[1];
$this->scaleWidth = $this->sourceWidth;
$this->scaleHeight = $this->sourceHeight;
$this->aspectRatio = $this->sourceWidth / $this->sourceHeight;
$this->frameWidth = $this->sourceWidth;
$this->frameHeight = $this->sourceHeight;
$this->sourceFormat = $imageDetails[ 2 ];
} | php | public function setSourceDetails()
{
if ( !file_exists( $this->sourcePath ) )
{
throw new FileNotFoundException( $this->sourcePath );
}
if ( is_dir( $this->sourcePath ) )
{
throw new FileNotFoundException( $this->sourcePath );
}
$imageDetails = getimagesize( $this->sourcePath );
$this->sourceWidth = $imageDetails[0];
$this->sourceHeight = $imageDetails[1];
$this->scaleWidth = $this->sourceWidth;
$this->scaleHeight = $this->sourceHeight;
$this->aspectRatio = $this->sourceWidth / $this->sourceHeight;
$this->frameWidth = $this->sourceWidth;
$this->frameHeight = $this->sourceHeight;
$this->sourceFormat = $imageDetails[ 2 ];
} | [
"public",
"function",
"setSourceDetails",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"sourcePath",
")",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"$",
"this",
"->",
"sourcePath",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"this",
"->",
"sourcePath",
")",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"$",
"this",
"->",
"sourcePath",
")",
";",
"}",
"$",
"imageDetails",
"=",
"getimagesize",
"(",
"$",
"this",
"->",
"sourcePath",
")",
";",
"$",
"this",
"->",
"sourceWidth",
"=",
"$",
"imageDetails",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"sourceHeight",
"=",
"$",
"imageDetails",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"scaleWidth",
"=",
"$",
"this",
"->",
"sourceWidth",
";",
"$",
"this",
"->",
"scaleHeight",
"=",
"$",
"this",
"->",
"sourceHeight",
";",
"$",
"this",
"->",
"aspectRatio",
"=",
"$",
"this",
"->",
"sourceWidth",
"/",
"$",
"this",
"->",
"sourceHeight",
";",
"$",
"this",
"->",
"frameWidth",
"=",
"$",
"this",
"->",
"sourceWidth",
";",
"$",
"this",
"->",
"frameHeight",
"=",
"$",
"this",
"->",
"sourceHeight",
";",
"$",
"this",
"->",
"sourceFormat",
"=",
"$",
"imageDetails",
"[",
"2",
"]",
";",
"}"
] | Reads basic information about the metrics of the source image.
@throws FileNotFoundException Thrown if the source image couldn't be found. | [
"Reads",
"basic",
"information",
"about",
"the",
"metrics",
"of",
"the",
"source",
"image",
"."
] | e980ae6b524ce60f550064257eb7318dce331c1a | https://github.com/RhubarbPHP/Module.ImageProcessing/blob/e980ae6b524ce60f550064257eb7318dce331c1a/src/ImageMetrics.php#L99-L125 | train |
RhubarbPHP/Module.ImageProcessing | src/ImageMetrics.php | ImageMetrics.resize | public function resize( $width, $height, $maintainAspect = false, $scaleUp = true )
{
$oldFrameWidth = $this->frameWidth;
$aspectRatio = $this->frameWidth / $this->frameHeight;
if ( $maintainAspect )
{
// Try width first
$newHeight = round( $width / $aspectRatio );
if ( $newHeight > $height )
{
$newWidth = round( $height * $aspectRatio );
$newHeight = $height;
}
else
{
$newWidth = $width;
}
if ( !$scaleUp && ( ( $newWidth > $this->frameWidth ) || ( $newHeight > $this->frameHeight ) ) )
{
// Make no changes as we don't want to scale up.
return;
}
// This is effectively changing the width of our frame.
$this->frameWidth = $newWidth;
$this->frameHeight = $newHeight;
// Use the change in width as a ratio to scale the offsets etc.
$scale = $oldFrameWidth / $this->frameWidth;
$this->scaleWidth = ceil( $this->scaleWidth / $scale );
$this->scaleHeight = ceil( $this->scaleHeight / $scale );
$this->offsetX = ceil( $this->offsetX / $scale );
$this->offsetY = ceil( $this->offsetY / $scale );
}
else
{
if ( !$scaleUp && ( ( $width > $this->scaleWidth ) || ( $height > $this->scaleHeight ) ) )
{
// Make no changes as we don't want to scale up
return;
}
$this->scaleWidth = $width;
$this->scaleHeight = $height;
$this->frameWidth = $width;
$this->frameHeight = $height;
}
$this->aspectRatio = $this->scaleWidth / $this->scaleHeight;
} | php | public function resize( $width, $height, $maintainAspect = false, $scaleUp = true )
{
$oldFrameWidth = $this->frameWidth;
$aspectRatio = $this->frameWidth / $this->frameHeight;
if ( $maintainAspect )
{
// Try width first
$newHeight = round( $width / $aspectRatio );
if ( $newHeight > $height )
{
$newWidth = round( $height * $aspectRatio );
$newHeight = $height;
}
else
{
$newWidth = $width;
}
if ( !$scaleUp && ( ( $newWidth > $this->frameWidth ) || ( $newHeight > $this->frameHeight ) ) )
{
// Make no changes as we don't want to scale up.
return;
}
// This is effectively changing the width of our frame.
$this->frameWidth = $newWidth;
$this->frameHeight = $newHeight;
// Use the change in width as a ratio to scale the offsets etc.
$scale = $oldFrameWidth / $this->frameWidth;
$this->scaleWidth = ceil( $this->scaleWidth / $scale );
$this->scaleHeight = ceil( $this->scaleHeight / $scale );
$this->offsetX = ceil( $this->offsetX / $scale );
$this->offsetY = ceil( $this->offsetY / $scale );
}
else
{
if ( !$scaleUp && ( ( $width > $this->scaleWidth ) || ( $height > $this->scaleHeight ) ) )
{
// Make no changes as we don't want to scale up
return;
}
$this->scaleWidth = $width;
$this->scaleHeight = $height;
$this->frameWidth = $width;
$this->frameHeight = $height;
}
$this->aspectRatio = $this->scaleWidth / $this->scaleHeight;
} | [
"public",
"function",
"resize",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"maintainAspect",
"=",
"false",
",",
"$",
"scaleUp",
"=",
"true",
")",
"{",
"$",
"oldFrameWidth",
"=",
"$",
"this",
"->",
"frameWidth",
";",
"$",
"aspectRatio",
"=",
"$",
"this",
"->",
"frameWidth",
"/",
"$",
"this",
"->",
"frameHeight",
";",
"if",
"(",
"$",
"maintainAspect",
")",
"{",
"// Try width first",
"$",
"newHeight",
"=",
"round",
"(",
"$",
"width",
"/",
"$",
"aspectRatio",
")",
";",
"if",
"(",
"$",
"newHeight",
">",
"$",
"height",
")",
"{",
"$",
"newWidth",
"=",
"round",
"(",
"$",
"height",
"*",
"$",
"aspectRatio",
")",
";",
"$",
"newHeight",
"=",
"$",
"height",
";",
"}",
"else",
"{",
"$",
"newWidth",
"=",
"$",
"width",
";",
"}",
"if",
"(",
"!",
"$",
"scaleUp",
"&&",
"(",
"(",
"$",
"newWidth",
">",
"$",
"this",
"->",
"frameWidth",
")",
"||",
"(",
"$",
"newHeight",
">",
"$",
"this",
"->",
"frameHeight",
")",
")",
")",
"{",
"// Make no changes as we don't want to scale up.",
"return",
";",
"}",
"// This is effectively changing the width of our frame.",
"$",
"this",
"->",
"frameWidth",
"=",
"$",
"newWidth",
";",
"$",
"this",
"->",
"frameHeight",
"=",
"$",
"newHeight",
";",
"// Use the change in width as a ratio to scale the offsets etc.",
"$",
"scale",
"=",
"$",
"oldFrameWidth",
"/",
"$",
"this",
"->",
"frameWidth",
";",
"$",
"this",
"->",
"scaleWidth",
"=",
"ceil",
"(",
"$",
"this",
"->",
"scaleWidth",
"/",
"$",
"scale",
")",
";",
"$",
"this",
"->",
"scaleHeight",
"=",
"ceil",
"(",
"$",
"this",
"->",
"scaleHeight",
"/",
"$",
"scale",
")",
";",
"$",
"this",
"->",
"offsetX",
"=",
"ceil",
"(",
"$",
"this",
"->",
"offsetX",
"/",
"$",
"scale",
")",
";",
"$",
"this",
"->",
"offsetY",
"=",
"ceil",
"(",
"$",
"this",
"->",
"offsetY",
"/",
"$",
"scale",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"scaleUp",
"&&",
"(",
"(",
"$",
"width",
">",
"$",
"this",
"->",
"scaleWidth",
")",
"||",
"(",
"$",
"height",
">",
"$",
"this",
"->",
"scaleHeight",
")",
")",
")",
"{",
"// Make no changes as we don't want to scale up",
"return",
";",
"}",
"$",
"this",
"->",
"scaleWidth",
"=",
"$",
"width",
";",
"$",
"this",
"->",
"scaleHeight",
"=",
"$",
"height",
";",
"$",
"this",
"->",
"frameWidth",
"=",
"$",
"width",
";",
"$",
"this",
"->",
"frameHeight",
"=",
"$",
"height",
";",
"}",
"$",
"this",
"->",
"aspectRatio",
"=",
"$",
"this",
"->",
"scaleWidth",
"/",
"$",
"this",
"->",
"scaleHeight",
";",
"}"
] | Resizes the image with the given bounds.
@param mixed $width
@param mixed $height
@param mixed $maintainAspect
@param bool $scaleUp | [
"Resizes",
"the",
"image",
"with",
"the",
"given",
"bounds",
"."
] | e980ae6b524ce60f550064257eb7318dce331c1a | https://github.com/RhubarbPHP/Module.ImageProcessing/blob/e980ae6b524ce60f550064257eb7318dce331c1a/src/ImageMetrics.php#L135-L189 | train |
swokit/utils | src/Coroutine.php | Coroutine.tid | public static function tid(): int
{
if (!ServerUtil::coroutineIsEnabled()) {
return -1;
}
$id = SwCoroutine::getuid();
return self::$idMap[$id] ?? $id;
} | php | public static function tid(): int
{
if (!ServerUtil::coroutineIsEnabled()) {
return -1;
}
$id = SwCoroutine::getuid();
return self::$idMap[$id] ?? $id;
} | [
"public",
"static",
"function",
"tid",
"(",
")",
":",
"int",
"{",
"if",
"(",
"!",
"ServerUtil",
"::",
"coroutineIsEnabled",
"(",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"$",
"id",
"=",
"SwCoroutine",
"::",
"getuid",
"(",
")",
";",
"return",
"self",
"::",
"$",
"idMap",
"[",
"$",
"id",
"]",
"??",
"$",
"id",
";",
"}"
] | get top coroutine id
@return int | [
"get",
"top",
"coroutine",
"id"
] | a91688ee6970e33be14047bf4714da3299796f56 | https://github.com/swokit/utils/blob/a91688ee6970e33be14047bf4714da3299796f56/src/Coroutine.php#L48-L57 | train |
swokit/utils | src/Coroutine.php | Coroutine.create | public static function create(callable $cb)
{
if (!ServerUtil::coroutineIsEnabled()) {
return false;
}
$tid = self::tid();
return SwCoroutine::create(function () use ($cb, $tid) {
$id = SwCoroutine::getuid();
self::$idMap[$id] = $tid;
PhpHelper::call($cb);
});
} | php | public static function create(callable $cb)
{
if (!ServerUtil::coroutineIsEnabled()) {
return false;
}
$tid = self::tid();
return SwCoroutine::create(function () use ($cb, $tid) {
$id = SwCoroutine::getuid();
self::$idMap[$id] = $tid;
PhpHelper::call($cb);
});
} | [
"public",
"static",
"function",
"create",
"(",
"callable",
"$",
"cb",
")",
"{",
"if",
"(",
"!",
"ServerUtil",
"::",
"coroutineIsEnabled",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tid",
"=",
"self",
"::",
"tid",
"(",
")",
";",
"return",
"SwCoroutine",
"::",
"create",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"cb",
",",
"$",
"tid",
")",
"{",
"$",
"id",
"=",
"SwCoroutine",
"::",
"getuid",
"(",
")",
";",
"self",
"::",
"$",
"idMap",
"[",
"$",
"id",
"]",
"=",
"$",
"tid",
";",
"PhpHelper",
"::",
"call",
"(",
"$",
"cb",
")",
";",
"}",
")",
";",
"}"
] | create a child coroutine
@param callable $cb
@return bool|int success return CID, fail return false. | [
"create",
"a",
"child",
"coroutine"
] | a91688ee6970e33be14047bf4714da3299796f56 | https://github.com/swokit/utils/blob/a91688ee6970e33be14047bf4714da3299796f56/src/Coroutine.php#L73-L88 | train |
PenoaksDev/Milky-Framework | src/Milky/Filesystem/FilesystemAdapter.php | FilesystemAdapter.parseVisibility | protected function parseVisibility( $visibility )
{
if ( is_null( $visibility ) )
return null;
switch ( $visibility )
{
case FilesystemContract::VISIBILITY_PUBLIC:
return AdapterInterface::VISIBILITY_PUBLIC;
case FilesystemContract::VISIBILITY_PRIVATE:
return AdapterInterface::VISIBILITY_PRIVATE;
}
throw new InvalidArgumentException( 'Unknown visibility: ' . $visibility );
} | php | protected function parseVisibility( $visibility )
{
if ( is_null( $visibility ) )
return null;
switch ( $visibility )
{
case FilesystemContract::VISIBILITY_PUBLIC:
return AdapterInterface::VISIBILITY_PUBLIC;
case FilesystemContract::VISIBILITY_PRIVATE:
return AdapterInterface::VISIBILITY_PRIVATE;
}
throw new InvalidArgumentException( 'Unknown visibility: ' . $visibility );
} | [
"protected",
"function",
"parseVisibility",
"(",
"$",
"visibility",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"visibility",
")",
")",
"return",
"null",
";",
"switch",
"(",
"$",
"visibility",
")",
"{",
"case",
"FilesystemContract",
"::",
"VISIBILITY_PUBLIC",
":",
"return",
"AdapterInterface",
"::",
"VISIBILITY_PUBLIC",
";",
"case",
"FilesystemContract",
"::",
"VISIBILITY_PRIVATE",
":",
"return",
"AdapterInterface",
"::",
"VISIBILITY_PRIVATE",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Unknown visibility: '",
".",
"$",
"visibility",
")",
";",
"}"
] | Parse the given visibility value.
@param string|null $visibility
@return string|null
@throws \InvalidArgumentException | [
"Parse",
"the",
"given",
"visibility",
"value",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Filesystem/FilesystemAdapter.php#L371-L385 | train |
kkthek/diqa-util | src/Util/ParserFunctions/ReadObjectCache.php | ReadObjectCache.readObjectCache | static function readObjectCache(Parser &$parser, $key = '') {
$parser->disableCache ();
$cache = \ObjectCache::getInstance(CACHE_DB);
global $wgDIQAAllowedObjectCacheKeys;
if (!isset($wgDIQAAllowedObjectCacheKeys)
|| !in_array($key, $wgDIQAAllowedObjectCacheKeys)) {
return 'not-allowed-to-access';
}
$value = $cache->get($key);
if (is_array($value)) {
return "$key is an array";
}
if (is_object($value)) {
return "$key is an object";
}
return array((string)$value, 'noparse' => true);
} | php | static function readObjectCache(Parser &$parser, $key = '') {
$parser->disableCache ();
$cache = \ObjectCache::getInstance(CACHE_DB);
global $wgDIQAAllowedObjectCacheKeys;
if (!isset($wgDIQAAllowedObjectCacheKeys)
|| !in_array($key, $wgDIQAAllowedObjectCacheKeys)) {
return 'not-allowed-to-access';
}
$value = $cache->get($key);
if (is_array($value)) {
return "$key is an array";
}
if (is_object($value)) {
return "$key is an object";
}
return array((string)$value, 'noparse' => true);
} | [
"static",
"function",
"readObjectCache",
"(",
"Parser",
"&",
"$",
"parser",
",",
"$",
"key",
"=",
"''",
")",
"{",
"$",
"parser",
"->",
"disableCache",
"(",
")",
";",
"$",
"cache",
"=",
"\\",
"ObjectCache",
"::",
"getInstance",
"(",
"CACHE_DB",
")",
";",
"global",
"$",
"wgDIQAAllowedObjectCacheKeys",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"wgDIQAAllowedObjectCacheKeys",
")",
"||",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"wgDIQAAllowedObjectCacheKeys",
")",
")",
"{",
"return",
"'not-allowed-to-access'",
";",
"}",
"$",
"value",
"=",
"$",
"cache",
"->",
"get",
"(",
"$",
"key",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"\"$key is an array\"",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"\"$key is an object\"",
";",
"}",
"return",
"array",
"(",
"(",
"string",
")",
"$",
"value",
",",
"'noparse'",
"=>",
"true",
")",
";",
"}"
] | Read key from ObjectCache | [
"Read",
"key",
"from",
"ObjectCache"
] | df35d16403b5dbf0f7570daded6cfa26814ae7e0 | https://github.com/kkthek/diqa-util/blob/df35d16403b5dbf0f7570daded6cfa26814ae7e0/src/Util/ParserFunctions/ReadObjectCache.php#L18-L38 | train |
covex-nn/JooS | src/JooS/Loader.php | Loader.loadClass | public static function loadClass($className)
{
if (!class_exists($className)) {
$path = self::getPath($className);
$realPath = stream_resolve_include_path($path);
if (file_exists($realPath)) {
require_once($realPath);
return class_exists($className);
}
return false;
} else {
return true;
}
} | php | public static function loadClass($className)
{
if (!class_exists($className)) {
$path = self::getPath($className);
$realPath = stream_resolve_include_path($path);
if (file_exists($realPath)) {
require_once($realPath);
return class_exists($className);
}
return false;
} else {
return true;
}
} | [
"public",
"static",
"function",
"loadClass",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"$",
"path",
"=",
"self",
"::",
"getPath",
"(",
"$",
"className",
")",
";",
"$",
"realPath",
"=",
"stream_resolve_include_path",
"(",
"$",
"path",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"realPath",
")",
")",
"{",
"require_once",
"(",
"$",
"realPath",
")",
";",
"return",
"class_exists",
"(",
"$",
"className",
")",
";",
"}",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] | Loads class.
@param string $className Class Name
@return bool | [
"Loads",
"class",
"."
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Loader.php#L21-L37 | train |
covex-nn/JooS | src/JooS/Loader.php | Loader.getPath | public static function getPath($className, $ext = "php")
{
if (substr($className, 0, 1) == "\\") {
$className = substr($className, 1);
}
$delimiters = array("_", "\\");
foreach ($delimiters as $symbol) {
$className = str_replace($symbol, "/", $className);
}
return $className . "." . $ext;
} | php | public static function getPath($className, $ext = "php")
{
if (substr($className, 0, 1) == "\\") {
$className = substr($className, 1);
}
$delimiters = array("_", "\\");
foreach ($delimiters as $symbol) {
$className = str_replace($symbol, "/", $className);
}
return $className . "." . $ext;
} | [
"public",
"static",
"function",
"getPath",
"(",
"$",
"className",
",",
"$",
"ext",
"=",
"\"php\"",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"className",
",",
"0",
",",
"1",
")",
"==",
"\"\\\\\"",
")",
"{",
"$",
"className",
"=",
"substr",
"(",
"$",
"className",
",",
"1",
")",
";",
"}",
"$",
"delimiters",
"=",
"array",
"(",
"\"_\"",
",",
"\"\\\\\"",
")",
";",
"foreach",
"(",
"$",
"delimiters",
"as",
"$",
"symbol",
")",
"{",
"$",
"className",
"=",
"str_replace",
"(",
"$",
"symbol",
",",
"\"/\"",
",",
"$",
"className",
")",
";",
"}",
"return",
"$",
"className",
".",
"\".\"",
".",
"$",
"ext",
";",
"}"
] | Returns class path.
@param string $className Class Name
@param string $ext Extention
@return string | [
"Returns",
"class",
"path",
"."
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Loader.php#L47-L58 | train |
covex-nn/JooS | src/JooS/Loader.php | Loader.getClassName | public static function getClassName($prefix, $name, $ucfirst = false)
{
if (substr($prefix, -1, 1) == "\\") {
$className = $prefix;
} else {
$className = $prefix . "_";
}
$className .= $name;
if ($ucfirst) {
$result = "";
$nsPath = explode("\\", $className);
$name = array_pop($nsPath);
if (sizeof($nsPath)) {
for ($i = 0; $i < sizeof($nsPath); $i++) {
$nsPath[$i] = ucfirst(strtolower($nsPath[$i]));
}
$result .= implode("\\", $nsPath);
}
if (strlen($result) && substr($result, -1, 1) != "\\") {
$result .= "\\";
}
$dirPath = explode("_", $name);
for ($i = 0; $i < sizeof($dirPath); $i++) {
$dirPath[$i] = ucfirst(strtolower($dirPath[$i]));
}
$result .= implode("_", $dirPath);
} else {
$result = $className;
}
return $result;
} | php | public static function getClassName($prefix, $name, $ucfirst = false)
{
if (substr($prefix, -1, 1) == "\\") {
$className = $prefix;
} else {
$className = $prefix . "_";
}
$className .= $name;
if ($ucfirst) {
$result = "";
$nsPath = explode("\\", $className);
$name = array_pop($nsPath);
if (sizeof($nsPath)) {
for ($i = 0; $i < sizeof($nsPath); $i++) {
$nsPath[$i] = ucfirst(strtolower($nsPath[$i]));
}
$result .= implode("\\", $nsPath);
}
if (strlen($result) && substr($result, -1, 1) != "\\") {
$result .= "\\";
}
$dirPath = explode("_", $name);
for ($i = 0; $i < sizeof($dirPath); $i++) {
$dirPath[$i] = ucfirst(strtolower($dirPath[$i]));
}
$result .= implode("_", $dirPath);
} else {
$result = $className;
}
return $result;
} | [
"public",
"static",
"function",
"getClassName",
"(",
"$",
"prefix",
",",
"$",
"name",
",",
"$",
"ucfirst",
"=",
"false",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"prefix",
",",
"-",
"1",
",",
"1",
")",
"==",
"\"\\\\\"",
")",
"{",
"$",
"className",
"=",
"$",
"prefix",
";",
"}",
"else",
"{",
"$",
"className",
"=",
"$",
"prefix",
".",
"\"_\"",
";",
"}",
"$",
"className",
".=",
"$",
"name",
";",
"if",
"(",
"$",
"ucfirst",
")",
"{",
"$",
"result",
"=",
"\"\"",
";",
"$",
"nsPath",
"=",
"explode",
"(",
"\"\\\\\"",
",",
"$",
"className",
")",
";",
"$",
"name",
"=",
"array_pop",
"(",
"$",
"nsPath",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"nsPath",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"sizeof",
"(",
"$",
"nsPath",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"nsPath",
"[",
"$",
"i",
"]",
"=",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"nsPath",
"[",
"$",
"i",
"]",
")",
")",
";",
"}",
"$",
"result",
".=",
"implode",
"(",
"\"\\\\\"",
",",
"$",
"nsPath",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"result",
")",
"&&",
"substr",
"(",
"$",
"result",
",",
"-",
"1",
",",
"1",
")",
"!=",
"\"\\\\\"",
")",
"{",
"$",
"result",
".=",
"\"\\\\\"",
";",
"}",
"$",
"dirPath",
"=",
"explode",
"(",
"\"_\"",
",",
"$",
"name",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"sizeof",
"(",
"$",
"dirPath",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"dirPath",
"[",
"$",
"i",
"]",
"=",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"dirPath",
"[",
"$",
"i",
"]",
")",
")",
";",
"}",
"$",
"result",
".=",
"implode",
"(",
"\"_\"",
",",
"$",
"dirPath",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"className",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns className.
@param string $prefix Prefix
@param string $name Name
@param bool $ucfirst First letter - caps
@return string | [
"Returns",
"className",
"."
] | 8dfb94edccecaf307787d4091ba7f20a674b7792 | https://github.com/covex-nn/JooS/blob/8dfb94edccecaf307787d4091ba7f20a674b7792/src/JooS/Loader.php#L69-L105 | train |
OxfordInfoLabs/kinikit-core | src/Util/Logging/CodeTimer.php | CodeTimer.timeFunction | public static function timeFunction($function, $description = null) {
$duration = self::time($function);
Logger::log("Code Block " . ($description ? '"' . $description . '"' : "") . " Executed in " . $duration . " Seconds");
return $duration;
} | php | public static function timeFunction($function, $description = null) {
$duration = self::time($function);
Logger::log("Code Block " . ($description ? '"' . $description . '"' : "") . " Executed in " . $duration . " Seconds");
return $duration;
} | [
"public",
"static",
"function",
"timeFunction",
"(",
"$",
"function",
",",
"$",
"description",
"=",
"null",
")",
"{",
"$",
"duration",
"=",
"self",
"::",
"time",
"(",
"$",
"function",
")",
";",
"Logger",
"::",
"log",
"(",
"\"Code Block \"",
".",
"(",
"$",
"description",
"?",
"'\"'",
".",
"$",
"description",
".",
"'\"'",
":",
"\"\"",
")",
".",
"\" Executed in \"",
".",
"$",
"duration",
".",
"\" Seconds\"",
")",
";",
"return",
"$",
"duration",
";",
"}"
] | Time the passed function
@param $function | [
"Time",
"the",
"passed",
"function"
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Logging/CodeTimer.php#L19-L26 | train |
OxfordInfoLabs/kinikit-core | src/Util/Logging/CodeTimer.php | CodeTimer.recordFunctionTimingForGroup | public static function recordFunctionTimingForGroup($function, $group) {
$functionTiming = CodeTimer::time($function);
if (isset(CodeTimer::$groupTimings[$group])) {
CodeTimer::$groupTimings[$group] += $functionTiming;
} else {
CodeTimer::$groupTimings[$group] = $functionTiming;
}
} | php | public static function recordFunctionTimingForGroup($function, $group) {
$functionTiming = CodeTimer::time($function);
if (isset(CodeTimer::$groupTimings[$group])) {
CodeTimer::$groupTimings[$group] += $functionTiming;
} else {
CodeTimer::$groupTimings[$group] = $functionTiming;
}
} | [
"public",
"static",
"function",
"recordFunctionTimingForGroup",
"(",
"$",
"function",
",",
"$",
"group",
")",
"{",
"$",
"functionTiming",
"=",
"CodeTimer",
"::",
"time",
"(",
"$",
"function",
")",
";",
"if",
"(",
"isset",
"(",
"CodeTimer",
"::",
"$",
"groupTimings",
"[",
"$",
"group",
"]",
")",
")",
"{",
"CodeTimer",
"::",
"$",
"groupTimings",
"[",
"$",
"group",
"]",
"+=",
"$",
"functionTiming",
";",
"}",
"else",
"{",
"CodeTimer",
"::",
"$",
"groupTimings",
"[",
"$",
"group",
"]",
"=",
"$",
"functionTiming",
";",
"}",
"}"
] | Record the timing of a passed function against a group. All Timings for a group are added up.
@param $function
@param $group | [
"Record",
"the",
"timing",
"of",
"a",
"passed",
"function",
"against",
"a",
"group",
".",
"All",
"Timings",
"for",
"a",
"group",
"are",
"added",
"up",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Logging/CodeTimer.php#L35-L43 | train |
OxfordInfoLabs/kinikit-core | src/Util/Logging/CodeTimer.php | CodeTimer.reportTimingsForGroup | public static function reportTimingsForGroup($group) {
if (isset(CodeTimer::$groupTimings[$group])) {
Logger::log('Group "' . $group . '" Executed in ' . CodeTimer::$groupTimings[$group] . " Seconds");
return CodeTimer::$groupTimings[$group];
} else {
Logger::log('No group timings recorded for group "' . $group . '"');
return 0;
}
} | php | public static function reportTimingsForGroup($group) {
if (isset(CodeTimer::$groupTimings[$group])) {
Logger::log('Group "' . $group . '" Executed in ' . CodeTimer::$groupTimings[$group] . " Seconds");
return CodeTimer::$groupTimings[$group];
} else {
Logger::log('No group timings recorded for group "' . $group . '"');
return 0;
}
} | [
"public",
"static",
"function",
"reportTimingsForGroup",
"(",
"$",
"group",
")",
"{",
"if",
"(",
"isset",
"(",
"CodeTimer",
"::",
"$",
"groupTimings",
"[",
"$",
"group",
"]",
")",
")",
"{",
"Logger",
"::",
"log",
"(",
"'Group \"'",
".",
"$",
"group",
".",
"'\" Executed in '",
".",
"CodeTimer",
"::",
"$",
"groupTimings",
"[",
"$",
"group",
"]",
".",
"\" Seconds\"",
")",
";",
"return",
"CodeTimer",
"::",
"$",
"groupTimings",
"[",
"$",
"group",
"]",
";",
"}",
"else",
"{",
"Logger",
"::",
"log",
"(",
"'No group timings recorded for group \"'",
".",
"$",
"group",
".",
"'\"'",
")",
";",
"return",
"0",
";",
"}",
"}"
] | Report timings for a group
@param $group | [
"Report",
"timings",
"for",
"a",
"group"
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Logging/CodeTimer.php#L51-L59 | train |
CroudTech/laravel-repositories | src/RepositoryGenerator.php | RepositoryGenerator.makeRepository | protected function makeRepository()
{
$full_path = $this->getFullRepositoryPath();
if (file_exists($full_path)) {
throw new RepositoryExistsException(sprintf('%s file already exists', $full_path));
}
$contract_contents = str_replace(
[
'%%MODEL_BASENAME%%',
'%%MODEL_NAME%%',
'%%CLASS_NAME%%',
'%%NAMESPACE%%',
'%%CONTRACT%%',
],
[
$this->getModelBasename(),
$this->getModelName(),
$this->getRepositoryBaseName(),
trim($this->getRepositoriesNamespace(), '\\'),
$this->getContractsNamespace() . '\\' . $this->getContractBaseName(),
],
$this->contentsFromStub('Repository')
);
if (!file_exists(dirname($full_path))) {
mkdir(dirname($full_path), 0755, true);
}
file_put_contents($full_path, $contract_contents);
} | php | protected function makeRepository()
{
$full_path = $this->getFullRepositoryPath();
if (file_exists($full_path)) {
throw new RepositoryExistsException(sprintf('%s file already exists', $full_path));
}
$contract_contents = str_replace(
[
'%%MODEL_BASENAME%%',
'%%MODEL_NAME%%',
'%%CLASS_NAME%%',
'%%NAMESPACE%%',
'%%CONTRACT%%',
],
[
$this->getModelBasename(),
$this->getModelName(),
$this->getRepositoryBaseName(),
trim($this->getRepositoriesNamespace(), '\\'),
$this->getContractsNamespace() . '\\' . $this->getContractBaseName(),
],
$this->contentsFromStub('Repository')
);
if (!file_exists(dirname($full_path))) {
mkdir(dirname($full_path), 0755, true);
}
file_put_contents($full_path, $contract_contents);
} | [
"protected",
"function",
"makeRepository",
"(",
")",
"{",
"$",
"full_path",
"=",
"$",
"this",
"->",
"getFullRepositoryPath",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"full_path",
")",
")",
"{",
"throw",
"new",
"RepositoryExistsException",
"(",
"sprintf",
"(",
"'%s file already exists'",
",",
"$",
"full_path",
")",
")",
";",
"}",
"$",
"contract_contents",
"=",
"str_replace",
"(",
"[",
"'%%MODEL_BASENAME%%'",
",",
"'%%MODEL_NAME%%'",
",",
"'%%CLASS_NAME%%'",
",",
"'%%NAMESPACE%%'",
",",
"'%%CONTRACT%%'",
",",
"]",
",",
"[",
"$",
"this",
"->",
"getModelBasename",
"(",
")",
",",
"$",
"this",
"->",
"getModelName",
"(",
")",
",",
"$",
"this",
"->",
"getRepositoryBaseName",
"(",
")",
",",
"trim",
"(",
"$",
"this",
"->",
"getRepositoriesNamespace",
"(",
")",
",",
"'\\\\'",
")",
",",
"$",
"this",
"->",
"getContractsNamespace",
"(",
")",
".",
"'\\\\'",
".",
"$",
"this",
"->",
"getContractBaseName",
"(",
")",
",",
"]",
",",
"$",
"this",
"->",
"contentsFromStub",
"(",
"'Repository'",
")",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"full_path",
")",
")",
")",
"{",
"mkdir",
"(",
"dirname",
"(",
"$",
"full_path",
")",
",",
"0755",
",",
"true",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"full_path",
",",
"$",
"contract_contents",
")",
";",
"}"
] | Make repository file
@method makeRepository
@return string The fully qualified contract name | [
"Make",
"repository",
"file"
] | 3146285be911728fe7b00cf27d2494ad22b773dc | https://github.com/CroudTech/laravel-repositories/blob/3146285be911728fe7b00cf27d2494ad22b773dc/src/RepositoryGenerator.php#L95-L123 | train |
CroudTech/laravel-repositories | src/RepositoryGenerator.php | RepositoryGenerator.makeContract | protected function makeContract()
{
$full_path = $this->getFullContractPath();
if (file_exists($full_path)) {
return true;
}
$contract_contents = str_replace(
[
'%%MODEL_BASENAME%%',
'%%MODEL_NAME%%',
'%%CLASS_NAME%%',
'%%NAMESPACE%%',
],
[
$this->getModelBasename(),
$this->getModelName(),
$this->getContractBaseName(),
trim($this->getContractsNamespace(), '\\'),
],
$this->contentsFromStub('Contract')
);
if (!file_exists(dirname($full_path))) {
mkdir(dirname($full_path), 0755, true);
}
file_put_contents($full_path, $contract_contents);
} | php | protected function makeContract()
{
$full_path = $this->getFullContractPath();
if (file_exists($full_path)) {
return true;
}
$contract_contents = str_replace(
[
'%%MODEL_BASENAME%%',
'%%MODEL_NAME%%',
'%%CLASS_NAME%%',
'%%NAMESPACE%%',
],
[
$this->getModelBasename(),
$this->getModelName(),
$this->getContractBaseName(),
trim($this->getContractsNamespace(), '\\'),
],
$this->contentsFromStub('Contract')
);
if (!file_exists(dirname($full_path))) {
mkdir(dirname($full_path), 0755, true);
}
file_put_contents($full_path, $contract_contents);
} | [
"protected",
"function",
"makeContract",
"(",
")",
"{",
"$",
"full_path",
"=",
"$",
"this",
"->",
"getFullContractPath",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"full_path",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"contract_contents",
"=",
"str_replace",
"(",
"[",
"'%%MODEL_BASENAME%%'",
",",
"'%%MODEL_NAME%%'",
",",
"'%%CLASS_NAME%%'",
",",
"'%%NAMESPACE%%'",
",",
"]",
",",
"[",
"$",
"this",
"->",
"getModelBasename",
"(",
")",
",",
"$",
"this",
"->",
"getModelName",
"(",
")",
",",
"$",
"this",
"->",
"getContractBaseName",
"(",
")",
",",
"trim",
"(",
"$",
"this",
"->",
"getContractsNamespace",
"(",
")",
",",
"'\\\\'",
")",
",",
"]",
",",
"$",
"this",
"->",
"contentsFromStub",
"(",
"'Contract'",
")",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"full_path",
")",
")",
")",
"{",
"mkdir",
"(",
"dirname",
"(",
"$",
"full_path",
")",
",",
"0755",
",",
"true",
")",
";",
"}",
"file_put_contents",
"(",
"$",
"full_path",
",",
"$",
"contract_contents",
")",
";",
"}"
] | Make contract file
@method makeContract
@return string The fully qualified contract name | [
"Make",
"contract",
"file"
] | 3146285be911728fe7b00cf27d2494ad22b773dc | https://github.com/CroudTech/laravel-repositories/blob/3146285be911728fe7b00cf27d2494ad22b773dc/src/RepositoryGenerator.php#L131-L156 | train |
p2made/yii2-p2y2-base | helpers/AssetsSettings.php | AssetsSettings.assetsSettings | public static function assetsSettings()
{
if(isset(self::$_assetsSettings)) {
return self::$_assetsSettings;
}
return self::getSettingsBlock(self::BLOCK_NAME);
} | php | public static function assetsSettings()
{
if(isset(self::$_assetsSettings)) {
return self::$_assetsSettings;
}
return self::getSettingsBlock(self::BLOCK_NAME);
} | [
"public",
"static",
"function",
"assetsSettings",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_assetsSettings",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_assetsSettings",
";",
"}",
"return",
"self",
"::",
"getSettingsBlock",
"(",
"self",
"::",
"BLOCK_NAME",
")",
";",
"}"
] | Get assets settings
@return array | false
@default false | [
"Get",
"assets",
"settings"
] | face3df8794407cdc8178ed64c06cc760c449de2 | https://github.com/p2made/yii2-p2y2-base/blob/face3df8794407cdc8178ed64c06cc760c449de2/helpers/AssetsSettings.php#L62-L69 | train |
p2made/yii2-p2y2-base | helpers/AssetsSettings.php | AssetsSettings.assetsUseStatic | public static function assetsUseStatic()
{
if(isset(self::$_useStatic)) {
return self::$_useStatic;
}
return self::getSettingsItem(
self::$_useStatic,
self::assetsSettings(),
self::USE_STATIC,
self::DEFAULT_USE_STATIC
);
} | php | public static function assetsUseStatic()
{
if(isset(self::$_useStatic)) {
return self::$_useStatic;
}
return self::getSettingsItem(
self::$_useStatic,
self::assetsSettings(),
self::USE_STATIC,
self::DEFAULT_USE_STATIC
);
} | [
"public",
"static",
"function",
"assetsUseStatic",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_useStatic",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_useStatic",
";",
"}",
"return",
"self",
"::",
"getSettingsItem",
"(",
"self",
"::",
"$",
"_useStatic",
",",
"self",
"::",
"assetsSettings",
"(",
")",
",",
"self",
"::",
"USE_STATIC",
",",
"self",
"::",
"DEFAULT_USE_STATIC",
")",
";",
"}"
] | Get assetsUseStatic setting - use static resources
@return boolean
@default false | [
"Get",
"assetsUseStatic",
"setting",
"-",
"use",
"static",
"resources"
] | face3df8794407cdc8178ed64c06cc760c449de2 | https://github.com/p2made/yii2-p2y2-base/blob/face3df8794407cdc8178ed64c06cc760c449de2/helpers/AssetsSettings.php#L76-L88 | train |
p2made/yii2-p2y2-base | helpers/AssetsSettings.php | AssetsSettings.assetsStaticEnd | public static function assetsStaticEnd()
{
if(isset(self::$_staticEnd)) {
return self::$_staticEnd;
}
return self::getSettingsItem(
self::$_staticEnd,
self::assetsSettings(),
self::STATIC_END,
self::DEFAULT_STATIC_END
);
} | php | public static function assetsStaticEnd()
{
if(isset(self::$_staticEnd)) {
return self::$_staticEnd;
}
return self::getSettingsItem(
self::$_staticEnd,
self::assetsSettings(),
self::STATIC_END,
self::DEFAULT_STATIC_END
);
} | [
"public",
"static",
"function",
"assetsStaticEnd",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_staticEnd",
")",
")",
"{",
"return",
"self",
"::",
"$",
"_staticEnd",
";",
"}",
"return",
"self",
"::",
"getSettingsItem",
"(",
"self",
"::",
"$",
"_staticEnd",
",",
"self",
"::",
"assetsSettings",
"(",
")",
",",
"self",
"::",
"STATIC_END",
",",
"self",
"::",
"DEFAULT_STATIC_END",
")",
";",
"}"
] | Get assetsStaticEnd setting - static application end
@return array | false
@default false | [
"Get",
"assetsStaticEnd",
"setting",
"-",
"static",
"application",
"end"
] | face3df8794407cdc8178ed64c06cc760c449de2 | https://github.com/p2made/yii2-p2y2-base/blob/face3df8794407cdc8178ed64c06cc760c449de2/helpers/AssetsSettings.php#L95-L107 | train |
InnovaLangues/LexiconBundle | Entity/Lemma.php | Lemma.setCategory | public function setCategory(\Innova\LexiconBundle\Entity\Category $category = null)
{
$this->category = $category;
return $this;
} | php | public function setCategory(\Innova\LexiconBundle\Entity\Category $category = null)
{
$this->category = $category;
return $this;
} | [
"public",
"function",
"setCategory",
"(",
"\\",
"Innova",
"\\",
"LexiconBundle",
"\\",
"Entity",
"\\",
"Category",
"$",
"category",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"category",
"=",
"$",
"category",
";",
"return",
"$",
"this",
";",
"}"
] | Set category.
@param \Innova\LexiconBundle\Entity\Category $category
@return Lemma | [
"Set",
"category",
"."
] | 38684b8a6c9f4636c7eb4d97f793844c2f703cb7 | https://github.com/InnovaLangues/LexiconBundle/blob/38684b8a6c9f4636c7eb4d97f793844c2f703cb7/Entity/Lemma.php#L185-L190 | train |
InnovaLangues/LexiconBundle | Entity/Lemma.php | Lemma.setSubcategory | public function setSubcategory(\Innova\LexiconBundle\Entity\Subcategory $subcategory = null)
{
$this->subcategory = $subcategory;
return $this;
} | php | public function setSubcategory(\Innova\LexiconBundle\Entity\Subcategory $subcategory = null)
{
$this->subcategory = $subcategory;
return $this;
} | [
"public",
"function",
"setSubcategory",
"(",
"\\",
"Innova",
"\\",
"LexiconBundle",
"\\",
"Entity",
"\\",
"Subcategory",
"$",
"subcategory",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"subcategory",
"=",
"$",
"subcategory",
";",
"return",
"$",
"this",
";",
"}"
] | Set subcategory.
@param \Innova\LexiconBundle\Entity\Subcategory $subcategory
@return Lemma | [
"Set",
"subcategory",
"."
] | 38684b8a6c9f4636c7eb4d97f793844c2f703cb7 | https://github.com/InnovaLangues/LexiconBundle/blob/38684b8a6c9f4636c7eb4d97f793844c2f703cb7/Entity/Lemma.php#L209-L214 | train |
wearenolte/wp-acf | src/Acf/Transforms/PostObject.php | PostObject.transform_sub_post_fields | public static function transform_sub_post_fields( &$field ) {
if ( is_array( $field['value'] ) ) {
$data = [];
foreach ( $field['value'] as $post_id ) {
$data[] = Acf::get_post_field( $post_id );
}
$field['value'] = $data;
} else {
$field['value'] = Acf::get_post_field( $field['value'] );
}
} | php | public static function transform_sub_post_fields( &$field ) {
if ( is_array( $field['value'] ) ) {
$data = [];
foreach ( $field['value'] as $post_id ) {
$data[] = Acf::get_post_field( $post_id );
}
$field['value'] = $data;
} else {
$field['value'] = Acf::get_post_field( $field['value'] );
}
} | [
"public",
"static",
"function",
"transform_sub_post_fields",
"(",
"&",
"$",
"field",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"field",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"field",
"[",
"'value'",
"]",
"as",
"$",
"post_id",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"Acf",
"::",
"get_post_field",
"(",
"$",
"post_id",
")",
";",
"}",
"$",
"field",
"[",
"'value'",
"]",
"=",
"$",
"data",
";",
"}",
"else",
"{",
"$",
"field",
"[",
"'value'",
"]",
"=",
"Acf",
"::",
"get_post_field",
"(",
"$",
"field",
"[",
"'value'",
"]",
")",
";",
"}",
"}"
] | Transform to get the WP and ACF fields of the sub post.
@param array $field The field.
@return array | [
"Transform",
"to",
"get",
"the",
"WP",
"and",
"ACF",
"fields",
"of",
"the",
"sub",
"post",
"."
] | 2f5093438d637fa0eca42ad6d10f6b433ec078b2 | https://github.com/wearenolte/wp-acf/blob/2f5093438d637fa0eca42ad6d10f6b433ec078b2/src/Acf/Transforms/PostObject.php#L31-L41 | train |
koolkode/k2 | src/Kernel/Kernel.php | Kernel.createContainer | protected function createContainer(ContainerModuleLoader $loader, ScopeLoader $scopes)
{
$contextCachePath = $this->cacheDirectory . DIRECTORY_SEPARATOR . $this->contextName;
$cacheFile = $contextCachePath . DIRECTORY_SEPARATOR . 'container.php';
$containerTypeName = __NAMESPACE__ . '\\CompiledContainer';
$proxyPath = Filesystem::createDirectory($contextCachePath . DIRECTORY_SEPARATOR . 'scoped');
$scopedProxies = [];
foreach($scopes as $scope)
{
foreach($scope->getProxyTypeNames() as $typeName)
{
$scopedProxies[] = $typeName;
}
}
if(!is_file($cacheFile) || $this->cache->isModified())
{
$builder = $this->createContainerBuilder();
foreach($this->komponents as $komponent)
{
$komponent->build($builder);
}
foreach($loader as $module)
{
$module->build($builder);
}
$this->build($builder);
if($this->isInstrumentationEnabled())
{
$manager = $this->getManifest();
}
else
{
$manager = new ReflectionTypeInfoManager();
}
$compiler = new ContainerCompiler($manager, $containerTypeName);
$code = $compiler->compile($builder, $proxyPath, $scopedProxies);
Filesystem::writeFile($cacheFile, $code);
}
require_once $cacheFile;
return new $containerTypeName($this->getContainerParams());
} | php | protected function createContainer(ContainerModuleLoader $loader, ScopeLoader $scopes)
{
$contextCachePath = $this->cacheDirectory . DIRECTORY_SEPARATOR . $this->contextName;
$cacheFile = $contextCachePath . DIRECTORY_SEPARATOR . 'container.php';
$containerTypeName = __NAMESPACE__ . '\\CompiledContainer';
$proxyPath = Filesystem::createDirectory($contextCachePath . DIRECTORY_SEPARATOR . 'scoped');
$scopedProxies = [];
foreach($scopes as $scope)
{
foreach($scope->getProxyTypeNames() as $typeName)
{
$scopedProxies[] = $typeName;
}
}
if(!is_file($cacheFile) || $this->cache->isModified())
{
$builder = $this->createContainerBuilder();
foreach($this->komponents as $komponent)
{
$komponent->build($builder);
}
foreach($loader as $module)
{
$module->build($builder);
}
$this->build($builder);
if($this->isInstrumentationEnabled())
{
$manager = $this->getManifest();
}
else
{
$manager = new ReflectionTypeInfoManager();
}
$compiler = new ContainerCompiler($manager, $containerTypeName);
$code = $compiler->compile($builder, $proxyPath, $scopedProxies);
Filesystem::writeFile($cacheFile, $code);
}
require_once $cacheFile;
return new $containerTypeName($this->getContainerParams());
} | [
"protected",
"function",
"createContainer",
"(",
"ContainerModuleLoader",
"$",
"loader",
",",
"ScopeLoader",
"$",
"scopes",
")",
"{",
"$",
"contextCachePath",
"=",
"$",
"this",
"->",
"cacheDirectory",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"contextName",
";",
"$",
"cacheFile",
"=",
"$",
"contextCachePath",
".",
"DIRECTORY_SEPARATOR",
".",
"'container.php'",
";",
"$",
"containerTypeName",
"=",
"__NAMESPACE__",
".",
"'\\\\CompiledContainer'",
";",
"$",
"proxyPath",
"=",
"Filesystem",
"::",
"createDirectory",
"(",
"$",
"contextCachePath",
".",
"DIRECTORY_SEPARATOR",
".",
"'scoped'",
")",
";",
"$",
"scopedProxies",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"scopes",
"as",
"$",
"scope",
")",
"{",
"foreach",
"(",
"$",
"scope",
"->",
"getProxyTypeNames",
"(",
")",
"as",
"$",
"typeName",
")",
"{",
"$",
"scopedProxies",
"[",
"]",
"=",
"$",
"typeName",
";",
"}",
"}",
"if",
"(",
"!",
"is_file",
"(",
"$",
"cacheFile",
")",
"||",
"$",
"this",
"->",
"cache",
"->",
"isModified",
"(",
")",
")",
"{",
"$",
"builder",
"=",
"$",
"this",
"->",
"createContainerBuilder",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"komponents",
"as",
"$",
"komponent",
")",
"{",
"$",
"komponent",
"->",
"build",
"(",
"$",
"builder",
")",
";",
"}",
"foreach",
"(",
"$",
"loader",
"as",
"$",
"module",
")",
"{",
"$",
"module",
"->",
"build",
"(",
"$",
"builder",
")",
";",
"}",
"$",
"this",
"->",
"build",
"(",
"$",
"builder",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isInstrumentationEnabled",
"(",
")",
")",
"{",
"$",
"manager",
"=",
"$",
"this",
"->",
"getManifest",
"(",
")",
";",
"}",
"else",
"{",
"$",
"manager",
"=",
"new",
"ReflectionTypeInfoManager",
"(",
")",
";",
"}",
"$",
"compiler",
"=",
"new",
"ContainerCompiler",
"(",
"$",
"manager",
",",
"$",
"containerTypeName",
")",
";",
"$",
"code",
"=",
"$",
"compiler",
"->",
"compile",
"(",
"$",
"builder",
",",
"$",
"proxyPath",
",",
"$",
"scopedProxies",
")",
";",
"Filesystem",
"::",
"writeFile",
"(",
"$",
"cacheFile",
",",
"$",
"code",
")",
";",
"}",
"require_once",
"$",
"cacheFile",
";",
"return",
"new",
"$",
"containerTypeName",
"(",
"$",
"this",
"->",
"getContainerParams",
"(",
")",
")",
";",
"}"
] | Create the DI container instance.
@param ScopeLoader $scopes
@return ContainerInterface | [
"Create",
"the",
"DI",
"container",
"instance",
"."
] | c425a1bc7d2f8c567b1b0cc724ca9e8be7087397 | https://github.com/koolkode/k2/blob/c425a1bc7d2f8c567b1b0cc724ca9e8be7087397/src/Kernel/Kernel.php#L486-L538 | train |
koolkode/k2 | src/Kernel/Kernel.php | Kernel.createContainerBuilder | protected function createContainerBuilder()
{
$builder = new ContainerBuilder();
foreach($this->getContainerParams() as $k => $v)
{
$builder->setParameter($k, $v);
}
return $builder;
} | php | protected function createContainerBuilder()
{
$builder = new ContainerBuilder();
foreach($this->getContainerParams() as $k => $v)
{
$builder->setParameter($k, $v);
}
return $builder;
} | [
"protected",
"function",
"createContainerBuilder",
"(",
")",
"{",
"$",
"builder",
"=",
"new",
"ContainerBuilder",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getContainerParams",
"(",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"builder",
"->",
"setParameter",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"return",
"$",
"builder",
";",
"}"
] | Create the DI container builder instance.
@return ContainerBuilder | [
"Create",
"the",
"DI",
"container",
"builder",
"instance",
"."
] | c425a1bc7d2f8c567b1b0cc724ca9e8be7087397 | https://github.com/koolkode/k2/blob/c425a1bc7d2f8c567b1b0cc724ca9e8be7087397/src/Kernel/Kernel.php#L545-L555 | train |
koolkode/k2 | src/Kernel/Kernel.php | Kernel.setupInstrumentationProcessor | protected function setupInstrumentationProcessor()
{
$file = $this->cacheDirectory . '/' . $this->contextName . '/instrument.php';
if(is_file($file))
{
$this->instrumentationProcessor = new InstrumentationProcessor($this, require $file);
$this->instrumentationProcessor->registertAutoload();
}
} | php | protected function setupInstrumentationProcessor()
{
$file = $this->cacheDirectory . '/' . $this->contextName . '/instrument.php';
if(is_file($file))
{
$this->instrumentationProcessor = new InstrumentationProcessor($this, require $file);
$this->instrumentationProcessor->registertAutoload();
}
} | [
"protected",
"function",
"setupInstrumentationProcessor",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"cacheDirectory",
".",
"'/'",
".",
"$",
"this",
"->",
"contextName",
".",
"'/instrument.php'",
";",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"instrumentationProcessor",
"=",
"new",
"InstrumentationProcessor",
"(",
"$",
"this",
",",
"require",
"$",
"file",
")",
";",
"$",
"this",
"->",
"instrumentationProcessor",
"->",
"registertAutoload",
"(",
")",
";",
"}",
"}"
] | Setup an instrumentation processor that hooks into the autoloader. | [
"Setup",
"an",
"instrumentation",
"processor",
"that",
"hooks",
"into",
"the",
"autoloader",
"."
] | c425a1bc7d2f8c567b1b0cc724ca9e8be7087397 | https://github.com/koolkode/k2/blob/c425a1bc7d2f8c567b1b0cc724ca9e8be7087397/src/Kernel/Kernel.php#L560-L569 | train |
koolkode/k2 | src/Kernel/Kernel.php | Kernel.bindInitialInstances | protected function bindInitialInstances(ContainerInterface $container)
{
foreach($this->komponents as $komponent)
{
$container->bindInstance(get_class($komponent), $komponent);
}
} | php | protected function bindInitialInstances(ContainerInterface $container)
{
foreach($this->komponents as $komponent)
{
$container->bindInstance(get_class($komponent), $komponent);
}
} | [
"protected",
"function",
"bindInitialInstances",
"(",
"ContainerInterface",
"$",
"container",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"komponents",
"as",
"$",
"komponent",
")",
"{",
"$",
"container",
"->",
"bindInstance",
"(",
"get_class",
"(",
"$",
"komponent",
")",
",",
"$",
"komponent",
")",
";",
"}",
"}"
] | Bind initial object instances to the DI container. | [
"Bind",
"initial",
"object",
"instances",
"to",
"the",
"DI",
"container",
"."
] | c425a1bc7d2f8c567b1b0cc724ca9e8be7087397 | https://github.com/koolkode/k2/blob/c425a1bc7d2f8c567b1b0cc724ca9e8be7087397/src/Kernel/Kernel.php#L574-L580 | train |
ARCANESOFT/Backups | src/Services/BackupStatuses.php | BackupStatuses.runBackups | public static function runBackups($disk = null)
{
try {
$backupJob = BackupJobFactory::createFromArray(config('laravel-backup'));
if ( ! is_null($disk)) {
$backupJob->onlyBackupTo($disk);
}
$backupJob->run();
}
catch (\Exception $ex) {
return false;
}
return true;
} | php | public static function runBackups($disk = null)
{
try {
$backupJob = BackupJobFactory::createFromArray(config('laravel-backup'));
if ( ! is_null($disk)) {
$backupJob->onlyBackupTo($disk);
}
$backupJob->run();
}
catch (\Exception $ex) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"runBackups",
"(",
"$",
"disk",
"=",
"null",
")",
"{",
"try",
"{",
"$",
"backupJob",
"=",
"BackupJobFactory",
"::",
"createFromArray",
"(",
"config",
"(",
"'laravel-backup'",
")",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"disk",
")",
")",
"{",
"$",
"backupJob",
"->",
"onlyBackupTo",
"(",
"$",
"disk",
")",
";",
"}",
"$",
"backupJob",
"->",
"run",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Run the backups.
@param string|null $disk
@return bool | [
"Run",
"the",
"backups",
"."
] | e191f0ccf55c7684173b82b7244fce9c0803bfe0 | https://github.com/ARCANESOFT/Backups/blob/e191f0ccf55c7684173b82b7244fce9c0803bfe0/src/Services/BackupStatuses.php#L50-L66 | train |
ARCANESOFT/Backups | src/Services/BackupStatuses.php | BackupStatuses.clearBackups | public static function clearBackups()
{
try {
$config = config('laravel-backup');
$backupDestinations = BackupDestinationFactory::createFromArray($config['backup']);
$strategy = app($config['cleanup']['strategy']);
$disableNotification = false; // TODO: Create a config for this
(new CleanupJob($backupDestinations, $strategy, $disableNotification))->run();
}
catch (\Exception $ex) {
return false;
}
return true;
} | php | public static function clearBackups()
{
try {
$config = config('laravel-backup');
$backupDestinations = BackupDestinationFactory::createFromArray($config['backup']);
$strategy = app($config['cleanup']['strategy']);
$disableNotification = false; // TODO: Create a config for this
(new CleanupJob($backupDestinations, $strategy, $disableNotification))->run();
}
catch (\Exception $ex) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"clearBackups",
"(",
")",
"{",
"try",
"{",
"$",
"config",
"=",
"config",
"(",
"'laravel-backup'",
")",
";",
"$",
"backupDestinations",
"=",
"BackupDestinationFactory",
"::",
"createFromArray",
"(",
"$",
"config",
"[",
"'backup'",
"]",
")",
";",
"$",
"strategy",
"=",
"app",
"(",
"$",
"config",
"[",
"'cleanup'",
"]",
"[",
"'strategy'",
"]",
")",
";",
"$",
"disableNotification",
"=",
"false",
";",
"// TODO: Create a config for this",
"(",
"new",
"CleanupJob",
"(",
"$",
"backupDestinations",
",",
"$",
"strategy",
",",
"$",
"disableNotification",
")",
")",
"->",
"run",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Clean the backups.
@return bool | [
"Clean",
"the",
"backups",
"."
] | e191f0ccf55c7684173b82b7244fce9c0803bfe0 | https://github.com/ARCANESOFT/Backups/blob/e191f0ccf55c7684173b82b7244fce9c0803bfe0/src/Services/BackupStatuses.php#L73-L91 | train |
itkg/core | src/Itkg/Core/Cache/Adapter/Chain/UseAllStrategy.php | UseAllStrategy.get | public function get(array $adapters, CacheableInterface $item)
{
foreach ($adapters as $adapter) {
if (false !== $value = $adapter->get($item)) {
return $value;
}
}
return false;
} | php | public function get(array $adapters, CacheableInterface $item)
{
foreach ($adapters as $adapter) {
if (false !== $value = $adapter->get($item)) {
return $value;
}
}
return false;
} | [
"public",
"function",
"get",
"(",
"array",
"$",
"adapters",
",",
"CacheableInterface",
"$",
"item",
")",
"{",
"foreach",
"(",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"value",
"=",
"$",
"adapter",
"->",
"get",
"(",
"$",
"item",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get cache from any adapter if contains
@param array $adapters
@param CacheableInterface $item
@throws UnhandledCacheException
@return mixed | [
"Get",
"cache",
"from",
"any",
"adapter",
"if",
"contains"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Cache/Adapter/Chain/UseAllStrategy.php#L37-L47 | train |
itkg/core | src/Itkg/Core/Cache/Adapter/Chain/UseAllStrategy.php | UseAllStrategy.set | public function set(array $adapters, CacheableInterface $item)
{
foreach ($adapters as $adapter) {
$adapter->set($item);
}
} | php | public function set(array $adapters, CacheableInterface $item)
{
foreach ($adapters as $adapter) {
$adapter->set($item);
}
} | [
"public",
"function",
"set",
"(",
"array",
"$",
"adapters",
",",
"CacheableInterface",
"$",
"item",
")",
"{",
"foreach",
"(",
"$",
"adapters",
"as",
"$",
"adapter",
")",
"{",
"$",
"adapter",
"->",
"set",
"(",
"$",
"item",
")",
";",
"}",
"}"
] | Set cache to all adapters
@param array $adapters
@param CacheableInterface $item
@throws UnhandledCacheException
@return void | [
"Set",
"cache",
"to",
"all",
"adapters"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Cache/Adapter/Chain/UseAllStrategy.php#L57-L62 | train |
modulusphp/http | Middleware/MustNotExceedAllowedRequests.php | MustNotExceedAllowedRequests.autoAssign | private function autoAssign($attributes = null)
{
if (!is_array($attributes)) return false;
$this->max = isset($attributes[0]) ? $attributes[0] : $this->max;
$this->minutes = isset($attributes[1]) ? $attributes[1] : 1;
$this->decay = isset($attributes[1]) ? strtotime($attributes[1] . ' minutes', 0) : $this->decay;
return true;
} | php | private function autoAssign($attributes = null)
{
if (!is_array($attributes)) return false;
$this->max = isset($attributes[0]) ? $attributes[0] : $this->max;
$this->minutes = isset($attributes[1]) ? $attributes[1] : 1;
$this->decay = isset($attributes[1]) ? strtotime($attributes[1] . ' minutes', 0) : $this->decay;
return true;
} | [
"private",
"function",
"autoAssign",
"(",
"$",
"attributes",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"attributes",
")",
")",
"return",
"false",
";",
"$",
"this",
"->",
"max",
"=",
"isset",
"(",
"$",
"attributes",
"[",
"0",
"]",
")",
"?",
"$",
"attributes",
"[",
"0",
"]",
":",
"$",
"this",
"->",
"max",
";",
"$",
"this",
"->",
"minutes",
"=",
"isset",
"(",
"$",
"attributes",
"[",
"1",
"]",
")",
"?",
"$",
"attributes",
"[",
"1",
"]",
":",
"1",
";",
"$",
"this",
"->",
"decay",
"=",
"isset",
"(",
"$",
"attributes",
"[",
"1",
"]",
")",
"?",
"strtotime",
"(",
"$",
"attributes",
"[",
"1",
"]",
".",
"' minutes'",
",",
"0",
")",
":",
"$",
"this",
"->",
"decay",
";",
"return",
"true",
";",
"}"
] | Set request attributes
@param array|mixed|null $attributes
@return void | [
"Set",
"request",
"attributes"
] | fc5c0f2b582a04de1685578d3fb790686a0a240c | https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Middleware/MustNotExceedAllowedRequests.php#L98-L107 | train |
modulusphp/http | Middleware/MustNotExceedAllowedRequests.php | MustNotExceedAllowedRequests.canProceed | private function canProceed($request) : bool
{
$time = $this->decay - date('s');
if ($request->cookies->has('clusters')) {
$value = $request->cookie('clusters');
$value = $this->hashids->decode($value)[0] - 1;
if ($value == 0) {
$this->withHeaders($request, $value, $time);
return false;
}
$this->cookie->setExpireTime($time);
$this->cookie->setValue($this->hashids->encode($value));
$this->withHeaders($request, $value);
return true;
}
$this->cookie->setValue($this->hashids->encode($this->max));
$this->withHeaders($request, $this->max);
return true;
} | php | private function canProceed($request) : bool
{
$time = $this->decay - date('s');
if ($request->cookies->has('clusters')) {
$value = $request->cookie('clusters');
$value = $this->hashids->decode($value)[0] - 1;
if ($value == 0) {
$this->withHeaders($request, $value, $time);
return false;
}
$this->cookie->setExpireTime($time);
$this->cookie->setValue($this->hashids->encode($value));
$this->withHeaders($request, $value);
return true;
}
$this->cookie->setValue($this->hashids->encode($this->max));
$this->withHeaders($request, $this->max);
return true;
} | [
"private",
"function",
"canProceed",
"(",
"$",
"request",
")",
":",
"bool",
"{",
"$",
"time",
"=",
"$",
"this",
"->",
"decay",
"-",
"date",
"(",
"'s'",
")",
";",
"if",
"(",
"$",
"request",
"->",
"cookies",
"->",
"has",
"(",
"'clusters'",
")",
")",
"{",
"$",
"value",
"=",
"$",
"request",
"->",
"cookie",
"(",
"'clusters'",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"hashids",
"->",
"decode",
"(",
"$",
"value",
")",
"[",
"0",
"]",
"-",
"1",
";",
"if",
"(",
"$",
"value",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"withHeaders",
"(",
"$",
"request",
",",
"$",
"value",
",",
"$",
"time",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"cookie",
"->",
"setExpireTime",
"(",
"$",
"time",
")",
";",
"$",
"this",
"->",
"cookie",
"->",
"setValue",
"(",
"$",
"this",
"->",
"hashids",
"->",
"encode",
"(",
"$",
"value",
")",
")",
";",
"$",
"this",
"->",
"withHeaders",
"(",
"$",
"request",
",",
"$",
"value",
")",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"cookie",
"->",
"setValue",
"(",
"$",
"this",
"->",
"hashids",
"->",
"encode",
"(",
"$",
"this",
"->",
"max",
")",
")",
";",
"$",
"this",
"->",
"withHeaders",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"max",
")",
";",
"return",
"true",
";",
"}"
] | Check if request can proceed
@param \Modulus\Http\Request $request
@return bool | [
"Check",
"if",
"request",
"can",
"proceed"
] | fc5c0f2b582a04de1685578d3fb790686a0a240c | https://github.com/modulusphp/http/blob/fc5c0f2b582a04de1685578d3fb790686a0a240c/Middleware/MustNotExceedAllowedRequests.php#L115-L140 | train |
RichardTrujilloTorres/validators | src/Validators/Traits/ArrayTrait.php | ArrayTrait.inArray | public function inArray($values, $args, $do, $strict = false)
{
if (!is_callable($do)) {
throw new \InvalidArgumentException('Third argument must be a callable');
}
foreach ($values as $single) {
$result = $do($single, $args);
if ($strict && !$result) {
break;
}
}
return $result;
} | php | public function inArray($values, $args, $do, $strict = false)
{
if (!is_callable($do)) {
throw new \InvalidArgumentException('Third argument must be a callable');
}
foreach ($values as $single) {
$result = $do($single, $args);
if ($strict && !$result) {
break;
}
}
return $result;
} | [
"public",
"function",
"inArray",
"(",
"$",
"values",
",",
"$",
"args",
",",
"$",
"do",
",",
"$",
"strict",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"do",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Third argument must be a callable'",
")",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"single",
")",
"{",
"$",
"result",
"=",
"$",
"do",
"(",
"$",
"single",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"strict",
"&&",
"!",
"$",
"result",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Performs an operation in a given array.
It stops if 'strict' is set to true and the result of the operation is false.
@param array $values The array
@param mixed $args The arguments to pass to the operation
@param callable $do The operation
@return bool | [
"Performs",
"an",
"operation",
"in",
"a",
"given",
"array",
".",
"It",
"stops",
"if",
"strict",
"is",
"set",
"to",
"true",
"and",
"the",
"result",
"of",
"the",
"operation",
"is",
"false",
"."
] | e29ff479d816c3f8a931bfbefedd0642dc50ea91 | https://github.com/RichardTrujilloTorres/validators/blob/e29ff479d816c3f8a931bfbefedd0642dc50ea91/src/Validators/Traits/ArrayTrait.php#L24-L38 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Loader/Bridge/Form/Type/EntityCollectionType.php | EntityCollectionType.registerLoader | public function registerLoader($alias, $loader)
{
if ($this->hasLoader($alias)) {
throw new \RuntimeException(sprintf('Alias "%s" already used by another form loader', $alias));
}
$this->loaders[$alias] = $loader;
} | php | public function registerLoader($alias, $loader)
{
if ($this->hasLoader($alias)) {
throw new \RuntimeException(sprintf('Alias "%s" already used by another form loader', $alias));
}
$this->loaders[$alias] = $loader;
} | [
"public",
"function",
"registerLoader",
"(",
"$",
"alias",
",",
"$",
"loader",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasLoader",
"(",
"$",
"alias",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Alias \"%s\" already used by another form loader'",
",",
"$",
"alias",
")",
")",
";",
"}",
"$",
"this",
"->",
"loaders",
"[",
"$",
"alias",
"]",
"=",
"$",
"loader",
";",
"}"
] | Register a loader.
@param $alias
@param $loader | [
"Register",
"a",
"loader",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Loader/Bridge/Form/Type/EntityCollectionType.php#L94-L101 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Loader/Bridge/Form/Type/EntityCollectionType.php | EntityCollectionType.getLoader | private function getLoader($alias)
{
if (!$this->hasLoader($alias)) {
throw new \RuntimeException(sprintf('Form loader with alias "%s" not found.', $alias));
}
return $this->loaders[$alias];
} | php | private function getLoader($alias)
{
if (!$this->hasLoader($alias)) {
throw new \RuntimeException(sprintf('Form loader with alias "%s" not found.', $alias));
}
return $this->loaders[$alias];
} | [
"private",
"function",
"getLoader",
"(",
"$",
"alias",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLoader",
"(",
"$",
"alias",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Form loader with alias \"%s\" not found.'",
",",
"$",
"alias",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"loaders",
"[",
"$",
"alias",
"]",
";",
"}"
] | Get a loader by his alias.
@param $alias
@return mixed | [
"Get",
"a",
"loader",
"by",
"his",
"alias",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Loader/Bridge/Form/Type/EntityCollectionType.php#L122-L129 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Map/C2MTableMap.php | C2MTableMap.doInsert | public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(C2MTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from C2M object
}
// Set the correct dbName
$query = C2MQuery::create()->mergeWith($criteria);
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
return $con->transaction(function () use ($con, $query) {
return $query->doInsert($con);
});
} | php | public static function doInsert($criteria, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(C2MTableMap::DATABASE_NAME);
}
if ($criteria instanceof Criteria) {
$criteria = clone $criteria; // rename for clarity
} else {
$criteria = $criteria->buildCriteria(); // build Criteria from C2M object
}
// Set the correct dbName
$query = C2MQuery::create()->mergeWith($criteria);
// use transaction because $criteria could contain info
// for more than one table (I guess, conceivably)
return $con->transaction(function () use ($con, $query) {
return $query->doInsert($con);
});
} | [
"public",
"static",
"function",
"doInsert",
"(",
"$",
"criteria",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"con",
")",
"{",
"$",
"con",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getWriteConnection",
"(",
"C2MTableMap",
"::",
"DATABASE_NAME",
")",
";",
"}",
"if",
"(",
"$",
"criteria",
"instanceof",
"Criteria",
")",
"{",
"$",
"criteria",
"=",
"clone",
"$",
"criteria",
";",
"// rename for clarity",
"}",
"else",
"{",
"$",
"criteria",
"=",
"$",
"criteria",
"->",
"buildCriteria",
"(",
")",
";",
"// build Criteria from C2M object",
"}",
"// Set the correct dbName",
"$",
"query",
"=",
"C2MQuery",
"::",
"create",
"(",
")",
"->",
"mergeWith",
"(",
"$",
"criteria",
")",
";",
"// use transaction because $criteria could contain info",
"// for more than one table (I guess, conceivably)",
"return",
"$",
"con",
"->",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"con",
",",
"$",
"query",
")",
"{",
"return",
"$",
"query",
"->",
"doInsert",
"(",
"$",
"con",
")",
";",
"}",
")",
";",
"}"
] | Performs an INSERT on the database, given a C2M or Criteria object.
@param mixed $criteria Criteria or C2M object containing data that is used to create the INSERT statement.
@param ConnectionInterface $con the ConnectionInterface connection to use
@return mixed The new primary key.
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException. | [
"Performs",
"an",
"INSERT",
"on",
"the",
"database",
"given",
"a",
"C2M",
"or",
"Criteria",
"object",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Map/C2MTableMap.php#L464-L485 | train |
asaokamei/ScoreSql | src/Paginate/Pager.php | Pager.loadQuery | protected function loadQuery()
{
if( !isset( $this->session[ $this->saveID ] ) ) {
return;
}
$saved = $this->session[ $this->saveID ];
$this->inputs = array_merge( $saved[ 'inputs' ], $this->inputs );
$this->perPage = $saved[ 'perPage' ];
if( $currPage=$this->getKey($this->pager) ) {
$this->currPage = $currPage;
} else{
$this->currPage = $saved['currPage'];
}
} | php | protected function loadQuery()
{
if( !isset( $this->session[ $this->saveID ] ) ) {
return;
}
$saved = $this->session[ $this->saveID ];
$this->inputs = array_merge( $saved[ 'inputs' ], $this->inputs );
$this->perPage = $saved[ 'perPage' ];
if( $currPage=$this->getKey($this->pager) ) {
$this->currPage = $currPage;
} else{
$this->currPage = $saved['currPage'];
}
} | [
"protected",
"function",
"loadQuery",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"session",
"[",
"$",
"this",
"->",
"saveID",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"saved",
"=",
"$",
"this",
"->",
"session",
"[",
"$",
"this",
"->",
"saveID",
"]",
";",
"$",
"this",
"->",
"inputs",
"=",
"array_merge",
"(",
"$",
"saved",
"[",
"'inputs'",
"]",
",",
"$",
"this",
"->",
"inputs",
")",
";",
"$",
"this",
"->",
"perPage",
"=",
"$",
"saved",
"[",
"'perPage'",
"]",
";",
"if",
"(",
"$",
"currPage",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"this",
"->",
"pager",
")",
")",
"{",
"$",
"this",
"->",
"currPage",
"=",
"$",
"currPage",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"currPage",
"=",
"$",
"saved",
"[",
"'currPage'",
"]",
";",
"}",
"}"
] | loads query information from saved session. | [
"loads",
"query",
"information",
"from",
"saved",
"session",
"."
] | f1fce28476629e98b3c4c1216859c7f5309de7a1 | https://github.com/asaokamei/ScoreSql/blob/f1fce28476629e98b3c4c1216859c7f5309de7a1/src/Paginate/Pager.php#L111-L124 | train |
asaokamei/ScoreSql | src/Paginate/Pager.php | Pager.saveQuery | protected function saveQuery()
{
$this->session[ $this->saveID ] = [
'perPage' => $this->perPage,
'currPage' => $this->currPage,
'inputs' => $this->inputs,
];
} | php | protected function saveQuery()
{
$this->session[ $this->saveID ] = [
'perPage' => $this->perPage,
'currPage' => $this->currPage,
'inputs' => $this->inputs,
];
} | [
"protected",
"function",
"saveQuery",
"(",
")",
"{",
"$",
"this",
"->",
"session",
"[",
"$",
"this",
"->",
"saveID",
"]",
"=",
"[",
"'perPage'",
"=>",
"$",
"this",
"->",
"perPage",
",",
"'currPage'",
"=>",
"$",
"this",
"->",
"currPage",
",",
"'inputs'",
"=>",
"$",
"this",
"->",
"inputs",
",",
"]",
";",
"}"
] | saves query information into session. | [
"saves",
"query",
"information",
"into",
"session",
"."
] | f1fce28476629e98b3c4c1216859c7f5309de7a1 | https://github.com/asaokamei/ScoreSql/blob/f1fce28476629e98b3c4c1216859c7f5309de7a1/src/Paginate/Pager.php#L129-L136 | train |
sndsgd/form | src/form/field/ValueField.php | ValueField.setDefaultValue | public function setDefaultValue($defaultValue): FieldInterface
{
if (!is_scalar($defaultValue) && !is_null($defaultValue)) {
throw new \InvalidArgumentException(
"invalid value provided for 'defaultValue'; ".
"expecting either a scalar or null value"
);
}
$this->defaultValue = $defaultValue;
return $this;
} | php | public function setDefaultValue($defaultValue): FieldInterface
{
if (!is_scalar($defaultValue) && !is_null($defaultValue)) {
throw new \InvalidArgumentException(
"invalid value provided for 'defaultValue'; ".
"expecting either a scalar or null value"
);
}
$this->defaultValue = $defaultValue;
return $this;
} | [
"public",
"function",
"setDefaultValue",
"(",
"$",
"defaultValue",
")",
":",
"FieldInterface",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"defaultValue",
")",
"&&",
"!",
"is_null",
"(",
"$",
"defaultValue",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"invalid value provided for 'defaultValue'; \"",
".",
"\"expecting either a scalar or null value\"",
")",
";",
"}",
"$",
"this",
"->",
"defaultValue",
"=",
"$",
"defaultValue",
";",
"return",
"$",
"this",
";",
"}"
] | Set the default value for the field
@param mixed $defaultValue A scalar value
@return \sndsgd\form\field\ValueField
@throws \InvalidArgumentException | [
"Set",
"the",
"default",
"value",
"for",
"the",
"field"
] | 56b5b9572a8942aea34c97c7c838b871e198e34f | https://github.com/sndsgd/form/blob/56b5b9572a8942aea34c97c7c838b871e198e34f/src/form/field/ValueField.php#L38-L48 | train |
maddoger/yii2-cms-user | backend/controllers/UserController.php | UserController.actionProfile | public function actionProfile()
{
/** @var User $user */
$user = Yii::$app->getUser()->getIdentity();
$model = new MultiModel([
'models' => [
'user' => $user,
'profile' => $user->profile,
],
]);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->addFlash('success', Yii::t('maddoger/user', 'Changes have been saved.'));
return $this->refresh();
} else {
return $this->render('profile', [
'model' => $model,
]);
}
} | php | public function actionProfile()
{
/** @var User $user */
$user = Yii::$app->getUser()->getIdentity();
$model = new MultiModel([
'models' => [
'user' => $user,
'profile' => $user->profile,
],
]);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->addFlash('success', Yii::t('maddoger/user', 'Changes have been saved.'));
return $this->refresh();
} else {
return $this->render('profile', [
'model' => $model,
]);
}
} | [
"public",
"function",
"actionProfile",
"(",
")",
"{",
"/** @var User $user */",
"$",
"user",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getUser",
"(",
")",
"->",
"getIdentity",
"(",
")",
";",
"$",
"model",
"=",
"new",
"MultiModel",
"(",
"[",
"'models'",
"=>",
"[",
"'user'",
"=>",
"$",
"user",
",",
"'profile'",
"=>",
"$",
"user",
"->",
"profile",
",",
"]",
",",
"]",
")",
";",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"addFlash",
"(",
"'success'",
",",
"Yii",
"::",
"t",
"(",
"'maddoger/user'",
",",
"'Changes have been saved.'",
")",
")",
";",
"return",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'profile'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}",
"}"
] | Updates own profile.
If update is successful, the browser will be redirected to the 'view' page.
@return mixed | [
"Updates",
"own",
"profile",
".",
"If",
"update",
"is",
"successful",
"the",
"browser",
"will",
"be",
"redirected",
"to",
"the",
"view",
"page",
"."
] | 6792d1d0d2c0bf01fe87729985b5659de4c1aac1 | https://github.com/maddoger/yii2-cms-user/blob/6792d1d0d2c0bf01fe87729985b5659de4c1aac1/backend/controllers/UserController.php#L179-L198 | train |
gplcart/cli | controllers/commands/ProductClass.php | ProductClass.cmdGetProductClass | public function cmdGetProductClass()
{
$result = $this->getListProductClass();
$this->outputFormat($result);
$this->outputFormatTableProductClass($result);
$this->output();
} | php | public function cmdGetProductClass()
{
$result = $this->getListProductClass();
$this->outputFormat($result);
$this->outputFormatTableProductClass($result);
$this->output();
} | [
"public",
"function",
"cmdGetProductClass",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListProductClass",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableProductClass",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "product-class-get" command | [
"Callback",
"for",
"product",
"-",
"class",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClass.php#L40-L46 | train |
gplcart/cli | controllers/commands/ProductClass.php | ProductClass.cmdDeleteProductClass | public function cmdDeleteProductClass()
{
$id = $this->getParam(0);
$result = null;
if (isset($id)) {
if (empty($id) || !is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->product_class->delete($id);
} else if ($this->getParam('all')) {
$deleted = $count = 0;
foreach ($this->product_class->getList() as $item) {
$count++;
$deleted += (int) $this->product_class->delete($item['product_class_id']);
}
$result = $count && $count == $deleted;
} else {
$this->errorAndExit($this->text('Invalid command'));
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | php | public function cmdDeleteProductClass()
{
$id = $this->getParam(0);
$result = null;
if (isset($id)) {
if (empty($id) || !is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->product_class->delete($id);
} else if ($this->getParam('all')) {
$deleted = $count = 0;
foreach ($this->product_class->getList() as $item) {
$count++;
$deleted += (int) $this->product_class->delete($item['product_class_id']);
}
$result = $count && $count == $deleted;
} else {
$this->errorAndExit($this->text('Invalid command'));
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | [
"public",
"function",
"cmdDeleteProductClass",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"product_class",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"getParam",
"(",
"'all'",
")",
")",
"{",
"$",
"deleted",
"=",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"product_class",
"->",
"getList",
"(",
")",
"as",
"$",
"item",
")",
"{",
"$",
"count",
"++",
";",
"$",
"deleted",
"+=",
"(",
"int",
")",
"$",
"this",
"->",
"product_class",
"->",
"delete",
"(",
"$",
"item",
"[",
"'product_class_id'",
"]",
")",
";",
"}",
"$",
"result",
"=",
"$",
"count",
"&&",
"$",
"count",
"==",
"$",
"deleted",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "product-class-delete" command | [
"Callback",
"for",
"product",
"-",
"class",
"-",
"delete",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClass.php#L51-L84 | train |
gplcart/cli | controllers/commands/ProductClass.php | ProductClass.cmdUpdateProductClass | public function cmdUpdateProductClass()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('product_class');
$this->updateProductClass($params[0]);
$this->output();
} | php | public function cmdUpdateProductClass()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('product_class');
$this->updateProductClass($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateProductClass",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'product_class'",
")",
";",
"$",
"this",
"->",
"updateProductClass",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "product-class-update" command | [
"Callback",
"for",
"product",
"-",
"class",
"-",
"update",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClass.php#L103-L121 | train |
gplcart/cli | controllers/commands/ProductClass.php | ProductClass.addProductClass | protected function addProductClass()
{
if (!$this->isError()) {
$id = $this->product_class->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | php | protected function addProductClass()
{
if (!$this->isError()) {
$id = $this->product_class->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | [
"protected",
"function",
"addProductClass",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"product_class",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Add a new product class | [
"Add",
"a",
"new",
"product",
"class"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClass.php#L176-L185 | train |
gplcart/cli | controllers/commands/ProductClass.php | ProductClass.submitAddProductClass | protected function submitAddProductClass()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('product_class');
$this->addProductClass();
} | php | protected function submitAddProductClass()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('product_class');
$this->addProductClass();
} | [
"protected",
"function",
"submitAddProductClass",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'product_class'",
")",
";",
"$",
"this",
"->",
"addProductClass",
"(",
")",
";",
"}"
] | Add a new product class at once | [
"Add",
"a",
"new",
"product",
"class",
"at",
"once"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClass.php#L201-L206 | train |
gplcart/cli | controllers/commands/ProductClass.php | ProductClass.wizardAddProductClass | protected function wizardAddProductClass()
{
$this->validatePrompt('title', $this->text('Title'), 'product_class');
$this->validatePrompt('status', $this->text('Status'), 'product_class', 0);
$this->validateComponent('product_class');
$this->addProductClass();
} | php | protected function wizardAddProductClass()
{
$this->validatePrompt('title', $this->text('Title'), 'product_class');
$this->validatePrompt('status', $this->text('Status'), 'product_class', 0);
$this->validateComponent('product_class');
$this->addProductClass();
} | [
"protected",
"function",
"wizardAddProductClass",
"(",
")",
"{",
"$",
"this",
"->",
"validatePrompt",
"(",
"'title'",
",",
"$",
"this",
"->",
"text",
"(",
"'Title'",
")",
",",
"'product_class'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'product_class'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'product_class'",
")",
";",
"$",
"this",
"->",
"addProductClass",
"(",
")",
";",
"}"
] | Add a new product class step by step | [
"Add",
"a",
"new",
"product",
"class",
"step",
"by",
"step"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/ProductClass.php#L211-L217 | train |
manialib/manialink | src/Manialib/Manialink/Utils.php | Utils.getAlignedPos | final public static function getAlignedPos(Base $object, $newHalign, $newValign)
{
$newPosX = self::getAlignedPosX(
$object->getPosnX(), $object->getRealSizeX(), $object->getHalign(), $newHalign);
$newPosY = self::getAlignedPosY(
$object->getPosnY(), $object->getRealSizeY(), $object->getValign(), $newValign);
return array('x' => $newPosX, 'y' => $newPosY);
} | php | final public static function getAlignedPos(Base $object, $newHalign, $newValign)
{
$newPosX = self::getAlignedPosX(
$object->getPosnX(), $object->getRealSizeX(), $object->getHalign(), $newHalign);
$newPosY = self::getAlignedPosY(
$object->getPosnY(), $object->getRealSizeY(), $object->getValign(), $newValign);
return array('x' => $newPosX, 'y' => $newPosY);
} | [
"final",
"public",
"static",
"function",
"getAlignedPos",
"(",
"Base",
"$",
"object",
",",
"$",
"newHalign",
",",
"$",
"newValign",
")",
"{",
"$",
"newPosX",
"=",
"self",
"::",
"getAlignedPosX",
"(",
"$",
"object",
"->",
"getPosnX",
"(",
")",
",",
"$",
"object",
"->",
"getRealSizeX",
"(",
")",
",",
"$",
"object",
"->",
"getHalign",
"(",
")",
",",
"$",
"newHalign",
")",
";",
"$",
"newPosY",
"=",
"self",
"::",
"getAlignedPosY",
"(",
"$",
"object",
"->",
"getPosnY",
"(",
")",
",",
"$",
"object",
"->",
"getRealSizeY",
"(",
")",
",",
"$",
"object",
"->",
"getValign",
"(",
")",
",",
"$",
"newValign",
")",
";",
"return",
"array",
"(",
"'x'",
"=>",
"$",
"newPosX",
",",
"'y'",
"=>",
"$",
"newPosY",
")",
";",
"}"
] | Returns the position of an element in relation to another element and
according to their respective alignments
@param Base Parent element
@param string Horizontal alignement of the element you want to place
@param string Vertical alignement of the element you want to place
@return array Calculated position of the element you want to place. The
array contains 2 elements with "x" and "y" indexes | [
"Returns",
"the",
"position",
"of",
"an",
"element",
"in",
"relation",
"to",
"another",
"element",
"and",
"according",
"to",
"their",
"respective",
"alignments"
] | a24c7979b3aa6b470556e95ba60a76a994bf506c | https://github.com/manialib/manialink/blob/a24c7979b3aa6b470556e95ba60a76a994bf506c/src/Manialib/Manialink/Utils.php#L104-L111 | train |
ekyna/Resource | Search/Elastica/ResourceRepository.php | ResourceRepository.createMatchQuery | protected function createMatchQuery($expression, array $fields = [])
{
if (0 == strlen($expression)) {
return new Query\MatchAll();
}
if (empty($fields)) {
$fields = $this->getDefaultMatchFields();
}
$query = new Query\MultiMatch();
$query
->setQuery($expression)
->setFields($fields);
return $query;
} | php | protected function createMatchQuery($expression, array $fields = [])
{
if (0 == strlen($expression)) {
return new Query\MatchAll();
}
if (empty($fields)) {
$fields = $this->getDefaultMatchFields();
}
$query = new Query\MultiMatch();
$query
->setQuery($expression)
->setFields($fields);
return $query;
} | [
"protected",
"function",
"createMatchQuery",
"(",
"$",
"expression",
",",
"array",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"0",
"==",
"strlen",
"(",
"$",
"expression",
")",
")",
"{",
"return",
"new",
"Query",
"\\",
"MatchAll",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getDefaultMatchFields",
"(",
")",
";",
"}",
"$",
"query",
"=",
"new",
"Query",
"\\",
"MultiMatch",
"(",
")",
";",
"$",
"query",
"->",
"setQuery",
"(",
"$",
"expression",
")",
"->",
"setFields",
"(",
"$",
"fields",
")",
";",
"return",
"$",
"query",
";",
"}"
] | Creates the match query.
@param string $expression
@param array $fields
@return Query\AbstractQuery | [
"Creates",
"the",
"match",
"query",
"."
] | 96ee3d28e02bd9513705408e3bb7f88a76e52f56 | https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Search/Elastica/ResourceRepository.php#L37-L53 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/Image/ImageSizeReducer.php | ImageSizeReducer.writeXML | public function writeXML( \XMLWriter $w, string $elementName = 'ImageSizeReducer' )
{
$w->startElement( $elementName );
$this->writeXMLAttributes( $w );
$w->endElement();
} | php | public function writeXML( \XMLWriter $w, string $elementName = 'ImageSizeReducer' )
{
$w->startElement( $elementName );
$this->writeXMLAttributes( $w );
$w->endElement();
} | [
"public",
"function",
"writeXML",
"(",
"\\",
"XMLWriter",
"$",
"w",
",",
"string",
"$",
"elementName",
"=",
"'ImageSizeReducer'",
")",
"{",
"$",
"w",
"->",
"startElement",
"(",
"$",
"elementName",
")",
";",
"$",
"this",
"->",
"writeXMLAttributes",
"(",
"$",
"w",
")",
";",
"$",
"w",
"->",
"endElement",
"(",
")",
";",
"}"
] | Writes all instance options to an XML element.
@param \XMLWriter $w
@param string $elementName | [
"Writes",
"all",
"instance",
"options",
"to",
"an",
"XML",
"element",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/ImageSizeReducer.php#L171-L178 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/Image/ImageSizeReducer.php | ImageSizeReducer.writeXMLAttributes | public function writeXMLAttributes( \XMLWriter $w )
{
switch ( $this->data[ 'type' ] )
{
case ImageSizeReducerType::CROP:
$w->writeAttribute( 'type', 'crop' );
$w->writeAttribute( 'width', $this->data[ 'width' ] );
$w->writeAttribute( 'height', $this->data[ 'height' ] );
break;
case ImageSizeReducerType::RESIZE:
$w->writeAttribute( 'type', 'resize' );
$w->writeAttribute( 'width', $this->data[ 'width' ] );
$w->writeAttribute( 'height', $this->data[ 'height' ] );
break;
case ImageSizeReducerType::LONG_SIDE:
$w->writeAttribute( 'type', 'long' );
$w->writeAttribute( 'landscape', $this->data[ 'landscape' ] );
$w->writeAttribute( 'portrait', $this->data[ 'portrait' ] );
break;
case ImageSizeReducerType::SHORT_SIDE:
$w->writeAttribute( 'type', 'short' );
$w->writeAttribute( 'landscape', $this->data[ 'landscape' ] );
$w->writeAttribute( 'portrait', $this->data[ 'portrait' ] );
break;
default: break;
}
} | php | public function writeXMLAttributes( \XMLWriter $w )
{
switch ( $this->data[ 'type' ] )
{
case ImageSizeReducerType::CROP:
$w->writeAttribute( 'type', 'crop' );
$w->writeAttribute( 'width', $this->data[ 'width' ] );
$w->writeAttribute( 'height', $this->data[ 'height' ] );
break;
case ImageSizeReducerType::RESIZE:
$w->writeAttribute( 'type', 'resize' );
$w->writeAttribute( 'width', $this->data[ 'width' ] );
$w->writeAttribute( 'height', $this->data[ 'height' ] );
break;
case ImageSizeReducerType::LONG_SIDE:
$w->writeAttribute( 'type', 'long' );
$w->writeAttribute( 'landscape', $this->data[ 'landscape' ] );
$w->writeAttribute( 'portrait', $this->data[ 'portrait' ] );
break;
case ImageSizeReducerType::SHORT_SIDE:
$w->writeAttribute( 'type', 'short' );
$w->writeAttribute( 'landscape', $this->data[ 'landscape' ] );
$w->writeAttribute( 'portrait', $this->data[ 'portrait' ] );
break;
default: break;
}
} | [
"public",
"function",
"writeXMLAttributes",
"(",
"\\",
"XMLWriter",
"$",
"w",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"data",
"[",
"'type'",
"]",
")",
"{",
"case",
"ImageSizeReducerType",
"::",
"CROP",
":",
"$",
"w",
"->",
"writeAttribute",
"(",
"'type'",
",",
"'crop'",
")",
";",
"$",
"w",
"->",
"writeAttribute",
"(",
"'width'",
",",
"$",
"this",
"->",
"data",
"[",
"'width'",
"]",
")",
";",
"$",
"w",
"->",
"writeAttribute",
"(",
"'height'",
",",
"$",
"this",
"->",
"data",
"[",
"'height'",
"]",
")",
";",
"break",
";",
"case",
"ImageSizeReducerType",
"::",
"RESIZE",
":",
"$",
"w",
"->",
"writeAttribute",
"(",
"'type'",
",",
"'resize'",
")",
";",
"$",
"w",
"->",
"writeAttribute",
"(",
"'width'",
",",
"$",
"this",
"->",
"data",
"[",
"'width'",
"]",
")",
";",
"$",
"w",
"->",
"writeAttribute",
"(",
"'height'",
",",
"$",
"this",
"->",
"data",
"[",
"'height'",
"]",
")",
";",
"break",
";",
"case",
"ImageSizeReducerType",
"::",
"LONG_SIDE",
":",
"$",
"w",
"->",
"writeAttribute",
"(",
"'type'",
",",
"'long'",
")",
";",
"$",
"w",
"->",
"writeAttribute",
"(",
"'landscape'",
",",
"$",
"this",
"->",
"data",
"[",
"'landscape'",
"]",
")",
";",
"$",
"w",
"->",
"writeAttribute",
"(",
"'portrait'",
",",
"$",
"this",
"->",
"data",
"[",
"'portrait'",
"]",
")",
";",
"break",
";",
"case",
"ImageSizeReducerType",
"::",
"SHORT_SIDE",
":",
"$",
"w",
"->",
"writeAttribute",
"(",
"'type'",
",",
"'short'",
")",
";",
"$",
"w",
"->",
"writeAttribute",
"(",
"'landscape'",
",",
"$",
"this",
"->",
"data",
"[",
"'landscape'",
"]",
")",
";",
"$",
"w",
"->",
"writeAttribute",
"(",
"'portrait'",
",",
"$",
"this",
"->",
"data",
"[",
"'portrait'",
"]",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"}"
] | Writes all instance options to XML attributes inside the opened XML element.
@param \XMLWriter $w | [
"Writes",
"all",
"instance",
"options",
"to",
"XML",
"attributes",
"inside",
"the",
"opened",
"XML",
"element",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/ImageSizeReducer.php#L185-L219 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/Image/ImageSizeReducer.php | ImageSizeReducer.Create | protected static function Create(
int $type, int $width, int $height, int $gravity = Gravity::MIDDLE_CENTER,
int $portraitLength = 0, int $landscapeLength = 0 )
: ImageSizeReducer
{
switch ( $type )
{
case ImageSizeReducerType::CROP:
if ( $width < 1 )
{
throw new ArgumentError( 'width', $width, 'Drawing.Image', 'Can not crop an image to a empty width!' );
}
if ( $height < 1 )
{
throw new ArgumentError( 'height', $height, 'Drawing.Image', 'Can not crop an image to a empty height!' );
}
if ( ! \in_array( $gravity, Gravity::KNOWN_VALUES ) )
{
$gravity = Gravity::MIDDLE_CENTER;
}
return static::CreateCropper( $width, $height, $gravity );
case ImageSizeReducerType::RESIZE:
if ( $width < 1 )
{
throw new ArgumentError( 'width', $width, 'Drawing.Image', 'Can not reduce an image to a empty width!' );
}
if ( $height < 1 )
{
throw new ArgumentError( 'height', $height, 'Drawing.Image', 'Can not reduce an image to a empty height!' );
}
return static::CreateResizer( $width, $height );
case ImageSizeReducerType::LONG_SIDE:
if ( $portraitLength < 1 )
{
throw new ArgumentError(
'portraitLength', $portraitLength, 'Drawing.Image',
'Can not reduce an image size to a empty side length!' );
}
if ( $landscapeLength < 1 )
{
throw new ArgumentError(
'landscapeLength', $landscapeLength, 'Drawing.Image',
'Can not reduce an image size to a empty side length!' );
}
return static::CreateLongSideReducer( $portraitLength, $landscapeLength );
case ImageSizeReducerType::SHORT_SIDE:
if ( $portraitLength < 1 )
{
throw new ArgumentError(
'portraitLength', $portraitLength, 'Drawing.Image',
'Can not reduce an image size to a empty side length!' );
}
if ( $landscapeLength < 1 )
{
throw new ArgumentError(
'landscapeLength', $landscapeLength, 'Drawing.Image',
'Can not reduce an image size to a empty side length!' );
}
return static::CreateShortSideReducer( $portraitLength, $landscapeLength );
default:
throw new ArgumentError(
'type', $type, 'Drawing.Image',
'Can not reduce an image size with a unknown reducer type!' );
}
} | php | protected static function Create(
int $type, int $width, int $height, int $gravity = Gravity::MIDDLE_CENTER,
int $portraitLength = 0, int $landscapeLength = 0 )
: ImageSizeReducer
{
switch ( $type )
{
case ImageSizeReducerType::CROP:
if ( $width < 1 )
{
throw new ArgumentError( 'width', $width, 'Drawing.Image', 'Can not crop an image to a empty width!' );
}
if ( $height < 1 )
{
throw new ArgumentError( 'height', $height, 'Drawing.Image', 'Can not crop an image to a empty height!' );
}
if ( ! \in_array( $gravity, Gravity::KNOWN_VALUES ) )
{
$gravity = Gravity::MIDDLE_CENTER;
}
return static::CreateCropper( $width, $height, $gravity );
case ImageSizeReducerType::RESIZE:
if ( $width < 1 )
{
throw new ArgumentError( 'width', $width, 'Drawing.Image', 'Can not reduce an image to a empty width!' );
}
if ( $height < 1 )
{
throw new ArgumentError( 'height', $height, 'Drawing.Image', 'Can not reduce an image to a empty height!' );
}
return static::CreateResizer( $width, $height );
case ImageSizeReducerType::LONG_SIDE:
if ( $portraitLength < 1 )
{
throw new ArgumentError(
'portraitLength', $portraitLength, 'Drawing.Image',
'Can not reduce an image size to a empty side length!' );
}
if ( $landscapeLength < 1 )
{
throw new ArgumentError(
'landscapeLength', $landscapeLength, 'Drawing.Image',
'Can not reduce an image size to a empty side length!' );
}
return static::CreateLongSideReducer( $portraitLength, $landscapeLength );
case ImageSizeReducerType::SHORT_SIDE:
if ( $portraitLength < 1 )
{
throw new ArgumentError(
'portraitLength', $portraitLength, 'Drawing.Image',
'Can not reduce an image size to a empty side length!' );
}
if ( $landscapeLength < 1 )
{
throw new ArgumentError(
'landscapeLength', $landscapeLength, 'Drawing.Image',
'Can not reduce an image size to a empty side length!' );
}
return static::CreateShortSideReducer( $portraitLength, $landscapeLength );
default:
throw new ArgumentError(
'type', $type, 'Drawing.Image',
'Can not reduce an image size with a unknown reducer type!' );
}
} | [
"protected",
"static",
"function",
"Create",
"(",
"int",
"$",
"type",
",",
"int",
"$",
"width",
",",
"int",
"$",
"height",
",",
"int",
"$",
"gravity",
"=",
"Gravity",
"::",
"MIDDLE_CENTER",
",",
"int",
"$",
"portraitLength",
"=",
"0",
",",
"int",
"$",
"landscapeLength",
"=",
"0",
")",
":",
"ImageSizeReducer",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"ImageSizeReducerType",
"::",
"CROP",
":",
"if",
"(",
"$",
"width",
"<",
"1",
")",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'width'",
",",
"$",
"width",
",",
"'Drawing.Image'",
",",
"'Can not crop an image to a empty width!'",
")",
";",
"}",
"if",
"(",
"$",
"height",
"<",
"1",
")",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'height'",
",",
"$",
"height",
",",
"'Drawing.Image'",
",",
"'Can not crop an image to a empty height!'",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"gravity",
",",
"Gravity",
"::",
"KNOWN_VALUES",
")",
")",
"{",
"$",
"gravity",
"=",
"Gravity",
"::",
"MIDDLE_CENTER",
";",
"}",
"return",
"static",
"::",
"CreateCropper",
"(",
"$",
"width",
",",
"$",
"height",
",",
"$",
"gravity",
")",
";",
"case",
"ImageSizeReducerType",
"::",
"RESIZE",
":",
"if",
"(",
"$",
"width",
"<",
"1",
")",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'width'",
",",
"$",
"width",
",",
"'Drawing.Image'",
",",
"'Can not reduce an image to a empty width!'",
")",
";",
"}",
"if",
"(",
"$",
"height",
"<",
"1",
")",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'height'",
",",
"$",
"height",
",",
"'Drawing.Image'",
",",
"'Can not reduce an image to a empty height!'",
")",
";",
"}",
"return",
"static",
"::",
"CreateResizer",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"case",
"ImageSizeReducerType",
"::",
"LONG_SIDE",
":",
"if",
"(",
"$",
"portraitLength",
"<",
"1",
")",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'portraitLength'",
",",
"$",
"portraitLength",
",",
"'Drawing.Image'",
",",
"'Can not reduce an image size to a empty side length!'",
")",
";",
"}",
"if",
"(",
"$",
"landscapeLength",
"<",
"1",
")",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'landscapeLength'",
",",
"$",
"landscapeLength",
",",
"'Drawing.Image'",
",",
"'Can not reduce an image size to a empty side length!'",
")",
";",
"}",
"return",
"static",
"::",
"CreateLongSideReducer",
"(",
"$",
"portraitLength",
",",
"$",
"landscapeLength",
")",
";",
"case",
"ImageSizeReducerType",
"::",
"SHORT_SIDE",
":",
"if",
"(",
"$",
"portraitLength",
"<",
"1",
")",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'portraitLength'",
",",
"$",
"portraitLength",
",",
"'Drawing.Image'",
",",
"'Can not reduce an image size to a empty side length!'",
")",
";",
"}",
"if",
"(",
"$",
"landscapeLength",
"<",
"1",
")",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'landscapeLength'",
",",
"$",
"landscapeLength",
",",
"'Drawing.Image'",
",",
"'Can not reduce an image size to a empty side length!'",
")",
";",
"}",
"return",
"static",
"::",
"CreateShortSideReducer",
"(",
"$",
"portraitLength",
",",
"$",
"landscapeLength",
")",
";",
"default",
":",
"throw",
"new",
"ArgumentError",
"(",
"'type'",
",",
"$",
"type",
",",
"'Drawing.Image'",
",",
"'Can not reduce an image size with a unknown reducer type!'",
")",
";",
"}",
"}"
] | Init an Image size reducer.
@param int $type The the image size reducer type
@param int $width The width of the required resulting image
@param int $height The height of the required resulting image
@param int $gravity The gravity of the cropped image part
@param int $portraitLength
@param int $landscapeLength
@return \Beluga\Drawing\Image\ImageSizeReducer
@throws \Beluga\ArgumentError | [
"Init",
"an",
"Image",
"size",
"reducer",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/ImageSizeReducer.php#L636-L708 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/Image/ImageSizeReducer.php | ImageSizeReducer.TryParse | public static function TryParse( $value, &$refReducer = null ) : bool
{
if ( \is_null( $value ) )
{
return false;
}
if ( $value instanceof \SimpleXMLElement )
{
return static::TryParseXmlElement( $value, $refReducer );
}
if ( \is_string( $value ) && ! empty( $value ) && $value[ 0 ] == '{' )
{
try
{
$array = \json_decode( $value, true );
if ( ! \is_array( $array ) )
{
return false;
}
$value = $array;
}
catch ( \Throwable $ex ) { $ex = null; return false; }
}
if ( \is_array( $value ) )
{
if ( ! isset( $value[ 'type' ] ) )
{
return false;
}
if ( ! isset( $value[ 'width' ] ) )
{
$value[ 'width' ] = 0;
}
if ( ! isset( $value[ 'height' ] ) )
{
$value[ 'height' ] = 0;
}
if ( ! isset( $value[ 'landscape' ] ) )
{
$value[ 'landscape' ] = 0;
}
if ( ! isset( $value[ 'portrait' ] ) )
{
$value[ 'portrait' ] = 0;
}
if ( ! isset( $value[ 'gravity' ] ) )
{
$value[ 'gravity' ] = Gravity::MIDDLE_CENTER;
}
$refReducer = static::Create(
\intval( $value[ 'type' ] ),
\intval( $value[ 'width' ] ),
\intval( $value[ 'height' ] ),
\intval( $value[ 'gravity' ] ),
\intval( $value[ 'portrait' ] ),
\intval( $value[ 'landscape' ] )
);
return true;
}
return false;
} | php | public static function TryParse( $value, &$refReducer = null ) : bool
{
if ( \is_null( $value ) )
{
return false;
}
if ( $value instanceof \SimpleXMLElement )
{
return static::TryParseXmlElement( $value, $refReducer );
}
if ( \is_string( $value ) && ! empty( $value ) && $value[ 0 ] == '{' )
{
try
{
$array = \json_decode( $value, true );
if ( ! \is_array( $array ) )
{
return false;
}
$value = $array;
}
catch ( \Throwable $ex ) { $ex = null; return false; }
}
if ( \is_array( $value ) )
{
if ( ! isset( $value[ 'type' ] ) )
{
return false;
}
if ( ! isset( $value[ 'width' ] ) )
{
$value[ 'width' ] = 0;
}
if ( ! isset( $value[ 'height' ] ) )
{
$value[ 'height' ] = 0;
}
if ( ! isset( $value[ 'landscape' ] ) )
{
$value[ 'landscape' ] = 0;
}
if ( ! isset( $value[ 'portrait' ] ) )
{
$value[ 'portrait' ] = 0;
}
if ( ! isset( $value[ 'gravity' ] ) )
{
$value[ 'gravity' ] = Gravity::MIDDLE_CENTER;
}
$refReducer = static::Create(
\intval( $value[ 'type' ] ),
\intval( $value[ 'width' ] ),
\intval( $value[ 'height' ] ),
\intval( $value[ 'gravity' ] ),
\intval( $value[ 'portrait' ] ),
\intval( $value[ 'landscape' ] )
);
return true;
}
return false;
} | [
"public",
"static",
"function",
"TryParse",
"(",
"$",
"value",
",",
"&",
"$",
"refReducer",
"=",
"null",
")",
":",
"bool",
"{",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"SimpleXMLElement",
")",
"{",
"return",
"static",
"::",
"TryParseXmlElement",
"(",
"$",
"value",
",",
"$",
"refReducer",
")",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"value",
")",
"&&",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"[",
"0",
"]",
"==",
"'{'",
")",
"{",
"try",
"{",
"$",
"array",
"=",
"\\",
"json_decode",
"(",
"$",
"value",
",",
"true",
")",
";",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"value",
"=",
"$",
"array",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"ex",
")",
"{",
"$",
"ex",
"=",
"null",
";",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"'type'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"'width'",
"]",
")",
")",
"{",
"$",
"value",
"[",
"'width'",
"]",
"=",
"0",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"'height'",
"]",
")",
")",
"{",
"$",
"value",
"[",
"'height'",
"]",
"=",
"0",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"'landscape'",
"]",
")",
")",
"{",
"$",
"value",
"[",
"'landscape'",
"]",
"=",
"0",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"'portrait'",
"]",
")",
")",
"{",
"$",
"value",
"[",
"'portrait'",
"]",
"=",
"0",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
"[",
"'gravity'",
"]",
")",
")",
"{",
"$",
"value",
"[",
"'gravity'",
"]",
"=",
"Gravity",
"::",
"MIDDLE_CENTER",
";",
"}",
"$",
"refReducer",
"=",
"static",
"::",
"Create",
"(",
"\\",
"intval",
"(",
"$",
"value",
"[",
"'type'",
"]",
")",
",",
"\\",
"intval",
"(",
"$",
"value",
"[",
"'width'",
"]",
")",
",",
"\\",
"intval",
"(",
"$",
"value",
"[",
"'height'",
"]",
")",
",",
"\\",
"intval",
"(",
"$",
"value",
"[",
"'gravity'",
"]",
")",
",",
"\\",
"intval",
"(",
"$",
"value",
"[",
"'portrait'",
"]",
")",
",",
"\\",
"intval",
"(",
"$",
"value",
"[",
"'landscape'",
"]",
")",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Tries to parse the defined value to an ImageSizeReducer instance
@param \SimpleXMLElement|array|string $value
@param \Beluga\Drawing\Image\ImageSizeReducer $refReducer Returns the resulting reducer instance
if the method return TRUE
@return bool | [
"Tries",
"to",
"parse",
"the",
"defined",
"value",
"to",
"an",
"ImageSizeReducer",
"instance"
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/Image/ImageSizeReducer.php#L811-L888 | train |
SlabPHP/database | src/Models/MySQL/Join.php | Join.resolve | public function resolve($databaseResult)
{
$className = $this->className;
try {
$object = new $className();
$this->loader
->mapObjectWithOptions($object, $databaseResult);
$databaseResult->{$this->fieldName} = $object;
} catch (\Exception $e) {
//This is fine, just an empty join
echo $e->getMessage();
}
} | php | public function resolve($databaseResult)
{
$className = $this->className;
try {
$object = new $className();
$this->loader
->mapObjectWithOptions($object, $databaseResult);
$databaseResult->{$this->fieldName} = $object;
} catch (\Exception $e) {
//This is fine, just an empty join
echo $e->getMessage();
}
} | [
"public",
"function",
"resolve",
"(",
"$",
"databaseResult",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"className",
";",
"try",
"{",
"$",
"object",
"=",
"new",
"$",
"className",
"(",
")",
";",
"$",
"this",
"->",
"loader",
"->",
"mapObjectWithOptions",
"(",
"$",
"object",
",",
"$",
"databaseResult",
")",
";",
"$",
"databaseResult",
"->",
"{",
"$",
"this",
"->",
"fieldName",
"}",
"=",
"$",
"object",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"//This is fine, just an empty join",
"echo",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}"
] | Resolve data by splicing in the completed object
@param $databaseResult | [
"Resolve",
"data",
"by",
"splicing",
"in",
"the",
"completed",
"object"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Join.php#L70-L85 | train |
SlabPHP/database | src/Models/MySQL/Join.php | Join.joinOn | public function joinOn($foreignKeyColumn)
{
return 'join ' . $this->getTable() . ' on ' . $this->loader->getPrimaryKey($this->alias) . ' = ' . $foreignKeyColumn . ' ';
} | php | public function joinOn($foreignKeyColumn)
{
return 'join ' . $this->getTable() . ' on ' . $this->loader->getPrimaryKey($this->alias) . ' = ' . $foreignKeyColumn . ' ';
} | [
"public",
"function",
"joinOn",
"(",
"$",
"foreignKeyColumn",
")",
"{",
"return",
"'join '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
".",
"' on '",
".",
"$",
"this",
"->",
"loader",
"->",
"getPrimaryKey",
"(",
"$",
"this",
"->",
"alias",
")",
".",
"' = '",
".",
"$",
"foreignKeyColumn",
".",
"' '",
";",
"}"
] | Print out Join SQL
@param $foreignKeyColumn
@return string | [
"Print",
"out",
"Join",
"SQL"
] | d77c38f2260429c6e054633eb0daf3f755c988a9 | https://github.com/SlabPHP/database/blob/d77c38f2260429c6e054633eb0daf3f755c988a9/src/Models/MySQL/Join.php#L113-L116 | train |
PenoaksDev/Milky-Framework | src/Milky/Http/Routing/ResourceRegistrar.php | ResourceRegistrar.prefixedResource | protected function prefixedResource( $name, $controller, array $options )
{
list( $name, $prefix ) = $this->getResourcePrefix( $name );
// We need to extract the base resource from the resource name. Nested resources
// are supported in the framework, but we need to know what name to use for a
// place-holder on the route parameters, which should be the base resources.
$callback = function ( $me ) use ( $name, $controller, $options )
{
$me->resource( $name, $controller, $options );
};
$this->router->group( compact( 'prefix' ), $callback );
} | php | protected function prefixedResource( $name, $controller, array $options )
{
list( $name, $prefix ) = $this->getResourcePrefix( $name );
// We need to extract the base resource from the resource name. Nested resources
// are supported in the framework, but we need to know what name to use for a
// place-holder on the route parameters, which should be the base resources.
$callback = function ( $me ) use ( $name, $controller, $options )
{
$me->resource( $name, $controller, $options );
};
$this->router->group( compact( 'prefix' ), $callback );
} | [
"protected",
"function",
"prefixedResource",
"(",
"$",
"name",
",",
"$",
"controller",
",",
"array",
"$",
"options",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"prefix",
")",
"=",
"$",
"this",
"->",
"getResourcePrefix",
"(",
"$",
"name",
")",
";",
"// We need to extract the base resource from the resource name. Nested resources",
"// are supported in the framework, but we need to know what name to use for a",
"// place-holder on the route parameters, which should be the base resources.",
"$",
"callback",
"=",
"function",
"(",
"$",
"me",
")",
"use",
"(",
"$",
"name",
",",
"$",
"controller",
",",
"$",
"options",
")",
"{",
"$",
"me",
"->",
"resource",
"(",
"$",
"name",
",",
"$",
"controller",
",",
"$",
"options",
")",
";",
"}",
";",
"$",
"this",
"->",
"router",
"->",
"group",
"(",
"compact",
"(",
"'prefix'",
")",
",",
"$",
"callback",
")",
";",
"}"
] | Build a set of prefixed resource routes.
@param string $name
@param string $controller
@param array $options | [
"Build",
"a",
"set",
"of",
"prefixed",
"resource",
"routes",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Routing/ResourceRegistrar.php#L92-L105 | train |
PenoaksDev/Milky-Framework | src/Milky/Http/Routing/ResourceRegistrar.php | ResourceRegistrar.addResourceShow | protected function addResourceShow( $name, $base, $controller, $options )
{
$uri = $this->getResourceUri( $name ) . '/{' . $base . '';
$action = $this->getResourceAction( $name, $controller, 'show', $options );
return $this->router->get( $uri, $action );
} | php | protected function addResourceShow( $name, $base, $controller, $options )
{
$uri = $this->getResourceUri( $name ) . '/{' . $base . '';
$action = $this->getResourceAction( $name, $controller, 'show', $options );
return $this->router->get( $uri, $action );
} | [
"protected",
"function",
"addResourceShow",
"(",
"$",
"name",
",",
"$",
"base",
",",
"$",
"controller",
",",
"$",
"options",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"getResourceUri",
"(",
"$",
"name",
")",
".",
"'/{'",
".",
"$",
"base",
".",
"''",
";",
"$",
"action",
"=",
"$",
"this",
"->",
"getResourceAction",
"(",
"$",
"name",
",",
"$",
"controller",
",",
"'show'",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"router",
"->",
"get",
"(",
"$",
"uri",
",",
"$",
"action",
")",
";",
"}"
] | Add the show method for a resourceful route.
@param string $name
@param string $base
@param string $controller
@param array $options
@return Route | [
"Add",
"the",
"show",
"method",
"for",
"a",
"resourceful",
"route",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Routing/ResourceRegistrar.php#L337-L344 | train |
WesamMikhail/Utils | src/Strings.php | Strings.generateRandomAlphaNumericString | public static function generateRandomAlphaNumericString($length) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen($chars);
$randomChars = array();
for ($i = 0; $i < $length; $i++) {
$randomChars[] = $chars[mt_rand(0, $size - 1)];
}
return implode('', $randomChars);
} | php | public static function generateRandomAlphaNumericString($length) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$size = strlen($chars);
$randomChars = array();
for ($i = 0; $i < $length; $i++) {
$randomChars[] = $chars[mt_rand(0, $size - 1)];
}
return implode('', $randomChars);
} | [
"public",
"static",
"function",
"generateRandomAlphaNumericString",
"(",
"$",
"length",
")",
"{",
"$",
"chars",
"=",
"\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\"",
";",
"$",
"size",
"=",
"strlen",
"(",
"$",
"chars",
")",
";",
"$",
"randomChars",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"randomChars",
"[",
"]",
"=",
"$",
"chars",
"[",
"mt_rand",
"(",
"0",
",",
"$",
"size",
"-",
"1",
")",
"]",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"randomChars",
")",
";",
"}"
] | Generate a random string with repeatable letters.
@param int $length Length of desired random string
@return string Random string | [
"Generate",
"a",
"random",
"string",
"with",
"repeatable",
"letters",
"."
] | 54933740f4500a7a1ebd37c7226cc00bc36e58db | https://github.com/WesamMikhail/Utils/blob/54933740f4500a7a1ebd37c7226cc00bc36e58db/src/Strings.php#L20-L30 | train |
Nicklas766/Comment | src/Comment/Modules/User.php | User.verifyPassword | public function verifyPassword($name, $pass)
{
$this->find("name", $name);
return password_verify($pass, $this->pass);
} | php | public function verifyPassword($name, $pass)
{
$this->find("name", $name);
return password_verify($pass, $this->pass);
} | [
"public",
"function",
"verifyPassword",
"(",
"$",
"name",
",",
"$",
"pass",
")",
"{",
"$",
"this",
"->",
"find",
"(",
"\"name\"",
",",
"$",
"name",
")",
";",
"return",
"password_verify",
"(",
"$",
"pass",
",",
"$",
"this",
"->",
"pass",
")",
";",
"}"
] | Verify the name and the pass, if successful the object contains
all details from the database row.
@param string $name name to check.
@param string $pass the pass to use.
@return boolean true if name and pass matches, else false. | [
"Verify",
"the",
"name",
"and",
"the",
"pass",
"if",
"successful",
"the",
"object",
"contains",
"all",
"details",
"from",
"the",
"database",
"row",
"."
] | 1483eaf1ebb120b8bd6c2a1552c084b3a288ff25 | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/Modules/User.php#L192-L196 | train |
Nicklas766/Comment | src/Comment/Modules/User.php | User.controlAuthority | public function controlAuthority($loggedUser, $name)
{
$this->find("name", $loggedUser);
// IF AUTHORITY == admin, then continue
if ($this->authority != "admin") {
return ($this->name == $name);
}
return true;
} | php | public function controlAuthority($loggedUser, $name)
{
$this->find("name", $loggedUser);
// IF AUTHORITY == admin, then continue
if ($this->authority != "admin") {
return ($this->name == $name);
}
return true;
} | [
"public",
"function",
"controlAuthority",
"(",
"$",
"loggedUser",
",",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"find",
"(",
"\"name\"",
",",
"$",
"loggedUser",
")",
";",
"// IF AUTHORITY == admin, then continue",
"if",
"(",
"$",
"this",
"->",
"authority",
"!=",
"\"admin\"",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"name",
"==",
"$",
"name",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Check if a post belongs to user
@return boolean | [
"Check",
"if",
"a",
"post",
"belongs",
"to",
"user"
] | 1483eaf1ebb120b8bd6c2a1552c084b3a288ff25 | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/Modules/User.php#L220-L228 | train |
EvanDarwin/JSend | src/JSendBuilder.php | JSendBuilder.get | public function get()
{
return new JSendResponse($this->status, $this->data, $this->errors, $this->code, $this->message);
} | php | public function get()
{
return new JSendResponse($this->status, $this->data, $this->errors, $this->code, $this->message);
} | [
"public",
"function",
"get",
"(",
")",
"{",
"return",
"new",
"JSendResponse",
"(",
"$",
"this",
"->",
"status",
",",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"errors",
",",
"$",
"this",
"->",
"code",
",",
"$",
"this",
"->",
"message",
")",
";",
"}"
] | Returns the built object
@return \EvanDarwin\JSend\JSendResponse
@throws \InvalidArgumentException | [
"Returns",
"the",
"built",
"object"
] | a31f7590e8503590d10012510ffc50a0ef064d02 | https://github.com/EvanDarwin/JSend/blob/a31f7590e8503590d10012510ffc50a0ef064d02/src/JSendBuilder.php#L174-L177 | train |
wevrem/dStruct | src/dConnection.php | dConnection.getStatement | function getStatement($cKey, $sqlCallback, $types, $params) {
// Lazily prepare and cache the statement.
if (!$this->stmtCache[$cKey]) {
if (!($stmt = $this->mysqli->prepare( $sqlCallback instanceof \Closure ? $sqlCallback() : $sqlCallback ))) { throw new \Exception("Statement Error: {$this->mysqli->error}", $this->mysqli->errno); }
$reflectMethod = new \ReflectionMethod('mysqli_stmt', 'bind_param');
$args[] = $types;
foreach (array_keys((array)$params) as $name) { $args[] = &$this->paramCache[$cKey][$name]; }
if (!($reflectMethod->invokeArgs($stmt, $args))) { throw new \Exception("Bind Param Error: {$stmt->error}", $stmt->errno); }
$this->stmtCache[$cKey] = $stmt;
}
foreach ((array)$params as $name=>$value) { $this->paramCache[$cKey][$name] = $value; }
return $this->stmtCache[$cKey];
} | php | function getStatement($cKey, $sqlCallback, $types, $params) {
// Lazily prepare and cache the statement.
if (!$this->stmtCache[$cKey]) {
if (!($stmt = $this->mysqli->prepare( $sqlCallback instanceof \Closure ? $sqlCallback() : $sqlCallback ))) { throw new \Exception("Statement Error: {$this->mysqli->error}", $this->mysqli->errno); }
$reflectMethod = new \ReflectionMethod('mysqli_stmt', 'bind_param');
$args[] = $types;
foreach (array_keys((array)$params) as $name) { $args[] = &$this->paramCache[$cKey][$name]; }
if (!($reflectMethod->invokeArgs($stmt, $args))) { throw new \Exception("Bind Param Error: {$stmt->error}", $stmt->errno); }
$this->stmtCache[$cKey] = $stmt;
}
foreach ((array)$params as $name=>$value) { $this->paramCache[$cKey][$name] = $value; }
return $this->stmtCache[$cKey];
} | [
"function",
"getStatement",
"(",
"$",
"cKey",
",",
"$",
"sqlCallback",
",",
"$",
"types",
",",
"$",
"params",
")",
"{",
"// Lazily prepare and cache the statement.",
"if",
"(",
"!",
"$",
"this",
"->",
"stmtCache",
"[",
"$",
"cKey",
"]",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"stmt",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"prepare",
"(",
"$",
"sqlCallback",
"instanceof",
"\\",
"Closure",
"?",
"$",
"sqlCallback",
"(",
")",
":",
"$",
"sqlCallback",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Statement Error: {$this->mysqli->error}\"",
",",
"$",
"this",
"->",
"mysqli",
"->",
"errno",
")",
";",
"}",
"$",
"reflectMethod",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"'mysqli_stmt'",
",",
"'bind_param'",
")",
";",
"$",
"args",
"[",
"]",
"=",
"$",
"types",
";",
"foreach",
"(",
"array_keys",
"(",
"(",
"array",
")",
"$",
"params",
")",
"as",
"$",
"name",
")",
"{",
"$",
"args",
"[",
"]",
"=",
"&",
"$",
"this",
"->",
"paramCache",
"[",
"$",
"cKey",
"]",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"reflectMethod",
"->",
"invokeArgs",
"(",
"$",
"stmt",
",",
"$",
"args",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Bind Param Error: {$stmt->error}\"",
",",
"$",
"stmt",
"->",
"errno",
")",
";",
"}",
"$",
"this",
"->",
"stmtCache",
"[",
"$",
"cKey",
"]",
"=",
"$",
"stmt",
";",
"}",
"foreach",
"(",
"(",
"array",
")",
"$",
"params",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"paramCache",
"[",
"$",
"cKey",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"stmtCache",
"[",
"$",
"cKey",
"]",
";",
"}"
] | array and returns the statement ready to execute. | [
"array",
"and",
"returns",
"the",
"statement",
"ready",
"to",
"execute",
"."
] | 6ede2c26a377475f48de043536d1f46e8863d8b3 | https://github.com/wevrem/dStruct/blob/6ede2c26a377475f48de043536d1f46e8863d8b3/src/dConnection.php#L235-L247 | train |
Brainsware/sauce | lib/Sauce/Path.php | Path.check | public static function check ($path, $fd, $rw)
{
if ($fd == 'f') {
if (is_file($path) != true) {
return false;
}
} elseif ($fd == 'd') {
if (is_dir($path) != true) {
return false;
}
} else {
return false;
}
if ($rw == 'r') {
if (!is_readable($path)) {
return false;
}
} elseif ($rw == 'w') {
if (!is_writable($path)) {
return false;
}
} elseif ($rw == 'rw') {
if (!is_readable($path) || !is_writable($path)) {
return false;
}
} else {
return false;
}
return true;
} | php | public static function check ($path, $fd, $rw)
{
if ($fd == 'f') {
if (is_file($path) != true) {
return false;
}
} elseif ($fd == 'd') {
if (is_dir($path) != true) {
return false;
}
} else {
return false;
}
if ($rw == 'r') {
if (!is_readable($path)) {
return false;
}
} elseif ($rw == 'w') {
if (!is_writable($path)) {
return false;
}
} elseif ($rw == 'rw') {
if (!is_readable($path) || !is_writable($path)) {
return false;
}
} else {
return false;
}
return true;
} | [
"public",
"static",
"function",
"check",
"(",
"$",
"path",
",",
"$",
"fd",
",",
"$",
"rw",
")",
"{",
"if",
"(",
"$",
"fd",
"==",
"'f'",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"path",
")",
"!=",
"true",
")",
"{",
"return",
"false",
";",
"}",
"}",
"elseif",
"(",
"$",
"fd",
"==",
"'d'",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
"!=",
"true",
")",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"rw",
"==",
"'r'",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"elseif",
"(",
"$",
"rw",
"==",
"'w'",
")",
"{",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"elseif",
"(",
"$",
"rw",
"==",
"'rw'",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"path",
")",
"||",
"!",
"is_writable",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Checks a file or directory existence and readability
@param string $path /path/to/dir/or/file
@param string $fd Either 'f' for file or 'd' for directory.
@param string $rw Either 'w' for a check on writability or 'r' for a check on readability.
@return bool | [
"Checks",
"a",
"file",
"or",
"directory",
"existence",
"and",
"readability"
] | 2294fd27286bf42cfac6d744e242b2bd9eea353d | https://github.com/Brainsware/sauce/blob/2294fd27286bf42cfac6d744e242b2bd9eea353d/lib/Sauce/Path.php#L81-L112 | train |
shazam/easy-config | src/Config.php | Config.loadConfig | public function loadConfig($configFiles)
{
if (!is_array($configFiles)) {
$configFiles = array($configFiles);
}
$this->configFiles = $configFiles;
foreach ($configFiles as $configFile) {
$this->config = array_merge(
$this->config,
$this->loadConfigFile($configFile)
);
}
} | php | public function loadConfig($configFiles)
{
if (!is_array($configFiles)) {
$configFiles = array($configFiles);
}
$this->configFiles = $configFiles;
foreach ($configFiles as $configFile) {
$this->config = array_merge(
$this->config,
$this->loadConfigFile($configFile)
);
}
} | [
"public",
"function",
"loadConfig",
"(",
"$",
"configFiles",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"configFiles",
")",
")",
"{",
"$",
"configFiles",
"=",
"array",
"(",
"$",
"configFiles",
")",
";",
"}",
"$",
"this",
"->",
"configFiles",
"=",
"$",
"configFiles",
";",
"foreach",
"(",
"$",
"configFiles",
"as",
"$",
"configFile",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"this",
"->",
"loadConfigFile",
"(",
"$",
"configFile",
")",
")",
";",
"}",
"}"
] | Sets to the config property the merged content from all the config files.
@param array|string $configFiles | [
"Sets",
"to",
"the",
"config",
"property",
"the",
"merged",
"content",
"from",
"all",
"the",
"config",
"files",
"."
] | 4017fc4c9669abf2fe58cc2ed4dd5dab5d7224a8 | https://github.com/shazam/easy-config/blob/4017fc4c9669abf2fe58cc2ed4dd5dab5d7224a8/src/Config.php#L82-L96 | train |
shazam/easy-config | src/Config.php | Config.fetch | public function fetch(/* $key1, $key2, ... $keyN */)
{
$keys = func_get_args();
$config = $this->config;
foreach ($keys as $key) {
if (isset($config[$key])) {
$config = $config[$key];
} else {
throw new KeyNotFoundException("Key $key not found.");
}
}
return $config;
} | php | public function fetch(/* $key1, $key2, ... $keyN */)
{
$keys = func_get_args();
$config = $this->config;
foreach ($keys as $key) {
if (isset($config[$key])) {
$config = $config[$key];
} else {
throw new KeyNotFoundException("Key $key not found.");
}
}
return $config;
} | [
"public",
"function",
"fetch",
"(",
"/* $key1, $key2, ... $keyN */",
")",
"{",
"$",
"keys",
"=",
"func_get_args",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"config",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"config",
"=",
"$",
"config",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"KeyNotFoundException",
"(",
"\"Key $key not found.\"",
")",
";",
"}",
"}",
"return",
"$",
"config",
";",
"}"
] | Fetches a single value from a key chain of N depth
@return array|mixed
@throws KeyNotFoundException | [
"Fetches",
"a",
"single",
"value",
"from",
"a",
"key",
"chain",
"of",
"N",
"depth"
] | 4017fc4c9669abf2fe58cc2ed4dd5dab5d7224a8 | https://github.com/shazam/easy-config/blob/4017fc4c9669abf2fe58cc2ed4dd5dab5d7224a8/src/Config.php#L111-L125 | train |
shazam/easy-config | src/Config.php | Config.flush | public function flush()
{
if ($this->useCache) {
foreach ($this->configFiles as $configFile) {
if (function_exists('apc_delete')) {
\apc_delete($configFile);
}
}
}
$this->config = array();
} | php | public function flush()
{
if ($this->useCache) {
foreach ($this->configFiles as $configFile) {
if (function_exists('apc_delete')) {
\apc_delete($configFile);
}
}
}
$this->config = array();
} | [
"public",
"function",
"flush",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"useCache",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"configFiles",
"as",
"$",
"configFile",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'apc_delete'",
")",
")",
"{",
"\\",
"apc_delete",
"(",
"$",
"configFile",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"config",
"=",
"array",
"(",
")",
";",
"}"
] | If cache is used, flushes it. Otherwise it just empties config property. | [
"If",
"cache",
"is",
"used",
"flushes",
"it",
".",
"Otherwise",
"it",
"just",
"empties",
"config",
"property",
"."
] | 4017fc4c9669abf2fe58cc2ed4dd5dab5d7224a8 | https://github.com/shazam/easy-config/blob/4017fc4c9669abf2fe58cc2ed4dd5dab5d7224a8/src/Config.php#L140-L150 | train |
shazam/easy-config | src/Config.php | Config.loadConfigFile | private function loadConfigFile($configFile)
{
if ($this->useCache) {
if (function_exists('apc_fetch')) {
$config = apc_fetch($configFile);
} elseif (function_exists('apcu_fetch')) {
$config = apcu_fetch($configFile);
}
if (!empty($config)) {
return $config;
}
}
if (!is_readable($configFile)) {
throw new FileNotFoundException("File $configFile could not be found.");
}
try {
$config = $this->parser->parse(file_get_contents($configFile));
} catch (ParseException $e) {
$line = $e->getParsedLine();
throw new InvalidConfigFileException(
"File $configFile does not have a valid format (line $line)"
);
}
if ($this->useCache) {
if (function_exists('apc_store')) {
apc_store($configFile, $config);
} elseif (function_exists('apcu_store')) {
apcu_store($configFile, $config);
}
}
return $config;
} | php | private function loadConfigFile($configFile)
{
if ($this->useCache) {
if (function_exists('apc_fetch')) {
$config = apc_fetch($configFile);
} elseif (function_exists('apcu_fetch')) {
$config = apcu_fetch($configFile);
}
if (!empty($config)) {
return $config;
}
}
if (!is_readable($configFile)) {
throw new FileNotFoundException("File $configFile could not be found.");
}
try {
$config = $this->parser->parse(file_get_contents($configFile));
} catch (ParseException $e) {
$line = $e->getParsedLine();
throw new InvalidConfigFileException(
"File $configFile does not have a valid format (line $line)"
);
}
if ($this->useCache) {
if (function_exists('apc_store')) {
apc_store($configFile, $config);
} elseif (function_exists('apcu_store')) {
apcu_store($configFile, $config);
}
}
return $config;
} | [
"private",
"function",
"loadConfigFile",
"(",
"$",
"configFile",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"useCache",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'apc_fetch'",
")",
")",
"{",
"$",
"config",
"=",
"apc_fetch",
"(",
"$",
"configFile",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'apcu_fetch'",
")",
")",
"{",
"$",
"config",
"=",
"apcu_fetch",
"(",
"$",
"configFile",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
")",
")",
"{",
"return",
"$",
"config",
";",
"}",
"}",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"configFile",
")",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"\"File $configFile could not be found.\"",
")",
";",
"}",
"try",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"file_get_contents",
"(",
"$",
"configFile",
")",
")",
";",
"}",
"catch",
"(",
"ParseException",
"$",
"e",
")",
"{",
"$",
"line",
"=",
"$",
"e",
"->",
"getParsedLine",
"(",
")",
";",
"throw",
"new",
"InvalidConfigFileException",
"(",
"\"File $configFile does not have a valid format (line $line)\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"useCache",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'apc_store'",
")",
")",
"{",
"apc_store",
"(",
"$",
"configFile",
",",
"$",
"config",
")",
";",
"}",
"elseif",
"(",
"function_exists",
"(",
"'apcu_store'",
")",
")",
"{",
"apcu_store",
"(",
"$",
"configFile",
",",
"$",
"config",
")",
";",
"}",
"}",
"return",
"$",
"config",
";",
"}"
] | Loads a config file into config property. If cache is used, first check if the config
file was previously loaded.
@throws FileNotFoundException
@throws InvalidConfigFileException | [
"Loads",
"a",
"config",
"file",
"into",
"config",
"property",
".",
"If",
"cache",
"is",
"used",
"first",
"check",
"if",
"the",
"config",
"file",
"was",
"previously",
"loaded",
"."
] | 4017fc4c9669abf2fe58cc2ed4dd5dab5d7224a8 | https://github.com/shazam/easy-config/blob/4017fc4c9669abf2fe58cc2ed4dd5dab5d7224a8/src/Config.php#L158-L194 | train |
werx/core | src/Controller.php | Controller.initializeRequest | public function initializeRequest($request = null)
{
if (empty($request)) {
$this->request = Request::createFromGlobals();
} else {
$this->request = $request;
}
// Shortcuts to the request object for cleaner syntax.
$this->input = new Input($this->request);
} | php | public function initializeRequest($request = null)
{
if (empty($request)) {
$this->request = Request::createFromGlobals();
} else {
$this->request = $request;
}
// Shortcuts to the request object for cleaner syntax.
$this->input = new Input($this->request);
} | [
"public",
"function",
"initializeRequest",
"(",
"$",
"request",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"request",
")",
")",
"{",
"$",
"this",
"->",
"request",
"=",
"Request",
"::",
"createFromGlobals",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"request",
"=",
"$",
"request",
";",
"}",
"// Shortcuts to the request object for cleaner syntax.",
"$",
"this",
"->",
"input",
"=",
"new",
"Input",
"(",
"$",
"this",
"->",
"request",
")",
";",
"}"
] | Get info about the HTTP Request
@var \Symfony\Component\HttpFoundation\Request $request | [
"Get",
"info",
"about",
"the",
"HTTP",
"Request"
] | 9ab7a9f7a8c02e1d41ca40301afada8129ea0a79 | https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Controller.php#L121-L131 | train |
werx/core | src/Controller.php | Controller.jsonp | public function jsonp($content = [], $jsonCallback = 'callback')
{
$response = new JsonResponse();
$response->setData($content);
$response->setCallback($jsonCallback);
$response->send();
} | php | public function jsonp($content = [], $jsonCallback = 'callback')
{
$response = new JsonResponse();
$response->setData($content);
$response->setCallback($jsonCallback);
$response->send();
} | [
"public",
"function",
"jsonp",
"(",
"$",
"content",
"=",
"[",
"]",
",",
"$",
"jsonCallback",
"=",
"'callback'",
")",
"{",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
")",
";",
"$",
"response",
"->",
"setData",
"(",
"$",
"content",
")",
";",
"$",
"response",
"->",
"setCallback",
"(",
"$",
"jsonCallback",
")",
";",
"$",
"response",
"->",
"send",
"(",
")",
";",
"}"
] | Send a jsonp response with given content.
@param array $content
@param string $jsonCallback | [
"Send",
"a",
"jsonp",
"response",
"with",
"given",
"content",
"."
] | 9ab7a9f7a8c02e1d41ca40301afada8129ea0a79 | https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Controller.php#L242-L248 | train |
werx/core | src/Controller.php | Controller.getRequestedController | public function getRequestedController($default = null)
{
if (property_exists($this, 'app') && is_object($this->app) && property_exists($this->app, 'controller')) {
return $this->app->controller;
} elseif (!empty($default)) {
return $default;
} else {
$reflect = new \ReflectionClass($this);
return strtolower($reflect->getShortName());
}
} | php | public function getRequestedController($default = null)
{
if (property_exists($this, 'app') && is_object($this->app) && property_exists($this->app, 'controller')) {
return $this->app->controller;
} elseif (!empty($default)) {
return $default;
} else {
$reflect = new \ReflectionClass($this);
return strtolower($reflect->getShortName());
}
} | [
"public",
"function",
"getRequestedController",
"(",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"'app'",
")",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"app",
")",
"&&",
"property_exists",
"(",
"$",
"this",
"->",
"app",
",",
"'controller'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"controller",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"default",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"else",
"{",
"$",
"reflect",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"return",
"strtolower",
"(",
"$",
"reflect",
"->",
"getShortName",
"(",
")",
")",
";",
"}",
"}"
] | Which controller was requested?
@param null $default
@return null|string | [
"Which",
"controller",
"was",
"requested?"
] | 9ab7a9f7a8c02e1d41ca40301afada8129ea0a79 | https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Controller.php#L256-L266 | train |
werx/core | src/Controller.php | Controller.getRequestedAction | public function getRequestedAction($default = 'index')
{
if (property_exists($this, 'app') && is_object($this->app) && property_exists($this->app, 'action')) {
return $this->app->action;
} else {
return $default;
}
} | php | public function getRequestedAction($default = 'index')
{
if (property_exists($this, 'app') && is_object($this->app) && property_exists($this->app, 'action')) {
return $this->app->action;
} else {
return $default;
}
} | [
"public",
"function",
"getRequestedAction",
"(",
"$",
"default",
"=",
"'index'",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"'app'",
")",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"app",
")",
"&&",
"property_exists",
"(",
"$",
"this",
"->",
"app",
",",
"'action'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"action",
";",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}"
] | Which action was requested?
@param string $default
@return string | [
"Which",
"action",
"was",
"requested?"
] | 9ab7a9f7a8c02e1d41ca40301afada8129ea0a79 | https://github.com/werx/core/blob/9ab7a9f7a8c02e1d41ca40301afada8129ea0a79/src/Controller.php#L274-L281 | train |
AlexyaFramework/Database | Alexya/Database/ORM/Model.php | Model.initialize | public static function initialize(Connection $connection, string $baseNamespace = "\\")
{
self::$_connection = $connection;
self::$_baseNamespace = Str::trailing($baseNamespace, "\\");
} | php | public static function initialize(Connection $connection, string $baseNamespace = "\\")
{
self::$_connection = $connection;
self::$_baseNamespace = Str::trailing($baseNamespace, "\\");
} | [
"public",
"static",
"function",
"initialize",
"(",
"Connection",
"$",
"connection",
",",
"string",
"$",
"baseNamespace",
"=",
"\"\\\\\"",
")",
"{",
"self",
"::",
"$",
"_connection",
"=",
"$",
"connection",
";",
"self",
"::",
"$",
"_baseNamespace",
"=",
"Str",
"::",
"trailing",
"(",
"$",
"baseNamespace",
",",
"\"\\\\\"",
")",
";",
"}"
] | Initializes the class.
@param Connection $connection Database connection.
@param string $baseNamespace Base namespace of the ORM classes. | [
"Initializes",
"the",
"class",
"."
] | 5eb12dc183700ed2357495f4d2c2863ca033eb5a | https://github.com/AlexyaFramework/Database/blob/5eb12dc183700ed2357495f4d2c2863ca033eb5a/Alexya/Database/ORM/Model.php#L196-L200 | train |
AlexyaFramework/Database | Alexya/Database/ORM/Model.php | Model.find | public static function find($id, $limit = -1, string $table = "", bool $setRelations = true)
{
$query = new QueryBuilder(self::$_connection);
$model = new static();
$query->select("*");
if($table === "") {
$query->from($model->getTable());
} else {
$query->from($table);
}
$query = static::_setWhere($id, $query, $model->_primaryKey);
if(
is_int($limit) &&
$limit < 0
) {
$query->limit(1);
} else {
$query->limit($limit);
}
$result = $query->execute();
$return = [];
foreach($result as $r) {
if(
empty($limit) ||
is_int($limit) && $limit < 0
) {
$model = new static($r, $setRelations);
if($table !== "") {
$model->_table = $table;
}
return $model;
}
$model = new static($r, $setRelations);
if($table !== "") {
$model->_table = $table;
}
$return[] = $model;
}
return $return;
} | php | public static function find($id, $limit = -1, string $table = "", bool $setRelations = true)
{
$query = new QueryBuilder(self::$_connection);
$model = new static();
$query->select("*");
if($table === "") {
$query->from($model->getTable());
} else {
$query->from($table);
}
$query = static::_setWhere($id, $query, $model->_primaryKey);
if(
is_int($limit) &&
$limit < 0
) {
$query->limit(1);
} else {
$query->limit($limit);
}
$result = $query->execute();
$return = [];
foreach($result as $r) {
if(
empty($limit) ||
is_int($limit) && $limit < 0
) {
$model = new static($r, $setRelations);
if($table !== "") {
$model->_table = $table;
}
return $model;
}
$model = new static($r, $setRelations);
if($table !== "") {
$model->_table = $table;
}
$return[] = $model;
}
return $return;
} | [
"public",
"static",
"function",
"find",
"(",
"$",
"id",
",",
"$",
"limit",
"=",
"-",
"1",
",",
"string",
"$",
"table",
"=",
"\"\"",
",",
"bool",
"$",
"setRelations",
"=",
"true",
")",
"{",
"$",
"query",
"=",
"new",
"QueryBuilder",
"(",
"self",
"::",
"$",
"_connection",
")",
";",
"$",
"model",
"=",
"new",
"static",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"\"*\"",
")",
";",
"if",
"(",
"$",
"table",
"===",
"\"\"",
")",
"{",
"$",
"query",
"->",
"from",
"(",
"$",
"model",
"->",
"getTable",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"from",
"(",
"$",
"table",
")",
";",
"}",
"$",
"query",
"=",
"static",
"::",
"_setWhere",
"(",
"$",
"id",
",",
"$",
"query",
",",
"$",
"model",
"->",
"_primaryKey",
")",
";",
"if",
"(",
"is_int",
"(",
"$",
"limit",
")",
"&&",
"$",
"limit",
"<",
"0",
")",
"{",
"$",
"query",
"->",
"limit",
"(",
"1",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"limit",
"(",
"$",
"limit",
")",
";",
"}",
"$",
"result",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"r",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"limit",
")",
"||",
"is_int",
"(",
"$",
"limit",
")",
"&&",
"$",
"limit",
"<",
"0",
")",
"{",
"$",
"model",
"=",
"new",
"static",
"(",
"$",
"r",
",",
"$",
"setRelations",
")",
";",
"if",
"(",
"$",
"table",
"!==",
"\"\"",
")",
"{",
"$",
"model",
"->",
"_table",
"=",
"$",
"table",
";",
"}",
"return",
"$",
"model",
";",
"}",
"$",
"model",
"=",
"new",
"static",
"(",
"$",
"r",
",",
"$",
"setRelations",
")",
";",
"if",
"(",
"$",
"table",
"!==",
"\"\"",
")",
"{",
"$",
"model",
"->",
"_table",
"=",
"$",
"table",
";",
"}",
"$",
"return",
"[",
"]",
"=",
"$",
"model",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Finds and returns one or more record from the database.
@param int|string|array $id Primary key value or `WHERE` clause.
@param int|array $limit Amount of records to retrieve from database,
if `-1` (or empty array) an instance of the Model
class will be returned.
@param string $table Table that will be used to get the records from.
@param bool $setRelations Whether relations should be processed or not.
@return Model|Model[] Records from the database. | [
"Finds",
"and",
"returns",
"one",
"or",
"more",
"record",
"from",
"the",
"database",
"."
] | 5eb12dc183700ed2357495f4d2c2863ca033eb5a | https://github.com/AlexyaFramework/Database/blob/5eb12dc183700ed2357495f4d2c2863ca033eb5a/Alexya/Database/ORM/Model.php#L244-L293 | train |
AlexyaFramework/Database | Alexya/Database/ORM/Model.php | Model.all | public static function all(array $where = [], string $table = "", bool $setRelations = true) : array
{
$query = new QueryBuilder(self::$_connection);
$model = new static();
$query->select("*");
if($table === "") {
$query->from($model->getTable());
} else {
$query->from($table);
}
$query = static::_setWhere($where, $query, $model->_primaryKey);
$result = $query->execute();
$return = [];
foreach($result as $r) {
$model = new static($r, $setRelations);
if($table !== "") {
$model->_table = $table;
}
$return[] = $model;
}
return $return;
} | php | public static function all(array $where = [], string $table = "", bool $setRelations = true) : array
{
$query = new QueryBuilder(self::$_connection);
$model = new static();
$query->select("*");
if($table === "") {
$query->from($model->getTable());
} else {
$query->from($table);
}
$query = static::_setWhere($where, $query, $model->_primaryKey);
$result = $query->execute();
$return = [];
foreach($result as $r) {
$model = new static($r, $setRelations);
if($table !== "") {
$model->_table = $table;
}
$return[] = $model;
}
return $return;
} | [
"public",
"static",
"function",
"all",
"(",
"array",
"$",
"where",
"=",
"[",
"]",
",",
"string",
"$",
"table",
"=",
"\"\"",
",",
"bool",
"$",
"setRelations",
"=",
"true",
")",
":",
"array",
"{",
"$",
"query",
"=",
"new",
"QueryBuilder",
"(",
"self",
"::",
"$",
"_connection",
")",
";",
"$",
"model",
"=",
"new",
"static",
"(",
")",
";",
"$",
"query",
"->",
"select",
"(",
"\"*\"",
")",
";",
"if",
"(",
"$",
"table",
"===",
"\"\"",
")",
"{",
"$",
"query",
"->",
"from",
"(",
"$",
"model",
"->",
"getTable",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"query",
"->",
"from",
"(",
"$",
"table",
")",
";",
"}",
"$",
"query",
"=",
"static",
"::",
"_setWhere",
"(",
"$",
"where",
",",
"$",
"query",
",",
"$",
"model",
"->",
"_primaryKey",
")",
";",
"$",
"result",
"=",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"r",
")",
"{",
"$",
"model",
"=",
"new",
"static",
"(",
"$",
"r",
",",
"$",
"setRelations",
")",
";",
"if",
"(",
"$",
"table",
"!==",
"\"\"",
")",
"{",
"$",
"model",
"->",
"_table",
"=",
"$",
"table",
";",
"}",
"$",
"return",
"[",
"]",
"=",
"$",
"model",
";",
"}",
"return",
"$",
"return",
";",
"}"
] | Returns all records from database.
@param array $where Where clause array.
@param string $table Table that will be used to get the records from.
@param bool $setRelations Whether relations should be processed or not.
@return Model[] Records from database. | [
"Returns",
"all",
"records",
"from",
"database",
"."
] | 5eb12dc183700ed2357495f4d2c2863ca033eb5a | https://github.com/AlexyaFramework/Database/blob/5eb12dc183700ed2357495f4d2c2863ca033eb5a/Alexya/Database/ORM/Model.php#L304-L332 | train |
AlexyaFramework/Database | Alexya/Database/ORM/Model.php | Model._setWhere | private static function _setWhere($where, QueryBuilder $query, string $primaryKey = "id") : QueryBuilder
{
if(!is_array($where)) {
return $query->where([
$primaryKey => $where
]);
}
$columns = $where;
unset($columns["ORDER BY"]);
unset($columns["LIMIT"]);
unset($columns["OFFSET"]);
if(!empty($columns)) {
$query->where($columns);
}
if(isset($where["ORDER BY"])) {
$order = $where["ORDER BY"];
if(!is_array($order)) {
$order = [$order];
}
$query->order(... $order);
}
if(isset($where["LIMIT"])) {
$limit = $where["LIMIT"];
if(!is_array($limit)) {
$limit = [$limit];
}
$query->limit(... $limit);
}
if(isset($where["OFFSET"])) {
$query->offset($where["OFFSET"]);
}
return $query;
} | php | private static function _setWhere($where, QueryBuilder $query, string $primaryKey = "id") : QueryBuilder
{
if(!is_array($where)) {
return $query->where([
$primaryKey => $where
]);
}
$columns = $where;
unset($columns["ORDER BY"]);
unset($columns["LIMIT"]);
unset($columns["OFFSET"]);
if(!empty($columns)) {
$query->where($columns);
}
if(isset($where["ORDER BY"])) {
$order = $where["ORDER BY"];
if(!is_array($order)) {
$order = [$order];
}
$query->order(... $order);
}
if(isset($where["LIMIT"])) {
$limit = $where["LIMIT"];
if(!is_array($limit)) {
$limit = [$limit];
}
$query->limit(... $limit);
}
if(isset($where["OFFSET"])) {
$query->offset($where["OFFSET"]);
}
return $query;
} | [
"private",
"static",
"function",
"_setWhere",
"(",
"$",
"where",
",",
"QueryBuilder",
"$",
"query",
",",
"string",
"$",
"primaryKey",
"=",
"\"id\"",
")",
":",
"QueryBuilder",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"where",
")",
")",
"{",
"return",
"$",
"query",
"->",
"where",
"(",
"[",
"$",
"primaryKey",
"=>",
"$",
"where",
"]",
")",
";",
"}",
"$",
"columns",
"=",
"$",
"where",
";",
"unset",
"(",
"$",
"columns",
"[",
"\"ORDER BY\"",
"]",
")",
";",
"unset",
"(",
"$",
"columns",
"[",
"\"LIMIT\"",
"]",
")",
";",
"unset",
"(",
"$",
"columns",
"[",
"\"OFFSET\"",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"columns",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"where",
"[",
"\"ORDER BY\"",
"]",
")",
")",
"{",
"$",
"order",
"=",
"$",
"where",
"[",
"\"ORDER BY\"",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"order",
")",
")",
"{",
"$",
"order",
"=",
"[",
"$",
"order",
"]",
";",
"}",
"$",
"query",
"->",
"order",
"(",
"...",
"$",
"order",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"where",
"[",
"\"LIMIT\"",
"]",
")",
")",
"{",
"$",
"limit",
"=",
"$",
"where",
"[",
"\"LIMIT\"",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"limit",
")",
")",
"{",
"$",
"limit",
"=",
"[",
"$",
"limit",
"]",
";",
"}",
"$",
"query",
"->",
"limit",
"(",
"...",
"$",
"limit",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"where",
"[",
"\"OFFSET\"",
"]",
")",
")",
"{",
"$",
"query",
"->",
"offset",
"(",
"$",
"where",
"[",
"\"OFFSET\"",
"]",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Sets the WHERE param to the query.
@param int|array $where WHERE param.
@param QueryBuilder $query Query to build.
@param string $primaryKey Table primary key.
@return QueryBuilder Query object. | [
"Sets",
"the",
"WHERE",
"param",
"to",
"the",
"query",
"."
] | 5eb12dc183700ed2357495f4d2c2863ca033eb5a | https://github.com/AlexyaFramework/Database/blob/5eb12dc183700ed2357495f4d2c2863ca033eb5a/Alexya/Database/ORM/Model.php#L384-L423 | train |
AlexyaFramework/Database | Alexya/Database/ORM/Model.php | Model.set | public function set(string $name, $value)
{
$this->_data[$name] = $value;
if(!is_object($value)) {
$this->_changed[$name] = $value;
}
} | php | public function set(string $name, $value)
{
$this->_data[$name] = $value;
if(!is_object($value)) {
$this->_changed[$name] = $value;
}
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_data",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"_changed",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | Sets a column.
@param string $name Column name.
@param string $value Column value. | [
"Sets",
"a",
"column",
"."
] | 5eb12dc183700ed2357495f4d2c2863ca033eb5a | https://github.com/AlexyaFramework/Database/blob/5eb12dc183700ed2357495f4d2c2863ca033eb5a/Alexya/Database/ORM/Model.php#L768-L775 | train |
AlexyaFramework/Database | Alexya/Database/ORM/Model.php | Model.save | public function save()
{
$query = new QueryBuilder(self::$_connection);
if($this->_isInsert) {
$query->insert($this->getTable())
->values($this->_changed);
$id = self::$_connection->insert($query->getQuery());
$this->_data[$this->_primaryKey] = $id;
$this->_isInsert = false;
$this->_changed = [];
return;
}
$query->update($this->getTable())
->set($this->_changed)
->where([
$this->_primaryKey => $this->_data[$this->_primaryKey]
])
->execute();
$this->_changed = [];
} | php | public function save()
{
$query = new QueryBuilder(self::$_connection);
if($this->_isInsert) {
$query->insert($this->getTable())
->values($this->_changed);
$id = self::$_connection->insert($query->getQuery());
$this->_data[$this->_primaryKey] = $id;
$this->_isInsert = false;
$this->_changed = [];
return;
}
$query->update($this->getTable())
->set($this->_changed)
->where([
$this->_primaryKey => $this->_data[$this->_primaryKey]
])
->execute();
$this->_changed = [];
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"query",
"=",
"new",
"QueryBuilder",
"(",
"self",
"::",
"$",
"_connection",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_isInsert",
")",
"{",
"$",
"query",
"->",
"insert",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
"->",
"values",
"(",
"$",
"this",
"->",
"_changed",
")",
";",
"$",
"id",
"=",
"self",
"::",
"$",
"_connection",
"->",
"insert",
"(",
"$",
"query",
"->",
"getQuery",
"(",
")",
")",
";",
"$",
"this",
"->",
"_data",
"[",
"$",
"this",
"->",
"_primaryKey",
"]",
"=",
"$",
"id",
";",
"$",
"this",
"->",
"_isInsert",
"=",
"false",
";",
"$",
"this",
"->",
"_changed",
"=",
"[",
"]",
";",
"return",
";",
"}",
"$",
"query",
"->",
"update",
"(",
"$",
"this",
"->",
"getTable",
"(",
")",
")",
"->",
"set",
"(",
"$",
"this",
"->",
"_changed",
")",
"->",
"where",
"(",
"[",
"$",
"this",
"->",
"_primaryKey",
"=>",
"$",
"this",
"->",
"_data",
"[",
"$",
"this",
"->",
"_primaryKey",
"]",
"]",
")",
"->",
"execute",
"(",
")",
";",
"$",
"this",
"->",
"_changed",
"=",
"[",
"]",
";",
"}"
] | Saves the changes to the database. | [
"Saves",
"the",
"changes",
"to",
"the",
"database",
"."
] | 5eb12dc183700ed2357495f4d2c2863ca033eb5a | https://github.com/AlexyaFramework/Database/blob/5eb12dc183700ed2357495f4d2c2863ca033eb5a/Alexya/Database/ORM/Model.php#L803-L828 | train |
AlexyaFramework/Database | Alexya/Database/ORM/Model.php | Model.getTable | public function getTable() : string
{
if(!empty($this->_table)) {
return $this->_table;
}
$class = explode("\\", str_replace(self::$_baseNamespace, "", "\\".get_called_class()));
$table = Str::snake(Str::plural($class));
$this->_table = $table;
return $this->_table;
} | php | public function getTable() : string
{
if(!empty($this->_table)) {
return $this->_table;
}
$class = explode("\\", str_replace(self::$_baseNamespace, "", "\\".get_called_class()));
$table = Str::snake(Str::plural($class));
$this->_table = $table;
return $this->_table;
} | [
"public",
"function",
"getTable",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_table",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_table",
";",
"}",
"$",
"class",
"=",
"explode",
"(",
"\"\\\\\"",
",",
"str_replace",
"(",
"self",
"::",
"$",
"_baseNamespace",
",",
"\"\"",
",",
"\"\\\\\"",
".",
"get_called_class",
"(",
")",
")",
")",
";",
"$",
"table",
"=",
"Str",
"::",
"snake",
"(",
"Str",
"::",
"plural",
"(",
"$",
"class",
")",
")",
";",
"$",
"this",
"->",
"_table",
"=",
"$",
"table",
";",
"return",
"$",
"this",
"->",
"_table",
";",
"}"
] | Builds and returns table name.
@return string Table name. | [
"Builds",
"and",
"returns",
"table",
"name",
"."
] | 5eb12dc183700ed2357495f4d2c2863ca033eb5a | https://github.com/AlexyaFramework/Database/blob/5eb12dc183700ed2357495f4d2c2863ca033eb5a/Alexya/Database/ORM/Model.php#L835-L847 | train |
AlexyaFramework/Database | Alexya/Database/ORM/Model.php | Model.asArray | public function asArray(bool $decodeJSON = true) : array
{
if(!$decodeJSON) {
return $this->_data;
}
$return = [];
foreach($this->_data as $key => $value) {
$decoded = json_decode($value);
$return[$key] = $decoded;
if(
!is_array($decoded) &&
!is_object($decoded)
) {
$return[$key] = $value;
}
}
return $return;
} | php | public function asArray(bool $decodeJSON = true) : array
{
if(!$decodeJSON) {
return $this->_data;
}
$return = [];
foreach($this->_data as $key => $value) {
$decoded = json_decode($value);
$return[$key] = $decoded;
if(
!is_array($decoded) &&
!is_object($decoded)
) {
$return[$key] = $value;
}
}
return $return;
} | [
"public",
"function",
"asArray",
"(",
"bool",
"$",
"decodeJSON",
"=",
"true",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"decodeJSON",
")",
"{",
"return",
"$",
"this",
"->",
"_data",
";",
"}",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"decoded",
"=",
"json_decode",
"(",
"$",
"value",
")",
";",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"$",
"decoded",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"decoded",
")",
"&&",
"!",
"is_object",
"(",
"$",
"decoded",
")",
")",
"{",
"$",
"return",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Returns table values.
@param bool $decodeJSON Whether the JSONs should be decoded or not.
@return array Table values. | [
"Returns",
"table",
"values",
"."
] | 5eb12dc183700ed2357495f4d2c2863ca033eb5a | https://github.com/AlexyaFramework/Database/blob/5eb12dc183700ed2357495f4d2c2863ca033eb5a/Alexya/Database/ORM/Model.php#L856-L876 | train |
AlexyaFramework/Database | Alexya/Database/ORM/Model.php | Model.asJSON | public function asJSON() : string
{
$fields = [];
foreach($this->_data as $key => $value) {
if(!is_object($value)) {
$fields[$key] = $value;
}
}
return json_encode($fields);
} | php | public function asJSON() : string
{
$fields = [];
foreach($this->_data as $key => $value) {
if(!is_object($value)) {
$fields[$key] = $value;
}
}
return json_encode($fields);
} | [
"public",
"function",
"asJSON",
"(",
")",
":",
"string",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"fields",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"json_encode",
"(",
"$",
"fields",
")",
";",
"}"
] | Returns values as a JSON.
@return string Encoded JSON. | [
"Returns",
"values",
"as",
"a",
"JSON",
"."
] | 5eb12dc183700ed2357495f4d2c2863ca033eb5a | https://github.com/AlexyaFramework/Database/blob/5eb12dc183700ed2357495f4d2c2863ca033eb5a/Alexya/Database/ORM/Model.php#L883-L894 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.