repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
freialib/freia.autoloader | src/SymbolEnvironment.php | SymbolEnvironment.findFirstFileMatchingAfterNext | function findFirstFileMatchingAfterNext($ns, $name, $filename) {
$nextPtr = \strrpos($ns, '\\next\\');
// due to the way the syntax works, the namespace before the keyword
// next is implied from the file namespace so it's always a complete
// namespace rather then a partial one
$skipNamespace = substr($ns, 0, $nextPtr + 1);
$targetNs = substr($ns, $nextPtr + 6); // strlen('\\next\\') = 6
$skipped = false;
foreach ($this->state['modules'] as $module) {
if ( ! $skipped) {
if ($module['namespace'] == $skipNamespace) {
$skipped = true;
}
continue;
}
if ( ! $module['enabled']) {
continue;
}
if (\strripos($module['namespace'], $targetNs) !== false) {
$targetfile = $module['path'].'/src/'.$filename.'.php';
if ($this->file_exists($targetfile)) {
$target = $module['namespace'].$name;
return [ $targetfile, $module['namespace'], $target ];
}
}
}
return null; // failed to match anything
} | php | function findFirstFileMatchingAfterNext($ns, $name, $filename) {
$nextPtr = \strrpos($ns, '\\next\\');
// due to the way the syntax works, the namespace before the keyword
// next is implied from the file namespace so it's always a complete
// namespace rather then a partial one
$skipNamespace = substr($ns, 0, $nextPtr + 1);
$targetNs = substr($ns, $nextPtr + 6); // strlen('\\next\\') = 6
$skipped = false;
foreach ($this->state['modules'] as $module) {
if ( ! $skipped) {
if ($module['namespace'] == $skipNamespace) {
$skipped = true;
}
continue;
}
if ( ! $module['enabled']) {
continue;
}
if (\strripos($module['namespace'], $targetNs) !== false) {
$targetfile = $module['path'].'/src/'.$filename.'.php';
if ($this->file_exists($targetfile)) {
$target = $module['namespace'].$name;
return [ $targetfile, $module['namespace'], $target ];
}
}
}
return null; // failed to match anything
} | [
"function",
"findFirstFileMatchingAfterNext",
"(",
"$",
"ns",
",",
"$",
"name",
",",
"$",
"filename",
")",
"{",
"$",
"nextPtr",
"=",
"\\",
"strrpos",
"(",
"$",
"ns",
",",
"'\\\\next\\\\'",
")",
";",
"// due to the way the syntax works, the namespace before the keyword",
"// next is implied from the file namespace so it's always a complete",
"// namespace rather then a partial one",
"$",
"skipNamespace",
"=",
"substr",
"(",
"$",
"ns",
",",
"0",
",",
"$",
"nextPtr",
"+",
"1",
")",
";",
"$",
"targetNs",
"=",
"substr",
"(",
"$",
"ns",
",",
"$",
"nextPtr",
"+",
"6",
")",
";",
"// strlen('\\\\next\\\\') = 6",
"$",
"skipped",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"state",
"[",
"'modules'",
"]",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"!",
"$",
"skipped",
")",
"{",
"if",
"(",
"$",
"module",
"[",
"'namespace'",
"]",
"==",
"$",
"skipNamespace",
")",
"{",
"$",
"skipped",
"=",
"true",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"module",
"[",
"'enabled'",
"]",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"\\",
"strripos",
"(",
"$",
"module",
"[",
"'namespace'",
"]",
",",
"$",
"targetNs",
")",
"!==",
"false",
")",
"{",
"$",
"targetfile",
"=",
"$",
"module",
"[",
"'path'",
"]",
".",
"'/src/'",
".",
"$",
"filename",
".",
"'.php'",
";",
"if",
"(",
"$",
"this",
"->",
"file_exists",
"(",
"$",
"targetfile",
")",
")",
"{",
"$",
"target",
"=",
"$",
"module",
"[",
"'namespace'",
"]",
".",
"$",
"name",
";",
"return",
"[",
"$",
"targetfile",
",",
"$",
"module",
"[",
"'namespace'",
"]",
",",
"$",
"target",
"]",
";",
"}",
"}",
"}",
"return",
"null",
";",
"// failed to match anything",
"}"
] | Similar to findFirstFileMatching but assumes /next/ in segment and
matches after skipping the everything up to and including the namespace
before the /next/ key segment.
@return array [ $targetfile, $targetns, $target ] | [
"Similar",
"to",
"findFirstFileMatching",
"but",
"assumes",
"/",
"next",
"/",
"in",
"segment",
"and",
"matches",
"after",
"skipping",
"the",
"everything",
"up",
"to",
"and",
"including",
"the",
"namespace",
"before",
"the",
"/",
"next",
"/",
"key",
"segment",
"."
] | train | https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolEnvironment.php#L350-L385 |
freialib/freia.autoloader | src/SymbolEnvironment.php | SymbolEnvironment.loadSymbol | function loadSymbol($symbol, $filepath) {
$this->requirefile($filepath);
$this->state['symbols'][$symbol] = $filepath;
$this->state['loaded'][] = $symbol;
} | php | function loadSymbol($symbol, $filepath) {
$this->requirefile($filepath);
$this->state['symbols'][$symbol] = $filepath;
$this->state['loaded'][] = $symbol;
} | [
"function",
"loadSymbol",
"(",
"$",
"symbol",
",",
"$",
"filepath",
")",
"{",
"$",
"this",
"->",
"requirefile",
"(",
"$",
"filepath",
")",
";",
"$",
"this",
"->",
"state",
"[",
"'symbols'",
"]",
"[",
"$",
"symbol",
"]",
"=",
"$",
"filepath",
";",
"$",
"this",
"->",
"state",
"[",
"'loaded'",
"]",
"[",
"]",
"=",
"$",
"symbol",
";",
"}"
] | ... | [
"..."
] | train | https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolEnvironment.php#L390-L394 |
freialib/freia.autoloader | src/SymbolEnvironment.php | SymbolEnvironment.aliasSymbol | function aliasSymbol($from, $to) {
$this->class_alias($from, $to);
$this->state['aliases'][$to] = $from;
$this->state['loaded'][] = $to;
} | php | function aliasSymbol($from, $to) {
$this->class_alias($from, $to);
$this->state['aliases'][$to] = $from;
$this->state['loaded'][] = $to;
} | [
"function",
"aliasSymbol",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"$",
"this",
"->",
"class_alias",
"(",
"$",
"from",
",",
"$",
"to",
")",
";",
"$",
"this",
"->",
"state",
"[",
"'aliases'",
"]",
"[",
"$",
"to",
"]",
"=",
"$",
"from",
";",
"$",
"this",
"->",
"state",
"[",
"'loaded'",
"]",
"[",
"]",
"=",
"$",
"to",
";",
"}"
] | ... | [
"..."
] | train | https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolEnvironment.php#L399-L403 |
freialib/freia.autoloader | src/SymbolEnvironment.php | SymbolEnvironment.autoresolve | function autoresolve($symbol) {
// is the symbol an alias?
if (\array_key_exists($symbol, $this->state['aliases'])) {
// then resolve the alias
// you can only alias to know symbols so the following will succeed
$this->autoresolve($this->state['aliases'][$symbol]);
// and afterwards alias the symbol
$this->class_alias($this->state['aliases'][$symbol], $symbol);
return true;
}
// do we know of the symbol's path?
if (\array_key_exists($symbol, $this->state['symbols'])) {
$this->requirefile($this->state['symbols'][$symbol]);
return true;
}
return false; // none of the above
} | php | function autoresolve($symbol) {
// is the symbol an alias?
if (\array_key_exists($symbol, $this->state['aliases'])) {
// then resolve the alias
// you can only alias to know symbols so the following will succeed
$this->autoresolve($this->state['aliases'][$symbol]);
// and afterwards alias the symbol
$this->class_alias($this->state['aliases'][$symbol], $symbol);
return true;
}
// do we know of the symbol's path?
if (\array_key_exists($symbol, $this->state['symbols'])) {
$this->requirefile($this->state['symbols'][$symbol]);
return true;
}
return false; // none of the above
} | [
"function",
"autoresolve",
"(",
"$",
"symbol",
")",
"{",
"// is the symbol an alias?",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"symbol",
",",
"$",
"this",
"->",
"state",
"[",
"'aliases'",
"]",
")",
")",
"{",
"// then resolve the alias",
"// you can only alias to know symbols so the following will succeed",
"$",
"this",
"->",
"autoresolve",
"(",
"$",
"this",
"->",
"state",
"[",
"'aliases'",
"]",
"[",
"$",
"symbol",
"]",
")",
";",
"// and afterwards alias the symbol",
"$",
"this",
"->",
"class_alias",
"(",
"$",
"this",
"->",
"state",
"[",
"'aliases'",
"]",
"[",
"$",
"symbol",
"]",
",",
"$",
"symbol",
")",
";",
"return",
"true",
";",
"}",
"// do we know of the symbol's path?",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"symbol",
",",
"$",
"this",
"->",
"state",
"[",
"'symbols'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"requirefile",
"(",
"$",
"this",
"->",
"state",
"[",
"'symbols'",
"]",
"[",
"$",
"symbol",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"// none of the above",
"}"
] | Attempt to auto-resolve a symbol based on past state. | [
"Attempt",
"to",
"auto",
"-",
"resolve",
"a",
"symbol",
"based",
"on",
"past",
"state",
"."
] | train | https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolEnvironment.php#L408-L427 |
freialib/freia.autoloader | src/SymbolEnvironment.php | SymbolEnvironment.save | function save() {
if ($this->cacheConf['type'] == 'noop') {
// do nothing
}
else { // non-noop
$stateCopy = $this->state;
$stateCopy['loaded'] = [];
if ($this->cacheConf['type'] == 'file') {
$username = \get_current_user();
$cacheDir = realpath($this->syspath.'/'.\trim($this->cacheConf['path'], '\\/'));
$cachePath = $cacheDir.'/freia.'.(\php_sapi_name() === 'cli' ? 'cli' : 'server').'.'.$username.'.symbols.json';
if ($this->file_exists($cacheDir)) {
try {
$this->file_put_contents($cachePath, \json_encode($stateCopy, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
if ( ! $this->chmod($cachePath, $this->filePermission())) {
$this->error_log("Unable to set permissions on cache file: $cachePath");
}
}
catch (\Exception $e) {
$this->error_log('Failed to save state to cache file ['.$cachePath.'] Error: '.$e->getMessage());
}
}
else {
$this->error_log('Missing cache directory: '.$this->cacheConf['path']);
}
}
else if ($this->cacheConf['type'] == 'memcached') {
$mc = $this->memcachedInstance();
$success = $mc->set('freia-symbols', $stateCopy, time() + 604800);
if ( ! $success) {
$this->error_log("Memcached failed to store key freia-symbols, code: ".$mc->getResultCode());
}
}
}
} | php | function save() {
if ($this->cacheConf['type'] == 'noop') {
// do nothing
}
else { // non-noop
$stateCopy = $this->state;
$stateCopy['loaded'] = [];
if ($this->cacheConf['type'] == 'file') {
$username = \get_current_user();
$cacheDir = realpath($this->syspath.'/'.\trim($this->cacheConf['path'], '\\/'));
$cachePath = $cacheDir.'/freia.'.(\php_sapi_name() === 'cli' ? 'cli' : 'server').'.'.$username.'.symbols.json';
if ($this->file_exists($cacheDir)) {
try {
$this->file_put_contents($cachePath, \json_encode($stateCopy, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
if ( ! $this->chmod($cachePath, $this->filePermission())) {
$this->error_log("Unable to set permissions on cache file: $cachePath");
}
}
catch (\Exception $e) {
$this->error_log('Failed to save state to cache file ['.$cachePath.'] Error: '.$e->getMessage());
}
}
else {
$this->error_log('Missing cache directory: '.$this->cacheConf['path']);
}
}
else if ($this->cacheConf['type'] == 'memcached') {
$mc = $this->memcachedInstance();
$success = $mc->set('freia-symbols', $stateCopy, time() + 604800);
if ( ! $success) {
$this->error_log("Memcached failed to store key freia-symbols, code: ".$mc->getResultCode());
}
}
}
} | [
"function",
"save",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'noop'",
")",
"{",
"// do nothing",
"}",
"else",
"{",
"// non-noop",
"$",
"stateCopy",
"=",
"$",
"this",
"->",
"state",
";",
"$",
"stateCopy",
"[",
"'loaded'",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'file'",
")",
"{",
"$",
"username",
"=",
"\\",
"get_current_user",
"(",
")",
";",
"$",
"cacheDir",
"=",
"realpath",
"(",
"$",
"this",
"->",
"syspath",
".",
"'/'",
".",
"\\",
"trim",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'path'",
"]",
",",
"'\\\\/'",
")",
")",
";",
"$",
"cachePath",
"=",
"$",
"cacheDir",
".",
"'/freia.'",
".",
"(",
"\\",
"php_sapi_name",
"(",
")",
"===",
"'cli'",
"?",
"'cli'",
":",
"'server'",
")",
".",
"'.'",
".",
"$",
"username",
".",
"'.symbols.json'",
";",
"if",
"(",
"$",
"this",
"->",
"file_exists",
"(",
"$",
"cacheDir",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"file_put_contents",
"(",
"$",
"cachePath",
",",
"\\",
"json_encode",
"(",
"$",
"stateCopy",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_SLASHES",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"chmod",
"(",
"$",
"cachePath",
",",
"$",
"this",
"->",
"filePermission",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"error_log",
"(",
"\"Unable to set permissions on cache file: $cachePath\"",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"error_log",
"(",
"'Failed to save state to cache file ['",
".",
"$",
"cachePath",
".",
"'] Error: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"error_log",
"(",
"'Missing cache directory: '",
".",
"$",
"this",
"->",
"cacheConf",
"[",
"'path'",
"]",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'memcached'",
")",
"{",
"$",
"mc",
"=",
"$",
"this",
"->",
"memcachedInstance",
"(",
")",
";",
"$",
"success",
"=",
"$",
"mc",
"->",
"set",
"(",
"'freia-symbols'",
",",
"$",
"stateCopy",
",",
"time",
"(",
")",
"+",
"604800",
")",
";",
"if",
"(",
"!",
"$",
"success",
")",
"{",
"$",
"this",
"->",
"error_log",
"(",
"\"Memcached failed to store key freia-symbols, code: \"",
".",
"$",
"mc",
"->",
"getResultCode",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] | Save current state to persistent store | [
"Save",
"current",
"state",
"to",
"persistent",
"store"
] | train | https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolEnvironment.php#L467-L504 |
freialib/freia.autoloader | src/SymbolEnvironment.php | SymbolEnvironment.load | function load() {
if ($this->cacheConf['type'] == 'noop') {
return null; // do nothing
}
else { // non-noop
$loadedState = null;
if ($this->cacheConf['type'] == 'file') {
$username = \get_current_user();
$cacheDir = realpath($this->syspath.'/'.\trim($this->cacheConf['path'], '\\/'));
$cachePath = $cacheDir.'/freia.'.(\php_sapi_name() === 'cli' ? 'cli' : 'server').'.'.$username.'.symbols.json';
if ($this->file_exists($cachePath)) {
try {
$loadedState = \json_decode($this->file_get_contents($cachePath), true);
}
catch (\Exception $e) {
$this->error_log('Failed to load cache file: '.$cachePath);
return null;
}
}
else { // couldn't find cache file
return null;
}
}
else if ($this->cacheConf['type'] == 'memcached') {
$mc = $this->memcachedInstance();
try {
$loadedState = $mc->get('freia-symbols');
}
catch (\Exception $e) {
$loadedState = null;
}
}
// Process Loaded State
// ====================
if ($loadedState == null) {
return null;
}
if ($loadedState['version'] == $this->state['version']) {
return $loadedState;
}
else { // deprecated state
return null;
}
}
} | php | function load() {
if ($this->cacheConf['type'] == 'noop') {
return null; // do nothing
}
else { // non-noop
$loadedState = null;
if ($this->cacheConf['type'] == 'file') {
$username = \get_current_user();
$cacheDir = realpath($this->syspath.'/'.\trim($this->cacheConf['path'], '\\/'));
$cachePath = $cacheDir.'/freia.'.(\php_sapi_name() === 'cli' ? 'cli' : 'server').'.'.$username.'.symbols.json';
if ($this->file_exists($cachePath)) {
try {
$loadedState = \json_decode($this->file_get_contents($cachePath), true);
}
catch (\Exception $e) {
$this->error_log('Failed to load cache file: '.$cachePath);
return null;
}
}
else { // couldn't find cache file
return null;
}
}
else if ($this->cacheConf['type'] == 'memcached') {
$mc = $this->memcachedInstance();
try {
$loadedState = $mc->get('freia-symbols');
}
catch (\Exception $e) {
$loadedState = null;
}
}
// Process Loaded State
// ====================
if ($loadedState == null) {
return null;
}
if ($loadedState['version'] == $this->state['version']) {
return $loadedState;
}
else { // deprecated state
return null;
}
}
} | [
"function",
"load",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'noop'",
")",
"{",
"return",
"null",
";",
"// do nothing",
"}",
"else",
"{",
"// non-noop",
"$",
"loadedState",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'file'",
")",
"{",
"$",
"username",
"=",
"\\",
"get_current_user",
"(",
")",
";",
"$",
"cacheDir",
"=",
"realpath",
"(",
"$",
"this",
"->",
"syspath",
".",
"'/'",
".",
"\\",
"trim",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'path'",
"]",
",",
"'\\\\/'",
")",
")",
";",
"$",
"cachePath",
"=",
"$",
"cacheDir",
".",
"'/freia.'",
".",
"(",
"\\",
"php_sapi_name",
"(",
")",
"===",
"'cli'",
"?",
"'cli'",
":",
"'server'",
")",
".",
"'.'",
".",
"$",
"username",
".",
"'.symbols.json'",
";",
"if",
"(",
"$",
"this",
"->",
"file_exists",
"(",
"$",
"cachePath",
")",
")",
"{",
"try",
"{",
"$",
"loadedState",
"=",
"\\",
"json_decode",
"(",
"$",
"this",
"->",
"file_get_contents",
"(",
"$",
"cachePath",
")",
",",
"true",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"error_log",
"(",
"'Failed to load cache file: '",
".",
"$",
"cachePath",
")",
";",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"// couldn't find cache file",
"return",
"null",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"cacheConf",
"[",
"'type'",
"]",
"==",
"'memcached'",
")",
"{",
"$",
"mc",
"=",
"$",
"this",
"->",
"memcachedInstance",
"(",
")",
";",
"try",
"{",
"$",
"loadedState",
"=",
"$",
"mc",
"->",
"get",
"(",
"'freia-symbols'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"loadedState",
"=",
"null",
";",
"}",
"}",
"// Process Loaded State",
"// ====================",
"if",
"(",
"$",
"loadedState",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"loadedState",
"[",
"'version'",
"]",
"==",
"$",
"this",
"->",
"state",
"[",
"'version'",
"]",
")",
"{",
"return",
"$",
"loadedState",
";",
"}",
"else",
"{",
"// deprecated state",
"return",
"null",
";",
"}",
"}",
"}"
] | Load state from persistent store
@return array previously saved state | [
"Load",
"state",
"from",
"persistent",
"store"
] | train | https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolEnvironment.php#L511-L561 |
benjamindulau/AnoDataGrid | src/Ano/DataGrid/Column/ColumnView.php | ColumnView.get | public function get($name, $default = null)
{
if ('value' === $name) {
$dataGrid = $this->get('dataGrid');
$data = $dataGrid->get('data');
if (null !== ($index = $this->get('index', null))) {
$this->set('value', $this->get('column')->getValue($data, $index));
}
}
return parent::get($name, $default);
} | php | public function get($name, $default = null)
{
if ('value' === $name) {
$dataGrid = $this->get('dataGrid');
$data = $dataGrid->get('data');
if (null !== ($index = $this->get('index', null))) {
$this->set('value', $this->get('column')->getValue($data, $index));
}
}
return parent::get($name, $default);
} | [
"public",
"function",
"get",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"'value'",
"===",
"$",
"name",
")",
"{",
"$",
"dataGrid",
"=",
"$",
"this",
"->",
"get",
"(",
"'dataGrid'",
")",
";",
"$",
"data",
"=",
"$",
"dataGrid",
"->",
"get",
"(",
"'data'",
")",
";",
"if",
"(",
"null",
"!==",
"(",
"$",
"index",
"=",
"$",
"this",
"->",
"get",
"(",
"'index'",
",",
"null",
")",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'value'",
",",
"$",
"this",
"->",
"get",
"(",
"'column'",
")",
"->",
"getValue",
"(",
"$",
"data",
",",
"$",
"index",
")",
")",
";",
"}",
"}",
"return",
"parent",
"::",
"get",
"(",
"$",
"name",
",",
"$",
"default",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/benjamindulau/AnoDataGrid/blob/69b31803929b04e9d6e807bb2213b9b3477d0367/src/Ano/DataGrid/Column/ColumnView.php#L19-L30 |
stubbles/stubbles-streams | src/main/php/file/FileInputStream.php | FileInputStream.castFrom | public static function castFrom($value): InputStream
{
if ($value instanceof InputStream) {
return $value;
}
if (is_string($value)) {
return new self($value);
}
throw new \InvalidArgumentException(
'Given value is neither an instance of' . InputStream::class
. ' nor a string denoting a file'
);
} | php | public static function castFrom($value): InputStream
{
if ($value instanceof InputStream) {
return $value;
}
if (is_string($value)) {
return new self($value);
}
throw new \InvalidArgumentException(
'Given value is neither an instance of' . InputStream::class
. ' nor a string denoting a file'
);
} | [
"public",
"static",
"function",
"castFrom",
"(",
"$",
"value",
")",
":",
"InputStream",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"InputStream",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"value",
")",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Given value is neither an instance of'",
".",
"InputStream",
"::",
"class",
".",
"' nor a string denoting a file'",
")",
";",
"}"
] | casts given value to an input stream
@param \stubbles\streams\InputStream|string $value
@return \stubbles\streams\InputStream
@throws \InvalidArgumentException
@since 5.2.0 | [
"casts",
"given",
"value",
"to",
"an",
"input",
"stream"
] | train | https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/file/FileInputStream.php#L81-L95 |
stubbles/stubbles-streams | src/main/php/file/FileInputStream.php | FileInputStream.getResourceLength | protected function getResourceLength(): int
{
if (null === $this->fileName) {
return parent::getResourceLength();
}
if (substr($this->fileName, 0, 16) === 'compress.zlib://') {
return filesize(substr($this->fileName, 16));
} elseif (substr($this->fileName, 0, 17) === 'compress.bzip2://') {
return filesize(substr($this->fileName, 17));
}
return parent::getResourceLength();
} | php | protected function getResourceLength(): int
{
if (null === $this->fileName) {
return parent::getResourceLength();
}
if (substr($this->fileName, 0, 16) === 'compress.zlib://') {
return filesize(substr($this->fileName, 16));
} elseif (substr($this->fileName, 0, 17) === 'compress.bzip2://') {
return filesize(substr($this->fileName, 17));
}
return parent::getResourceLength();
} | [
"protected",
"function",
"getResourceLength",
"(",
")",
":",
"int",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"fileName",
")",
"{",
"return",
"parent",
"::",
"getResourceLength",
"(",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"fileName",
",",
"0",
",",
"16",
")",
"===",
"'compress.zlib://'",
")",
"{",
"return",
"filesize",
"(",
"substr",
"(",
"$",
"this",
"->",
"fileName",
",",
"16",
")",
")",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"this",
"->",
"fileName",
",",
"0",
",",
"17",
")",
"===",
"'compress.bzip2://'",
")",
"{",
"return",
"filesize",
"(",
"substr",
"(",
"$",
"this",
"->",
"fileName",
",",
"17",
")",
")",
";",
"}",
"return",
"parent",
"::",
"getResourceLength",
"(",
")",
";",
"}"
] | helper method to retrieve the length of the resource
@return int | [
"helper",
"method",
"to",
"retrieve",
"the",
"length",
"of",
"the",
"resource"
] | train | https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/file/FileInputStream.php#L102-L115 |
stubbles/stubbles-streams | src/main/php/file/FileInputStream.php | FileInputStream.tell | public function tell(): int
{
if (null === $this->handle) {
throw new \LogicException('Can not read from closed input stream.');
}
$position = @ftell($this->handle);
if (false === $position) {
throw new StreamException(
'Can not read current position in file: '
. lastErrorMessage('unknown error')
);
}
return $position;
} | php | public function tell(): int
{
if (null === $this->handle) {
throw new \LogicException('Can not read from closed input stream.');
}
$position = @ftell($this->handle);
if (false === $position) {
throw new StreamException(
'Can not read current position in file: '
. lastErrorMessage('unknown error')
);
}
return $position;
} | [
"public",
"function",
"tell",
"(",
")",
":",
"int",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"handle",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Can not read from closed input stream.'",
")",
";",
"}",
"$",
"position",
"=",
"@",
"ftell",
"(",
"$",
"this",
"->",
"handle",
")",
";",
"if",
"(",
"false",
"===",
"$",
"position",
")",
"{",
"throw",
"new",
"StreamException",
"(",
"'Can not read current position in file: '",
".",
"lastErrorMessage",
"(",
"'unknown error'",
")",
")",
";",
"}",
"return",
"$",
"position",
";",
"}"
] | return current position
@return int
@throws \LogicException
@throws \stubbles\streams\StreamException | [
"return",
"current",
"position"
] | train | https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/file/FileInputStream.php#L140-L155 |
afroware/jwtauth | src/Http/Middleware/BaseMiddleware.php | BaseMiddleware.checkForToken | public function checkForToken(Request $request)
{
if (! $this->auth->parser()->setRequest($request)->hasToken()) {
throw new UnauthorizedHttpException('jwTauth', 'Token not provided');
}
} | php | public function checkForToken(Request $request)
{
if (! $this->auth->parser()->setRequest($request)->hasToken()) {
throw new UnauthorizedHttpException('jwTauth', 'Token not provided');
}
} | [
"public",
"function",
"checkForToken",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"auth",
"->",
"parser",
"(",
")",
"->",
"setRequest",
"(",
"$",
"request",
")",
"->",
"hasToken",
"(",
")",
")",
"{",
"throw",
"new",
"UnauthorizedHttpException",
"(",
"'jwTauth'",
",",
"'Token not provided'",
")",
";",
"}",
"}"
] | Check the request for the presence of a token.
@param \Illuminate\Http\Request $request
@throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
@return void | [
"Check",
"the",
"request",
"for",
"the",
"presence",
"of",
"a",
"token",
"."
] | train | https://github.com/afroware/jwtauth/blob/54a0aebd811d87bfdd2b3668696fd53f50490cc1/src/Http/Middleware/BaseMiddleware.php#L49-L54 |
afroware/jwtauth | src/Http/Middleware/BaseMiddleware.php | BaseMiddleware.authenticate | public function authenticate(Request $request)
{
$this->checkForToken($request);
try {
if (! $this->auth->parseToken()->authenticate()) {
throw new UnauthorizedHttpException('jwTauth', 'User not found');
}
} catch (JwTException $e) {
throw new UnauthorizedHttpException('jwTauth', $e->getMessage(), $e, $e->getCode());
}
} | php | public function authenticate(Request $request)
{
$this->checkForToken($request);
try {
if (! $this->auth->parseToken()->authenticate()) {
throw new UnauthorizedHttpException('jwTauth', 'User not found');
}
} catch (JwTException $e) {
throw new UnauthorizedHttpException('jwTauth', $e->getMessage(), $e, $e->getCode());
}
} | [
"public",
"function",
"authenticate",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"checkForToken",
"(",
"$",
"request",
")",
";",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"auth",
"->",
"parseToken",
"(",
")",
"->",
"authenticate",
"(",
")",
")",
"{",
"throw",
"new",
"UnauthorizedHttpException",
"(",
"'jwTauth'",
",",
"'User not found'",
")",
";",
"}",
"}",
"catch",
"(",
"JwTException",
"$",
"e",
")",
"{",
"throw",
"new",
"UnauthorizedHttpException",
"(",
"'jwTauth'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"}"
] | Attempt to authenticate a user via the token in the request.
@param \Illuminate\Http\Request $request
@throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
@return void | [
"Attempt",
"to",
"authenticate",
"a",
"user",
"via",
"the",
"token",
"in",
"the",
"request",
"."
] | train | https://github.com/afroware/jwtauth/blob/54a0aebd811d87bfdd2b3668696fd53f50490cc1/src/Http/Middleware/BaseMiddleware.php#L65-L76 |
Danack/Weaver | src/Weaver/ImplementWeaveGenerator.php | ImplementWeaveGenerator.addDecoratedMethod | function addDecoratedMethod(MethodReflection $sourceMethod, MethodReflection $decoratorMethodReflection ) {
$weavedMethod = MethodGenerator::fromReflection($sourceMethod);
$newBody = $decoratorMethodReflection->getBody();
$newBody = trimBody($newBody);
$parameters = $sourceMethod->getParameters();
$paramArray = [];
$searchArray = [];
$count = 0;
foreach ($parameters as $parameter) {
$searchArray[] = '$param'.$count;
$paramArray[] = '$'.$parameter->getName();
}
$paramList = implode(', ', $paramArray);
$newBody = str_replace(
'$this->__prototype()',
'$this->weavedInstance->'.$sourceMethod->getName()."($paramList)",
$newBody
);
$newBody = str_replace($searchArray, $paramArray, $newBody);
$weavedMethod->setBody($newBody);
$this->generator->addMethodFromGenerator($weavedMethod);
} | php | function addDecoratedMethod(MethodReflection $sourceMethod, MethodReflection $decoratorMethodReflection ) {
$weavedMethod = MethodGenerator::fromReflection($sourceMethod);
$newBody = $decoratorMethodReflection->getBody();
$newBody = trimBody($newBody);
$parameters = $sourceMethod->getParameters();
$paramArray = [];
$searchArray = [];
$count = 0;
foreach ($parameters as $parameter) {
$searchArray[] = '$param'.$count;
$paramArray[] = '$'.$parameter->getName();
}
$paramList = implode(', ', $paramArray);
$newBody = str_replace(
'$this->__prototype()',
'$this->weavedInstance->'.$sourceMethod->getName()."($paramList)",
$newBody
);
$newBody = str_replace($searchArray, $paramArray, $newBody);
$weavedMethod->setBody($newBody);
$this->generator->addMethodFromGenerator($weavedMethod);
} | [
"function",
"addDecoratedMethod",
"(",
"MethodReflection",
"$",
"sourceMethod",
",",
"MethodReflection",
"$",
"decoratorMethodReflection",
")",
"{",
"$",
"weavedMethod",
"=",
"MethodGenerator",
"::",
"fromReflection",
"(",
"$",
"sourceMethod",
")",
";",
"$",
"newBody",
"=",
"$",
"decoratorMethodReflection",
"->",
"getBody",
"(",
")",
";",
"$",
"newBody",
"=",
"trimBody",
"(",
"$",
"newBody",
")",
";",
"$",
"parameters",
"=",
"$",
"sourceMethod",
"->",
"getParameters",
"(",
")",
";",
"$",
"paramArray",
"=",
"[",
"]",
";",
"$",
"searchArray",
"=",
"[",
"]",
";",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"$",
"searchArray",
"[",
"]",
"=",
"'$param'",
".",
"$",
"count",
";",
"$",
"paramArray",
"[",
"]",
"=",
"'$'",
".",
"$",
"parameter",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"paramList",
"=",
"implode",
"(",
"', '",
",",
"$",
"paramArray",
")",
";",
"$",
"newBody",
"=",
"str_replace",
"(",
"'$this->__prototype()'",
",",
"'$this->weavedInstance->'",
".",
"$",
"sourceMethod",
"->",
"getName",
"(",
")",
".",
"\"($paramList)\"",
",",
"$",
"newBody",
")",
";",
"$",
"newBody",
"=",
"str_replace",
"(",
"$",
"searchArray",
",",
"$",
"paramArray",
",",
"$",
"newBody",
")",
";",
"$",
"weavedMethod",
"->",
"setBody",
"(",
"$",
"newBody",
")",
";",
"$",
"this",
"->",
"generator",
"->",
"addMethodFromGenerator",
"(",
"$",
"weavedMethod",
")",
";",
"}"
] | Decorate the method and call the instance.
@param MethodReflection $sourceMethod
@param MethodReflection $decoratorMethodReflection | [
"Decorate",
"the",
"method",
"and",
"call",
"the",
"instance",
"."
] | train | https://github.com/Danack/Weaver/blob/414894cd397daff22d2c71e4988784a1f71b702e/src/Weaver/ImplementWeaveGenerator.php#L112-L140 |
Danack/Weaver | src/Weaver/ImplementWeaveGenerator.php | ImplementWeaveGenerator.addPlainMethod | function addPlainMethod(MethodReflection $sourceMethod) {
$parameters = $sourceMethod->getParameters();
$paramArray = [];
foreach ($parameters as $parameter) {
$paramArray[] = '$'.$parameter->getName();
}
$paramList = implode(', ', $paramArray);
$weavedMethod = MethodGenerator::fromReflection($sourceMethod);
$body = sprintf(
" return \$this->%s->%s(%s);",
$this->implementWeaveInfo->getInstancePropertyName(),
$sourceMethod->getName(),
$paramList
);
$weavedMethod->setBody($body);
$this->generator->addMethodFromGenerator($weavedMethod);
} | php | function addPlainMethod(MethodReflection $sourceMethod) {
$parameters = $sourceMethod->getParameters();
$paramArray = [];
foreach ($parameters as $parameter) {
$paramArray[] = '$'.$parameter->getName();
}
$paramList = implode(', ', $paramArray);
$weavedMethod = MethodGenerator::fromReflection($sourceMethod);
$body = sprintf(
" return \$this->%s->%s(%s);",
$this->implementWeaveInfo->getInstancePropertyName(),
$sourceMethod->getName(),
$paramList
);
$weavedMethod->setBody($body);
$this->generator->addMethodFromGenerator($weavedMethod);
} | [
"function",
"addPlainMethod",
"(",
"MethodReflection",
"$",
"sourceMethod",
")",
"{",
"$",
"parameters",
"=",
"$",
"sourceMethod",
"->",
"getParameters",
"(",
")",
";",
"$",
"paramArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameter",
")",
"{",
"$",
"paramArray",
"[",
"]",
"=",
"'$'",
".",
"$",
"parameter",
"->",
"getName",
"(",
")",
";",
"}",
"$",
"paramList",
"=",
"implode",
"(",
"', '",
",",
"$",
"paramArray",
")",
";",
"$",
"weavedMethod",
"=",
"MethodGenerator",
"::",
"fromReflection",
"(",
"$",
"sourceMethod",
")",
";",
"$",
"body",
"=",
"sprintf",
"(",
"\" return \\$this->%s->%s(%s);\"",
",",
"$",
"this",
"->",
"implementWeaveInfo",
"->",
"getInstancePropertyName",
"(",
")",
",",
"$",
"sourceMethod",
"->",
"getName",
"(",
")",
",",
"$",
"paramList",
")",
";",
"$",
"weavedMethod",
"->",
"setBody",
"(",
"$",
"body",
")",
";",
"$",
"this",
"->",
"generator",
"->",
"addMethodFromGenerator",
"(",
"$",
"weavedMethod",
")",
";",
"}"
] | Add a call to the instance method.
@param MethodReflection $sourceMethod | [
"Add",
"a",
"call",
"to",
"the",
"instance",
"method",
"."
] | train | https://github.com/Danack/Weaver/blob/414894cd397daff22d2c71e4988784a1f71b702e/src/Weaver/ImplementWeaveGenerator.php#L147-L168 |
Danack/Weaver | src/Weaver/ImplementWeaveGenerator.php | ImplementWeaveGenerator.addSourceMethods | function addSourceMethods() {
$methodBindingArray = $this->implementWeaveInfo->getMethodBindingArray();
$methods = $this->sourceClassReflection->getMethods();
foreach ($methods as $sourceMethod) {
if ($sourceMethod->getName() === '__construct') {
continue;
}
$methodBindingToApply = null;
foreach ($methodBindingArray as $methodBinding) {
if ($methodBinding->matchesMethod($sourceMethod->getName()) ) {
$methodBindingToApply = $methodBinding;
break;
}
}
if ($methodBindingToApply != null) {
$decoratorMethod = $methodBindingToApply->getMethod();
$decoratorMethodReflection = $this->decoratorReflection->getMethod($decoratorMethod);
$this->addDecoratedMethod($sourceMethod, $decoratorMethodReflection);
}
else {
$this->addPlainMethod($sourceMethod);
}
}
} | php | function addSourceMethods() {
$methodBindingArray = $this->implementWeaveInfo->getMethodBindingArray();
$methods = $this->sourceClassReflection->getMethods();
foreach ($methods as $sourceMethod) {
if ($sourceMethod->getName() === '__construct') {
continue;
}
$methodBindingToApply = null;
foreach ($methodBindingArray as $methodBinding) {
if ($methodBinding->matchesMethod($sourceMethod->getName()) ) {
$methodBindingToApply = $methodBinding;
break;
}
}
if ($methodBindingToApply != null) {
$decoratorMethod = $methodBindingToApply->getMethod();
$decoratorMethodReflection = $this->decoratorReflection->getMethod($decoratorMethod);
$this->addDecoratedMethod($sourceMethod, $decoratorMethodReflection);
}
else {
$this->addPlainMethod($sourceMethod);
}
}
} | [
"function",
"addSourceMethods",
"(",
")",
"{",
"$",
"methodBindingArray",
"=",
"$",
"this",
"->",
"implementWeaveInfo",
"->",
"getMethodBindingArray",
"(",
")",
";",
"$",
"methods",
"=",
"$",
"this",
"->",
"sourceClassReflection",
"->",
"getMethods",
"(",
")",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"sourceMethod",
")",
"{",
"if",
"(",
"$",
"sourceMethod",
"->",
"getName",
"(",
")",
"===",
"'__construct'",
")",
"{",
"continue",
";",
"}",
"$",
"methodBindingToApply",
"=",
"null",
";",
"foreach",
"(",
"$",
"methodBindingArray",
"as",
"$",
"methodBinding",
")",
"{",
"if",
"(",
"$",
"methodBinding",
"->",
"matchesMethod",
"(",
"$",
"sourceMethod",
"->",
"getName",
"(",
")",
")",
")",
"{",
"$",
"methodBindingToApply",
"=",
"$",
"methodBinding",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"methodBindingToApply",
"!=",
"null",
")",
"{",
"$",
"decoratorMethod",
"=",
"$",
"methodBindingToApply",
"->",
"getMethod",
"(",
")",
";",
"$",
"decoratorMethodReflection",
"=",
"$",
"this",
"->",
"decoratorReflection",
"->",
"getMethod",
"(",
"$",
"decoratorMethod",
")",
";",
"$",
"this",
"->",
"addDecoratedMethod",
"(",
"$",
"sourceMethod",
",",
"$",
"decoratorMethodReflection",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addPlainMethod",
"(",
"$",
"sourceMethod",
")",
";",
"}",
"}",
"}"
] | For all of the methods in that need to be decorated, generate the decorated version
and all the to the generator.
@TODO Shouldn't this only implement the methods in the interface that is being exposed? | [
"For",
"all",
"of",
"the",
"methods",
"in",
"that",
"need",
"to",
"be",
"decorated",
"generate",
"the",
"decorated",
"version",
"and",
"all",
"the",
"to",
"the",
"generator",
"."
] | train | https://github.com/Danack/Weaver/blob/414894cd397daff22d2c71e4988784a1f71b702e/src/Weaver/ImplementWeaveGenerator.php#L175-L201 |
drdplusinfo/drdplus-background | DrdPlus/Background/BackgroundParts/Partials/AbstractBackgroundAdvantage.php | AbstractBackgroundAdvantage.getSpentBackgroundPoints | public function getSpentBackgroundPoints(): PositiveIntegerObject
{
if ($this->spentBackgroundPoints === null) {
$this->spentBackgroundPoints = new PositiveIntegerObject($this->getValue());
}
return $this->spentBackgroundPoints;
} | php | public function getSpentBackgroundPoints(): PositiveIntegerObject
{
if ($this->spentBackgroundPoints === null) {
$this->spentBackgroundPoints = new PositiveIntegerObject($this->getValue());
}
return $this->spentBackgroundPoints;
} | [
"public",
"function",
"getSpentBackgroundPoints",
"(",
")",
":",
"PositiveIntegerObject",
"{",
"if",
"(",
"$",
"this",
"->",
"spentBackgroundPoints",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"spentBackgroundPoints",
"=",
"new",
"PositiveIntegerObject",
"(",
"$",
"this",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"spentBackgroundPoints",
";",
"}"
] | Spent background points are the same as advantage level.
@return PositiveIntegerObject | [
"Spent",
"background",
"points",
"are",
"the",
"same",
"as",
"advantage",
"level",
"."
] | train | https://github.com/drdplusinfo/drdplus-background/blob/70aca51902e6c151c4b0e5d9066c6043c777435c/DrdPlus/Background/BackgroundParts/Partials/AbstractBackgroundAdvantage.php#L31-L38 |
Nicklas766/Comment | src/Comment/AdminController.php | AdminController.checkIsAdmin | public function checkIsAdmin()
{
$this->checkIsLogin();
$user = new User($this->di->get("db"));
$user = $user->getUser($this->di->get("session")->get("user"));
if ($user->authority != "admin") {
$views = [
["comment/admin/fail", [], "main"]
];
$this->di->get("pageRenderComment")->renderPage([
"views" => $views,
"title" => "Not authorized"
]);
}
} | php | public function checkIsAdmin()
{
$this->checkIsLogin();
$user = new User($this->di->get("db"));
$user = $user->getUser($this->di->get("session")->get("user"));
if ($user->authority != "admin") {
$views = [
["comment/admin/fail", [], "main"]
];
$this->di->get("pageRenderComment")->renderPage([
"views" => $views,
"title" => "Not authorized"
]);
}
} | [
"public",
"function",
"checkIsAdmin",
"(",
")",
"{",
"$",
"this",
"->",
"checkIsLogin",
"(",
")",
";",
"$",
"user",
"=",
"new",
"User",
"(",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"\"db\"",
")",
")",
";",
"$",
"user",
"=",
"$",
"user",
"->",
"getUser",
"(",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"\"session\"",
")",
"->",
"get",
"(",
"\"user\"",
")",
")",
";",
"if",
"(",
"$",
"user",
"->",
"authority",
"!=",
"\"admin\"",
")",
"{",
"$",
"views",
"=",
"[",
"[",
"\"comment/admin/fail\"",
",",
"[",
"]",
",",
"\"main\"",
"]",
"]",
";",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"\"pageRenderComment\"",
")",
"->",
"renderPage",
"(",
"[",
"\"views\"",
"=>",
"$",
"views",
",",
"\"title\"",
"=>",
"\"Not authorized\"",
"]",
")",
";",
"}",
"}"
] | check if user is logged in
@return void | [
"check",
"if",
"user",
"is",
"logged",
"in"
] | train | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/AdminController.php#L33-L49 |
Nicklas766/Comment | src/Comment/AdminController.php | AdminController.getPostAdminEditUser | public function getPostAdminEditUser($id)
{
$form = new EditUserForm($this->di, $id);
$form->check();
$views = [
["comment/admin/navbar", [], "main"],
["comment/admin/crud/edit", ["form" => $form->getHTML()], "main"]
];
$this->di->get("pageRenderComment")->renderPage([
"views" => $views,
"title" => "Edit user"
]);
} | php | public function getPostAdminEditUser($id)
{
$form = new EditUserForm($this->di, $id);
$form->check();
$views = [
["comment/admin/navbar", [], "main"],
["comment/admin/crud/edit", ["form" => $form->getHTML()], "main"]
];
$this->di->get("pageRenderComment")->renderPage([
"views" => $views,
"title" => "Edit user"
]);
} | [
"public",
"function",
"getPostAdminEditUser",
"(",
"$",
"id",
")",
"{",
"$",
"form",
"=",
"new",
"EditUserForm",
"(",
"$",
"this",
"->",
"di",
",",
"$",
"id",
")",
";",
"$",
"form",
"->",
"check",
"(",
")",
";",
"$",
"views",
"=",
"[",
"[",
"\"comment/admin/navbar\"",
",",
"[",
"]",
",",
"\"main\"",
"]",
",",
"[",
"\"comment/admin/crud/edit\"",
",",
"[",
"\"form\"",
"=>",
"$",
"form",
"->",
"getHTML",
"(",
")",
"]",
",",
"\"main\"",
"]",
"]",
";",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"\"pageRenderComment\"",
")",
"->",
"renderPage",
"(",
"[",
"\"views\"",
"=>",
"$",
"views",
",",
"\"title\"",
"=>",
"\"Edit user\"",
"]",
")",
";",
"}"
] | Description.
@param int $id
@return void | [
"Description",
"."
] | train | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/AdminController.php#L78-L92 |
Nicklas766/Comment | src/Comment/AdminController.php | AdminController.getPostAdminCreateUser | public function getPostAdminCreateUser()
{
$form = new CreateUserForm2($this->di);
$form->check();
$views = [
["comment/admin/navbar", [], "main"],
["comment/admin/crud/edit", ["form" => $form->getHTML()], "main"]
];
$this->di->get("pageRenderComment")->renderPage([
"views" => $views,
"title" => "Create user"
]);
} | php | public function getPostAdminCreateUser()
{
$form = new CreateUserForm2($this->di);
$form->check();
$views = [
["comment/admin/navbar", [], "main"],
["comment/admin/crud/edit", ["form" => $form->getHTML()], "main"]
];
$this->di->get("pageRenderComment")->renderPage([
"views" => $views,
"title" => "Create user"
]);
} | [
"public",
"function",
"getPostAdminCreateUser",
"(",
")",
"{",
"$",
"form",
"=",
"new",
"CreateUserForm2",
"(",
"$",
"this",
"->",
"di",
")",
";",
"$",
"form",
"->",
"check",
"(",
")",
";",
"$",
"views",
"=",
"[",
"[",
"\"comment/admin/navbar\"",
",",
"[",
"]",
",",
"\"main\"",
"]",
",",
"[",
"\"comment/admin/crud/edit\"",
",",
"[",
"\"form\"",
"=>",
"$",
"form",
"->",
"getHTML",
"(",
")",
"]",
",",
"\"main\"",
"]",
"]",
";",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"\"pageRenderComment\"",
")",
"->",
"renderPage",
"(",
"[",
"\"views\"",
"=>",
"$",
"views",
",",
"\"title\"",
"=>",
"\"Create user\"",
"]",
")",
";",
"}"
] | Description.
@return void | [
"Description",
"."
] | train | https://github.com/Nicklas766/Comment/blob/1483eaf1ebb120b8bd6c2a1552c084b3a288ff25/src/Comment/AdminController.php#L99-L113 |
theopera/framework | src/Component/Http/Header/Headers.php | Headers.get | public function get(string $name)
{
return isset($this->headers[$name]) ? $this->headers[$name] : null;
} | php | public function get(string $name)
{
return isset($this->headers[$name]) ? $this->headers[$name] : null;
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | @param string $name
@return null|Header | [
"@param",
"string",
"$name"
] | train | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/Http/Header/Headers.php#L44-L47 |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImageHelper.php | ResponsiveImageHelper.addClass | public function addClass(ResponsiveImageClass $class)
{
$this->classes_added = true;
if (array_key_exists($class->getName(), $this->classes)) {
throw new \Exception(sprintf('A responsive image class with name "%s" is already registered', $class->getName()));
}
if ($this->default_filters instanceof FilterInterface) {
$class->addFilter($this->default_filters);
}
if ($this->default_post_filters instanceof FilterInterface) {
$class->addPostFilter($this->default_post_filters);
}
if ($this->default_scaling_algorithm != '') {
$class->setScaleAlgorithm($this->default_scaling_algorithm);
}
if ($this->default_output_type_map instanceof OutputTypeMap) {
$class->setOutputTypeMap($this->default_output_type_map);
}
$this->classes[$class->getName()] = $class;
} | php | public function addClass(ResponsiveImageClass $class)
{
$this->classes_added = true;
if (array_key_exists($class->getName(), $this->classes)) {
throw new \Exception(sprintf('A responsive image class with name "%s" is already registered', $class->getName()));
}
if ($this->default_filters instanceof FilterInterface) {
$class->addFilter($this->default_filters);
}
if ($this->default_post_filters instanceof FilterInterface) {
$class->addPostFilter($this->default_post_filters);
}
if ($this->default_scaling_algorithm != '') {
$class->setScaleAlgorithm($this->default_scaling_algorithm);
}
if ($this->default_output_type_map instanceof OutputTypeMap) {
$class->setOutputTypeMap($this->default_output_type_map);
}
$this->classes[$class->getName()] = $class;
} | [
"public",
"function",
"addClass",
"(",
"ResponsiveImageClass",
"$",
"class",
")",
"{",
"$",
"this",
"->",
"classes_added",
"=",
"true",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"class",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"classes",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'A responsive image class with name \"%s\" is already registered'",
",",
"$",
"class",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"default_filters",
"instanceof",
"FilterInterface",
")",
"{",
"$",
"class",
"->",
"addFilter",
"(",
"$",
"this",
"->",
"default_filters",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"default_post_filters",
"instanceof",
"FilterInterface",
")",
"{",
"$",
"class",
"->",
"addPostFilter",
"(",
"$",
"this",
"->",
"default_post_filters",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"default_scaling_algorithm",
"!=",
"''",
")",
"{",
"$",
"class",
"->",
"setScaleAlgorithm",
"(",
"$",
"this",
"->",
"default_scaling_algorithm",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"default_output_type_map",
"instanceof",
"OutputTypeMap",
")",
"{",
"$",
"class",
"->",
"setOutputTypeMap",
"(",
"$",
"this",
"->",
"default_output_type_map",
")",
";",
"}",
"$",
"this",
"->",
"classes",
"[",
"$",
"class",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"class",
";",
"}"
] | Add a ResponsiveImageClass object to the registered responsive image classes
@param ResponsiveImageClass $class The ResponsiveImageClass object
@throws \Exception | [
"Add",
"a",
"ResponsiveImageClass",
"object",
"to",
"the",
"registered",
"responsive",
"image",
"classes"
] | train | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L102-L121 |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImageHelper.php | ResponsiveImageHelper.getClass | public function getClass($classname)
{
if ((string) $classname == '' || !array_key_exists($classname, $this->classes)) {
throw new ImageClassNotRegisteredException($classname);
}
return $this->classes[$classname];
} | php | public function getClass($classname)
{
if ((string) $classname == '' || !array_key_exists($classname, $this->classes)) {
throw new ImageClassNotRegisteredException($classname);
}
return $this->classes[$classname];
} | [
"public",
"function",
"getClass",
"(",
"$",
"classname",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"classname",
"==",
"''",
"||",
"!",
"array_key_exists",
"(",
"$",
"classname",
",",
"$",
"this",
"->",
"classes",
")",
")",
"{",
"throw",
"new",
"ImageClassNotRegisteredException",
"(",
"$",
"classname",
")",
";",
"}",
"return",
"$",
"this",
"->",
"classes",
"[",
"$",
"classname",
"]",
";",
"}"
] | Get a ResponsiveImageClass by it's name
@param string $classname
@return ResponsiveImageClass | [
"Get",
"a",
"ResponsiveImageClass",
"by",
"it",
"s",
"name"
] | train | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L140-L146 |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImageHelper.php | ResponsiveImageHelper.makeImgElementResponsive | public function makeImgElementResponsive(
\DOMElement &$img,
$class,
$change_src_attr = false,
$add_default_dimension_attrs = false
)
{
if ($img->tagName != 'img') throw new \InvalidArgumentException('$img must be an "img" element');
if ((string) $class == '' || !array_key_exists($class, $this->classes)) {
throw new ImageClassNotRegisteredException($class);
}
$imageurl = $img->getAttribute('src');
if ($imageurl != '') {
try {
$ri = $this->getResponsiveImage($imageurl, $class);
$img->setAttribute('srcset', $ri->getSrcsetAttributeValue());
$img->setAttribute('sizes', $ri->getSizesAttributeValue());
$default = $ri->getDefaultImageInfo();
if ($default instanceof WebImageInfo) {
if ($change_src_attr) {
$img->setAttribute('src', $default->getUrl());
}
if ($add_default_dimension_attrs) {
$img->setAttribute('width', $default->getWidth());
$img->setAttribute('height', $default->getHeight());
}
}
} catch (\Exception $e) {
};
}
} | php | public function makeImgElementResponsive(
\DOMElement &$img,
$class,
$change_src_attr = false,
$add_default_dimension_attrs = false
)
{
if ($img->tagName != 'img') throw new \InvalidArgumentException('$img must be an "img" element');
if ((string) $class == '' || !array_key_exists($class, $this->classes)) {
throw new ImageClassNotRegisteredException($class);
}
$imageurl = $img->getAttribute('src');
if ($imageurl != '') {
try {
$ri = $this->getResponsiveImage($imageurl, $class);
$img->setAttribute('srcset', $ri->getSrcsetAttributeValue());
$img->setAttribute('sizes', $ri->getSizesAttributeValue());
$default = $ri->getDefaultImageInfo();
if ($default instanceof WebImageInfo) {
if ($change_src_attr) {
$img->setAttribute('src', $default->getUrl());
}
if ($add_default_dimension_attrs) {
$img->setAttribute('width', $default->getWidth());
$img->setAttribute('height', $default->getHeight());
}
}
} catch (\Exception $e) {
};
}
} | [
"public",
"function",
"makeImgElementResponsive",
"(",
"\\",
"DOMElement",
"&",
"$",
"img",
",",
"$",
"class",
",",
"$",
"change_src_attr",
"=",
"false",
",",
"$",
"add_default_dimension_attrs",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"img",
"->",
"tagName",
"!=",
"'img'",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$img must be an \"img\" element'",
")",
";",
"if",
"(",
"(",
"string",
")",
"$",
"class",
"==",
"''",
"||",
"!",
"array_key_exists",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"classes",
")",
")",
"{",
"throw",
"new",
"ImageClassNotRegisteredException",
"(",
"$",
"class",
")",
";",
"}",
"$",
"imageurl",
"=",
"$",
"img",
"->",
"getAttribute",
"(",
"'src'",
")",
";",
"if",
"(",
"$",
"imageurl",
"!=",
"''",
")",
"{",
"try",
"{",
"$",
"ri",
"=",
"$",
"this",
"->",
"getResponsiveImage",
"(",
"$",
"imageurl",
",",
"$",
"class",
")",
";",
"$",
"img",
"->",
"setAttribute",
"(",
"'srcset'",
",",
"$",
"ri",
"->",
"getSrcsetAttributeValue",
"(",
")",
")",
";",
"$",
"img",
"->",
"setAttribute",
"(",
"'sizes'",
",",
"$",
"ri",
"->",
"getSizesAttributeValue",
"(",
")",
")",
";",
"$",
"default",
"=",
"$",
"ri",
"->",
"getDefaultImageInfo",
"(",
")",
";",
"if",
"(",
"$",
"default",
"instanceof",
"WebImageInfo",
")",
"{",
"if",
"(",
"$",
"change_src_attr",
")",
"{",
"$",
"img",
"->",
"setAttribute",
"(",
"'src'",
",",
"$",
"default",
"->",
"getUrl",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"add_default_dimension_attrs",
")",
"{",
"$",
"img",
"->",
"setAttribute",
"(",
"'width'",
",",
"$",
"default",
"->",
"getWidth",
"(",
")",
")",
";",
"$",
"img",
"->",
"setAttribute",
"(",
"'height'",
",",
"$",
"default",
"->",
"getHeight",
"(",
")",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
";",
"}",
"}"
] | Add srcset and sizes attributes to an HTML "img" tag
This method reads the image URL from the "src" attribute of an "img" element, calculates the URLs and dimensions of
the various available image sizes according to the given "responsive image class", and adds the "srcset" and
"sizes" attribute value.
Optionally, it can change the "src" attribute value to the URL of the default image size, and set the
"width" and "height" attributes for the default image size.
N.B. The URL given in the "src" attribute of the img element must be in a form the
ResponsiveImageRouterInterface object $this->router is able to convert to a local file path.
If the conversion fails, the method fails silently, i.e. the img element will not be changed.
@param \DOMElement $img The "img" HTML element
@param string $class The name of an "responsive image class" registered via addClass()
@param bool $change_src_attr If true, set "src" attribute to the URL of the default image size
@param bool $add_default_dimension_attrs If true, add "width" and "height" attributes for the default image size
@throws \InvalidArgumentException If the DOMElement provided as $img parameter is not an "img" element
@throws ImageClassNotRegisteredException If the $class parameter is not a registerd image class name
@API | [
"Add",
"srcset",
"and",
"sizes",
"attributes",
"to",
"an",
"HTML",
"img",
"tag"
] | train | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L170-L200 |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImageHelper.php | ResponsiveImageHelper.createResizedImageVersions | public function createResizedImageVersions($imageurl, $imageclass)
{
if (!$this->resizer instanceof ImageResizer) {
throw new \LogicException('no ImageResizer available, set it using ResponsiveImageHelper::setResizer()');
}
$image = $this->getResponsiveImage($imageurl, $imageclass);
$image->createResizedVersions($this->resizer);
} | php | public function createResizedImageVersions($imageurl, $imageclass)
{
if (!$this->resizer instanceof ImageResizer) {
throw new \LogicException('no ImageResizer available, set it using ResponsiveImageHelper::setResizer()');
}
$image = $this->getResponsiveImage($imageurl, $imageclass);
$image->createResizedVersions($this->resizer);
} | [
"public",
"function",
"createResizedImageVersions",
"(",
"$",
"imageurl",
",",
"$",
"imageclass",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"resizer",
"instanceof",
"ImageResizer",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'no ImageResizer available, set it using ResponsiveImageHelper::setResizer()'",
")",
";",
"}",
"$",
"image",
"=",
"$",
"this",
"->",
"getResponsiveImage",
"(",
"$",
"imageurl",
",",
"$",
"imageclass",
")",
";",
"$",
"image",
"->",
"createResizedVersions",
"(",
"$",
"this",
"->",
"resizer",
")",
";",
"}"
] | Create the resized image versions for an image and a given image class
@param string $imageurl
@param string $imageclass
@throws \Exception | [
"Create",
"the",
"resized",
"image",
"versions",
"for",
"an",
"image",
"and",
"a",
"given",
"image",
"class"
] | train | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L263-L270 |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImageHelper.php | ResponsiveImageHelper.addDefaultFilter | public function addDefaultFilter(FilterInterface $default_filter)
{
if ($this->classes_added) {
throw new \LogicException('Defaults must be set before image classes are added.');
}
if (!$this->default_filters instanceof FilterChain) {
$this->default_filters = new FilterChain();
}
$this->default_filters->add($default_filter);
return $this;
} | php | public function addDefaultFilter(FilterInterface $default_filter)
{
if ($this->classes_added) {
throw new \LogicException('Defaults must be set before image classes are added.');
}
if (!$this->default_filters instanceof FilterChain) {
$this->default_filters = new FilterChain();
}
$this->default_filters->add($default_filter);
return $this;
} | [
"public",
"function",
"addDefaultFilter",
"(",
"FilterInterface",
"$",
"default_filter",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classes_added",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Defaults must be set before image classes are added.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"default_filters",
"instanceof",
"FilterChain",
")",
"{",
"$",
"this",
"->",
"default_filters",
"=",
"new",
"FilterChain",
"(",
")",
";",
"}",
"$",
"this",
"->",
"default_filters",
"->",
"add",
"(",
"$",
"default_filter",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add additional default filters to be applied when resizing for all classes.
This setting will be passed to a ResponsiveImageClass object when it is added by the addClass() method
@param FilterInterface $default_filter
@return ResponsiveImageHelper $this | [
"Add",
"additional",
"default",
"filters",
"to",
"be",
"applied",
"when",
"resizing",
"for",
"all",
"classes",
".",
"This",
"setting",
"will",
"be",
"passed",
"to",
"a",
"ResponsiveImageClass",
"object",
"when",
"it",
"is",
"added",
"by",
"the",
"addClass",
"()",
"method"
] | train | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L319-L329 |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImageHelper.php | ResponsiveImageHelper.addDefaultPostFilter | public function addDefaultPostFilter(FilterInterface $default_post_filter)
{
if ($this->classes_added) {
throw new \LogicException('Defaults must be set before image classes are added.');
}
if (!$this->default_post_filters instanceof FilterChain) {
$this->default_post_filters = new FilterChain();
}
$this->default_post_filters->add($default_post_filter);
return $this;
} | php | public function addDefaultPostFilter(FilterInterface $default_post_filter)
{
if ($this->classes_added) {
throw new \LogicException('Defaults must be set before image classes are added.');
}
if (!$this->default_post_filters instanceof FilterChain) {
$this->default_post_filters = new FilterChain();
}
$this->default_post_filters->add($default_post_filter);
return $this;
} | [
"public",
"function",
"addDefaultPostFilter",
"(",
"FilterInterface",
"$",
"default_post_filter",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classes_added",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Defaults must be set before image classes are added.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"default_post_filters",
"instanceof",
"FilterChain",
")",
"{",
"$",
"this",
"->",
"default_post_filters",
"=",
"new",
"FilterChain",
"(",
")",
";",
"}",
"$",
"this",
"->",
"default_post_filters",
"->",
"add",
"(",
"$",
"default_post_filter",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set default post filters for all image classes.
This setting will be passed to a ResponsiveImageClass object when it is added by the addClass() method
@param \Imagine\Filter\FilterInterface $default_post_filter
@return ResponsiveImageHelper $this | [
"Set",
"default",
"post",
"filters",
"for",
"all",
"image",
"classes",
".",
"This",
"setting",
"will",
"be",
"passed",
"to",
"a",
"ResponsiveImageClass",
"object",
"when",
"it",
"is",
"added",
"by",
"the",
"addClass",
"()",
"method"
] | train | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L338-L348 |
wasinger/adaptimage | src/ResponsiveImages/ResponsiveImageHelper.php | ResponsiveImageHelper.setDefaultOutputTypeMap | public function setDefaultOutputTypeMap(OutputTypeMap $default_output_type_map)
{
if ($this->classes_added) {
throw new \LogicException('Defaults must be set before image classes are added.');
}
$this->default_output_type_map = $default_output_type_map;
return $this;
} | php | public function setDefaultOutputTypeMap(OutputTypeMap $default_output_type_map)
{
if ($this->classes_added) {
throw new \LogicException('Defaults must be set before image classes are added.');
}
$this->default_output_type_map = $default_output_type_map;
return $this;
} | [
"public",
"function",
"setDefaultOutputTypeMap",
"(",
"OutputTypeMap",
"$",
"default_output_type_map",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classes_added",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Defaults must be set before image classes are added.'",
")",
";",
"}",
"$",
"this",
"->",
"default_output_type_map",
"=",
"$",
"default_output_type_map",
";",
"return",
"$",
"this",
";",
"}"
] | Set a default OutputTypeMap for all image classes.
This setting will be passed to a ResponsiveImageClass object when it is added by the addClass() method
@param OutputTypeMap $default_output_type_map
@return ResponsiveImageHelper $this | [
"Set",
"a",
"default",
"OutputTypeMap",
"for",
"all",
"image",
"classes",
".",
"This",
"setting",
"will",
"be",
"passed",
"to",
"a",
"ResponsiveImageClass",
"object",
"when",
"it",
"is",
"added",
"by",
"the",
"addClass",
"()",
"method"
] | train | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ResponsiveImages/ResponsiveImageHelper.php#L357-L364 |
uneak/OAuthClientBundle | OAuth/OAuth2.php | OAuth2.fetch | public static function fetch(AccessTokenInterface $accessToken, array $options) {
switch ($accessToken->getOption('token_type')) {
case AccessToken::ACCESS_TOKEN_URI:
if (is_array($options['parameters'])) {
$options['parameters']['access_token'] = $accessToken->getOption('access_token');
} else {
throw new InvalidArgumentException(
'You need to give parameters as array if you want to give the token within the URI.', InvalidArgumentException::REQUIRE_PARAMS_AS_ARRAY
);
}
break;
case AccessToken::ACCESS_TOKEN_BEARER:
$options['http_headers']['Authorization'] = 'Bearer ' . $accessToken->getOption('access_token');
break;
case AccessToken::ACCESS_TOKEN_OAUTH:
$options['http_headers']['Authorization'] = 'OAuth ' . $accessToken->getOption('access_token');
break;
case AccessToken::ACCESS_TOKEN_MAC:
$options['http_headers']['Authorization'] = 'MAC ' . $accessToken->generateMACSignature($options);
break;
default:
throw new Exception('Unknown access token type.', Exception::INVALID_ACCESS_TOKEN_TYPE);
}
$request = new CurlRequest($options);
return $request->getResponse();
} | php | public static function fetch(AccessTokenInterface $accessToken, array $options) {
switch ($accessToken->getOption('token_type')) {
case AccessToken::ACCESS_TOKEN_URI:
if (is_array($options['parameters'])) {
$options['parameters']['access_token'] = $accessToken->getOption('access_token');
} else {
throw new InvalidArgumentException(
'You need to give parameters as array if you want to give the token within the URI.', InvalidArgumentException::REQUIRE_PARAMS_AS_ARRAY
);
}
break;
case AccessToken::ACCESS_TOKEN_BEARER:
$options['http_headers']['Authorization'] = 'Bearer ' . $accessToken->getOption('access_token');
break;
case AccessToken::ACCESS_TOKEN_OAUTH:
$options['http_headers']['Authorization'] = 'OAuth ' . $accessToken->getOption('access_token');
break;
case AccessToken::ACCESS_TOKEN_MAC:
$options['http_headers']['Authorization'] = 'MAC ' . $accessToken->generateMACSignature($options);
break;
default:
throw new Exception('Unknown access token type.', Exception::INVALID_ACCESS_TOKEN_TYPE);
}
$request = new CurlRequest($options);
return $request->getResponse();
} | [
"public",
"static",
"function",
"fetch",
"(",
"AccessTokenInterface",
"$",
"accessToken",
",",
"array",
"$",
"options",
")",
"{",
"switch",
"(",
"$",
"accessToken",
"->",
"getOption",
"(",
"'token_type'",
")",
")",
"{",
"case",
"AccessToken",
"::",
"ACCESS_TOKEN_URI",
":",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'parameters'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'parameters'",
"]",
"[",
"'access_token'",
"]",
"=",
"$",
"accessToken",
"->",
"getOption",
"(",
"'access_token'",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'You need to give parameters as array if you want to give the token within the URI.'",
",",
"InvalidArgumentException",
"::",
"REQUIRE_PARAMS_AS_ARRAY",
")",
";",
"}",
"break",
";",
"case",
"AccessToken",
"::",
"ACCESS_TOKEN_BEARER",
":",
"$",
"options",
"[",
"'http_headers'",
"]",
"[",
"'Authorization'",
"]",
"=",
"'Bearer '",
".",
"$",
"accessToken",
"->",
"getOption",
"(",
"'access_token'",
")",
";",
"break",
";",
"case",
"AccessToken",
"::",
"ACCESS_TOKEN_OAUTH",
":",
"$",
"options",
"[",
"'http_headers'",
"]",
"[",
"'Authorization'",
"]",
"=",
"'OAuth '",
".",
"$",
"accessToken",
"->",
"getOption",
"(",
"'access_token'",
")",
";",
"break",
";",
"case",
"AccessToken",
"::",
"ACCESS_TOKEN_MAC",
":",
"$",
"options",
"[",
"'http_headers'",
"]",
"[",
"'Authorization'",
"]",
"=",
"'MAC '",
".",
"$",
"accessToken",
"->",
"generateMACSignature",
"(",
"$",
"options",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"'Unknown access token type.'",
",",
"Exception",
"::",
"INVALID_ACCESS_TOKEN_TYPE",
")",
";",
"}",
"$",
"request",
"=",
"new",
"CurlRequest",
"(",
"$",
"options",
")",
";",
"return",
"$",
"request",
"->",
"getResponse",
"(",
")",
";",
"}"
] | @param \Uneak\OAuthClientBundle\OAuth\Token\AccessTokenInterface $accessToken
@param array $options
@return \Uneak\OAuthClientBundle\OAuth\Curl\CurlResponse
@throws \Uneak\OAuthClientBundle\OAuth\Exception | [
"@param",
"\\",
"Uneak",
"\\",
"OAuthClientBundle",
"\\",
"OAuth",
"\\",
"Token",
"\\",
"AccessTokenInterface",
"$accessToken",
"@param",
"array",
"$options"
] | train | https://github.com/uneak/OAuthClientBundle/blob/e24b7734d63cf0a114167e025aebcae8c04647bb/OAuth/OAuth2.php#L24-L51 |
uneak/OAuthClientBundle | OAuth/OAuth2.php | OAuth2.getAccessToken | public static function getAccessToken(CredentialsConfigurationInterface $credentialsConfiguration, ServerOAuth2ConfigurationInterface $serverConfiguration, AuthenticationOAuth2ConfigurationInterface $authenticationConfiguration, GrantInterface $grant) {
$options = array();
$grant->buildRequestOptions($credentialsConfiguration, $serverConfiguration, $authenticationConfiguration, $options);
$request = new CurlRequest($options);
return $request->getResponse();
} | php | public static function getAccessToken(CredentialsConfigurationInterface $credentialsConfiguration, ServerOAuth2ConfigurationInterface $serverConfiguration, AuthenticationOAuth2ConfigurationInterface $authenticationConfiguration, GrantInterface $grant) {
$options = array();
$grant->buildRequestOptions($credentialsConfiguration, $serverConfiguration, $authenticationConfiguration, $options);
$request = new CurlRequest($options);
return $request->getResponse();
} | [
"public",
"static",
"function",
"getAccessToken",
"(",
"CredentialsConfigurationInterface",
"$",
"credentialsConfiguration",
",",
"ServerOAuth2ConfigurationInterface",
"$",
"serverConfiguration",
",",
"AuthenticationOAuth2ConfigurationInterface",
"$",
"authenticationConfiguration",
",",
"GrantInterface",
"$",
"grant",
")",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"$",
"grant",
"->",
"buildRequestOptions",
"(",
"$",
"credentialsConfiguration",
",",
"$",
"serverConfiguration",
",",
"$",
"authenticationConfiguration",
",",
"$",
"options",
")",
";",
"$",
"request",
"=",
"new",
"CurlRequest",
"(",
"$",
"options",
")",
";",
"return",
"$",
"request",
"->",
"getResponse",
"(",
")",
";",
"}"
] | @param \Uneak\OAuthClientBundle\OAuth\Configuration\CredentialsConfigurationInterface $credentialsConfiguration
@param \Uneak\OAuthClientBundle\OAuth\Configuration\ServerConfigurationInterface $serverConfiguration
@param \Uneak\OAuthClientBundle\OAuth\Configuration\AuthenticationConfigurationInterface $authenticationConfiguration
@param \Uneak\OAuthClientBundle\OAuth\Grant\GrantInterface $grant
@param int $authType
@return \Uneak\OAuthClientBundle\OAuth\Curl\CurlResponse | [
"@param",
"\\",
"Uneak",
"\\",
"OAuthClientBundle",
"\\",
"OAuth",
"\\",
"Configuration",
"\\",
"CredentialsConfigurationInterface",
"$credentialsConfiguration",
"@param",
"\\",
"Uneak",
"\\",
"OAuthClientBundle",
"\\",
"OAuth",
"\\",
"Configuration",
"\\",
"ServerConfigurationInterface",
"$serverConfiguration",
"@param",
"\\",
"Uneak",
"\\",
"OAuthClientBundle",
"\\",
"OAuth",
"\\",
"Configuration",
"\\",
"AuthenticationConfigurationInterface",
"$authenticationConfiguration",
"@param",
"\\",
"Uneak",
"\\",
"OAuthClientBundle",
"\\",
"OAuth",
"\\",
"Grant",
"\\",
"GrantInterface",
"$grant",
"@param",
"int",
"$authType"
] | train | https://github.com/uneak/OAuthClientBundle/blob/e24b7734d63cf0a114167e025aebcae8c04647bb/OAuth/OAuth2.php#L63-L68 |
uneak/OAuthClientBundle | OAuth/OAuth2.php | OAuth2.getAuthenticationUrl | public static function getAuthenticationUrl(CredentialsConfigurationInterface $credentialsConfiguration, ServerOAuth2ConfigurationInterface $serverConfiguration, AuthenticationOAuth2ConfigurationInterface $authenticationConfiguration) {
return $authenticationConfiguration->getAuthenticationPath($credentialsConfiguration, $serverConfiguration);
} | php | public static function getAuthenticationUrl(CredentialsConfigurationInterface $credentialsConfiguration, ServerOAuth2ConfigurationInterface $serverConfiguration, AuthenticationOAuth2ConfigurationInterface $authenticationConfiguration) {
return $authenticationConfiguration->getAuthenticationPath($credentialsConfiguration, $serverConfiguration);
} | [
"public",
"static",
"function",
"getAuthenticationUrl",
"(",
"CredentialsConfigurationInterface",
"$",
"credentialsConfiguration",
",",
"ServerOAuth2ConfigurationInterface",
"$",
"serverConfiguration",
",",
"AuthenticationOAuth2ConfigurationInterface",
"$",
"authenticationConfiguration",
")",
"{",
"return",
"$",
"authenticationConfiguration",
"->",
"getAuthenticationPath",
"(",
"$",
"credentialsConfiguration",
",",
"$",
"serverConfiguration",
")",
";",
"}"
] | @param \Uneak\OAuthClientBundle\OAuth\Configuration\CredentialsConfigurationInterface $credentialsConfiguration
@param \Uneak\OAuthClientBundle\OAuth\Configuration\ServerConfigurationInterface $serverConfiguration
@param \Uneak\OAuthClientBundle\OAuth\Configuration\AuthenticationConfigurationInterface $authenticationConfiguration
@return string | [
"@param",
"\\",
"Uneak",
"\\",
"OAuthClientBundle",
"\\",
"OAuth",
"\\",
"Configuration",
"\\",
"CredentialsConfigurationInterface",
"$credentialsConfiguration",
"@param",
"\\",
"Uneak",
"\\",
"OAuthClientBundle",
"\\",
"OAuth",
"\\",
"Configuration",
"\\",
"ServerConfigurationInterface",
"$serverConfiguration",
"@param",
"\\",
"Uneak",
"\\",
"OAuthClientBundle",
"\\",
"OAuth",
"\\",
"Configuration",
"\\",
"AuthenticationConfigurationInterface",
"$authenticationConfiguration"
] | train | https://github.com/uneak/OAuthClientBundle/blob/e24b7734d63cf0a114167e025aebcae8c04647bb/OAuth/OAuth2.php#L78-L81 |
Fenzland/php-http-client | libs/Response.php | Response.header | public function header( string$key=null )
{
return ( isset($key) ?
$this->headers[ucwords( strtolower($key), '-' )]
:
$this->getHeaders()
);
} | php | public function header( string$key=null )
{
return ( isset($key) ?
$this->headers[ucwords( strtolower($key), '-' )]
:
$this->getHeaders()
);
} | [
"public",
"function",
"header",
"(",
"string",
"$",
"key",
"=",
"null",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"key",
")",
"?",
"$",
"this",
"->",
"headers",
"[",
"ucwords",
"(",
"strtolower",
"(",
"$",
"key",
")",
",",
"'-'",
")",
"]",
":",
"$",
"this",
"->",
"getHeaders",
"(",
")",
")",
";",
"}"
] | Method header
@access public
@param string $key
@return mixed | [
"Method",
"header"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Response.php#L164-L171 |
Fenzland/php-http-client | libs/Response.php | Response.getLine | private function getLine():string
{
$line= fgets( $this->handle );
$this->raw.= $line;
return trim( $line );
} | php | private function getLine():string
{
$line= fgets( $this->handle );
$this->raw.= $line;
return trim( $line );
} | [
"private",
"function",
"getLine",
"(",
")",
":",
"string",
"{",
"$",
"line",
"=",
"fgets",
"(",
"$",
"this",
"->",
"handle",
")",
";",
"$",
"this",
"->",
"raw",
".=",
"$",
"line",
";",
"return",
"trim",
"(",
"$",
"line",
")",
";",
"}"
] | Method getLine
@access private
@return string | [
"Method",
"getLine"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Response.php#L234-L241 |
Fenzland/php-http-client | libs/Response.php | Response.parsMessageLine | private function parsMessageLine( string$messageLine )
{
preg_replace_callback( '/^HTTP\\/(\\S+) (\\S+) (.+)$/', function( array$matches ){
list( $null, $this->version, $this->statusCode, $this->statusMessage )= $matches;
}, $messageLine );
} | php | private function parsMessageLine( string$messageLine )
{
preg_replace_callback( '/^HTTP\\/(\\S+) (\\S+) (.+)$/', function( array$matches ){
list( $null, $this->version, $this->statusCode, $this->statusMessage )= $matches;
}, $messageLine );
} | [
"private",
"function",
"parsMessageLine",
"(",
"string",
"$",
"messageLine",
")",
"{",
"preg_replace_callback",
"(",
"'/^HTTP\\\\/(\\\\S+) (\\\\S+) (.+)$/'",
",",
"function",
"(",
"array",
"$",
"matches",
")",
"{",
"list",
"(",
"$",
"null",
",",
"$",
"this",
"->",
"version",
",",
"$",
"this",
"->",
"statusCode",
",",
"$",
"this",
"->",
"statusMessage",
")",
"=",
"$",
"matches",
";",
"}",
",",
"$",
"messageLine",
")",
";",
"}"
] | Method parsMessageLine
@access private
@param string $messageLine
@return void | [
"Method",
"parsMessageLine"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Response.php#L252-L257 |
Fenzland/php-http-client | libs/Response.php | Response.parseHeader | private function parseHeader( string$headerLine )
{
list( $key, $value, )= explode(': ', $headerLine);
$this->headers[ucwords( strtolower($key), '-' )]= $value;
} | php | private function parseHeader( string$headerLine )
{
list( $key, $value, )= explode(': ', $headerLine);
$this->headers[ucwords( strtolower($key), '-' )]= $value;
} | [
"private",
"function",
"parseHeader",
"(",
"string",
"$",
"headerLine",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"value",
",",
")",
"=",
"explode",
"(",
"': '",
",",
"$",
"headerLine",
")",
";",
"$",
"this",
"->",
"headers",
"[",
"ucwords",
"(",
"strtolower",
"(",
"$",
"key",
")",
",",
"'-'",
")",
"]",
"=",
"$",
"value",
";",
"}"
] | Method parseHeader
@access private
@param string $headerLine
@return void | [
"Method",
"parseHeader"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Response.php#L268-L273 |
Fenzland/php-http-client | libs/Response.php | Response.readBody | private function readBody()
{
$body= '';
while( !feof($this->handle) )
{
$body.= fgets($this->handle);
}
if( isset( $this->headers['Transfer-Encoding'] ) && $this->headers['Transfer-Encoding']==='chunked' )
{
$this->body= $this->unchunk( $body );
}else{
$this->body= $body;
}
} | php | private function readBody()
{
$body= '';
while( !feof($this->handle) )
{
$body.= fgets($this->handle);
}
if( isset( $this->headers['Transfer-Encoding'] ) && $this->headers['Transfer-Encoding']==='chunked' )
{
$this->body= $this->unchunk( $body );
}else{
$this->body= $body;
}
} | [
"private",
"function",
"readBody",
"(",
")",
"{",
"$",
"body",
"=",
"''",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"handle",
")",
")",
"{",
"$",
"body",
".=",
"fgets",
"(",
"$",
"this",
"->",
"handle",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'Transfer-Encoding'",
"]",
")",
"&&",
"$",
"this",
"->",
"headers",
"[",
"'Transfer-Encoding'",
"]",
"===",
"'chunked'",
")",
"{",
"$",
"this",
"->",
"body",
"=",
"$",
"this",
"->",
"unchunk",
"(",
"$",
"body",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"body",
"=",
"$",
"body",
";",
"}",
"}"
] | Method readBody
@access private
@return void | [
"Method",
"readBody"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Response.php#L282-L297 |
Fenzland/php-http-client | libs/Response.php | Response.unchunk | private function unchunk( string$chunked ):string
{
return preg_replace_callback(
'/(?:(?:\r\n|\n)|^)([0-9A-F]+)(?:\r\n|\n){1,2}(.*?)((?:\r\n|\n)(?:[0-9A-F]+(?:\r\n|\n))|$)/si'
,
function( array$matches ){
return hexdec( $matches[1] )==strlen( $matches[2] )? $matches[2] : $matches[0];
}
,
$chunked
);
} | php | private function unchunk( string$chunked ):string
{
return preg_replace_callback(
'/(?:(?:\r\n|\n)|^)([0-9A-F]+)(?:\r\n|\n){1,2}(.*?)((?:\r\n|\n)(?:[0-9A-F]+(?:\r\n|\n))|$)/si'
,
function( array$matches ){
return hexdec( $matches[1] )==strlen( $matches[2] )? $matches[2] : $matches[0];
}
,
$chunked
);
} | [
"private",
"function",
"unchunk",
"(",
"string",
"$",
"chunked",
")",
":",
"string",
"{",
"return",
"preg_replace_callback",
"(",
"'/(?:(?:\\r\\n|\\n)|^)([0-9A-F]+)(?:\\r\\n|\\n){1,2}(.*?)((?:\\r\\n|\\n)(?:[0-9A-F]+(?:\\r\\n|\\n))|$)/si'",
",",
"function",
"(",
"array",
"$",
"matches",
")",
"{",
"return",
"hexdec",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
"==",
"strlen",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"?",
"$",
"matches",
"[",
"2",
"]",
":",
"$",
"matches",
"[",
"0",
"]",
";",
"}",
",",
"$",
"chunked",
")",
";",
"}"
] | Method unchunk
@access private
@param string $chunked
@return string | [
"Method",
"unchunk"
] | train | https://github.com/Fenzland/php-http-client/blob/2f8df0f5f5f81e45453efad02f8926167a029630/libs/Response.php#L308-L319 |
fridge-project/dbal | src/Fridge/DBAL/Type/BlobType.php | BlobType.convertToPHPValue | public function convertToPHPValue($value, PlatformInterface $platform)
{
if ($value === null) {
return;
}
if (is_string($value)) {
$value = fopen('data://text/plain;base64,'.base64_encode($value), 'r');
}
if (!is_resource($value)) {
throw TypeException::conversionToPHPFailed($value, $this->getName());
}
return $value;
} | php | public function convertToPHPValue($value, PlatformInterface $platform)
{
if ($value === null) {
return;
}
if (is_string($value)) {
$value = fopen('data://text/plain;base64,'.base64_encode($value), 'r');
}
if (!is_resource($value)) {
throw TypeException::conversionToPHPFailed($value, $this->getName());
}
return $value;
} | [
"public",
"function",
"convertToPHPValue",
"(",
"$",
"value",
",",
"PlatformInterface",
"$",
"platform",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"fopen",
"(",
"'data://text/plain;base64,'",
".",
"base64_encode",
"(",
"$",
"value",
")",
",",
"'r'",
")",
";",
"}",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"TypeException",
"::",
"conversionToPHPFailed",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | {@inheritdoc}
@throws \Fridge\DBAL\Exception\TypeException If the database value can not be convert to this PHP value. | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Type/BlobType.php#L46-L61 |
Dhii/exception-helper-base | src/CreateExceptionCapableTrait.php | CreateExceptionCapableTrait._createException | protected function _createException($message = null, $code = null, $previous = null)
{
return new Exception($message, $code, $previous);
} | php | protected function _createException($message = null, $code = null, $previous = null)
{
return new Exception($message, $code, $previous);
} | [
"protected",
"function",
"_createException",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"code",
"=",
"null",
",",
"$",
"previous",
"=",
"null",
")",
"{",
"return",
"new",
"Exception",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
")",
";",
"}"
] | Creates a new basic Dhii exception.
@since [*next-version*]
@param string|Stringable|int|float|bool|null $message The message, if any.
@param int|float|string|Stringable|null $code The numeric error code, if any.
@param RootException|null $previous The inner exception, if any.
@return ThrowableInterface The new exception. | [
"Creates",
"a",
"new",
"basic",
"Dhii",
"exception",
"."
] | train | https://github.com/Dhii/exception-helper-base/blob/e97bfa6c0f79ea079e36b2f1d8f84d7566a3ccf5/src/CreateExceptionCapableTrait.php#L26-L29 |
Mandarin-Medien/MMCmfContentBundle | EventListeners/PageHookListener.php | PageHookListener.postLoad | public function postLoad(Page $page, LifecycleEventArgs $args)
{
$hookManager = $this->container->get('mm_cmf_content.page_hook_manager');
foreach($hookManager->getHooks() as $hook) {
$hook->process($page, $this->container->get('request_stack')->getCurrentRequest());
};
} | php | public function postLoad(Page $page, LifecycleEventArgs $args)
{
$hookManager = $this->container->get('mm_cmf_content.page_hook_manager');
foreach($hookManager->getHooks() as $hook) {
$hook->process($page, $this->container->get('request_stack')->getCurrentRequest());
};
} | [
"public",
"function",
"postLoad",
"(",
"Page",
"$",
"page",
",",
"LifecycleEventArgs",
"$",
"args",
")",
"{",
"$",
"hookManager",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'mm_cmf_content.page_hook_manager'",
")",
";",
"foreach",
"(",
"$",
"hookManager",
"->",
"getHooks",
"(",
")",
"as",
"$",
"hook",
")",
"{",
"$",
"hook",
"->",
"process",
"(",
"$",
"page",
",",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'request_stack'",
")",
"->",
"getCurrentRequest",
"(",
")",
")",
";",
"}",
";",
"}"
] | postLoad Callback for Page entity, gets all defined PageHooks and calls it
@param Page $page
@param LifecycleEventArgs $args | [
"postLoad",
"Callback",
"for",
"Page",
"entity",
"gets",
"all",
"defined",
"PageHooks",
"and",
"calls",
"it"
] | train | https://github.com/Mandarin-Medien/MMCmfContentBundle/blob/503ab31cef3ce068f767de5b72f833526355b726/EventListeners/PageHookListener.php#L42-L49 |
rougin/blueprint | src/Commands/InitializeCommand.php | InitializeCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$filepath = __DIR__ . '/../Templates/blueprint.yml';
$template = file_get_contents($filepath);
$this->filesystem->write('blueprint.yml', $template);
$text = '"blueprint.yml" has been created successfully!';
return $output->writeln('<info>' . $text . '</info>');
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$filepath = __DIR__ . '/../Templates/blueprint.yml';
$template = file_get_contents($filepath);
$this->filesystem->write('blueprint.yml', $template);
$text = '"blueprint.yml" has been created successfully!';
return $output->writeln('<info>' . $text . '</info>');
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"filepath",
"=",
"__DIR__",
".",
"'/../Templates/blueprint.yml'",
";",
"$",
"template",
"=",
"file_get_contents",
"(",
"$",
"filepath",
")",
";",
"$",
"this",
"->",
"filesystem",
"->",
"write",
"(",
"'blueprint.yml'",
",",
"$",
"template",
")",
";",
"$",
"text",
"=",
"'\"blueprint.yml\" has been created successfully!'",
";",
"return",
"$",
"output",
"->",
"writeln",
"(",
"'<info>'",
".",
"$",
"text",
".",
"'</info>'",
")",
";",
"}"
] | Executes the current command.
@param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Input\OutputInterface $output
@return void | [
"Executes",
"the",
"current",
"command",
"."
] | train | https://github.com/rougin/blueprint/blob/02dab857b0fab60e060632f11f73e24467483e5b/src/Commands/InitializeCommand.php#L47-L58 |
this7/framework | src/kernel.php | kernel.start | public function start() {
#设置DEBUG引导程序
(new This7Debug())->bootstrap();
#设置配置文件
This7Config::defineConst();
#获取驱动列表
$this->drives = $this->getDeviceList(VENDOR_DIR . DS . 'this7');
#自动加载类
spl_autoload_register(array($this, 'autoload'));
#设置静态化
staticize::setApplication($this);
#绑定核心驱动
$this->bindDrives();
#启动路由
routes::start();
} | php | public function start() {
#设置DEBUG引导程序
(new This7Debug())->bootstrap();
#设置配置文件
This7Config::defineConst();
#获取驱动列表
$this->drives = $this->getDeviceList(VENDOR_DIR . DS . 'this7');
#自动加载类
spl_autoload_register(array($this, 'autoload'));
#设置静态化
staticize::setApplication($this);
#绑定核心驱动
$this->bindDrives();
#启动路由
routes::start();
} | [
"public",
"function",
"start",
"(",
")",
"{",
"#设置DEBUG引导程序",
"(",
"new",
"This7Debug",
"(",
")",
")",
"->",
"bootstrap",
"(",
")",
";",
"#设置配置文件",
"This7Config",
"::",
"defineConst",
"(",
")",
";",
"#获取驱动列表",
"$",
"this",
"->",
"drives",
"=",
"$",
"this",
"->",
"getDeviceList",
"(",
"VENDOR_DIR",
".",
"DS",
".",
"'this7'",
")",
";",
"#自动加载类",
"spl_autoload_register",
"(",
"array",
"(",
"$",
"this",
",",
"'autoload'",
")",
")",
";",
"#设置静态化",
"staticize",
"::",
"setApplication",
"(",
"$",
"this",
")",
";",
"#绑定核心驱动",
"$",
"this",
"->",
"bindDrives",
"(",
")",
";",
"#启动路由",
"routes",
"::",
"start",
"(",
")",
";",
"}"
] | 框架启动器
@return [type] [description] | [
"框架启动器"
] | train | https://github.com/this7/framework/blob/1248f4ea79cf2a61da11de0aaf1fbbf25a91ca97/src/kernel.php#L25-L40 |
this7/framework | src/kernel.php | kernel.setConnector | public function setConnector($dir = '', $class) {
$name = $class . md5($class);
$path = ROOT_DIR . DS . $dir . DS . $name . '.php';
$connector = <<<CON
<?php
namespace server\\connector;
use \\this7\\framework\\staticize;
class $name extends staticize{
public static function getAppAccessor() {
return '$class';
}
}
CON;
if (!is_file($path)) {
to_mkdir($path, $connector, true, true);
}
return $name;
} | php | public function setConnector($dir = '', $class) {
$name = $class . md5($class);
$path = ROOT_DIR . DS . $dir . DS . $name . '.php';
$connector = <<<CON
<?php
namespace server\\connector;
use \\this7\\framework\\staticize;
class $name extends staticize{
public static function getAppAccessor() {
return '$class';
}
}
CON;
if (!is_file($path)) {
to_mkdir($path, $connector, true, true);
}
return $name;
} | [
"public",
"function",
"setConnector",
"(",
"$",
"dir",
"=",
"''",
",",
"$",
"class",
")",
"{",
"$",
"name",
"=",
"$",
"class",
".",
"md5",
"(",
"$",
"class",
")",
";",
"$",
"path",
"=",
"ROOT_DIR",
".",
"DS",
".",
"$",
"dir",
".",
"DS",
".",
"$",
"name",
".",
"'.php'",
";",
"$",
"connector",
"=",
" <<<CON\n<?php\nnamespace server\\\\connector;\nuse \\\\this7\\\\framework\\\\staticize;\n\nclass $name extends staticize{\n public static function getAppAccessor() {\n return '$class';\n }\n}\nCON",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"to_mkdir",
"(",
"$",
"path",
",",
"$",
"connector",
",",
"true",
",",
"true",
")",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | 创建链接文件
@param string $value [description] | [
"创建链接文件"
] | train | https://github.com/this7/framework/blob/1248f4ea79cf2a61da11de0aaf1fbbf25a91ca97/src/kernel.php#L57-L75 |
this7/framework | src/kernel.php | kernel.getDeviceList | public function getDeviceList($dir) {
$path = array('.', '..', '.htaccess', '.DS_Store', 'controllers', 'config', 'debug', 'framework');
$ext = array("php", "html", "htm");
$list = array();
if (is_dir($dir)) {
if ($handle = opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if (!in_array($file, $path) && !in_array(pathinfo($file, PATHINFO_EXTENSION), $ext)) {
$list[$file] = VENDOR_DIR . DS . FRAMEWORK . DS . $file;
}
}
closedir($handle);
}
}
return $list;
} | php | public function getDeviceList($dir) {
$path = array('.', '..', '.htaccess', '.DS_Store', 'controllers', 'config', 'debug', 'framework');
$ext = array("php", "html", "htm");
$list = array();
if (is_dir($dir)) {
if ($handle = opendir($dir)) {
while (($file = readdir($handle)) !== false) {
if (!in_array($file, $path) && !in_array(pathinfo($file, PATHINFO_EXTENSION), $ext)) {
$list[$file] = VENDOR_DIR . DS . FRAMEWORK . DS . $file;
}
}
closedir($handle);
}
}
return $list;
} | [
"public",
"function",
"getDeviceList",
"(",
"$",
"dir",
")",
"{",
"$",
"path",
"=",
"array",
"(",
"'.'",
",",
"'..'",
",",
"'.htaccess'",
",",
"'.DS_Store'",
",",
"'controllers'",
",",
"'config'",
",",
"'debug'",
",",
"'framework'",
")",
";",
"$",
"ext",
"=",
"array",
"(",
"\"php\"",
",",
"\"html\"",
",",
"\"htm\"",
")",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"$",
"handle",
"=",
"opendir",
"(",
"$",
"dir",
")",
")",
"{",
"while",
"(",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"handle",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"file",
",",
"$",
"path",
")",
"&&",
"!",
"in_array",
"(",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
",",
"$",
"ext",
")",
")",
"{",
"$",
"list",
"[",
"$",
"file",
"]",
"=",
"VENDOR_DIR",
".",
"DS",
".",
"FRAMEWORK",
".",
"DS",
".",
"$",
"file",
";",
"}",
"}",
"closedir",
"(",
"$",
"handle",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
] | 获取驱动列表.
@param string $dir 驱动目录
@return array 驱动列表 | [
"获取驱动列表",
"."
] | train | https://github.com/this7/framework/blob/1248f4ea79cf2a61da11de0aaf1fbbf25a91ca97/src/kernel.php#L84-L99 |
Nicofuma/phpbb-ext-webprofiler | phpbb/template/timed.php | timed.display | public function display($handle)
{
$e = $this->stopwatch->start(sprintf('template (%s)', $this->get_source_file_for_handle($handle)), 'template');
$this->template->display($handle);
$e->stop();
return $this;
} | php | public function display($handle)
{
$e = $this->stopwatch->start(sprintf('template (%s)', $this->get_source_file_for_handle($handle)), 'template');
$this->template->display($handle);
$e->stop();
return $this;
} | [
"public",
"function",
"display",
"(",
"$",
"handle",
")",
"{",
"$",
"e",
"=",
"$",
"this",
"->",
"stopwatch",
"->",
"start",
"(",
"sprintf",
"(",
"'template (%s)'",
",",
"$",
"this",
"->",
"get_source_file_for_handle",
"(",
"$",
"handle",
")",
")",
",",
"'template'",
")",
";",
"$",
"this",
"->",
"template",
"->",
"display",
"(",
"$",
"handle",
")",
";",
"$",
"e",
"->",
"stop",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Nicofuma/phpbb-ext-webprofiler/blob/5f52e2b67f5b8278af18907615f30ffe20f4802c/phpbb/template/timed.php#L109-L118 |
Nicofuma/phpbb-ext-webprofiler | phpbb/template/timed.php | timed.assign_display | public function assign_display($handle, $template_var = '', $return_content = true)
{
$e = $this->stopwatch->start(sprintf('template (%s)', $this->get_source_file_for_handle($handle)), 'template');
$result = $this->template->assign_display($handle, $template_var, $return_content);
$e->stop();
if ($return_content)
{
return $result;
}
return $this;
} | php | public function assign_display($handle, $template_var = '', $return_content = true)
{
$e = $this->stopwatch->start(sprintf('template (%s)', $this->get_source_file_for_handle($handle)), 'template');
$result = $this->template->assign_display($handle, $template_var, $return_content);
$e->stop();
if ($return_content)
{
return $result;
}
return $this;
} | [
"public",
"function",
"assign_display",
"(",
"$",
"handle",
",",
"$",
"template_var",
"=",
"''",
",",
"$",
"return_content",
"=",
"true",
")",
"{",
"$",
"e",
"=",
"$",
"this",
"->",
"stopwatch",
"->",
"start",
"(",
"sprintf",
"(",
"'template (%s)'",
",",
"$",
"this",
"->",
"get_source_file_for_handle",
"(",
"$",
"handle",
")",
")",
",",
"'template'",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"template",
"->",
"assign_display",
"(",
"$",
"handle",
",",
"$",
"template_var",
",",
"$",
"return_content",
")",
";",
"$",
"e",
"->",
"stop",
"(",
")",
";",
"if",
"(",
"$",
"return_content",
")",
"{",
"return",
"$",
"result",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Nicofuma/phpbb-ext-webprofiler/blob/5f52e2b67f5b8278af18907615f30ffe20f4802c/phpbb/template/timed.php#L123-L137 |
Nicofuma/phpbb-ext-webprofiler | phpbb/template/timed.php | timed.alter_block_array | public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert')
{
return $this->template->alter_block_array($blockname, $vararray, $key, $mode);
} | php | public function alter_block_array($blockname, array $vararray, $key = false, $mode = 'insert')
{
return $this->template->alter_block_array($blockname, $vararray, $key, $mode);
} | [
"public",
"function",
"alter_block_array",
"(",
"$",
"blockname",
",",
"array",
"$",
"vararray",
",",
"$",
"key",
"=",
"false",
",",
"$",
"mode",
"=",
"'insert'",
")",
"{",
"return",
"$",
"this",
"->",
"template",
"->",
"alter_block_array",
"(",
"$",
"blockname",
",",
"$",
"vararray",
",",
"$",
"key",
",",
"$",
"mode",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Nicofuma/phpbb-ext-webprofiler/blob/5f52e2b67f5b8278af18907615f30ffe20f4802c/phpbb/template/timed.php#L192-L195 |
loevgaard/dandomain-foundation-entities | src/Repository/ProductRepository.php | ProductRepository.updateParentChildRelationships | public function updateParentChildRelationships(array $productIds = [])
{
$variantMasterIdCache = [];
$innerQb = $this->createQueryBuilder('p');
$innerQb->where('p.isVariantMaster = 1')
->andWhere('p.number = :number');
$qb = $this->createQueryBuilder('p');
$qb
->where('p.isVariantMaster = 0')
->andWhere('p.variantMasterId is not null')
;
if (count($productIds)) {
$qb->andWhere($qb->expr()->in('p.id', ':productIds'));
$qb->setParameter('productIds', $productIds);
}
$batchSize = 50;
$i = 1;
$iterableResult = $qb->getQuery()->iterate();
foreach ($iterableResult as $row) {
/** @var ProductInterface $product */
$product = $row[0];
if (!isset($variantMasterIdCache[$product->getVariantMasterId()])) {
try {
/** @var ProductInterface $parent */
$parent = $innerQb->setParameter(
'number',
$product->getVariantMasterId()
)->getQuery()->getSingleResult();
$parent = $parent->getId();
} catch (UnexpectedResultException $e) {
$parent = null;
}
$variantMasterIdCache[$product->getVariantMasterId()] = $parent;
}
$ref = $variantMasterIdCache[$product->getVariantMasterId()];
if ($ref) {
try {
$ref = $this->getEntityManager()->getReference(Product::class, $ref);
} catch (ORMException $e) {
$ref = null;
}
}
$product->setParent($ref);
if (0 === ($i % $batchSize)) {
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
}
++$i;
}
$this->getEntityManager()->flush();
} | php | public function updateParentChildRelationships(array $productIds = [])
{
$variantMasterIdCache = [];
$innerQb = $this->createQueryBuilder('p');
$innerQb->where('p.isVariantMaster = 1')
->andWhere('p.number = :number');
$qb = $this->createQueryBuilder('p');
$qb
->where('p.isVariantMaster = 0')
->andWhere('p.variantMasterId is not null')
;
if (count($productIds)) {
$qb->andWhere($qb->expr()->in('p.id', ':productIds'));
$qb->setParameter('productIds', $productIds);
}
$batchSize = 50;
$i = 1;
$iterableResult = $qb->getQuery()->iterate();
foreach ($iterableResult as $row) {
/** @var ProductInterface $product */
$product = $row[0];
if (!isset($variantMasterIdCache[$product->getVariantMasterId()])) {
try {
/** @var ProductInterface $parent */
$parent = $innerQb->setParameter(
'number',
$product->getVariantMasterId()
)->getQuery()->getSingleResult();
$parent = $parent->getId();
} catch (UnexpectedResultException $e) {
$parent = null;
}
$variantMasterIdCache[$product->getVariantMasterId()] = $parent;
}
$ref = $variantMasterIdCache[$product->getVariantMasterId()];
if ($ref) {
try {
$ref = $this->getEntityManager()->getReference(Product::class, $ref);
} catch (ORMException $e) {
$ref = null;
}
}
$product->setParent($ref);
if (0 === ($i % $batchSize)) {
$this->getEntityManager()->flush();
$this->getEntityManager()->clear();
}
++$i;
}
$this->getEntityManager()->flush();
} | [
"public",
"function",
"updateParentChildRelationships",
"(",
"array",
"$",
"productIds",
"=",
"[",
"]",
")",
"{",
"$",
"variantMasterIdCache",
"=",
"[",
"]",
";",
"$",
"innerQb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'p'",
")",
";",
"$",
"innerQb",
"->",
"where",
"(",
"'p.isVariantMaster = 1'",
")",
"->",
"andWhere",
"(",
"'p.number = :number'",
")",
";",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'p'",
")",
";",
"$",
"qb",
"->",
"where",
"(",
"'p.isVariantMaster = 0'",
")",
"->",
"andWhere",
"(",
"'p.variantMasterId is not null'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"productIds",
")",
")",
"{",
"$",
"qb",
"->",
"andWhere",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"in",
"(",
"'p.id'",
",",
"':productIds'",
")",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"'productIds'",
",",
"$",
"productIds",
")",
";",
"}",
"$",
"batchSize",
"=",
"50",
";",
"$",
"i",
"=",
"1",
";",
"$",
"iterableResult",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"iterate",
"(",
")",
";",
"foreach",
"(",
"$",
"iterableResult",
"as",
"$",
"row",
")",
"{",
"/** @var ProductInterface $product */",
"$",
"product",
"=",
"$",
"row",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"variantMasterIdCache",
"[",
"$",
"product",
"->",
"getVariantMasterId",
"(",
")",
"]",
")",
")",
"{",
"try",
"{",
"/** @var ProductInterface $parent */",
"$",
"parent",
"=",
"$",
"innerQb",
"->",
"setParameter",
"(",
"'number'",
",",
"$",
"product",
"->",
"getVariantMasterId",
"(",
")",
")",
"->",
"getQuery",
"(",
")",
"->",
"getSingleResult",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"parent",
"->",
"getId",
"(",
")",
";",
"}",
"catch",
"(",
"UnexpectedResultException",
"$",
"e",
")",
"{",
"$",
"parent",
"=",
"null",
";",
"}",
"$",
"variantMasterIdCache",
"[",
"$",
"product",
"->",
"getVariantMasterId",
"(",
")",
"]",
"=",
"$",
"parent",
";",
"}",
"$",
"ref",
"=",
"$",
"variantMasterIdCache",
"[",
"$",
"product",
"->",
"getVariantMasterId",
"(",
")",
"]",
";",
"if",
"(",
"$",
"ref",
")",
"{",
"try",
"{",
"$",
"ref",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getReference",
"(",
"Product",
"::",
"class",
",",
"$",
"ref",
")",
";",
"}",
"catch",
"(",
"ORMException",
"$",
"e",
")",
"{",
"$",
"ref",
"=",
"null",
";",
"}",
"}",
"$",
"product",
"->",
"setParent",
"(",
"$",
"ref",
")",
";",
"if",
"(",
"0",
"===",
"(",
"$",
"i",
"%",
"$",
"batchSize",
")",
")",
"{",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"clear",
"(",
")",
";",
"}",
"++",
"$",
"i",
";",
"}",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"}"
] | @param array $productIds
@throws \Doctrine\ORM\OptimisticLockException | [
"@param",
"array",
"$productIds"
] | train | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Repository/ProductRepository.php#L55-L117 |
eureka-framework/component-notification | src/Notification/NotificationBootstrap.php | NotificationBootstrap.getCss | public function getCss()
{
switch ($this->type) {
case self::TYPE_ERROR:
$css = 'danger';
break;
case self::TYPE_WARNING:
$css = 'warning';
break;
case self::TYPE_INFO:
$css = 'info';
break;
case self::TYPE_SUCCESS:
$css = 'success';
break;
default:
$css = 'info';
break;
}
return $css;
} | php | public function getCss()
{
switch ($this->type) {
case self::TYPE_ERROR:
$css = 'danger';
break;
case self::TYPE_WARNING:
$css = 'warning';
break;
case self::TYPE_INFO:
$css = 'info';
break;
case self::TYPE_SUCCESS:
$css = 'success';
break;
default:
$css = 'info';
break;
}
return $css;
} | [
"public",
"function",
"getCss",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_ERROR",
":",
"$",
"css",
"=",
"'danger'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_WARNING",
":",
"$",
"css",
"=",
"'warning'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_INFO",
":",
"$",
"css",
"=",
"'info'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_SUCCESS",
":",
"$",
"css",
"=",
"'success'",
";",
"break",
";",
"default",
":",
"$",
"css",
"=",
"'info'",
";",
"break",
";",
"}",
"return",
"$",
"css",
";",
"}"
] | Get css used.
@return string | [
"Get",
"css",
"used",
"."
] | train | https://github.com/eureka-framework/component-notification/blob/346c2932cf4ebdbae651aae513ac350df8f8c33a/src/Notification/NotificationBootstrap.php#L24-L45 |
eureka-framework/component-notification | src/Notification/NotificationBootstrap.php | NotificationBootstrap.getHeader | public function getHeader()
{
switch ($this->type) {
case self::TYPE_ERROR:
$header = 'Error!';
break;
case self::TYPE_WARNING:
$header = 'Warning!';
break;
case self::TYPE_INFO:
$header = 'Info';
break;
case self::TYPE_SUCCESS:
$header = 'Success';
break;
default:
$header = 'Info';
break;
}
return $header;
} | php | public function getHeader()
{
switch ($this->type) {
case self::TYPE_ERROR:
$header = 'Error!';
break;
case self::TYPE_WARNING:
$header = 'Warning!';
break;
case self::TYPE_INFO:
$header = 'Info';
break;
case self::TYPE_SUCCESS:
$header = 'Success';
break;
default:
$header = 'Info';
break;
}
return $header;
} | [
"public",
"function",
"getHeader",
"(",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_ERROR",
":",
"$",
"header",
"=",
"'Error!'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_WARNING",
":",
"$",
"header",
"=",
"'Warning!'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_INFO",
":",
"$",
"header",
"=",
"'Info'",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_SUCCESS",
":",
"$",
"header",
"=",
"'Success'",
";",
"break",
";",
"default",
":",
"$",
"header",
"=",
"'Info'",
";",
"break",
";",
"}",
"return",
"$",
"header",
";",
"}"
] | Get header title.
@return string | [
"Get",
"header",
"title",
"."
] | train | https://github.com/eureka-framework/component-notification/blob/346c2932cf4ebdbae651aae513ac350df8f8c33a/src/Notification/NotificationBootstrap.php#L52-L73 |
nicmart/DomainSpecificQuery | src/Language/Grammar.php | Grammar.unescape | public function unescape($string, $chars, $escapeChar = "\\")
{
if (!$chars)
return $string;
$escapeChar = preg_quote($escapeChar);
$chars = preg_quote($chars);
return preg_replace("/$escapeChar([$chars])/", "$1", $string);
} | php | public function unescape($string, $chars, $escapeChar = "\\")
{
if (!$chars)
return $string;
$escapeChar = preg_quote($escapeChar);
$chars = preg_quote($chars);
return preg_replace("/$escapeChar([$chars])/", "$1", $string);
} | [
"public",
"function",
"unescape",
"(",
"$",
"string",
",",
"$",
"chars",
",",
"$",
"escapeChar",
"=",
"\"\\\\\"",
")",
"{",
"if",
"(",
"!",
"$",
"chars",
")",
"return",
"$",
"string",
";",
"$",
"escapeChar",
"=",
"preg_quote",
"(",
"$",
"escapeChar",
")",
";",
"$",
"chars",
"=",
"preg_quote",
"(",
"$",
"chars",
")",
";",
"return",
"preg_replace",
"(",
"\"/$escapeChar([$chars])/\"",
",",
"\"$1\"",
",",
"$",
"string",
")",
";",
"}"
] | Do unescaping
@param string $string
@param string $chars
@param string $escapeChar
@return string | [
"Do",
"unescaping"
] | train | https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Language/Grammar.php#L172-L180 |
MindyPHP/QueryBuilder | Utils/TableNameResolver.php | TableNameResolver.getTableName | public static function getTableName(string $name, string $prefix = null): string
{
if (false !== strpos($name, '{{')) {
$name = preg_replace('/\\{\\{(.*?)\\}\\}/', '\1', $name);
return str_replace('%', $prefix, $name);
}
return $name;
} | php | public static function getTableName(string $name, string $prefix = null): string
{
if (false !== strpos($name, '{{')) {
$name = preg_replace('/\\{\\{(.*?)\\}\\}/', '\1', $name);
return str_replace('%', $prefix, $name);
}
return $name;
} | [
"public",
"static",
"function",
"getTableName",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"prefix",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"name",
",",
"'{{'",
")",
")",
"{",
"$",
"name",
"=",
"preg_replace",
"(",
"'/\\\\{\\\\{(.*?)\\\\}\\\\}/'",
",",
"'\\1'",
",",
"$",
"name",
")",
";",
"return",
"str_replace",
"(",
"'%'",
",",
"$",
"prefix",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Returns the actual name of a given table name.
This method will strip off curly brackets from the given table name
and replace the percentage character '%' with [[Connection::tablePrefix]].
@param string $name the table name to be converted
@param string|null $prefix
@return string the real name of the given table name | [
"Returns",
"the",
"actual",
"name",
"of",
"a",
"given",
"table",
"name",
".",
"This",
"method",
"will",
"strip",
"off",
"curly",
"brackets",
"from",
"the",
"given",
"table",
"name",
"and",
"replace",
"the",
"percentage",
"character",
"%",
"with",
"[[",
"Connection",
"::",
"tablePrefix",
"]]",
"."
] | train | https://github.com/MindyPHP/QueryBuilder/blob/fc486454786f3d38887dd7246802ea11e2954e54/Utils/TableNameResolver.php#L26-L35 |
judus/minimal-collections | src/Collection.php | Collection.add | public function add($obj, $key = null, $overwrite = false): CollectionInterface
{
$this->validateKey($key);
if ($key == null) {
$this->items[] = $obj;
} else {
if (isset($this->items[$key]) && !$overwrite) {
throw new KeyInUseException("Collection key '".$key."' is already in use.");
} else {
$this->items[$key] = $obj;
}
}
return $this;
} | php | public function add($obj, $key = null, $overwrite = false): CollectionInterface
{
$this->validateKey($key);
if ($key == null) {
$this->items[] = $obj;
} else {
if (isset($this->items[$key]) && !$overwrite) {
throw new KeyInUseException("Collection key '".$key."' is already in use.");
} else {
$this->items[$key] = $obj;
}
}
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"obj",
",",
"$",
"key",
"=",
"null",
",",
"$",
"overwrite",
"=",
"false",
")",
":",
"CollectionInterface",
"{",
"$",
"this",
"->",
"validateKey",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"key",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"items",
"[",
"]",
"=",
"$",
"obj",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"$",
"overwrite",
")",
"{",
"throw",
"new",
"KeyInUseException",
"(",
"\"Collection key '\"",
".",
"$",
"key",
".",
"\"' is already in use.\"",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
"=",
"$",
"obj",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | @param $obj
@param null $key
@param bool $overwrite
@return CollectionInterface
@throws InvalidKeyException
@throws KeyInUseException | [
"@param",
"$obj",
"@param",
"null",
"$key"
] | train | https://github.com/judus/minimal-collections/blob/0dd5d1980164f1479358b821937e1b236e0e15d4/src/Collection.php#L34-L49 |
judus/minimal-collections | src/Collection.php | Collection.delete | public function delete($key)
{
$this->validateKey($key);
if (isset($this->items[$key])) {
unset($this->items[$key]);
} else {
throw new InvalidKeyException("Collection key '".$key."' does not exist.");
}
} | php | public function delete($key)
{
$this->validateKey($key);
if (isset($this->items[$key])) {
unset($this->items[$key]);
} else {
throw new InvalidKeyException("Collection key '".$key."' does not exist.");
}
} | [
"public",
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"validateKey",
"(",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidKeyException",
"(",
"\"Collection key '\"",
".",
"$",
"key",
".",
"\"' does not exist.\"",
")",
";",
"}",
"}"
] | @param $key
@throws InvalidKeyException | [
"@param",
"$key"
] | train | https://github.com/judus/minimal-collections/blob/0dd5d1980164f1479358b821937e1b236e0e15d4/src/Collection.php#L56-L65 |
judus/minimal-collections | src/Collection.php | Collection.get | public function get($key)
{
if (isset($this->items[$key])) {
return $this->items[$key];
} else {
throw new InvalidKeyException("Collection key '" . $key . "' does not exist.");
}
} | php | public function get($key)
{
if (isset($this->items[$key])) {
return $this->items[$key];
} else {
throw new InvalidKeyException("Collection key '" . $key . "' does not exist.");
}
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidKeyException",
"(",
"\"Collection key '\"",
".",
"$",
"key",
".",
"\"' does not exist.\"",
")",
";",
"}",
"}"
] | @param $key
@return mixed
@throws InvalidKeyException | [
"@param",
"$key"
] | train | https://github.com/judus/minimal-collections/blob/0dd5d1980164f1479358b821937e1b236e0e15d4/src/Collection.php#L89-L96 |
judus/minimal-collections | src/Collection.php | Collection.count | public function count($key = null)
{
if (!is_null($key) && isset($this->items[$key])) {
return count($this->items[$key]);
} else {
return count($this->items);
}
} | php | public function count($key = null)
{
if (!is_null($key) && isset($this->items[$key])) {
return count($this->items[$key]);
} else {
return count($this->items);
}
} | [
"public",
"function",
"count",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"key",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"count",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"return",
"count",
"(",
"$",
"this",
"->",
"items",
")",
";",
"}",
"}"
] | @param null $key
@return int | [
"@param",
"null",
"$key"
] | train | https://github.com/judus/minimal-collections/blob/0dd5d1980164f1479358b821937e1b236e0e15d4/src/Collection.php#L103-L110 |
judus/minimal-collections | src/Collection.php | Collection.exists | public function exists(string $name, $else = null)
{
return isset($this->items[$name]) ?
$this->items[$name] : $else;
} | php | public function exists(string $name, $else = null)
{
return isset($this->items[$name]) ?
$this->items[$name] : $else;
} | [
"public",
"function",
"exists",
"(",
"string",
"$",
"name",
",",
"$",
"else",
"=",
"null",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
":",
"$",
"else",
";",
"}"
] | @param string $name
@param null $else
@return mixed|null | [
"@param",
"string",
"$name",
"@param",
"null",
"$else"
] | train | https://github.com/judus/minimal-collections/blob/0dd5d1980164f1479358b821937e1b236e0e15d4/src/Collection.php#L126-L130 |
judus/minimal-collections | src/Collection.php | Collection.each | public function each($closure)
{
$container = new static();
$index = -1;
foreach ($this->items as $key => $item) {
$container->add($closure($key, $item, $index++), $key);
}
return $container;
} | php | public function each($closure)
{
$container = new static();
$index = -1;
foreach ($this->items as $key => $item) {
$container->add($closure($key, $item, $index++), $key);
}
return $container;
} | [
"public",
"function",
"each",
"(",
"$",
"closure",
")",
"{",
"$",
"container",
"=",
"new",
"static",
"(",
")",
";",
"$",
"index",
"=",
"-",
"1",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"container",
"->",
"add",
"(",
"$",
"closure",
"(",
"$",
"key",
",",
"$",
"item",
",",
"$",
"index",
"++",
")",
",",
"$",
"key",
")",
";",
"}",
"return",
"$",
"container",
";",
"}"
] | @param $closure
@return Collection | [
"@param",
"$closure"
] | train | https://github.com/judus/minimal-collections/blob/0dd5d1980164f1479358b821937e1b236e0e15d4/src/Collection.php#L137-L147 |
judus/minimal-collections | src/Collection.php | Collection.filter | public function filter(\Closure $closure, $keepKeys = false)
{
$collection = new Collection();
$i = 0;
foreach ($this->items as $key => $value) {
if ( ! $closure($value, $key, $i++)) {
$keepKeys || $key = null;
$collection->add($value, $key);
}
}
return $collection;
} | php | public function filter(\Closure $closure, $keepKeys = false)
{
$collection = new Collection();
$i = 0;
foreach ($this->items as $key => $value) {
if ( ! $closure($value, $key, $i++)) {
$keepKeys || $key = null;
$collection->add($value, $key);
}
}
return $collection;
} | [
"public",
"function",
"filter",
"(",
"\\",
"Closure",
"$",
"closure",
",",
"$",
"keepKeys",
"=",
"false",
")",
"{",
"$",
"collection",
"=",
"new",
"Collection",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"closure",
"(",
"$",
"value",
",",
"$",
"key",
",",
"$",
"i",
"++",
")",
")",
"{",
"$",
"keepKeys",
"||",
"$",
"key",
"=",
"null",
";",
"$",
"collection",
"->",
"add",
"(",
"$",
"value",
",",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"collection",
";",
"}"
] | @param \Closure $closure
@param bool $keepKeys
@return Collection
@throws InvalidKeyException
@throws KeyInUseException | [
"@param",
"\\",
"Closure",
"$closure",
"@param",
"bool",
"$keepKeys"
] | train | https://github.com/judus/minimal-collections/blob/0dd5d1980164f1479358b821937e1b236e0e15d4/src/Collection.php#L157-L170 |
judus/minimal-collections | src/Collection.php | Collection.extract | public function extract($key)
{
$extracted = [];
foreach ($this->items as $item) {
foreach (func_get_args() as $key) {
if ($item instanceof CollectionInterface) {
$extracted[] = $item->get($key);
} else if (is_object($item)) {
$extracted[] = $item->{$key};
} else {
$extracted[] = $item[$key];
}
}
}
return $extracted;
} | php | public function extract($key)
{
$extracted = [];
foreach ($this->items as $item) {
foreach (func_get_args() as $key) {
if ($item instanceof CollectionInterface) {
$extracted[] = $item->get($key);
} else if (is_object($item)) {
$extracted[] = $item->{$key};
} else {
$extracted[] = $item[$key];
}
}
}
return $extracted;
} | [
"public",
"function",
"extract",
"(",
"$",
"key",
")",
"{",
"$",
"extracted",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"item",
")",
"{",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"item",
"instanceof",
"CollectionInterface",
")",
"{",
"$",
"extracted",
"[",
"]",
"=",
"$",
"item",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"item",
")",
")",
"{",
"$",
"extracted",
"[",
"]",
"=",
"$",
"item",
"->",
"{",
"$",
"key",
"}",
";",
"}",
"else",
"{",
"$",
"extracted",
"[",
"]",
"=",
"$",
"item",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"extracted",
";",
"}"
] | @param $key
@return array
@throws InvalidKeyException | [
"@param",
"$key"
] | train | https://github.com/judus/minimal-collections/blob/0dd5d1980164f1479358b821937e1b236e0e15d4/src/Collection.php#L178-L195 |
AnonymPHP/Anonym-Route | Matchers/NewMatcher.php | NewMatcher.match | public function match($url = null)
{
$match = parent::match($url);
$find = $this->replaceParameters();
if (false !== $find || true === $match) {
return true;
} else {
return false;
}
} | php | public function match($url = null)
{
$match = parent::match($url);
$find = $this->replaceParameters();
if (false !== $find || true === $match) {
return true;
} else {
return false;
}
} | [
"public",
"function",
"match",
"(",
"$",
"url",
"=",
"null",
")",
"{",
"$",
"match",
"=",
"parent",
"::",
"match",
"(",
"$",
"url",
")",
";",
"$",
"find",
"=",
"$",
"this",
"->",
"replaceParameters",
"(",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"find",
"||",
"true",
"===",
"$",
"match",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | make the match
@param string|null $url
@return bool | [
"make",
"the",
"match"
] | train | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Matchers/NewMatcher.php#L51-L62 |
AnonymPHP/Anonym-Route | Matchers/NewMatcher.php | NewMatcher.resolvePregCallback | private function resolvePregCallback($finded)
{
$matchEx = explode(' ', $this->getMatchUrl());
$requestEx = explode(' ', $this->getRequestedUrl());
$key = array_search($finded[0], $matchEx);
$cln = $finded[1];
if (strstr($cln, ':')) {
list($cln, $filter) = explode(':', $cln);
}
if (!strstr($cln, '?')) {
$add = isset($requestEx[$key]) && $requestEx[$key] !== '' ? $requestEx[$key] : false;
} else {
$add = isset($requestEx[$key]) ? $requestEx[$key] : null;
}
if($add !== null){
// we gonna do run filter now
if (!$this->runFilter(isset($filter) ? $filter : $cln, $add)) {
throw new FilterMatchException('Your filter do not match');
}
}
$this->parameters[$cln] = $add;
} | php | private function resolvePregCallback($finded)
{
$matchEx = explode(' ', $this->getMatchUrl());
$requestEx = explode(' ', $this->getRequestedUrl());
$key = array_search($finded[0], $matchEx);
$cln = $finded[1];
if (strstr($cln, ':')) {
list($cln, $filter) = explode(':', $cln);
}
if (!strstr($cln, '?')) {
$add = isset($requestEx[$key]) && $requestEx[$key] !== '' ? $requestEx[$key] : false;
} else {
$add = isset($requestEx[$key]) ? $requestEx[$key] : null;
}
if($add !== null){
// we gonna do run filter now
if (!$this->runFilter(isset($filter) ? $filter : $cln, $add)) {
throw new FilterMatchException('Your filter do not match');
}
}
$this->parameters[$cln] = $add;
} | [
"private",
"function",
"resolvePregCallback",
"(",
"$",
"finded",
")",
"{",
"$",
"matchEx",
"=",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"getMatchUrl",
"(",
")",
")",
";",
"$",
"requestEx",
"=",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"getRequestedUrl",
"(",
")",
")",
";",
"$",
"key",
"=",
"array_search",
"(",
"$",
"finded",
"[",
"0",
"]",
",",
"$",
"matchEx",
")",
";",
"$",
"cln",
"=",
"$",
"finded",
"[",
"1",
"]",
";",
"if",
"(",
"strstr",
"(",
"$",
"cln",
",",
"':'",
")",
")",
"{",
"list",
"(",
"$",
"cln",
",",
"$",
"filter",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"cln",
")",
";",
"}",
"if",
"(",
"!",
"strstr",
"(",
"$",
"cln",
",",
"'?'",
")",
")",
"{",
"$",
"add",
"=",
"isset",
"(",
"$",
"requestEx",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"requestEx",
"[",
"$",
"key",
"]",
"!==",
"''",
"?",
"$",
"requestEx",
"[",
"$",
"key",
"]",
":",
"false",
";",
"}",
"else",
"{",
"$",
"add",
"=",
"isset",
"(",
"$",
"requestEx",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"requestEx",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}",
"if",
"(",
"$",
"add",
"!==",
"null",
")",
"{",
"// we gonna do run filter now",
"if",
"(",
"!",
"$",
"this",
"->",
"runFilter",
"(",
"isset",
"(",
"$",
"filter",
")",
"?",
"$",
"filter",
":",
"$",
"cln",
",",
"$",
"add",
")",
")",
"{",
"throw",
"new",
"FilterMatchException",
"(",
"'Your filter do not match'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"parameters",
"[",
"$",
"cln",
"]",
"=",
"$",
"add",
";",
"}"
] | resolve the preg callback
@param array $finded
@return bool|string | [
"resolve",
"the",
"preg",
"callback"
] | train | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Matchers/NewMatcher.php#L99-L125 |
AnonymPHP/Anonym-Route | Matchers/NewMatcher.php | NewMatcher.runFilter | private function runFilter($filter, $parameter)
{
if (!strstr($filter, '(') && !strstr($filter, ')')) {
if (!$filter = $this->getFilter($filter)) {
return false;
}
}
return preg_match('@' . $filter . '@si', $parameter) ?: false;
} | php | private function runFilter($filter, $parameter)
{
if (!strstr($filter, '(') && !strstr($filter, ')')) {
if (!$filter = $this->getFilter($filter)) {
return false;
}
}
return preg_match('@' . $filter . '@si', $parameter) ?: false;
} | [
"private",
"function",
"runFilter",
"(",
"$",
"filter",
",",
"$",
"parameter",
")",
"{",
"if",
"(",
"!",
"strstr",
"(",
"$",
"filter",
",",
"'('",
")",
"&&",
"!",
"strstr",
"(",
"$",
"filter",
",",
"')'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"filter",
"=",
"$",
"this",
"->",
"getFilter",
"(",
"$",
"filter",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"preg_match",
"(",
"'@'",
".",
"$",
"filter",
".",
"'@si'",
",",
"$",
"parameter",
")",
"?",
":",
"false",
";",
"}"
] | execute a filter
@param string $filter
@param string $parameter
@return bool|int | [
"execute",
"a",
"filter"
] | train | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Matchers/NewMatcher.php#L134-L143 |
linuxjuggler/lumen-make | src/LumenMakeServiceProvider.php | LumenMakeServiceProvider.register | public function register()
{
$this->commands([
ConsoleMakeCommand::class,
ControllerMakeCommand::class,
EnvironmentCommand::class,
EventMakeCommand::class,
JobMakeCommand::class,
KeyGenerateCommand::class,
ListenerMakeCommand::class,
MailMakeCommand::class,
MiddlewareMakeCommand::class,
ModelMakeCommand::class,
NotificationMakeCommand::class,
ProviderMakeCommand::class,
ResourceMakeCommand::class,
TestMakeCommand::class,
]);
} | php | public function register()
{
$this->commands([
ConsoleMakeCommand::class,
ControllerMakeCommand::class,
EnvironmentCommand::class,
EventMakeCommand::class,
JobMakeCommand::class,
KeyGenerateCommand::class,
ListenerMakeCommand::class,
MailMakeCommand::class,
MiddlewareMakeCommand::class,
ModelMakeCommand::class,
NotificationMakeCommand::class,
ProviderMakeCommand::class,
ResourceMakeCommand::class,
TestMakeCommand::class,
]);
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"commands",
"(",
"[",
"ConsoleMakeCommand",
"::",
"class",
",",
"ControllerMakeCommand",
"::",
"class",
",",
"EnvironmentCommand",
"::",
"class",
",",
"EventMakeCommand",
"::",
"class",
",",
"JobMakeCommand",
"::",
"class",
",",
"KeyGenerateCommand",
"::",
"class",
",",
"ListenerMakeCommand",
"::",
"class",
",",
"MailMakeCommand",
"::",
"class",
",",
"MiddlewareMakeCommand",
"::",
"class",
",",
"ModelMakeCommand",
"::",
"class",
",",
"NotificationMakeCommand",
"::",
"class",
",",
"ProviderMakeCommand",
"::",
"class",
",",
"ResourceMakeCommand",
"::",
"class",
",",
"TestMakeCommand",
"::",
"class",
",",
"]",
")",
";",
"}"
] | Register any application services. | [
"Register",
"any",
"application",
"services",
"."
] | train | https://github.com/linuxjuggler/lumen-make/blob/80e794f78957ea56770a1b27c0f7160d0b7ea76d/src/LumenMakeServiceProvider.php#L26-L44 |
opensourcerefinery/vicus | src/Component/CallbackResolver.php | CallbackResolver.convertCallback | public function convertCallback($name)
{
list($service, $method) = explode(':', $name, 2);
if (!isset($this->container[$service])) {
throw new \InvalidArgumentException(sprintf('Service "%s" does not exist.', $service));
}
return array($this->container[$service], $method);
} | php | public function convertCallback($name)
{
list($service, $method) = explode(':', $name, 2);
if (!isset($this->container[$service])) {
throw new \InvalidArgumentException(sprintf('Service "%s" does not exist.', $service));
}
return array($this->container[$service], $method);
} | [
"public",
"function",
"convertCallback",
"(",
"$",
"name",
")",
"{",
"list",
"(",
"$",
"service",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"name",
",",
"2",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"container",
"[",
"$",
"service",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Service \"%s\" does not exist.'",
",",
"$",
"service",
")",
")",
";",
"}",
"return",
"array",
"(",
"$",
"this",
"->",
"container",
"[",
"$",
"service",
"]",
",",
"$",
"method",
")",
";",
"}"
] | Returns a callable given its string representation.
@param string $name
@return array A callable array
@throws \InvalidArgumentException In case the method does not exist. | [
"Returns",
"a",
"callable",
"given",
"its",
"string",
"representation",
"."
] | train | https://github.com/opensourcerefinery/vicus/blob/5be93d75bf6ab8009a299e9946c8333f0017fa3e/src/Component/CallbackResolver.php#L46-L55 |
bseries/base_tag | models/Tags.php | Tags.depend | public function depend($entity, $type) {
$depend = $type === 'count' ? 0 : [];
foreach (static::_dependent() as $model) {
$results = $model::find($type, [
'conditions' => [
'tags' => $entity->name
]
]);
if (!$results) {
continue;
}
if ($type === 'count') {
$depend += $results;
} else {
foreach ($results as $result) {
$depend[] = $result;
}
}
}
return $depend;
} | php | public function depend($entity, $type) {
$depend = $type === 'count' ? 0 : [];
foreach (static::_dependent() as $model) {
$results = $model::find($type, [
'conditions' => [
'tags' => $entity->name
]
]);
if (!$results) {
continue;
}
if ($type === 'count') {
$depend += $results;
} else {
foreach ($results as $result) {
$depend[] = $result;
}
}
}
return $depend;
} | [
"public",
"function",
"depend",
"(",
"$",
"entity",
",",
"$",
"type",
")",
"{",
"$",
"depend",
"=",
"$",
"type",
"===",
"'count'",
"?",
"0",
":",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"_dependent",
"(",
")",
"as",
"$",
"model",
")",
"{",
"$",
"results",
"=",
"$",
"model",
"::",
"find",
"(",
"$",
"type",
",",
"[",
"'conditions'",
"=>",
"[",
"'tags'",
"=>",
"$",
"entity",
"->",
"name",
"]",
"]",
")",
";",
"if",
"(",
"!",
"$",
"results",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"'count'",
")",
"{",
"$",
"depend",
"+=",
"$",
"results",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"$",
"depend",
"[",
"]",
"=",
"$",
"result",
";",
"}",
"}",
"}",
"return",
"$",
"depend",
";",
"}"
] | Do not use in performance criticial parts. | [
"Do",
"not",
"use",
"in",
"performance",
"criticial",
"parts",
"."
] | train | https://github.com/bseries/base_tag/blob/b66e817ac8268813790677fed259d8904b6dbb92/models/Tags.php#L79-L100 |
vanilla/legacy-passwords | src/DrupalPassword.php | DrupalPassword.needsRehash | public function needsRehash($hash) {
if (strpos($hash, '$') === false) {
return true;
} else {
if (strpos($hash, '$S$') !== 0) {
return true;
}
}
return true;
} | php | public function needsRehash($hash) {
if (strpos($hash, '$') === false) {
return true;
} else {
if (strpos($hash, '$S$') !== 0) {
return true;
}
}
return true;
} | [
"public",
"function",
"needsRehash",
"(",
"$",
"hash",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"hash",
",",
"'$'",
")",
"===",
"false",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"strpos",
"(",
"$",
"hash",
",",
"'$S$'",
")",
"!==",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/vanilla/legacy-passwords/blob/3363312791bef1ea781b2896f99feb65d116c6cd/src/DrupalPassword.php#L30-L40 |
nicodevs/laito | src/Laito/Database.php | Database.reset | public function reset()
{
$this->table = '';
$this->columns = [];
$this->joins = [];
$this->wheres = [];
$this->whereIn = [];
$this->groupBy = false;
$this->orderBy = false;
$this->offset = 0;
$this->limit = 10;
$this->fields = [];
return $this;
} | php | public function reset()
{
$this->table = '';
$this->columns = [];
$this->joins = [];
$this->wheres = [];
$this->whereIn = [];
$this->groupBy = false;
$this->orderBy = false;
$this->offset = 0;
$this->limit = 10;
$this->fields = [];
return $this;
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"table",
"=",
"''",
";",
"$",
"this",
"->",
"columns",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"joins",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"wheres",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"whereIn",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"groupBy",
"=",
"false",
";",
"$",
"this",
"->",
"orderBy",
"=",
"false",
";",
"$",
"this",
"->",
"offset",
"=",
"0",
";",
"$",
"this",
"->",
"limit",
"=",
"10",
";",
"$",
"this",
"->",
"fields",
"=",
"[",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Reset to default values
@return object Database instance | [
"Reset",
"to",
"default",
"values"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L101-L114 |
nicodevs/laito | src/Laito/Database.php | Database.select | public function select($columns)
{
if (is_array($columns)) {
$this->columns = $columns;
} elseif ($columns === '*') {
$this->columns = ['*'];
}
return $this;
} | php | public function select($columns)
{
if (is_array($columns)) {
$this->columns = $columns;
} elseif ($columns === '*') {
$this->columns = ['*'];
}
return $this;
} | [
"public",
"function",
"select",
"(",
"$",
"columns",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"this",
"->",
"columns",
"=",
"$",
"columns",
";",
"}",
"elseif",
"(",
"$",
"columns",
"===",
"'*'",
")",
"{",
"$",
"this",
"->",
"columns",
"=",
"[",
"'*'",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the columns to be selected
@param array $columns Columns to select
@return object Database instance | [
"Sets",
"the",
"columns",
"to",
"be",
"selected"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L122-L130 |
nicodevs/laito | src/Laito/Database.php | Database.join | public function join($table, $first, $operator, $second, $type = 'LEFT')
{
$this->joins[] = [
'table' => $table,
'first' => $first,
'operator' => $operator,
'second' => $second,
'type' => $type
];
return $this;
} | php | public function join($table, $first, $operator, $second, $type = 'LEFT')
{
$this->joins[] = [
'table' => $table,
'first' => $first,
'operator' => $operator,
'second' => $second,
'type' => $type
];
return $this;
} | [
"public",
"function",
"join",
"(",
"$",
"table",
",",
"$",
"first",
",",
"$",
"operator",
",",
"$",
"second",
",",
"$",
"type",
"=",
"'LEFT'",
")",
"{",
"$",
"this",
"->",
"joins",
"[",
"]",
"=",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'first'",
"=>",
"$",
"first",
",",
"'operator'",
"=>",
"$",
"operator",
",",
"'second'",
"=>",
"$",
"second",
",",
"'type'",
"=>",
"$",
"type",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a table to JOIN with
@param string $table Table name
@param string $first Left key for the ON condition
@param string $operator Operator for the ON condition
@param string $second Right key for the ON condition
@param string $type Join type
@return object Database instance | [
"Sets",
"a",
"table",
"to",
"JOIN",
"with"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L169-L179 |
nicodevs/laito | src/Laito/Database.php | Database.where | public function where($column, $value, $operator = '=', $table = null)
{
$table = $table? $table : $this->table;
$this->wheres[] = [
'table' => $table,
'column' => $column,
'value' => $value,
'operator' => $operator
];
return $this;
} | php | public function where($column, $value, $operator = '=', $table = null)
{
$table = $table? $table : $this->table;
$this->wheres[] = [
'table' => $table,
'column' => $column,
'value' => $value,
'operator' => $operator
];
return $this;
} | [
"public",
"function",
"where",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"operator",
"=",
"'='",
",",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"table",
"=",
"$",
"table",
"?",
"$",
"table",
":",
"$",
"this",
"->",
"table",
";",
"$",
"this",
"->",
"wheres",
"[",
"]",
"=",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'column'",
"=>",
"$",
"column",
",",
"'value'",
"=>",
"$",
"value",
",",
"'operator'",
"=>",
"$",
"operator",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a WHERE condition
@param string $column Column name
@param string $value Value to match
@param string $operator Operator to compare with
@param string $table Table
@return object Database instance | [
"Sets",
"a",
"WHERE",
"condition"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L190-L200 |
nicodevs/laito | src/Laito/Database.php | Database.whereIn | public function whereIn($column, $values, $table = null)
{
$table = isset($table)? $table : $this->table;
$this->whereIn[] = [
'table' => $table,
'column' => $column,
'values' => $values
];
return $this;
} | php | public function whereIn($column, $values, $table = null)
{
$table = isset($table)? $table : $this->table;
$this->whereIn[] = [
'table' => $table,
'column' => $column,
'values' => $values
];
return $this;
} | [
"public",
"function",
"whereIn",
"(",
"$",
"column",
",",
"$",
"values",
",",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"table",
"=",
"isset",
"(",
"$",
"table",
")",
"?",
"$",
"table",
":",
"$",
"this",
"->",
"table",
";",
"$",
"this",
"->",
"whereIn",
"[",
"]",
"=",
"[",
"'table'",
"=>",
"$",
"table",
",",
"'column'",
"=>",
"$",
"column",
",",
"'values'",
"=>",
"$",
"values",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a WHERE IN condition
@param string $column Column name
@param string $values Values to match
@param string $table Table
@return object Database instance | [
"Sets",
"a",
"WHERE",
"IN",
"condition"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L210-L219 |
nicodevs/laito | src/Laito/Database.php | Database.get | public function get()
{
// Define columns
$columns = count($this->columns)? $this->getColumnsString() : $this->table . '.*';
// Define root
$root = 'SELECT ' . $columns . ' FROM ' . $this->table;
// Define joins
$joins = count($this->joins)? $this->getJoinString() : '';
// Define where conditions
$where = $this->getWhereString();
// Define where in conditions
$whereIn = $this->getWhereInString();
// Define group by
$groupBy = ($this->groupBy)? 'GROUP BY ' . $this->groupBy : '';
// Define order
$orderBy = ($this->orderBy)? $this->getOrderByString() : '';
// Define limit
$limit = 'LIMIT ' . $this->offset . ',' . $this->limit;
// Build query
$this->query = implode(' ', [$root, $joins, $where, $whereIn, $groupBy, $orderBy, $limit]);
// Debug
if ($this->app->config('queries.log')) {
file_put_contents($this->app->config('queries.log'), date('Y-m-d h:i:s') . ' - ' . $this->query . "\r\n", FILE_APPEND);
}
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
if (!$this->statement->execute()) {
throw new \PDOException('Error reading from database', 500);
}
// Return results
$result = $this->statement->fetchAll(\PDO::FETCH_ASSOC);
// Reset
$this->reset();
// Return result
return $result;
} | php | public function get()
{
// Define columns
$columns = count($this->columns)? $this->getColumnsString() : $this->table . '.*';
// Define root
$root = 'SELECT ' . $columns . ' FROM ' . $this->table;
// Define joins
$joins = count($this->joins)? $this->getJoinString() : '';
// Define where conditions
$where = $this->getWhereString();
// Define where in conditions
$whereIn = $this->getWhereInString();
// Define group by
$groupBy = ($this->groupBy)? 'GROUP BY ' . $this->groupBy : '';
// Define order
$orderBy = ($this->orderBy)? $this->getOrderByString() : '';
// Define limit
$limit = 'LIMIT ' . $this->offset . ',' . $this->limit;
// Build query
$this->query = implode(' ', [$root, $joins, $where, $whereIn, $groupBy, $orderBy, $limit]);
// Debug
if ($this->app->config('queries.log')) {
file_put_contents($this->app->config('queries.log'), date('Y-m-d h:i:s') . ' - ' . $this->query . "\r\n", FILE_APPEND);
}
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
if (!$this->statement->execute()) {
throw new \PDOException('Error reading from database', 500);
}
// Return results
$result = $this->statement->fetchAll(\PDO::FETCH_ASSOC);
// Reset
$this->reset();
// Return result
return $result;
} | [
"public",
"function",
"get",
"(",
")",
"{",
"// Define columns",
"$",
"columns",
"=",
"count",
"(",
"$",
"this",
"->",
"columns",
")",
"?",
"$",
"this",
"->",
"getColumnsString",
"(",
")",
":",
"$",
"this",
"->",
"table",
".",
"'.*'",
";",
"// Define root",
"$",
"root",
"=",
"'SELECT '",
".",
"$",
"columns",
".",
"' FROM '",
".",
"$",
"this",
"->",
"table",
";",
"// Define joins",
"$",
"joins",
"=",
"count",
"(",
"$",
"this",
"->",
"joins",
")",
"?",
"$",
"this",
"->",
"getJoinString",
"(",
")",
":",
"''",
";",
"// Define where conditions",
"$",
"where",
"=",
"$",
"this",
"->",
"getWhereString",
"(",
")",
";",
"// Define where in conditions",
"$",
"whereIn",
"=",
"$",
"this",
"->",
"getWhereInString",
"(",
")",
";",
"// Define group by",
"$",
"groupBy",
"=",
"(",
"$",
"this",
"->",
"groupBy",
")",
"?",
"'GROUP BY '",
".",
"$",
"this",
"->",
"groupBy",
":",
"''",
";",
"// Define order",
"$",
"orderBy",
"=",
"(",
"$",
"this",
"->",
"orderBy",
")",
"?",
"$",
"this",
"->",
"getOrderByString",
"(",
")",
":",
"''",
";",
"// Define limit",
"$",
"limit",
"=",
"'LIMIT '",
".",
"$",
"this",
"->",
"offset",
".",
"','",
".",
"$",
"this",
"->",
"limit",
";",
"// Build query",
"$",
"this",
"->",
"query",
"=",
"implode",
"(",
"' '",
",",
"[",
"$",
"root",
",",
"$",
"joins",
",",
"$",
"where",
",",
"$",
"whereIn",
",",
"$",
"groupBy",
",",
"$",
"orderBy",
",",
"$",
"limit",
"]",
")",
";",
"// Debug",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'queries.log'",
")",
")",
"{",
"file_put_contents",
"(",
"$",
"this",
"->",
"app",
"->",
"config",
"(",
"'queries.log'",
")",
",",
"date",
"(",
"'Y-m-d h:i:s'",
")",
".",
"' - '",
".",
"$",
"this",
"->",
"query",
".",
"\"\\r\\n\"",
",",
"FILE_APPEND",
")",
";",
"}",
"// Prepare statement",
"$",
"this",
"->",
"statement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"this",
"->",
"query",
")",
";",
"// Bind where values",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"wheres",
")",
")",
"{",
"$",
"this",
"->",
"bindWheres",
"(",
")",
";",
"}",
"// Execute statement",
"if",
"(",
"!",
"$",
"this",
"->",
"statement",
"->",
"execute",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"PDOException",
"(",
"'Error reading from database'",
",",
"500",
")",
";",
"}",
"// Return results",
"$",
"result",
"=",
"$",
"this",
"->",
"statement",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"// Reset",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Return result",
"return",
"$",
"result",
";",
"}"
] | Performs a SELECT query
@return bool|array Array of results, or false | [
"Performs",
"a",
"SELECT",
"query"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L290-L345 |
nicodevs/laito | src/Laito/Database.php | Database.count | public function count($column)
{
// Set a really hight limit
$this->limit(pow(100, 3));
// Select only the COUNT column and get
$result = $this->select(['COUNT(' . $this->table . '.' . $column .') as count'])->get();
// Reset
$this->reset();
// Return number of records
return (count($result) === 1)? (int) reset($result)['count'] : count($result);
} | php | public function count($column)
{
// Set a really hight limit
$this->limit(pow(100, 3));
// Select only the COUNT column and get
$result = $this->select(['COUNT(' . $this->table . '.' . $column .') as count'])->get();
// Reset
$this->reset();
// Return number of records
return (count($result) === 1)? (int) reset($result)['count'] : count($result);
} | [
"public",
"function",
"count",
"(",
"$",
"column",
")",
"{",
"// Set a really hight limit",
"$",
"this",
"->",
"limit",
"(",
"pow",
"(",
"100",
",",
"3",
")",
")",
";",
"// Select only the COUNT column and get",
"$",
"result",
"=",
"$",
"this",
"->",
"select",
"(",
"[",
"'COUNT('",
".",
"$",
"this",
"->",
"table",
".",
"'.'",
".",
"$",
"column",
".",
"') as count'",
"]",
")",
"->",
"get",
"(",
")",
";",
"// Reset",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Return number of records",
"return",
"(",
"count",
"(",
"$",
"result",
")",
"===",
"1",
")",
"?",
"(",
"int",
")",
"reset",
"(",
"$",
"result",
")",
"[",
"'count'",
"]",
":",
"count",
"(",
"$",
"result",
")",
";",
"}"
] | Performs a SELECT COUNT query
@param string $column Column to count by
@return int Number of rows matching the SELECT query | [
"Performs",
"a",
"SELECT",
"COUNT",
"query"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L367-L380 |
nicodevs/laito | src/Laito/Database.php | Database.insert | public function insert($fields)
{
// Set fields
$this->fields($fields);
// Define fields
$fields = $this->getInsertFieldsString();
// Build query
$this->query = 'INSERT INTO ' . $this->table . $fields;
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind fields values
$this->bindFields();
// Execute statement
$result = $this->statement->execute();
// Reset values
$this->reset();
// Return result
return $result;
} | php | public function insert($fields)
{
// Set fields
$this->fields($fields);
// Define fields
$fields = $this->getInsertFieldsString();
// Build query
$this->query = 'INSERT INTO ' . $this->table . $fields;
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind fields values
$this->bindFields();
// Execute statement
$result = $this->statement->execute();
// Reset values
$this->reset();
// Return result
return $result;
} | [
"public",
"function",
"insert",
"(",
"$",
"fields",
")",
"{",
"// Set fields",
"$",
"this",
"->",
"fields",
"(",
"$",
"fields",
")",
";",
"// Define fields",
"$",
"fields",
"=",
"$",
"this",
"->",
"getInsertFieldsString",
"(",
")",
";",
"// Build query",
"$",
"this",
"->",
"query",
"=",
"'INSERT INTO '",
".",
"$",
"this",
"->",
"table",
".",
"$",
"fields",
";",
"// Prepare statement",
"$",
"this",
"->",
"statement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"this",
"->",
"query",
")",
";",
"// Bind fields values",
"$",
"this",
"->",
"bindFields",
"(",
")",
";",
"// Execute statement",
"$",
"result",
"=",
"$",
"this",
"->",
"statement",
"->",
"execute",
"(",
")",
";",
"// Reset values",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Return result",
"return",
"$",
"result",
";",
"}"
] | Performs an INSERT query
@param array $fields Array of columns names and values to insert
@return bool Query success or fail | [
"Performs",
"an",
"INSERT",
"query"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L388-L413 |
nicodevs/laito | src/Laito/Database.php | Database.update | public function update($fields)
{
// Set fields
$this->fields($fields);
// Resolve fields
$fields = $this->getUpdateFieldsString();
// Define wheres
$where = $this->getWhereString();
// Build query
$this->query = 'UPDATE ' . $this->table . ' SET ' . $fields . ' '. $where;
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind fields values
$this->bindFields();
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
$result = $this->statement->execute();
// Reset values
$this->reset();
// Return result
return $result;
} | php | public function update($fields)
{
// Set fields
$this->fields($fields);
// Resolve fields
$fields = $this->getUpdateFieldsString();
// Define wheres
$where = $this->getWhereString();
// Build query
$this->query = 'UPDATE ' . $this->table . ' SET ' . $fields . ' '. $where;
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind fields values
$this->bindFields();
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
$result = $this->statement->execute();
// Reset values
$this->reset();
// Return result
return $result;
} | [
"public",
"function",
"update",
"(",
"$",
"fields",
")",
"{",
"// Set fields",
"$",
"this",
"->",
"fields",
"(",
"$",
"fields",
")",
";",
"// Resolve fields",
"$",
"fields",
"=",
"$",
"this",
"->",
"getUpdateFieldsString",
"(",
")",
";",
"// Define wheres",
"$",
"where",
"=",
"$",
"this",
"->",
"getWhereString",
"(",
")",
";",
"// Build query",
"$",
"this",
"->",
"query",
"=",
"'UPDATE '",
".",
"$",
"this",
"->",
"table",
".",
"' SET '",
".",
"$",
"fields",
".",
"' '",
".",
"$",
"where",
";",
"// Prepare statement",
"$",
"this",
"->",
"statement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"this",
"->",
"query",
")",
";",
"// Bind fields values",
"$",
"this",
"->",
"bindFields",
"(",
")",
";",
"// Bind where values",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"wheres",
")",
")",
"{",
"$",
"this",
"->",
"bindWheres",
"(",
")",
";",
"}",
"// Execute statement",
"$",
"result",
"=",
"$",
"this",
"->",
"statement",
"->",
"execute",
"(",
")",
";",
"// Reset values",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Return result",
"return",
"$",
"result",
";",
"}"
] | Performs an UPDATE query
@param array $fields Array of columns names and values to insert
@return bool Query success or fail | [
"Performs",
"an",
"UPDATE",
"query"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L438-L471 |
nicodevs/laito | src/Laito/Database.php | Database.delete | public function delete()
{
// Define wheres
$where = $this->getWhereString();
// Define where in
$whereIn = $this->getWhereInString();
// Build query
$this->query = 'DELETE FROM ' . $this->table . ' '. $where . ' ' . $whereIn;
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
$result = $this->statement->execute();
// Reset values
$this->reset();
// Return result
return $result;
} | php | public function delete()
{
// Define wheres
$where = $this->getWhereString();
// Define where in
$whereIn = $this->getWhereInString();
// Build query
$this->query = 'DELETE FROM ' . $this->table . ' '. $where . ' ' . $whereIn;
// Prepare statement
$this->statement = $this->pdo->prepare($this->query);
// Bind where values
if (count($this->wheres)) {
$this->bindWheres();
}
// Execute statement
$result = $this->statement->execute();
// Reset values
$this->reset();
// Return result
return $result;
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"// Define wheres",
"$",
"where",
"=",
"$",
"this",
"->",
"getWhereString",
"(",
")",
";",
"// Define where in",
"$",
"whereIn",
"=",
"$",
"this",
"->",
"getWhereInString",
"(",
")",
";",
"// Build query",
"$",
"this",
"->",
"query",
"=",
"'DELETE FROM '",
".",
"$",
"this",
"->",
"table",
".",
"' '",
".",
"$",
"where",
".",
"' '",
".",
"$",
"whereIn",
";",
"// Prepare statement",
"$",
"this",
"->",
"statement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"this",
"->",
"query",
")",
";",
"// Bind where values",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"wheres",
")",
")",
"{",
"$",
"this",
"->",
"bindWheres",
"(",
")",
";",
"}",
"// Execute statement",
"$",
"result",
"=",
"$",
"this",
"->",
"statement",
"->",
"execute",
"(",
")",
";",
"// Reset values",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// Return result",
"return",
"$",
"result",
";",
"}"
] | Performs a DELETE query
@return bool Query success or fail | [
"Performs",
"a",
"DELETE",
"query"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L478-L505 |
nicodevs/laito | src/Laito/Database.php | Database.getWhereString | private function getWhereString()
{
// If there are not where conditions, return empty
if (!count($this->wheres)) {
return 'WHERE 1=1 ';
}
// Create where named placeholders
$wheres = array_map(function ($where) {
return $where['table'] . '.' . $where['column'] . ' ' . $where['operator'] . ' :' . $where['table'] . $where['column'];
}, $this->wheres);
// String holder
return 'WHERE 1 AND ' . implode(' AND ', $wheres);
} | php | private function getWhereString()
{
// If there are not where conditions, return empty
if (!count($this->wheres)) {
return 'WHERE 1=1 ';
}
// Create where named placeholders
$wheres = array_map(function ($where) {
return $where['table'] . '.' . $where['column'] . ' ' . $where['operator'] . ' :' . $where['table'] . $where['column'];
}, $this->wheres);
// String holder
return 'WHERE 1 AND ' . implode(' AND ', $wheres);
} | [
"private",
"function",
"getWhereString",
"(",
")",
"{",
"// If there are not where conditions, return empty",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"wheres",
")",
")",
"{",
"return",
"'WHERE 1=1 '",
";",
"}",
"// Create where named placeholders",
"$",
"wheres",
"=",
"array_map",
"(",
"function",
"(",
"$",
"where",
")",
"{",
"return",
"$",
"where",
"[",
"'table'",
"]",
".",
"'.'",
".",
"$",
"where",
"[",
"'column'",
"]",
".",
"' '",
".",
"$",
"where",
"[",
"'operator'",
"]",
".",
"' :'",
".",
"$",
"where",
"[",
"'table'",
"]",
".",
"$",
"where",
"[",
"'column'",
"]",
";",
"}",
",",
"$",
"this",
"->",
"wheres",
")",
";",
"// String holder",
"return",
"'WHERE 1 AND '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"wheres",
")",
";",
"}"
] | Returns the wheres array as a WHERE string
@return string WHERE string | [
"Returns",
"the",
"wheres",
"array",
"as",
"a",
"WHERE",
"string"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L542-L556 |
nicodevs/laito | src/Laito/Database.php | Database.getWhereInString | private function getWhereInString()
{
// String holder
$string = '';
// If there are not where in conditions, return empty
if (!count($this->whereIn)) {
return $string;
}
// Iterate where creating the full conditions
foreach ($this->whereIn as $where) {
$string .= ' AND ' . $where['column'] . ' IN (' . implode(', ', $where['values']) . ')';
}
// Return complete where in string
return $string;
} | php | private function getWhereInString()
{
// String holder
$string = '';
// If there are not where in conditions, return empty
if (!count($this->whereIn)) {
return $string;
}
// Iterate where creating the full conditions
foreach ($this->whereIn as $where) {
$string .= ' AND ' . $where['column'] . ' IN (' . implode(', ', $where['values']) . ')';
}
// Return complete where in string
return $string;
} | [
"private",
"function",
"getWhereInString",
"(",
")",
"{",
"// String holder",
"$",
"string",
"=",
"''",
";",
"// If there are not where in conditions, return empty",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"whereIn",
")",
")",
"{",
"return",
"$",
"string",
";",
"}",
"// Iterate where creating the full conditions",
"foreach",
"(",
"$",
"this",
"->",
"whereIn",
"as",
"$",
"where",
")",
"{",
"$",
"string",
".=",
"' AND '",
".",
"$",
"where",
"[",
"'column'",
"]",
".",
"' IN ('",
".",
"implode",
"(",
"', '",
",",
"$",
"where",
"[",
"'values'",
"]",
")",
".",
"')'",
";",
"}",
"// Return complete where in string",
"return",
"$",
"string",
";",
"}"
] | Returns the where in array as a WHERE IN string
@return string WHERE string | [
"Returns",
"the",
"where",
"in",
"array",
"as",
"a",
"WHERE",
"IN",
"string"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L563-L580 |
nicodevs/laito | src/Laito/Database.php | Database.getColumnsString | private function getColumnsString()
{
if (count($this->columns) === 1 && $this->columns[0] === '*') {
return '*';
}
$columns = array_map(function ($column) {
return (strpos($column, '.') === false)? $this->table . '.' . $column : $column;
}, $this->columns);
return implode(', ', $columns);
} | php | private function getColumnsString()
{
if (count($this->columns) === 1 && $this->columns[0] === '*') {
return '*';
}
$columns = array_map(function ($column) {
return (strpos($column, '.') === false)? $this->table . '.' . $column : $column;
}, $this->columns);
return implode(', ', $columns);
} | [
"private",
"function",
"getColumnsString",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"columns",
")",
"===",
"1",
"&&",
"$",
"this",
"->",
"columns",
"[",
"0",
"]",
"===",
"'*'",
")",
"{",
"return",
"'*'",
";",
"}",
"$",
"columns",
"=",
"array_map",
"(",
"function",
"(",
"$",
"column",
")",
"{",
"return",
"(",
"strpos",
"(",
"$",
"column",
",",
"'.'",
")",
"===",
"false",
")",
"?",
"$",
"this",
"->",
"table",
".",
"'.'",
".",
"$",
"column",
":",
"$",
"column",
";",
"}",
",",
"$",
"this",
"->",
"columns",
")",
";",
"return",
"implode",
"(",
"', '",
",",
"$",
"columns",
")",
";",
"}"
] | Returns the columns array as a field list string
@return string Field list string | [
"Returns",
"the",
"columns",
"array",
"as",
"a",
"field",
"list",
"string"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L587-L596 |
nicodevs/laito | src/Laito/Database.php | Database.getJoinString | private function getJoinString()
{
// If there are not joins, return empty
if (!count($this->orderBy)) {
return '';
}
// Create join strings
$joins = array_map(function ($join) {
return $join['type'] . ' JOIN ' . $join['table'] . ' ON ' . $this->table . '.' . $join['first'] . $join['operator'] . $join['table'] . '.' . $join['second'];
}, $this->joins);
// Return complete join string
return implode(' ', $joins);
} | php | private function getJoinString()
{
// If there are not joins, return empty
if (!count($this->orderBy)) {
return '';
}
// Create join strings
$joins = array_map(function ($join) {
return $join['type'] . ' JOIN ' . $join['table'] . ' ON ' . $this->table . '.' . $join['first'] . $join['operator'] . $join['table'] . '.' . $join['second'];
}, $this->joins);
// Return complete join string
return implode(' ', $joins);
} | [
"private",
"function",
"getJoinString",
"(",
")",
"{",
"// If there are not joins, return empty",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"orderBy",
")",
")",
"{",
"return",
"''",
";",
"}",
"// Create join strings",
"$",
"joins",
"=",
"array_map",
"(",
"function",
"(",
"$",
"join",
")",
"{",
"return",
"$",
"join",
"[",
"'type'",
"]",
".",
"' JOIN '",
".",
"$",
"join",
"[",
"'table'",
"]",
".",
"' ON '",
".",
"$",
"this",
"->",
"table",
".",
"'.'",
".",
"$",
"join",
"[",
"'first'",
"]",
".",
"$",
"join",
"[",
"'operator'",
"]",
".",
"$",
"join",
"[",
"'table'",
"]",
".",
"'.'",
".",
"$",
"join",
"[",
"'second'",
"]",
";",
"}",
",",
"$",
"this",
"->",
"joins",
")",
";",
"// Return complete join string",
"return",
"implode",
"(",
"' '",
",",
"$",
"joins",
")",
";",
"}"
] | Returns the joins array as a JOIN string
@return string JOIN string | [
"Returns",
"the",
"joins",
"array",
"as",
"a",
"JOIN",
"string"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L603-L617 |
nicodevs/laito | src/Laito/Database.php | Database.getInsertFieldsString | private function getInsertFieldsString()
{
// Get field keys
$fieldKeys = array_keys($this->fields);
// Create placeholders
$fieldsPlaceholders = array_map(function ($field) {
return ':' . $field;
}, $fieldKeys);
// Return complete fields string
return '(' . implode(',', $fieldKeys) . ') VALUES ('. implode(',', $fieldsPlaceholders) . ')';
} | php | private function getInsertFieldsString()
{
// Get field keys
$fieldKeys = array_keys($this->fields);
// Create placeholders
$fieldsPlaceholders = array_map(function ($field) {
return ':' . $field;
}, $fieldKeys);
// Return complete fields string
return '(' . implode(',', $fieldKeys) . ') VALUES ('. implode(',', $fieldsPlaceholders) . ')';
} | [
"private",
"function",
"getInsertFieldsString",
"(",
")",
"{",
"// Get field keys",
"$",
"fieldKeys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"fields",
")",
";",
"// Create placeholders",
"$",
"fieldsPlaceholders",
"=",
"array_map",
"(",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"':'",
".",
"$",
"field",
";",
"}",
",",
"$",
"fieldKeys",
")",
";",
"// Return complete fields string",
"return",
"'('",
".",
"implode",
"(",
"','",
",",
"$",
"fieldKeys",
")",
".",
"') VALUES ('",
".",
"implode",
"(",
"','",
",",
"$",
"fieldsPlaceholders",
")",
".",
"')'",
";",
"}"
] | Returns the fields array as a VALUES string for inserts
@return string VALUES string for inserts | [
"Returns",
"the",
"fields",
"array",
"as",
"a",
"VALUES",
"string",
"for",
"inserts"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L640-L652 |
nicodevs/laito | src/Laito/Database.php | Database.getUpdateFieldsString | private function getUpdateFieldsString()
{
// Create placeholders
$fieldsPlaceholders = array_map(function ($field) {
return $field . '=:' . $field;
}, array_keys($this->fields));
// Return complete fields string
return implode(',', $fieldsPlaceholders);
} | php | private function getUpdateFieldsString()
{
// Create placeholders
$fieldsPlaceholders = array_map(function ($field) {
return $field . '=:' . $field;
}, array_keys($this->fields));
// Return complete fields string
return implode(',', $fieldsPlaceholders);
} | [
"private",
"function",
"getUpdateFieldsString",
"(",
")",
"{",
"// Create placeholders",
"$",
"fieldsPlaceholders",
"=",
"array_map",
"(",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"$",
"field",
".",
"'=:'",
".",
"$",
"field",
";",
"}",
",",
"array_keys",
"(",
"$",
"this",
"->",
"fields",
")",
")",
";",
"// Return complete fields string",
"return",
"implode",
"(",
"','",
",",
"$",
"fieldsPlaceholders",
")",
";",
"}"
] | Returns the fields array as a 'foo=:foo, bar=:bar' string for updates
@return string String for updates | [
"Returns",
"the",
"fields",
"array",
"as",
"a",
"foo",
"=",
":",
"foo",
"bar",
"=",
":",
"bar",
"string",
"for",
"updates"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L659-L668 |
nicodevs/laito | src/Laito/Database.php | Database.bindWheres | private function bindWheres()
{
foreach ($this->wheres as $where) {
$this->statement->bindValue(':' . $where['table'] . $where['column'], $where['value']);
}
} | php | private function bindWheres()
{
foreach ($this->wheres as $where) {
$this->statement->bindValue(':' . $where['table'] . $where['column'], $where['value']);
}
} | [
"private",
"function",
"bindWheres",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"wheres",
"as",
"$",
"where",
")",
"{",
"$",
"this",
"->",
"statement",
"->",
"bindValue",
"(",
"':'",
".",
"$",
"where",
"[",
"'table'",
"]",
".",
"$",
"where",
"[",
"'column'",
"]",
",",
"$",
"where",
"[",
"'value'",
"]",
")",
";",
"}",
"}"
] | Binds the values of the WHERE conditions | [
"Binds",
"the",
"values",
"of",
"the",
"WHERE",
"conditions"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L674-L679 |
nicodevs/laito | src/Laito/Database.php | Database.bindFields | private function bindFields()
{
foreach ($this->fields as $key => $value) {
$this->statement->bindValue(':' . $key, $value);
}
} | php | private function bindFields()
{
foreach ($this->fields as $key => $value) {
$this->statement->bindValue(':' . $key, $value);
}
} | [
"private",
"function",
"bindFields",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"statement",
"->",
"bindValue",
"(",
"':'",
".",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Binds the values of the fields to insert or update | [
"Binds",
"the",
"values",
"of",
"the",
"fields",
"to",
"insert",
"or",
"update"
] | train | https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Database.php#L685-L690 |
Hnto/nuki | src/Handlers/Http/Files.php | Files.file | public function file($key) {
if (!isset($this->files[$key])) {
return null;
}
return $this->createFile($this->files[$key]);
} | php | public function file($key) {
if (!isset($this->files[$key])) {
return null;
}
return $this->createFile($this->files[$key]);
} | [
"public",
"function",
"file",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"files",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"createFile",
"(",
"$",
"this",
"->",
"files",
"[",
"$",
"key",
"]",
")",
";",
"}"
] | Get file by key
@param int $key
@return \Nuki\Models\Data\File | [
"Get",
"file",
"by",
"key"
] | train | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Http/Files.php#L31-L37 |
Hnto/nuki | src/Handlers/Http/Files.php | Files.createFile | private function createFile(array $fileInfo = []) {
$file = new \Nuki\Models\Data\File($fileInfo['tmp_name'], $fileInfo['size']);
$file->setExtension(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
$file->setName(pathinfo($fileInfo['name'], PATHINFO_BASENAME));
return $file;
} | php | private function createFile(array $fileInfo = []) {
$file = new \Nuki\Models\Data\File($fileInfo['tmp_name'], $fileInfo['size']);
$file->setExtension(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
$file->setName(pathinfo($fileInfo['name'], PATHINFO_BASENAME));
return $file;
} | [
"private",
"function",
"createFile",
"(",
"array",
"$",
"fileInfo",
"=",
"[",
"]",
")",
"{",
"$",
"file",
"=",
"new",
"\\",
"Nuki",
"\\",
"Models",
"\\",
"Data",
"\\",
"File",
"(",
"$",
"fileInfo",
"[",
"'tmp_name'",
"]",
",",
"$",
"fileInfo",
"[",
"'size'",
"]",
")",
";",
"$",
"file",
"->",
"setExtension",
"(",
"pathinfo",
"(",
"$",
"fileInfo",
"[",
"'name'",
"]",
",",
"PATHINFO_EXTENSION",
")",
")",
";",
"$",
"file",
"->",
"setName",
"(",
"pathinfo",
"(",
"$",
"fileInfo",
"[",
"'name'",
"]",
",",
"PATHINFO_BASENAME",
")",
")",
";",
"return",
"$",
"file",
";",
"}"
] | Create file object
@param array $fileInfo
@return \Nuki\Models\Data\File | [
"Create",
"file",
"object"
] | train | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Http/Files.php#L61-L68 |
Hnto/nuki | src/Handlers/Http/Files.php | Files.normalize | private function normalize() : array {
$files = [];
foreach($_FILES as $key => $file) {
if (!is_array($file['name'])) {
$files[$key][] = $file;
continue;
}
foreach($file['name'] as $subKey => $name) {
$files[$key][$subKey] = [
'name' => $name,
'type' => $file['type'][$subKey],
'tmp_name' => $file['tmp_name'][$subKey],
'error' => $file['error'][$subKey],
'size' => $file['size'][$subKey]
];
}
}
return $files;
} | php | private function normalize() : array {
$files = [];
foreach($_FILES as $key => $file) {
if (!is_array($file['name'])) {
$files[$key][] = $file;
continue;
}
foreach($file['name'] as $subKey => $name) {
$files[$key][$subKey] = [
'name' => $name,
'type' => $file['type'][$subKey],
'tmp_name' => $file['tmp_name'][$subKey],
'error' => $file['error'][$subKey],
'size' => $file['size'][$subKey]
];
}
}
return $files;
} | [
"private",
"function",
"normalize",
"(",
")",
":",
"array",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"_FILES",
"as",
"$",
"key",
"=>",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"file",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"files",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"file",
";",
"continue",
";",
"}",
"foreach",
"(",
"$",
"file",
"[",
"'name'",
"]",
"as",
"$",
"subKey",
"=>",
"$",
"name",
")",
"{",
"$",
"files",
"[",
"$",
"key",
"]",
"[",
"$",
"subKey",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'type'",
"=>",
"$",
"file",
"[",
"'type'",
"]",
"[",
"$",
"subKey",
"]",
",",
"'tmp_name'",
"=>",
"$",
"file",
"[",
"'tmp_name'",
"]",
"[",
"$",
"subKey",
"]",
",",
"'error'",
"=>",
"$",
"file",
"[",
"'error'",
"]",
"[",
"$",
"subKey",
"]",
",",
"'size'",
"=>",
"$",
"file",
"[",
"'size'",
"]",
"[",
"$",
"subKey",
"]",
"]",
";",
"}",
"}",
"return",
"$",
"files",
";",
"}"
] | Normalize $_FILES array
@return array | [
"Normalize",
"$_FILES",
"array"
] | train | https://github.com/Hnto/nuki/blob/c3fb16244e8d611c335a88e3b9c9ee7d81fafc0c/src/Handlers/Http/Files.php#L75-L97 |
anime-db/catalog-bundle | src/Entity/Type.php | Type.addItem | public function addItem(Item $item)
{
if (!$this->items->contains($item)) {
$this->items->add($item);
$item->setType($this);
}
return $this;
} | php | public function addItem(Item $item)
{
if (!$this->items->contains($item)) {
$this->items->add($item);
$item->setType($this);
}
return $this;
} | [
"public",
"function",
"addItem",
"(",
"Item",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"items",
"->",
"contains",
"(",
"$",
"item",
")",
")",
"{",
"$",
"this",
"->",
"items",
"->",
"add",
"(",
"$",
"item",
")",
";",
"$",
"item",
"->",
"setType",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param Item $item
@return Type | [
"@param",
"Item",
"$item"
] | train | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Entity/Type.php#L111-L119 |
anime-db/catalog-bundle | src/Entity/Type.php | Type.removeItem | public function removeItem(Item $item)
{
if ($this->items->contains($item)) {
$this->items->removeElement($item);
$item->setType(null);
}
return $this;
} | php | public function removeItem(Item $item)
{
if ($this->items->contains($item)) {
$this->items->removeElement($item);
$item->setType(null);
}
return $this;
} | [
"public",
"function",
"removeItem",
"(",
"Item",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"items",
"->",
"contains",
"(",
"$",
"item",
")",
")",
"{",
"$",
"this",
"->",
"items",
"->",
"removeElement",
"(",
"$",
"item",
")",
";",
"$",
"item",
"->",
"setType",
"(",
"null",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | @param Item $item
@return Type | [
"@param",
"Item",
"$item"
] | train | https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Entity/Type.php#L126-L134 |
bseddon/XPath20 | Proxy/DateProxy.php | DateProxy.Gt | protected function Gt( $val )
{
if ( $val->GetValueCode() != DateProxyFactory::Code )
throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::BinaryOperatorNotDefined,
array(
"op:gt",
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $this->_value ), XmlTypeCardinality::One ),
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $val->getValue() ), XmlTypeCardinality::One )
)
);
return $this->_value->CompareTo( $val->getValue() ) > 0;
} | php | protected function Gt( $val )
{
if ( $val->GetValueCode() != DateProxyFactory::Code )
throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::BinaryOperatorNotDefined,
array(
"op:gt",
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $this->_value ), XmlTypeCardinality::One ),
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $val->getValue() ), XmlTypeCardinality::One )
)
);
return $this->_value->CompareTo( $val->getValue() ) > 0;
} | [
"protected",
"function",
"Gt",
"(",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"->",
"GetValueCode",
"(",
")",
"!=",
"DateProxyFactory",
"::",
"Code",
")",
"throw",
"XPath2Exception",
"::",
"withErrorCodeAndParams",
"(",
"\"XPTY0004\"",
",",
"Resources",
"::",
"BinaryOperatorNotDefined",
",",
"array",
"(",
"\"op:gt\"",
",",
"SequenceType",
"::",
"WithTypeCodeAndCardinality",
"(",
"SequenceType",
"::",
"GetXmlTypeCodeFromObject",
"(",
"$",
"this",
"->",
"_value",
")",
",",
"XmlTypeCardinality",
"::",
"One",
")",
",",
"SequenceType",
"::",
"WithTypeCodeAndCardinality",
"(",
"SequenceType",
"::",
"GetXmlTypeCodeFromObject",
"(",
"$",
"val",
"->",
"getValue",
"(",
")",
")",
",",
"XmlTypeCardinality",
"::",
"One",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"_value",
"->",
"CompareTo",
"(",
"$",
"val",
"->",
"getValue",
"(",
")",
")",
">",
"0",
";",
"}"
] | Gt
@param ValueProxy $val
@return bool | [
"Gt"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Proxy/DateProxy.php#L115-L126 |
bseddon/XPath20 | Proxy/DateProxy.php | DateProxy.Neg | protected function Neg()
{
throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::UnaryOperatorNotDefined,
array(
"fn:unary-minus",
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $this->_value ), XmlTypeCardinality::One )
)
);
} | php | protected function Neg()
{
throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::UnaryOperatorNotDefined,
array(
"fn:unary-minus",
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $this->_value ), XmlTypeCardinality::One )
)
);
} | [
"protected",
"function",
"Neg",
"(",
")",
"{",
"throw",
"XPath2Exception",
"::",
"withErrorCodeAndParams",
"(",
"\"XPTY0004\"",
",",
"Resources",
"::",
"UnaryOperatorNotDefined",
",",
"array",
"(",
"\"fn:unary-minus\"",
",",
"SequenceType",
"::",
"WithTypeCodeAndCardinality",
"(",
"SequenceType",
"::",
"GetXmlTypeCodeFromObject",
"(",
"$",
"this",
"->",
"_value",
")",
",",
"XmlTypeCardinality",
"::",
"One",
")",
")",
")",
";",
"}"
] | Neg
@return ValueProxy | [
"Neg"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Proxy/DateProxy.php#L142-L150 |
bseddon/XPath20 | Proxy/DateProxy.php | DateProxy.Sub | protected function Sub( $value )
{
switch ( $value->GetValueCode() )
{
case DateProxyFactory::Code:
return new DayTimeDurationProxy( DateValue::Sub( $this->_value, /* DateValue */ $value->getValue() ) );
case YearMonthDurationProxyFactory::Code:
/**
* @var YearMonthDurationProxy $value
*/
// Clone the DateValue contained in the proxy or the original is changed
$clone = new DateValue( $this->_value->S, clone $this->_value->Value );
$value->getValue()->Value->invert = ! $value->getValue()->Value->invert;
return new DateProxy( DateValue::AddYearMonthDuration( $clone, $value->getValue() ) );
case DayTimeDurationProxyFactory::Code:
/**
* @var DayTimeDurationProxy $value
*/
// Clone the DateValue contained in the proxy or the original is changed
$clone = new DateValue( $this->_value->S, clone $this->_value->Value );
$value->getValue()->Value->invert = ! $value->getValue()->Value->invert;
return new DateProxy( DateValue::AddDayTimeDuration( $clone, $value->getValue() ) );
default:
throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::BinaryOperatorNotDefined,
array(
"op:sub",
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $this->_value ), XmlTypeCardinality::One ),
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $value->getValue() ), XmlTypeCardinality::One )
)
);
}
} | php | protected function Sub( $value )
{
switch ( $value->GetValueCode() )
{
case DateProxyFactory::Code:
return new DayTimeDurationProxy( DateValue::Sub( $this->_value, /* DateValue */ $value->getValue() ) );
case YearMonthDurationProxyFactory::Code:
/**
* @var YearMonthDurationProxy $value
*/
// Clone the DateValue contained in the proxy or the original is changed
$clone = new DateValue( $this->_value->S, clone $this->_value->Value );
$value->getValue()->Value->invert = ! $value->getValue()->Value->invert;
return new DateProxy( DateValue::AddYearMonthDuration( $clone, $value->getValue() ) );
case DayTimeDurationProxyFactory::Code:
/**
* @var DayTimeDurationProxy $value
*/
// Clone the DateValue contained in the proxy or the original is changed
$clone = new DateValue( $this->_value->S, clone $this->_value->Value );
$value->getValue()->Value->invert = ! $value->getValue()->Value->invert;
return new DateProxy( DateValue::AddDayTimeDuration( $clone, $value->getValue() ) );
default:
throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::BinaryOperatorNotDefined,
array(
"op:sub",
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $this->_value ), XmlTypeCardinality::One ),
SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $value->getValue() ), XmlTypeCardinality::One )
)
);
}
} | [
"protected",
"function",
"Sub",
"(",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"value",
"->",
"GetValueCode",
"(",
")",
")",
"{",
"case",
"DateProxyFactory",
"::",
"Code",
":",
"return",
"new",
"DayTimeDurationProxy",
"(",
"DateValue",
"::",
"Sub",
"(",
"$",
"this",
"->",
"_value",
",",
"/* DateValue */",
"$",
"value",
"->",
"getValue",
"(",
")",
")",
")",
";",
"case",
"YearMonthDurationProxyFactory",
"::",
"Code",
":",
"/**\r\n\t \t * @var YearMonthDurationProxy $value\r\n\t \t */",
"// Clone the DateValue contained in the proxy or the original is changed\r",
"$",
"clone",
"=",
"new",
"DateValue",
"(",
"$",
"this",
"->",
"_value",
"->",
"S",
",",
"clone",
"$",
"this",
"->",
"_value",
"->",
"Value",
")",
";",
"$",
"value",
"->",
"getValue",
"(",
")",
"->",
"Value",
"->",
"invert",
"=",
"!",
"$",
"value",
"->",
"getValue",
"(",
")",
"->",
"Value",
"->",
"invert",
";",
"return",
"new",
"DateProxy",
"(",
"DateValue",
"::",
"AddYearMonthDuration",
"(",
"$",
"clone",
",",
"$",
"value",
"->",
"getValue",
"(",
")",
")",
")",
";",
"case",
"DayTimeDurationProxyFactory",
"::",
"Code",
":",
"/**\r\n\t \t * @var DayTimeDurationProxy $value\r\n\t \t */",
"// Clone the DateValue contained in the proxy or the original is changed\r",
"$",
"clone",
"=",
"new",
"DateValue",
"(",
"$",
"this",
"->",
"_value",
"->",
"S",
",",
"clone",
"$",
"this",
"->",
"_value",
"->",
"Value",
")",
";",
"$",
"value",
"->",
"getValue",
"(",
")",
"->",
"Value",
"->",
"invert",
"=",
"!",
"$",
"value",
"->",
"getValue",
"(",
")",
"->",
"Value",
"->",
"invert",
";",
"return",
"new",
"DateProxy",
"(",
"DateValue",
"::",
"AddDayTimeDuration",
"(",
"$",
"clone",
",",
"$",
"value",
"->",
"getValue",
"(",
")",
")",
")",
";",
"default",
":",
"throw",
"XPath2Exception",
"::",
"withErrorCodeAndParams",
"(",
"\"XPTY0004\"",
",",
"Resources",
"::",
"BinaryOperatorNotDefined",
",",
"array",
"(",
"\"op:sub\"",
",",
"SequenceType",
"::",
"WithTypeCodeAndCardinality",
"(",
"SequenceType",
"::",
"GetXmlTypeCodeFromObject",
"(",
"$",
"this",
"->",
"_value",
")",
",",
"XmlTypeCardinality",
"::",
"One",
")",
",",
"SequenceType",
"::",
"WithTypeCodeAndCardinality",
"(",
"SequenceType",
"::",
"GetXmlTypeCodeFromObject",
"(",
"$",
"value",
"->",
"getValue",
"(",
")",
")",
",",
"XmlTypeCardinality",
"::",
"One",
")",
")",
")",
";",
"}",
"}"
] | Sub
@param ValueProxy $value
@return ValueProxy | [
"Sub"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Proxy/DateProxy.php#L193-L227 |
nguyenanhung/image | src/Utils.php | Utils.getImageFromUrl | public static function getImageFromUrl($url = '')
{
try {
$curl = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE);
$curl->setOpt(CURLOPT_ENCODING, "");
$curl->setOpt(CURLOPT_MAXREDIRS, 10);
$curl->setOpt(CURLOPT_TIMEOUT, 30);
$curl->setOpt(CURLOPT_CONNECTTIMEOUT, 30);
$curl->setOpt(CURLOPT_FOLLOWLOCATION, TRUE);
$curl->get($url);
if ($curl->error === TRUE) {
self::debug('Error Exception: ' . $curl->httpErrorMessage);
return array(
'status' => 'error',
'code' => $curl->httpStatusCode,
'error' => $curl->errorMessage,
'response_header' => $curl->responseHeaders,
'content' => NULL
);
} else {
return array(
'status' => 'success',
'code' => $curl->httpStatusCode,
'error' => $curl->errorMessage,
'response_header' => $curl->responseHeaders,
'content' => $curl->response
);
}
}
catch (\Exception $e) {
if (function_exists('log_message')) {
$message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
log_message('error', $message);
}
return file_get_contents($url);
}
} | php | public static function getImageFromUrl($url = '')
{
try {
$curl = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE);
$curl->setOpt(CURLOPT_ENCODING, "");
$curl->setOpt(CURLOPT_MAXREDIRS, 10);
$curl->setOpt(CURLOPT_TIMEOUT, 30);
$curl->setOpt(CURLOPT_CONNECTTIMEOUT, 30);
$curl->setOpt(CURLOPT_FOLLOWLOCATION, TRUE);
$curl->get($url);
if ($curl->error === TRUE) {
self::debug('Error Exception: ' . $curl->httpErrorMessage);
return array(
'status' => 'error',
'code' => $curl->httpStatusCode,
'error' => $curl->errorMessage,
'response_header' => $curl->responseHeaders,
'content' => NULL
);
} else {
return array(
'status' => 'success',
'code' => $curl->httpStatusCode,
'error' => $curl->errorMessage,
'response_header' => $curl->responseHeaders,
'content' => $curl->response
);
}
}
catch (\Exception $e) {
if (function_exists('log_message')) {
$message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
log_message('error', $message);
}
return file_get_contents($url);
}
} | [
"public",
"static",
"function",
"getImageFromUrl",
"(",
"$",
"url",
"=",
"''",
")",
"{",
"try",
"{",
"$",
"curl",
"=",
"new",
"Curl",
"(",
")",
";",
"$",
"curl",
"->",
"setOpt",
"(",
"CURLOPT_RETURNTRANSFER",
",",
"TRUE",
")",
";",
"$",
"curl",
"->",
"setOpt",
"(",
"CURLOPT_ENCODING",
",",
"\"\"",
")",
";",
"$",
"curl",
"->",
"setOpt",
"(",
"CURLOPT_MAXREDIRS",
",",
"10",
")",
";",
"$",
"curl",
"->",
"setOpt",
"(",
"CURLOPT_TIMEOUT",
",",
"30",
")",
";",
"$",
"curl",
"->",
"setOpt",
"(",
"CURLOPT_CONNECTTIMEOUT",
",",
"30",
")",
";",
"$",
"curl",
"->",
"setOpt",
"(",
"CURLOPT_FOLLOWLOCATION",
",",
"TRUE",
")",
";",
"$",
"curl",
"->",
"get",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"curl",
"->",
"error",
"===",
"TRUE",
")",
"{",
"self",
"::",
"debug",
"(",
"'Error Exception: '",
".",
"$",
"curl",
"->",
"httpErrorMessage",
")",
";",
"return",
"array",
"(",
"'status'",
"=>",
"'error'",
",",
"'code'",
"=>",
"$",
"curl",
"->",
"httpStatusCode",
",",
"'error'",
"=>",
"$",
"curl",
"->",
"errorMessage",
",",
"'response_header'",
"=>",
"$",
"curl",
"->",
"responseHeaders",
",",
"'content'",
"=>",
"NULL",
")",
";",
"}",
"else",
"{",
"return",
"array",
"(",
"'status'",
"=>",
"'success'",
",",
"'code'",
"=>",
"$",
"curl",
"->",
"httpStatusCode",
",",
"'error'",
"=>",
"$",
"curl",
"->",
"errorMessage",
",",
"'response_header'",
"=>",
"$",
"curl",
"->",
"responseHeaders",
",",
"'content'",
"=>",
"$",
"curl",
"->",
"response",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'log_message'",
")",
")",
"{",
"$",
"message",
"=",
"'Error Code: '",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"' - File: '",
".",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"' - Line: '",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
".",
"' - Message: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"log_message",
"(",
"'error'",
",",
"$",
"message",
")",
";",
"}",
"return",
"file_get_contents",
"(",
"$",
"url",
")",
";",
"}",
"}"
] | Function getImageFromUrl
@author: 713uk13m <[email protected]>
@time : 11/2/18 16:48
@param string $url
@return array|bool|null|string
@throws \Exception | [
"Function",
"getImageFromUrl"
] | train | https://github.com/nguyenanhung/image/blob/5d30dfa203c0411209b8985ab4a86a6be9a7b2d1/src/Utils.php#L50-L89 |
nguyenanhung/image | src/Utils.php | Utils.debug | public static function debug($msg = 'test')
{
try {
if (function_exists('log_message')) {
log_message('debug', $msg);
} else {
if (self::USE_DEBUG === TRUE) {
$logger = new Logger('imageCache');
$logger->pushHandler(new StreamHandler(__DIR__ . '/../storage/logs/Log-' . date('Y-m-d') . '.log', Logger::DEBUG));
$logger->debug($msg);
}
}
}
catch (\Exception $e) {
if (function_exists('log_message')) {
$message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
log_message('error', $message);
}
return;
}
} | php | public static function debug($msg = 'test')
{
try {
if (function_exists('log_message')) {
log_message('debug', $msg);
} else {
if (self::USE_DEBUG === TRUE) {
$logger = new Logger('imageCache');
$logger->pushHandler(new StreamHandler(__DIR__ . '/../storage/logs/Log-' . date('Y-m-d') . '.log', Logger::DEBUG));
$logger->debug($msg);
}
}
}
catch (\Exception $e) {
if (function_exists('log_message')) {
$message = 'Error Code: ' . $e->getCode() . ' - File: ' . $e->getFile() . ' - Line: ' . $e->getLine() . ' - Message: ' . $e->getMessage();
log_message('error', $message);
}
return;
}
} | [
"public",
"static",
"function",
"debug",
"(",
"$",
"msg",
"=",
"'test'",
")",
"{",
"try",
"{",
"if",
"(",
"function_exists",
"(",
"'log_message'",
")",
")",
"{",
"log_message",
"(",
"'debug'",
",",
"$",
"msg",
")",
";",
"}",
"else",
"{",
"if",
"(",
"self",
"::",
"USE_DEBUG",
"===",
"TRUE",
")",
"{",
"$",
"logger",
"=",
"new",
"Logger",
"(",
"'imageCache'",
")",
";",
"$",
"logger",
"->",
"pushHandler",
"(",
"new",
"StreamHandler",
"(",
"__DIR__",
".",
"'/../storage/logs/Log-'",
".",
"date",
"(",
"'Y-m-d'",
")",
".",
"'.log'",
",",
"Logger",
"::",
"DEBUG",
")",
")",
";",
"$",
"logger",
"->",
"debug",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'log_message'",
")",
")",
"{",
"$",
"message",
"=",
"'Error Code: '",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"' - File: '",
".",
"$",
"e",
"->",
"getFile",
"(",
")",
".",
"' - Line: '",
".",
"$",
"e",
"->",
"getLine",
"(",
")",
".",
"' - Message: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"log_message",
"(",
"'error'",
",",
"$",
"message",
")",
";",
"}",
"return",
";",
"}",
"}"
] | Function debug
@author: 713uk13m <[email protected]>
@time : 11/3/18 17:43
@param string $msg | [
"Function",
"debug"
] | train | https://github.com/nguyenanhung/image/blob/5d30dfa203c0411209b8985ab4a86a6be9a7b2d1/src/Utils.php#L99-L120 |
stubbles/stubbles-streams | src/main/php/file/FileOutputStream.php | FileOutputStream.write | public function write(string $bytes): int
{
if ($this->isFileCreationDelayed()) {
$this->setHandle($this->openFile($this->file, $this->mode));
}
return parent::write($bytes);
} | php | public function write(string $bytes): int
{
if ($this->isFileCreationDelayed()) {
$this->setHandle($this->openFile($this->file, $this->mode));
}
return parent::write($bytes);
} | [
"public",
"function",
"write",
"(",
"string",
"$",
"bytes",
")",
":",
"int",
"{",
"if",
"(",
"$",
"this",
"->",
"isFileCreationDelayed",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setHandle",
"(",
"$",
"this",
"->",
"openFile",
"(",
"$",
"this",
"->",
"file",
",",
"$",
"this",
"->",
"mode",
")",
")",
";",
"}",
"return",
"parent",
"::",
"write",
"(",
"$",
"bytes",
")",
";",
"}"
] | writes given bytes
@param string $bytes
@return int amount of written bytes | [
"writes",
"given",
"bytes"
] | train | https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/file/FileOutputStream.php#L81-L88 |
stubbles/stubbles-streams | src/main/php/file/FileOutputStream.php | FileOutputStream.openFile | protected function openFile(string $file, string $mode)
{
$fp = @fopen($file, $mode);
if (false === $fp) {
throw new StreamException(
'Can not open file ' . $file . ' with mode ' . $mode . ': '
.
str_replace('fopen(' . $file . '): ', '', lastErrorMessage())
);
}
return $fp;
} | php | protected function openFile(string $file, string $mode)
{
$fp = @fopen($file, $mode);
if (false === $fp) {
throw new StreamException(
'Can not open file ' . $file . ' with mode ' . $mode . ': '
.
str_replace('fopen(' . $file . '): ', '', lastErrorMessage())
);
}
return $fp;
} | [
"protected",
"function",
"openFile",
"(",
"string",
"$",
"file",
",",
"string",
"$",
"mode",
")",
"{",
"$",
"fp",
"=",
"@",
"fopen",
"(",
"$",
"file",
",",
"$",
"mode",
")",
";",
"if",
"(",
"false",
"===",
"$",
"fp",
")",
"{",
"throw",
"new",
"StreamException",
"(",
"'Can not open file '",
".",
"$",
"file",
".",
"' with mode '",
".",
"$",
"mode",
".",
"': '",
".",
"str_replace",
"(",
"'fopen('",
".",
"$",
"file",
".",
"'): '",
",",
"''",
",",
"lastErrorMessage",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"fp",
";",
"}"
] | helper method to open a file handle
@param string $file
@param string $mode
@return resource
@throws \stubbles\streams\StreamException | [
"helper",
"method",
"to",
"open",
"a",
"file",
"handle"
] | train | https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/file/FileOutputStream.php#L108-L120 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.fetch | public function fetch(array $conditions = null)
{
$cursor = new DrupalMessageCursor($this);
if (!empty($conditions)) {
$cursor->setConditions($conditions);
}
return $cursor;
} | php | public function fetch(array $conditions = null)
{
$cursor = new DrupalMessageCursor($this);
if (!empty($conditions)) {
$cursor->setConditions($conditions);
}
return $cursor;
} | [
"public",
"function",
"fetch",
"(",
"array",
"$",
"conditions",
"=",
"null",
")",
"{",
"$",
"cursor",
"=",
"new",
"DrupalMessageCursor",
"(",
"$",
"this",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"cursor",
"->",
"setConditions",
"(",
"$",
"conditions",
")",
";",
"}",
"return",
"$",
"cursor",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L76-L85 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.fetchChannels | public function fetchChannels(array $conditions = null)
{
$cursor = new DrupalChannelCursor($this);
if (!empty($conditions)) {
$cursor->setConditions($conditions);
}
return $cursor;
} | php | public function fetchChannels(array $conditions = null)
{
$cursor = new DrupalChannelCursor($this);
if (!empty($conditions)) {
$cursor->setConditions($conditions);
}
return $cursor;
} | [
"public",
"function",
"fetchChannels",
"(",
"array",
"$",
"conditions",
"=",
"null",
")",
"{",
"$",
"cursor",
"=",
"new",
"DrupalChannelCursor",
"(",
"$",
"this",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"cursor",
"->",
"setConditions",
"(",
"$",
"conditions",
")",
";",
"}",
"return",
"$",
"cursor",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L90-L99 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.createChannel | public function createChannel($id, $title = null, $ignoreErrors = false)
{
$chan = null;
$created = new \DateTime();
$dbId = null;
$cx = $this->db;
$tx = null;
try {
$tx = $cx->startTransaction();
// Do not ever use cache here, we cannot afford to try to create
// a channel that have been deleted by another thread
$exists = $cx
->query("SELECT 1 FROM {apb_chan} c WHERE c.name = :name", array(
':name' => $id,
))
->fetchField();
if ($exists) {
if ($ignoreErrors) {
$chan = $this->getChannel($id);
} else {
throw new ChannelAlreadyExistsException();
}
} else {
$dateStr = $created->format(Misc::SQL_DATETIME);
$cx
->insert('apb_chan')
->fields([
'name' => $id,
'title' => $title,
'created' => $dateStr,
'updated' => $dateStr,
])
->execute()
;
// Specify the name of the sequence object for PDO_PGSQL.
// @see http://php.net/manual/en/pdo.lastinsertid.php.
$seq = ($cx->driver() === 'pgsql') ? 'apb_chan_id_seq' : null;
$dbId = (int)$cx->lastInsertId($seq);
$chan = new DefaultChannel($id, $this, $created, null, $title, $dbId);
}
unset($tx); // Explicit commit
} catch (\Exception $e) {
if ($tx) {
try {
$tx->rollback();
} catch (\Exception $e2) {}
}
throw $e;
}
return $chan;
} | php | public function createChannel($id, $title = null, $ignoreErrors = false)
{
$chan = null;
$created = new \DateTime();
$dbId = null;
$cx = $this->db;
$tx = null;
try {
$tx = $cx->startTransaction();
// Do not ever use cache here, we cannot afford to try to create
// a channel that have been deleted by another thread
$exists = $cx
->query("SELECT 1 FROM {apb_chan} c WHERE c.name = :name", array(
':name' => $id,
))
->fetchField();
if ($exists) {
if ($ignoreErrors) {
$chan = $this->getChannel($id);
} else {
throw new ChannelAlreadyExistsException();
}
} else {
$dateStr = $created->format(Misc::SQL_DATETIME);
$cx
->insert('apb_chan')
->fields([
'name' => $id,
'title' => $title,
'created' => $dateStr,
'updated' => $dateStr,
])
->execute()
;
// Specify the name of the sequence object for PDO_PGSQL.
// @see http://php.net/manual/en/pdo.lastinsertid.php.
$seq = ($cx->driver() === 'pgsql') ? 'apb_chan_id_seq' : null;
$dbId = (int)$cx->lastInsertId($seq);
$chan = new DefaultChannel($id, $this, $created, null, $title, $dbId);
}
unset($tx); // Explicit commit
} catch (\Exception $e) {
if ($tx) {
try {
$tx->rollback();
} catch (\Exception $e2) {}
}
throw $e;
}
return $chan;
} | [
"public",
"function",
"createChannel",
"(",
"$",
"id",
",",
"$",
"title",
"=",
"null",
",",
"$",
"ignoreErrors",
"=",
"false",
")",
"{",
"$",
"chan",
"=",
"null",
";",
"$",
"created",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"dbId",
"=",
"null",
";",
"$",
"cx",
"=",
"$",
"this",
"->",
"db",
";",
"$",
"tx",
"=",
"null",
";",
"try",
"{",
"$",
"tx",
"=",
"$",
"cx",
"->",
"startTransaction",
"(",
")",
";",
"// Do not ever use cache here, we cannot afford to try to create",
"// a channel that have been deleted by another thread",
"$",
"exists",
"=",
"$",
"cx",
"->",
"query",
"(",
"\"SELECT 1 FROM {apb_chan} c WHERE c.name = :name\"",
",",
"array",
"(",
"':name'",
"=>",
"$",
"id",
",",
")",
")",
"->",
"fetchField",
"(",
")",
";",
"if",
"(",
"$",
"exists",
")",
"{",
"if",
"(",
"$",
"ignoreErrors",
")",
"{",
"$",
"chan",
"=",
"$",
"this",
"->",
"getChannel",
"(",
"$",
"id",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"ChannelAlreadyExistsException",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"dateStr",
"=",
"$",
"created",
"->",
"format",
"(",
"Misc",
"::",
"SQL_DATETIME",
")",
";",
"$",
"cx",
"->",
"insert",
"(",
"'apb_chan'",
")",
"->",
"fields",
"(",
"[",
"'name'",
"=>",
"$",
"id",
",",
"'title'",
"=>",
"$",
"title",
",",
"'created'",
"=>",
"$",
"dateStr",
",",
"'updated'",
"=>",
"$",
"dateStr",
",",
"]",
")",
"->",
"execute",
"(",
")",
";",
"// Specify the name of the sequence object for PDO_PGSQL.",
"// @see http://php.net/manual/en/pdo.lastinsertid.php.",
"$",
"seq",
"=",
"(",
"$",
"cx",
"->",
"driver",
"(",
")",
"===",
"'pgsql'",
")",
"?",
"'apb_chan_id_seq'",
":",
"null",
";",
"$",
"dbId",
"=",
"(",
"int",
")",
"$",
"cx",
"->",
"lastInsertId",
"(",
"$",
"seq",
")",
";",
"$",
"chan",
"=",
"new",
"DefaultChannel",
"(",
"$",
"id",
",",
"$",
"this",
",",
"$",
"created",
",",
"null",
",",
"$",
"title",
",",
"$",
"dbId",
")",
";",
"}",
"unset",
"(",
"$",
"tx",
")",
";",
"// Explicit commit",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"tx",
")",
"{",
"try",
"{",
"$",
"tx",
"->",
"rollback",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e2",
")",
"{",
"}",
"}",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"chan",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L104-L163 |
makinacorpus/drupal-apubsub | src/Backend/DrupalBackend.php | DrupalBackend.createChannels | public function createChannels($idList, $ignoreErrors = false)
{
if (empty($idList)) {
return [];
}
$ret = [];
$created = new \DateTime();
$createdString = $created->format(Misc::SQL_DATETIME);
$cx = $this->db;
$tx = $cx->startTransaction();
try {
// Do not ever use cache here, we cannot afford to try to create
// a channel that have been deleted by another thread
$existingList = $cx
->select('apb_chan', 'c')
->fields('c', ['name'])
->condition('c.name', $idList, 'IN')
->execute()
->fetchCol()
;
if ($existingList && !$ignoreErrors) {
throw new ChannelAlreadyExistsException();
}
if (count($existingList) !== count($idList)) {
$query = $cx
->insert('apb_chan')
->fields(['name', 'created', 'updated'])
;
// Create only the non existing one, in one query
foreach (array_diff($idList, $existingList) as $id) {
$query->values([$id, $createdString, $createdString]);
}
$query->execute();
}
// We can get back an id with the last insert id, but if the
// user created 10 chans, better do 2 SQL queries than 10!
// This is also the smart part of this function: we will load
// all channels at once instead of doing a first query for
// existing and a second for newly created ones, thus allowing
// us to keep the list ordered implicitely as long as the get
// method keeps it ordered too
$ret = $this->fetchChannels([Field::CHAN_ID => $idList]);
unset($tx); // Explicit commit
} catch (\Exception $e) {
$tx->rollback();
throw $e;
}
return iterator_to_array($ret);
} | php | public function createChannels($idList, $ignoreErrors = false)
{
if (empty($idList)) {
return [];
}
$ret = [];
$created = new \DateTime();
$createdString = $created->format(Misc::SQL_DATETIME);
$cx = $this->db;
$tx = $cx->startTransaction();
try {
// Do not ever use cache here, we cannot afford to try to create
// a channel that have been deleted by another thread
$existingList = $cx
->select('apb_chan', 'c')
->fields('c', ['name'])
->condition('c.name', $idList, 'IN')
->execute()
->fetchCol()
;
if ($existingList && !$ignoreErrors) {
throw new ChannelAlreadyExistsException();
}
if (count($existingList) !== count($idList)) {
$query = $cx
->insert('apb_chan')
->fields(['name', 'created', 'updated'])
;
// Create only the non existing one, in one query
foreach (array_diff($idList, $existingList) as $id) {
$query->values([$id, $createdString, $createdString]);
}
$query->execute();
}
// We can get back an id with the last insert id, but if the
// user created 10 chans, better do 2 SQL queries than 10!
// This is also the smart part of this function: we will load
// all channels at once instead of doing a first query for
// existing and a second for newly created ones, thus allowing
// us to keep the list ordered implicitely as long as the get
// method keeps it ordered too
$ret = $this->fetchChannels([Field::CHAN_ID => $idList]);
unset($tx); // Explicit commit
} catch (\Exception $e) {
$tx->rollback();
throw $e;
}
return iterator_to_array($ret);
} | [
"public",
"function",
"createChannels",
"(",
"$",
"idList",
",",
"$",
"ignoreErrors",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"idList",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"ret",
"=",
"[",
"]",
";",
"$",
"created",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"createdString",
"=",
"$",
"created",
"->",
"format",
"(",
"Misc",
"::",
"SQL_DATETIME",
")",
";",
"$",
"cx",
"=",
"$",
"this",
"->",
"db",
";",
"$",
"tx",
"=",
"$",
"cx",
"->",
"startTransaction",
"(",
")",
";",
"try",
"{",
"// Do not ever use cache here, we cannot afford to try to create",
"// a channel that have been deleted by another thread",
"$",
"existingList",
"=",
"$",
"cx",
"->",
"select",
"(",
"'apb_chan'",
",",
"'c'",
")",
"->",
"fields",
"(",
"'c'",
",",
"[",
"'name'",
"]",
")",
"->",
"condition",
"(",
"'c.name'",
",",
"$",
"idList",
",",
"'IN'",
")",
"->",
"execute",
"(",
")",
"->",
"fetchCol",
"(",
")",
";",
"if",
"(",
"$",
"existingList",
"&&",
"!",
"$",
"ignoreErrors",
")",
"{",
"throw",
"new",
"ChannelAlreadyExistsException",
"(",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"existingList",
")",
"!==",
"count",
"(",
"$",
"idList",
")",
")",
"{",
"$",
"query",
"=",
"$",
"cx",
"->",
"insert",
"(",
"'apb_chan'",
")",
"->",
"fields",
"(",
"[",
"'name'",
",",
"'created'",
",",
"'updated'",
"]",
")",
";",
"// Create only the non existing one, in one query",
"foreach",
"(",
"array_diff",
"(",
"$",
"idList",
",",
"$",
"existingList",
")",
"as",
"$",
"id",
")",
"{",
"$",
"query",
"->",
"values",
"(",
"[",
"$",
"id",
",",
"$",
"createdString",
",",
"$",
"createdString",
"]",
")",
";",
"}",
"$",
"query",
"->",
"execute",
"(",
")",
";",
"}",
"// We can get back an id with the last insert id, but if the",
"// user created 10 chans, better do 2 SQL queries than 10!",
"// This is also the smart part of this function: we will load",
"// all channels at once instead of doing a first query for",
"// existing and a second for newly created ones, thus allowing",
"// us to keep the list ordered implicitely as long as the get",
"// method keeps it ordered too",
"$",
"ret",
"=",
"$",
"this",
"->",
"fetchChannels",
"(",
"[",
"Field",
"::",
"CHAN_ID",
"=>",
"$",
"idList",
"]",
")",
";",
"unset",
"(",
"$",
"tx",
")",
";",
"// Explicit commit",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"tx",
"->",
"rollback",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"return",
"iterator_to_array",
"(",
"$",
"ret",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/DrupalBackend.php#L168-L228 |
Subsets and Splits