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
|
---|---|---|---|---|---|---|---|---|---|---|
alevilar/ristorantino-vendor | Printers/Lib/DriverView/Helper/HasarSMHP321fFiscalHelper.php | HasarSMHP321fFiscalHelper.generalDiscount | public function generalDiscount($porcentaje_descuento = 0){
$comando = "T".$this->cm('FS').
'Descuento'.$this->cm('FS').
$porcentaje_descuento.$this->cm('FS').
'm'.$this->cm('FS').
'0'.$this->cm('FS').
'T';
return $comando;
} | php | public function generalDiscount($porcentaje_descuento = 0){
$comando = "T".$this->cm('FS').
'Descuento'.$this->cm('FS').
$porcentaje_descuento.$this->cm('FS').
'm'.$this->cm('FS').
'0'.$this->cm('FS').
'T';
return $comando;
} | [
"public",
"function",
"generalDiscount",
"(",
"$",
"porcentaje_descuento",
"=",
"0",
")",
"{",
"$",
"comando",
"=",
"\"T\"",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"'Descuento'",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"$",
"porcentaje_descuento",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"'m'",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"'0'",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"'T'",
";",
"return",
"$",
"comando",
";",
"}"
] | Responde:
a. Imprimiendo una línea donde se muestra: descripción del descuento (o recargo), impuestos y monto del
descuento (o recargo) -con posterioridad a la impresión de la línea con la leyenda “Descuento (o Recargo)
general”-;
b. Restando
EJEMPLO: T∟Pago Efectivo...∟5.0∟m∟0∟T
@param float $porcentaje_descuento
@return string comando | [
"Responde",
":",
"a",
".",
"Imprimiendo",
"una",
"línea",
"donde",
"se",
"muestra",
":",
"descripción",
"del",
"descuento",
"(",
"o",
"recargo",
")",
"impuestos",
"y",
"monto",
"del",
"descuento",
"(",
"o",
"recargo",
")",
"-",
"con",
"posterioridad",
"a",
"la",
"impresión",
"de",
"la",
"línea",
"con",
"la",
"leyenda",
"“Descuento",
"(",
"o",
"Recargo",
")",
"general”",
"-",
";",
"b",
".",
"Restando"
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Printers/Lib/DriverView/Helper/HasarSMHP321fFiscalHelper.php#L103-L111 |
alevilar/ristorantino-vendor | Printers/Lib/DriverView/Helper/HasarSMHP321fFiscalHelper.php | HasarSMHP321fFiscalHelper.dailyClose | public function dailyClose($tipo_cierre = 'X'){
$tipo_cierre = strtoupper($tipo_cierre);
if($tipo_cierre == 'X' || $tipo_cierre == 'Z'){
$comando = "9".$this->cm('FS').$tipo_cierre;
}
else{
$comando = false;
}
return $comando;
} | php | public function dailyClose($tipo_cierre = 'X'){
$tipo_cierre = strtoupper($tipo_cierre);
if($tipo_cierre == 'X' || $tipo_cierre == 'Z'){
$comando = "9".$this->cm('FS').$tipo_cierre;
}
else{
$comando = false;
}
return $comando;
} | [
"public",
"function",
"dailyClose",
"(",
"$",
"tipo_cierre",
"=",
"'X'",
")",
"{",
"$",
"tipo_cierre",
"=",
"strtoupper",
"(",
"$",
"tipo_cierre",
")",
";",
"if",
"(",
"$",
"tipo_cierre",
"==",
"'X'",
"||",
"$",
"tipo_cierre",
"==",
"'Z'",
")",
"{",
"$",
"comando",
"=",
"\"9\"",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"$",
"tipo_cierre",
";",
"}",
"else",
"{",
"$",
"comando",
"=",
"false",
";",
"}",
"return",
"$",
"comando",
";",
"}"
] | Imprime el comprobante X/Z
@param $tipo_cierre puede ser:
'X': imprime un cierre X
'Z': imprime un cierre Z | [
"Imprime",
"el",
"comprobante",
"X",
"/",
"Z"
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Printers/Lib/DriverView/Helper/HasarSMHP321fFiscalHelper.php#L160-L169 |
alevilar/ristorantino-vendor | Printers/Lib/DriverView/Helper/HasarSMHP321fFiscalHelper.php | HasarSMHP321fFiscalHelper.setCustomerData | public function setCustomerData($nombre_cliente = " ",$documento = " ",$respo_iva = 'C', $tipo_documento = " ", $domicilio = '-') {
$nombre_cliente = substr($nombre_cliente,0,45);
$respo_iva = strtoupper($respo_iva);
$tipo_documento = strtoupper($tipo_documento);
if($respo_iva == 'I' || $respo_iva == 'E' || $respo_iva == 'A' || $respo_iva == 'C' || $respo_iva == 'T'){
if( $tipo_documento == 'C' || $tipo_documento == 'L' || $tipo_documento == '0' || $tipo_documento == '1' || $tipo_documento == '2' || $tipo_documento == '3' || $tipo_documento == '4')
{
$comando = "b".$this->cm('FS').$nombre_cliente.$this->cm('FS').$documento.$this->cm('FS').$respo_iva.$this->cm('FS').$tipo_documento;
if($domicilio){
$comando .= $this->cm('FS').$domicilio;
}
}
else{
return -1; //fallo tipo_documento
}
}
else{
return -2; // fallo respo_iva
}
return $comando;
} | php | public function setCustomerData($nombre_cliente = " ",$documento = " ",$respo_iva = 'C', $tipo_documento = " ", $domicilio = '-') {
$nombre_cliente = substr($nombre_cliente,0,45);
$respo_iva = strtoupper($respo_iva);
$tipo_documento = strtoupper($tipo_documento);
if($respo_iva == 'I' || $respo_iva == 'E' || $respo_iva == 'A' || $respo_iva == 'C' || $respo_iva == 'T'){
if( $tipo_documento == 'C' || $tipo_documento == 'L' || $tipo_documento == '0' || $tipo_documento == '1' || $tipo_documento == '2' || $tipo_documento == '3' || $tipo_documento == '4')
{
$comando = "b".$this->cm('FS').$nombre_cliente.$this->cm('FS').$documento.$this->cm('FS').$respo_iva.$this->cm('FS').$tipo_documento;
if($domicilio){
$comando .= $this->cm('FS').$domicilio;
}
}
else{
return -1; //fallo tipo_documento
}
}
else{
return -2; // fallo respo_iva
}
return $comando;
} | [
"public",
"function",
"setCustomerData",
"(",
"$",
"nombre_cliente",
"=",
"\" \"",
",",
"$",
"documento",
"=",
"\" \"",
",",
"$",
"respo_iva",
"=",
"'C'",
",",
"$",
"tipo_documento",
"=",
"\" \"",
",",
"$",
"domicilio",
"=",
"'-'",
")",
"{",
"$",
"nombre_cliente",
"=",
"substr",
"(",
"$",
"nombre_cliente",
",",
"0",
",",
"45",
")",
";",
"$",
"respo_iva",
"=",
"strtoupper",
"(",
"$",
"respo_iva",
")",
";",
"$",
"tipo_documento",
"=",
"strtoupper",
"(",
"$",
"tipo_documento",
")",
";",
"if",
"(",
"$",
"respo_iva",
"==",
"'I'",
"||",
"$",
"respo_iva",
"==",
"'E'",
"||",
"$",
"respo_iva",
"==",
"'A'",
"||",
"$",
"respo_iva",
"==",
"'C'",
"||",
"$",
"respo_iva",
"==",
"'T'",
")",
"{",
"if",
"(",
"$",
"tipo_documento",
"==",
"'C'",
"||",
"$",
"tipo_documento",
"==",
"'L'",
"||",
"$",
"tipo_documento",
"==",
"'0'",
"||",
"$",
"tipo_documento",
"==",
"'1'",
"||",
"$",
"tipo_documento",
"==",
"'2'",
"||",
"$",
"tipo_documento",
"==",
"'3'",
"||",
"$",
"tipo_documento",
"==",
"'4'",
")",
"{",
"$",
"comando",
"=",
"\"b\"",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"$",
"nombre_cliente",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"$",
"documento",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"$",
"respo_iva",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"$",
"tipo_documento",
";",
"if",
"(",
"$",
"domicilio",
")",
"{",
"$",
"comando",
".=",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"$",
"domicilio",
";",
"}",
"}",
"else",
"{",
"return",
"-",
"1",
";",
"//fallo tipo_documento",
"}",
"}",
"else",
"{",
"return",
"-",
"2",
";",
"// fallo respo_iva",
"}",
"return",
"$",
"comando",
";",
"}"
] | Setea los datos del Cliente, por lo general se usa para hacer factura A
@param string $nombre_cliente nombre o razon social
@param integer $documento valor del DNI, CIUT, CUIL, etc
@param CHAR $respo_iva
'I' responsable inscripto
'E' Excento
'A' No responsable
'C' Consumidor final
'T' No categorizado
@param CHAR $tipo_documento
'C' CUIT
'L' CUIL
'0' Lbreta enrolamiento
'1' Libreta civica
'2' DNI
'3' Pasaporte
'4' Cedula de Identidad
@param string $domicilio | [
"Setea",
"los",
"datos",
"del",
"Cliente",
"por",
"lo",
"general",
"se",
"usa",
"para",
"hacer",
"factura",
"A"
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Printers/Lib/DriverView/Helper/HasarSMHP321fFiscalHelper.php#L324-L346 |
alevilar/ristorantino-vendor | Printers/Lib/DriverView/Helper/HasarSMHP321fFiscalHelper.php | HasarSMHP321fFiscalHelper.openDNFH | public function openDNFH($tipoDocumento, $identificacion = ''){
return "Ç" . $this->cm('FS') .
$tipoDocumento . $this->cm('FS') .
"T" . $this->cm('FS') .
$identificacion
;
} | php | public function openDNFH($tipoDocumento, $identificacion = ''){
return "Ç" . $this->cm('FS') .
$tipoDocumento . $this->cm('FS') .
"T" . $this->cm('FS') .
$identificacion
;
} | [
"public",
"function",
"openDNFH",
"(",
"$",
"tipoDocumento",
",",
"$",
"identificacion",
"=",
"''",
")",
"{",
"return",
"\"Ç\" ",
" ",
"t",
"his-",
">c",
"m(",
"'",
"FS')",
" ",
"",
"$",
"tipoDocumento",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"\"T\"",
".",
"$",
"this",
"->",
"cm",
"(",
"'FS'",
")",
".",
"$",
"identificacion",
";",
"}"
] | Tipo de documento
R: Nota de crédito ‘A’
S: Nota de crédito ‘B/C’
x: Tique recibo ‘X’
<: Tique pagaré
,: Tique presupuesto
-: Comp. de entrega
.: Talón Estacionamiento
/: Cobro de Servicios
0: Ingreso de Dinero
1: Retiro de Dinero
2: Talón de Cambio
3: Talón de reparto
4: Talón de regalo
5: Cuenta Corriente
6: Avisode Operación de Crédito
7: Cupón de Promoción
8: Uso Interno Farmacia
Ejemplo: Ç∟R∟T∟1211241 | [
"Tipo",
"de",
"documento",
"R",
":",
"Nota",
"de",
"crédito",
"‘A’",
"S",
":",
"Nota",
"de",
"crédito",
"‘B",
"/",
"C’",
"x",
":",
"Tique",
"recibo",
"‘X’",
"<",
":",
"Tique",
"pagaré",
":",
"Tique",
"presupuesto",
"-",
":",
"Comp",
".",
"de",
"entrega",
".",
":",
"Talón",
"Estacionamiento",
"/",
":",
"Cobro",
"de",
"Servicios",
"0",
":",
"Ingreso",
"de",
"Dinero",
"1",
":",
"Retiro",
"de",
"Dinero",
"2",
":",
"Talón",
"de",
"Cambio",
"3",
":",
"Talón",
"de",
"reparto",
"4",
":",
"Talón",
"de",
"regalo",
"5",
":",
"Cuenta",
"Corriente",
"6",
":",
"Avisode",
"Operación",
"de",
"Crédito",
"7",
":",
"Cupón",
"de",
"Promoción",
"8",
":",
"Uso",
"Interno",
"Farmacia"
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Printers/Lib/DriverView/Helper/HasarSMHP321fFiscalHelper.php#L393-L399 |
phootwork/lang | src/text/EnglishPluralizer.php | EnglishPluralizer.getPluralForm | public function getPluralForm($root) {
$pluralForm = $root;
if (!is_string($root)) {
throw new \InvalidArgumentException('The pluralizer expects a string.');
}
if (!in_array(strtolower($root), $this->uncountable)) {
// This check must be run before `checkIrregularForm` call
if (!$this->isAmbiguousPlural($root)) {
if (null !== $replacement = $this->checkIrregularForm($root, $this->irregular)) {
$pluralForm = $replacement;
} elseif (null !== $replacement = $this->checkIrregularSuffix($root, $this->plural)) {
$pluralForm = $replacement;
} elseif (!$this->isPlural($root)) {
// fallback to naive pluralization
$pluralForm = $root . 's';
}
}
}
return $pluralForm;
} | php | public function getPluralForm($root) {
$pluralForm = $root;
if (!is_string($root)) {
throw new \InvalidArgumentException('The pluralizer expects a string.');
}
if (!in_array(strtolower($root), $this->uncountable)) {
// This check must be run before `checkIrregularForm` call
if (!$this->isAmbiguousPlural($root)) {
if (null !== $replacement = $this->checkIrregularForm($root, $this->irregular)) {
$pluralForm = $replacement;
} elseif (null !== $replacement = $this->checkIrregularSuffix($root, $this->plural)) {
$pluralForm = $replacement;
} elseif (!$this->isPlural($root)) {
// fallback to naive pluralization
$pluralForm = $root . 's';
}
}
}
return $pluralForm;
} | [
"public",
"function",
"getPluralForm",
"(",
"$",
"root",
")",
"{",
"$",
"pluralForm",
"=",
"$",
"root",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"root",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The pluralizer expects a string.'",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"root",
")",
",",
"$",
"this",
"->",
"uncountable",
")",
")",
"{",
"// This check must be run before `checkIrregularForm` call",
"if",
"(",
"!",
"$",
"this",
"->",
"isAmbiguousPlural",
"(",
"$",
"root",
")",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"replacement",
"=",
"$",
"this",
"->",
"checkIrregularForm",
"(",
"$",
"root",
",",
"$",
"this",
"->",
"irregular",
")",
")",
"{",
"$",
"pluralForm",
"=",
"$",
"replacement",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"replacement",
"=",
"$",
"this",
"->",
"checkIrregularSuffix",
"(",
"$",
"root",
",",
"$",
"this",
"->",
"plural",
")",
")",
"{",
"$",
"pluralForm",
"=",
"$",
"replacement",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"isPlural",
"(",
"$",
"root",
")",
")",
"{",
"// fallback to naive pluralization",
"$",
"pluralForm",
"=",
"$",
"root",
".",
"'s'",
";",
"}",
"}",
"}",
"return",
"$",
"pluralForm",
";",
"}"
] | Generate a plural name based on the passed in root.
@param string $root The root that needs to be pluralized (e.g. Author)
@return string The plural form of $root (e.g. Authors).
@throws \InvalidArgumentException If the parameter is not a string. | [
"Generate",
"a",
"plural",
"name",
"based",
"on",
"the",
"passed",
"in",
"root",
"."
] | train | https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/EnglishPluralizer.php#L145-L167 |
phootwork/lang | src/text/EnglishPluralizer.php | EnglishPluralizer.getSingularForm | public function getSingularForm($root) {
$singularForm = $root;
if (!is_string($root)) {
throw new \InvalidArgumentException('The pluralizer expects a string.');
}
if (!in_array(strtolower($root), $this->uncountable)) {
if (null !== $replacement = $this->checkIrregularForm($root, array_flip($this->irregular))) {
$singularForm = $replacement;
} elseif (null !== $replacement = $this->checkIrregularSuffix($root, $this->singular)) {
$singularForm = $replacement;
} elseif (!$this->isSingular($root)) {
// fallback to naive singularization
return substr($root, 0, -1);
}
}
return $singularForm;
} | php | public function getSingularForm($root) {
$singularForm = $root;
if (!is_string($root)) {
throw new \InvalidArgumentException('The pluralizer expects a string.');
}
if (!in_array(strtolower($root), $this->uncountable)) {
if (null !== $replacement = $this->checkIrregularForm($root, array_flip($this->irregular))) {
$singularForm = $replacement;
} elseif (null !== $replacement = $this->checkIrregularSuffix($root, $this->singular)) {
$singularForm = $replacement;
} elseif (!$this->isSingular($root)) {
// fallback to naive singularization
return substr($root, 0, -1);
}
}
return $singularForm;
} | [
"public",
"function",
"getSingularForm",
"(",
"$",
"root",
")",
"{",
"$",
"singularForm",
"=",
"$",
"root",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"root",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The pluralizer expects a string.'",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"root",
")",
",",
"$",
"this",
"->",
"uncountable",
")",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"replacement",
"=",
"$",
"this",
"->",
"checkIrregularForm",
"(",
"$",
"root",
",",
"array_flip",
"(",
"$",
"this",
"->",
"irregular",
")",
")",
")",
"{",
"$",
"singularForm",
"=",
"$",
"replacement",
";",
"}",
"elseif",
"(",
"null",
"!==",
"$",
"replacement",
"=",
"$",
"this",
"->",
"checkIrregularSuffix",
"(",
"$",
"root",
",",
"$",
"this",
"->",
"singular",
")",
")",
"{",
"$",
"singularForm",
"=",
"$",
"replacement",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"isSingular",
"(",
"$",
"root",
")",
")",
"{",
"// fallback to naive singularization",
"return",
"substr",
"(",
"$",
"root",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"}",
"return",
"$",
"singularForm",
";",
"}"
] | Generate a singular name based on the passed in root.
@param string $root The root that needs to be pluralized (e.g. Author)
@return string The singular form of $root (e.g. Authors).
@throws \InvalidArgumentException If the parameter is not a string. | [
"Generate",
"a",
"singular",
"name",
"based",
"on",
"the",
"passed",
"in",
"root",
"."
] | train | https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/EnglishPluralizer.php#L176-L195 |
phootwork/lang | src/text/EnglishPluralizer.php | EnglishPluralizer.isPlural | public function isPlural($root) {
$out = false;
if ('' !== $root) {
if (in_array(strtolower($root), $this->uncountable)) {
$out = true;
} else {
$out = $this->isIrregular($this->irregular, $root);
if (!$out) {
$out = $this->isIrregular(array_keys($this->singular), $root);
}
if (!$out && 's' == $root[strlen($root) - 1]) {
$out = true;
}
}
}
return $out;
} | php | public function isPlural($root) {
$out = false;
if ('' !== $root) {
if (in_array(strtolower($root), $this->uncountable)) {
$out = true;
} else {
$out = $this->isIrregular($this->irregular, $root);
if (!$out) {
$out = $this->isIrregular(array_keys($this->singular), $root);
}
if (!$out && 's' == $root[strlen($root) - 1]) {
$out = true;
}
}
}
return $out;
} | [
"public",
"function",
"isPlural",
"(",
"$",
"root",
")",
"{",
"$",
"out",
"=",
"false",
";",
"if",
"(",
"''",
"!==",
"$",
"root",
")",
"{",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"root",
")",
",",
"$",
"this",
"->",
"uncountable",
")",
")",
"{",
"$",
"out",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"isIrregular",
"(",
"$",
"this",
"->",
"irregular",
",",
"$",
"root",
")",
";",
"if",
"(",
"!",
"$",
"out",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"isIrregular",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"singular",
")",
",",
"$",
"root",
")",
";",
"}",
"if",
"(",
"!",
"$",
"out",
"&&",
"'s'",
"==",
"$",
"root",
"[",
"strlen",
"(",
"$",
"root",
")",
"-",
"1",
"]",
")",
"{",
"$",
"out",
"=",
"true",
";",
"}",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] | Check if $root word is plural.
@param string $root
@return bool | [
"Check",
"if",
"$root",
"word",
"is",
"plural",
"."
] | train | https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/EnglishPluralizer.php#L204-L224 |
phootwork/lang | src/text/EnglishPluralizer.php | EnglishPluralizer.isSingular | public function isSingular($root) {
$out = false;
if ('' === $root) {
$out = true;
} elseif (in_array(strtolower($root), $this->uncountable)) {
$out = true;
} elseif (!$this->isAmbiguousPlural($root)) {
$out = $this->isIrregular($this->irregular, $root);
if (!$out) {
$out = $this->isIrregular(array_keys($this->plural), $root);
}
if (!$out && 's' !== $root[strlen($root) - 1]) {
$out = true;
}
}
return $out;
} | php | public function isSingular($root) {
$out = false;
if ('' === $root) {
$out = true;
} elseif (in_array(strtolower($root), $this->uncountable)) {
$out = true;
} elseif (!$this->isAmbiguousPlural($root)) {
$out = $this->isIrregular($this->irregular, $root);
if (!$out) {
$out = $this->isIrregular(array_keys($this->plural), $root);
}
if (!$out && 's' !== $root[strlen($root) - 1]) {
$out = true;
}
}
return $out;
} | [
"public",
"function",
"isSingular",
"(",
"$",
"root",
")",
"{",
"$",
"out",
"=",
"false",
";",
"if",
"(",
"''",
"===",
"$",
"root",
")",
"{",
"$",
"out",
"=",
"true",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"root",
")",
",",
"$",
"this",
"->",
"uncountable",
")",
")",
"{",
"$",
"out",
"=",
"true",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"isAmbiguousPlural",
"(",
"$",
"root",
")",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"isIrregular",
"(",
"$",
"this",
"->",
"irregular",
",",
"$",
"root",
")",
";",
"if",
"(",
"!",
"$",
"out",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"isIrregular",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"plural",
")",
",",
"$",
"root",
")",
";",
"}",
"if",
"(",
"!",
"$",
"out",
"&&",
"'s'",
"!==",
"$",
"root",
"[",
"strlen",
"(",
"$",
"root",
")",
"-",
"1",
"]",
")",
"{",
"$",
"out",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] | Check if $root word is singular.
@param $root
@return bool | [
"Check",
"if",
"$root",
"word",
"is",
"singular",
"."
] | train | https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/EnglishPluralizer.php#L233-L253 |
phootwork/lang | src/text/EnglishPluralizer.php | EnglishPluralizer.checkIrregularForm | private function checkIrregularForm($root, $irregular) {
foreach ($irregular as $pattern => $result) {
$searchPattern = '/' . $pattern . '$/i';
if ($root !== $replacement = preg_replace($searchPattern, $result, $root)) {
// look at the first char and see if it's upper case
// I know it won't handle more than one upper case char here (but I'm OK with that)
if (preg_match('/^[A-Z]/', $root)) {
$replacement = ucfirst($replacement);
}
return $replacement;
}
}
return null;
} | php | private function checkIrregularForm($root, $irregular) {
foreach ($irregular as $pattern => $result) {
$searchPattern = '/' . $pattern . '$/i';
if ($root !== $replacement = preg_replace($searchPattern, $result, $root)) {
// look at the first char and see if it's upper case
// I know it won't handle more than one upper case char here (but I'm OK with that)
if (preg_match('/^[A-Z]/', $root)) {
$replacement = ucfirst($replacement);
}
return $replacement;
}
}
return null;
} | [
"private",
"function",
"checkIrregularForm",
"(",
"$",
"root",
",",
"$",
"irregular",
")",
"{",
"foreach",
"(",
"$",
"irregular",
"as",
"$",
"pattern",
"=>",
"$",
"result",
")",
"{",
"$",
"searchPattern",
"=",
"'/'",
".",
"$",
"pattern",
".",
"'$/i'",
";",
"if",
"(",
"$",
"root",
"!==",
"$",
"replacement",
"=",
"preg_replace",
"(",
"$",
"searchPattern",
",",
"$",
"result",
",",
"$",
"root",
")",
")",
"{",
"// look at the first char and see if it's upper case",
"// I know it won't handle more than one upper case char here (but I'm OK with that)",
"if",
"(",
"preg_match",
"(",
"'/^[A-Z]/'",
",",
"$",
"root",
")",
")",
"{",
"$",
"replacement",
"=",
"ucfirst",
"(",
"$",
"replacement",
")",
";",
"}",
"return",
"$",
"replacement",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Pluralize/Singularize irregular forms.
@param string $root The string to pluralize/singularize
@param array $irregular Array of irregular forms
@return null|string | [
"Pluralize",
"/",
"Singularize",
"irregular",
"forms",
"."
] | train | https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/EnglishPluralizer.php#L263-L278 |
phootwork/lang | src/text/EnglishPluralizer.php | EnglishPluralizer.checkIrregularSuffix | private function checkIrregularSuffix($root, $irregular) {
foreach ($irregular as $pattern => $result) {
$searchPattern = '/' . $pattern . '$/i';
if ($root !== $replacement = preg_replace($searchPattern, $result, $root)) {
return $replacement;
}
}
return null;
} | php | private function checkIrregularSuffix($root, $irregular) {
foreach ($irregular as $pattern => $result) {
$searchPattern = '/' . $pattern . '$/i';
if ($root !== $replacement = preg_replace($searchPattern, $result, $root)) {
return $replacement;
}
}
return null;
} | [
"private",
"function",
"checkIrregularSuffix",
"(",
"$",
"root",
",",
"$",
"irregular",
")",
"{",
"foreach",
"(",
"$",
"irregular",
"as",
"$",
"pattern",
"=>",
"$",
"result",
")",
"{",
"$",
"searchPattern",
"=",
"'/'",
".",
"$",
"pattern",
".",
"'$/i'",
";",
"if",
"(",
"$",
"root",
"!==",
"$",
"replacement",
"=",
"preg_replace",
"(",
"$",
"searchPattern",
",",
"$",
"result",
",",
"$",
"root",
")",
")",
"{",
"return",
"$",
"replacement",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | @param string $root
@param array $irregular Array of irregular suffixes
@return null|string | [
"@param",
"string",
"$root",
"@param",
"array",
"$irregular",
"Array",
"of",
"irregular",
"suffixes"
] | train | https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/EnglishPluralizer.php#L286-L295 |
phootwork/lang | src/text/EnglishPluralizer.php | EnglishPluralizer.isAmbiguousPlural | private function isAmbiguousPlural($root) {
foreach ($this->ambiguous as $pattern) {
if (preg_match('/' . $pattern . '$/i', $root)) {
return true;
}
}
return false;
} | php | private function isAmbiguousPlural($root) {
foreach ($this->ambiguous as $pattern) {
if (preg_match('/' . $pattern . '$/i', $root)) {
return true;
}
}
return false;
} | [
"private",
"function",
"isAmbiguousPlural",
"(",
"$",
"root",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"ambiguous",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/'",
".",
"$",
"pattern",
".",
"'$/i'",
",",
"$",
"root",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param $root
@return bool | [
"@param",
"$root"
] | train | https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/EnglishPluralizer.php#L302-L310 |
phootwork/lang | src/text/EnglishPluralizer.php | EnglishPluralizer.isIrregular | private function isIrregular($irregular, $root) {
foreach ($irregular as $pattern) {
if (preg_match('/' . $pattern . '$/i', $root)) {
return true;
}
}
return false;
} | php | private function isIrregular($irregular, $root) {
foreach ($irregular as $pattern) {
if (preg_match('/' . $pattern . '$/i', $root)) {
return true;
}
}
return false;
} | [
"private",
"function",
"isIrregular",
"(",
"$",
"irregular",
",",
"$",
"root",
")",
"{",
"foreach",
"(",
"$",
"irregular",
"as",
"$",
"pattern",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/'",
".",
"$",
"pattern",
".",
"'$/i'",
",",
"$",
"root",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | @param array $irregular
@param $root
@return bool | [
"@param",
"array",
"$irregular",
"@param",
"$root"
] | train | https://github.com/phootwork/lang/blob/2e5dc084d9102bf6b4c60f3ec2acc2ef49861588/src/text/EnglishPluralizer.php#L318-L326 |
mothership-ec/composer | src/Composer/Repository/WritableArrayRepository.php | WritableArrayRepository.getCanonicalPackages | public function getCanonicalPackages()
{
$packages = $this->getPackages();
// get at most one package of each name, prefering non-aliased ones
$packagesByName = array();
foreach ($packages as $package) {
if (!isset($packagesByName[$package->getName()]) || $packagesByName[$package->getName()] instanceof AliasPackage) {
$packagesByName[$package->getName()] = $package;
}
}
$canonicalPackages = array();
// unfold aliased packages
foreach ($packagesByName as $package) {
while ($package instanceof AliasPackage) {
$package = $package->getAliasOf();
}
$canonicalPackages[] = $package;
}
return $canonicalPackages;
} | php | public function getCanonicalPackages()
{
$packages = $this->getPackages();
// get at most one package of each name, prefering non-aliased ones
$packagesByName = array();
foreach ($packages as $package) {
if (!isset($packagesByName[$package->getName()]) || $packagesByName[$package->getName()] instanceof AliasPackage) {
$packagesByName[$package->getName()] = $package;
}
}
$canonicalPackages = array();
// unfold aliased packages
foreach ($packagesByName as $package) {
while ($package instanceof AliasPackage) {
$package = $package->getAliasOf();
}
$canonicalPackages[] = $package;
}
return $canonicalPackages;
} | [
"public",
"function",
"getCanonicalPackages",
"(",
")",
"{",
"$",
"packages",
"=",
"$",
"this",
"->",
"getPackages",
"(",
")",
";",
"// get at most one package of each name, prefering non-aliased ones",
"$",
"packagesByName",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"package",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"packagesByName",
"[",
"$",
"package",
"->",
"getName",
"(",
")",
"]",
")",
"||",
"$",
"packagesByName",
"[",
"$",
"package",
"->",
"getName",
"(",
")",
"]",
"instanceof",
"AliasPackage",
")",
"{",
"$",
"packagesByName",
"[",
"$",
"package",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"package",
";",
"}",
"}",
"$",
"canonicalPackages",
"=",
"array",
"(",
")",
";",
"// unfold aliased packages",
"foreach",
"(",
"$",
"packagesByName",
"as",
"$",
"package",
")",
"{",
"while",
"(",
"$",
"package",
"instanceof",
"AliasPackage",
")",
"{",
"$",
"package",
"=",
"$",
"package",
"->",
"getAliasOf",
"(",
")",
";",
"}",
"$",
"canonicalPackages",
"[",
"]",
"=",
"$",
"package",
";",
"}",
"return",
"$",
"canonicalPackages",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Repository/WritableArrayRepository.php#L41-L65 |
DesignPond/newsletter | src/Http/Controllers/Frontend/InscriptionController.php | InscriptionController.activation | public function activation($token,$newsletter_id)
{
// Activate the email on the website
$user = $this->subscription->activate($token);
if(!$user)
{
alert()->danger('Le jeton ne correspond pas ou à expiré');
return redirect('/');
}
$newsletter = $this->newsletter->find($newsletter_id);
if(!$newsletter)
{
alert()->danger('Cette newsletter n\'existe pas');
return redirect('/');
}
//Subscribe to mailjet
$this->worker->setList($newsletter->list_id);
$result = $this->worker->subscribeEmailToList($user->email);
if(!$result){
alert()->danger('Problème');
return redirect('/');
}
alert()->success('Vous êtes maintenant abonné à la newsletter');
return redirect('/');
} | php | public function activation($token,$newsletter_id)
{
// Activate the email on the website
$user = $this->subscription->activate($token);
if(!$user)
{
alert()->danger('Le jeton ne correspond pas ou à expiré');
return redirect('/');
}
$newsletter = $this->newsletter->find($newsletter_id);
if(!$newsletter)
{
alert()->danger('Cette newsletter n\'existe pas');
return redirect('/');
}
//Subscribe to mailjet
$this->worker->setList($newsletter->list_id);
$result = $this->worker->subscribeEmailToList($user->email);
if(!$result){
alert()->danger('Problème');
return redirect('/');
}
alert()->success('Vous êtes maintenant abonné à la newsletter');
return redirect('/');
} | [
"public",
"function",
"activation",
"(",
"$",
"token",
",",
"$",
"newsletter_id",
")",
"{",
"// Activate the email on the website",
"$",
"user",
"=",
"$",
"this",
"->",
"subscription",
"->",
"activate",
"(",
"$",
"token",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"alert",
"(",
")",
"->",
"danger",
"(",
"'Le jeton ne correspond pas ou à expiré');",
"",
"",
"return",
"redirect",
"(",
"'/'",
")",
";",
"}",
"$",
"newsletter",
"=",
"$",
"this",
"->",
"newsletter",
"->",
"find",
"(",
"$",
"newsletter_id",
")",
";",
"if",
"(",
"!",
"$",
"newsletter",
")",
"{",
"alert",
"(",
")",
"->",
"danger",
"(",
"'Cette newsletter n\\'existe pas'",
")",
";",
"return",
"redirect",
"(",
"'/'",
")",
";",
"}",
"//Subscribe to mailjet",
"$",
"this",
"->",
"worker",
"->",
"setList",
"(",
"$",
"newsletter",
"->",
"list_id",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"worker",
"->",
"subscribeEmailToList",
"(",
"$",
"user",
"->",
"email",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"alert",
"(",
")",
"->",
"danger",
"(",
"'Problème')",
";",
"",
"return",
"redirect",
"(",
"'/'",
")",
";",
"}",
"alert",
"(",
")",
"->",
"success",
"(",
"'Vous êtes maintenant abonné à la newsletter');",
"",
"",
"return",
"redirect",
"(",
"'/'",
")",
";",
"}"
] | Activate newsletter abo
GET //activation
@return Response | [
"Activate",
"newsletter",
"abo",
"GET",
"//",
"activation"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Frontend/InscriptionController.php#L33-L68 |
DesignPond/newsletter | src/Http/Controllers/Frontend/InscriptionController.php | InscriptionController.subscribe | public function subscribe(SubscribeRequest $request)
{
$subscribe = $this->subscription->findByEmail($request->input('email'));
if($subscribe)
{
if(!$subscribe->activated_at)
{
alert()->warning('Cet email existe déjà');
return redirect('/')->withInput()->with('resend', true);
}
$subscriptions = $subscribe->subscriptions->pluck('id')->all();
if(in_array($request->input('newsletter_id'),$subscriptions))
{
alert()->warning('Vous êtes déjà inscrit à la newsletter');
return redirect($request->input('return_path', '/'));
}
}
else
{
// Subscribe user with activation token to website list and sync newsletter abos
$subscribe = $this->subscription->create(['email' => $request->input('email'), 'activation_token' => md5($request->email.\Carbon\Carbon::now()) ]);
}
$subscribe->subscriptions()->attach($request->input('newsletter_id'));
\Mail::send('newsletter::Email.confirmation', array('token' => $subscribe->activation_token, 'newsletter_id' => $request->input('newsletter_id')), function($message) use ($subscribe)
{
$message->to($subscribe->email, $subscribe->email)->subject('Inscription!');
});
alert()->success('<strong>Merci pour votre inscription!</strong><br/>Veuillez confirmer votre adresse email en cliquant le lien qui vous a été envoyé par email');
return redirect($request->input('return_path', '/'));
} | php | public function subscribe(SubscribeRequest $request)
{
$subscribe = $this->subscription->findByEmail($request->input('email'));
if($subscribe)
{
if(!$subscribe->activated_at)
{
alert()->warning('Cet email existe déjà');
return redirect('/')->withInput()->with('resend', true);
}
$subscriptions = $subscribe->subscriptions->pluck('id')->all();
if(in_array($request->input('newsletter_id'),$subscriptions))
{
alert()->warning('Vous êtes déjà inscrit à la newsletter');
return redirect($request->input('return_path', '/'));
}
}
else
{
// Subscribe user with activation token to website list and sync newsletter abos
$subscribe = $this->subscription->create(['email' => $request->input('email'), 'activation_token' => md5($request->email.\Carbon\Carbon::now()) ]);
}
$subscribe->subscriptions()->attach($request->input('newsletter_id'));
\Mail::send('newsletter::Email.confirmation', array('token' => $subscribe->activation_token, 'newsletter_id' => $request->input('newsletter_id')), function($message) use ($subscribe)
{
$message->to($subscribe->email, $subscribe->email)->subject('Inscription!');
});
alert()->success('<strong>Merci pour votre inscription!</strong><br/>Veuillez confirmer votre adresse email en cliquant le lien qui vous a été envoyé par email');
return redirect($request->input('return_path', '/'));
} | [
"public",
"function",
"subscribe",
"(",
"SubscribeRequest",
"$",
"request",
")",
"{",
"$",
"subscribe",
"=",
"$",
"this",
"->",
"subscription",
"->",
"findByEmail",
"(",
"$",
"request",
"->",
"input",
"(",
"'email'",
")",
")",
";",
"if",
"(",
"$",
"subscribe",
")",
"{",
"if",
"(",
"!",
"$",
"subscribe",
"->",
"activated_at",
")",
"{",
"alert",
"(",
")",
"->",
"warning",
"(",
"'Cet email existe déjà');",
"",
"",
"return",
"redirect",
"(",
"'/'",
")",
"->",
"withInput",
"(",
")",
"->",
"with",
"(",
"'resend'",
",",
"true",
")",
";",
"}",
"$",
"subscriptions",
"=",
"$",
"subscribe",
"->",
"subscriptions",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"all",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"request",
"->",
"input",
"(",
"'newsletter_id'",
")",
",",
"$",
"subscriptions",
")",
")",
"{",
"alert",
"(",
")",
"->",
"warning",
"(",
"'Vous êtes déjà inscrit à la newsletter');",
"",
"",
"return",
"redirect",
"(",
"$",
"request",
"->",
"input",
"(",
"'return_path'",
",",
"'/'",
")",
")",
";",
"}",
"}",
"else",
"{",
"// Subscribe user with activation token to website list and sync newsletter abos",
"$",
"subscribe",
"=",
"$",
"this",
"->",
"subscription",
"->",
"create",
"(",
"[",
"'email'",
"=>",
"$",
"request",
"->",
"input",
"(",
"'email'",
")",
",",
"'activation_token'",
"=>",
"md5",
"(",
"$",
"request",
"->",
"email",
".",
"\\",
"Carbon",
"\\",
"Carbon",
"::",
"now",
"(",
")",
")",
"]",
")",
";",
"}",
"$",
"subscribe",
"->",
"subscriptions",
"(",
")",
"->",
"attach",
"(",
"$",
"request",
"->",
"input",
"(",
"'newsletter_id'",
")",
")",
";",
"\\",
"Mail",
"::",
"send",
"(",
"'newsletter::Email.confirmation'",
",",
"array",
"(",
"'token'",
"=>",
"$",
"subscribe",
"->",
"activation_token",
",",
"'newsletter_id'",
"=>",
"$",
"request",
"->",
"input",
"(",
"'newsletter_id'",
")",
")",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"subscribe",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"subscribe",
"->",
"email",
",",
"$",
"subscribe",
"->",
"email",
")",
"->",
"subject",
"(",
"'Inscription!'",
")",
";",
"}",
")",
";",
"alert",
"(",
")",
"->",
"success",
"(",
"'<strong>Merci pour votre inscription!</strong><br/>Veuillez confirmer votre adresse email en cliquant le lien qui vous a été envoyé par email');",
"",
"",
"return",
"redirect",
"(",
"$",
"request",
"->",
"input",
"(",
"'return_path'",
",",
"'/'",
")",
")",
";",
"}"
] | Store a newly created resource in storage.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\Response | [
"Store",
"a",
"newly",
"created",
"resource",
"in",
"storage",
"."
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Frontend/InscriptionController.php#L76-L114 |
DesignPond/newsletter | src/Http/Controllers/Frontend/InscriptionController.php | InscriptionController.unsubscribe | public function unsubscribe(SubscribeRequest $request)
{
// find the abo
$abonne = $this->subscription->findByEmail( $request->input('email') );
if(!$abonne){
return redirect('/')->with(['status' => 'danger', 'message' => '<strong>Aucun abonné avec cet email</strong>']);
}
// Sync the abos to newsletter we have
$abonne->subscriptions()->detach($request->input('newsletter_id'));
$newsletter = $this->newsletter->find($request->input('newsletter_id'));
if(!$newsletter)
{
alert()->danger('Cette newsletter n\'existe pas');
return redirect('/');
}
//Subscribe to mailjet
$this->worker->setList($newsletter->list_id);
if(!$this->worker->removeContact($abonne->email))
{
throw new \designpond\newsletter\Exceptions\SubscribeUserException('Erreur synchronisation email vers mailjet');
}
// Delete person only if no subscription left
if($abonne->subscriptions->isEmpty())
{
$this->subscription->delete($abonne->email);
}
$back = $request->input('return_path', '/');
alert()->success('<strong>Vous avez été désinscrit</strong>');
return redirect($back);
} | php | public function unsubscribe(SubscribeRequest $request)
{
// find the abo
$abonne = $this->subscription->findByEmail( $request->input('email') );
if(!$abonne){
return redirect('/')->with(['status' => 'danger', 'message' => '<strong>Aucun abonné avec cet email</strong>']);
}
// Sync the abos to newsletter we have
$abonne->subscriptions()->detach($request->input('newsletter_id'));
$newsletter = $this->newsletter->find($request->input('newsletter_id'));
if(!$newsletter)
{
alert()->danger('Cette newsletter n\'existe pas');
return redirect('/');
}
//Subscribe to mailjet
$this->worker->setList($newsletter->list_id);
if(!$this->worker->removeContact($abonne->email))
{
throw new \designpond\newsletter\Exceptions\SubscribeUserException('Erreur synchronisation email vers mailjet');
}
// Delete person only if no subscription left
if($abonne->subscriptions->isEmpty())
{
$this->subscription->delete($abonne->email);
}
$back = $request->input('return_path', '/');
alert()->success('<strong>Vous avez été désinscrit</strong>');
return redirect($back);
} | [
"public",
"function",
"unsubscribe",
"(",
"SubscribeRequest",
"$",
"request",
")",
"{",
"// find the abo",
"$",
"abonne",
"=",
"$",
"this",
"->",
"subscription",
"->",
"findByEmail",
"(",
"$",
"request",
"->",
"input",
"(",
"'email'",
")",
")",
";",
"if",
"(",
"!",
"$",
"abonne",
")",
"{",
"return",
"redirect",
"(",
"'/'",
")",
"->",
"with",
"(",
"[",
"'status'",
"=>",
"'danger'",
",",
"'message'",
"=>",
"'<strong>Aucun abonné avec cet email</strong>']",
")",
";",
"",
"}",
"// Sync the abos to newsletter we have",
"$",
"abonne",
"->",
"subscriptions",
"(",
")",
"->",
"detach",
"(",
"$",
"request",
"->",
"input",
"(",
"'newsletter_id'",
")",
")",
";",
"$",
"newsletter",
"=",
"$",
"this",
"->",
"newsletter",
"->",
"find",
"(",
"$",
"request",
"->",
"input",
"(",
"'newsletter_id'",
")",
")",
";",
"if",
"(",
"!",
"$",
"newsletter",
")",
"{",
"alert",
"(",
")",
"->",
"danger",
"(",
"'Cette newsletter n\\'existe pas'",
")",
";",
"return",
"redirect",
"(",
"'/'",
")",
";",
"}",
"//Subscribe to mailjet",
"$",
"this",
"->",
"worker",
"->",
"setList",
"(",
"$",
"newsletter",
"->",
"list_id",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"worker",
"->",
"removeContact",
"(",
"$",
"abonne",
"->",
"email",
")",
")",
"{",
"throw",
"new",
"\\",
"designpond",
"\\",
"newsletter",
"\\",
"Exceptions",
"\\",
"SubscribeUserException",
"(",
"'Erreur synchronisation email vers mailjet'",
")",
";",
"}",
"// Delete person only if no subscription left",
"if",
"(",
"$",
"abonne",
"->",
"subscriptions",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"this",
"->",
"subscription",
"->",
"delete",
"(",
"$",
"abonne",
"->",
"email",
")",
";",
"}",
"$",
"back",
"=",
"$",
"request",
"->",
"input",
"(",
"'return_path'",
",",
"'/'",
")",
";",
"alert",
"(",
")",
"->",
"success",
"(",
"'<strong>Vous avez été désinscrit</strong>');",
"",
"",
"return",
"redirect",
"(",
"$",
"back",
")",
";",
"}"
] | Remove the specified resource from storage.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\Response | [
"Remove",
"the",
"specified",
"resource",
"from",
"storage",
"."
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Frontend/InscriptionController.php#L121-L161 |
DesignPond/newsletter | src/Http/Controllers/Frontend/InscriptionController.php | InscriptionController.resend | public function resend(Request $request)
{
$subscribe = $this->subscription->findByEmail($request->input('email'));
\Mail::send('newsletter::Email.confirmation', ['token' => $subscribe->activation_token, 'newsletter_id' => $request->input('newsletter_id')], function($message) use ($subscribe)
{
$message->to($subscribe->email, $subscribe->email)->subject('Inscription!');
});
alert()->success('<strong>Lien d\'activation envoyé</strong>');
return redirect('/');
} | php | public function resend(Request $request)
{
$subscribe = $this->subscription->findByEmail($request->input('email'));
\Mail::send('newsletter::Email.confirmation', ['token' => $subscribe->activation_token, 'newsletter_id' => $request->input('newsletter_id')], function($message) use ($subscribe)
{
$message->to($subscribe->email, $subscribe->email)->subject('Inscription!');
});
alert()->success('<strong>Lien d\'activation envoyé</strong>');
return redirect('/');
} | [
"public",
"function",
"resend",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"subscribe",
"=",
"$",
"this",
"->",
"subscription",
"->",
"findByEmail",
"(",
"$",
"request",
"->",
"input",
"(",
"'email'",
")",
")",
";",
"\\",
"Mail",
"::",
"send",
"(",
"'newsletter::Email.confirmation'",
",",
"[",
"'token'",
"=>",
"$",
"subscribe",
"->",
"activation_token",
",",
"'newsletter_id'",
"=>",
"$",
"request",
"->",
"input",
"(",
"'newsletter_id'",
")",
"]",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"subscribe",
")",
"{",
"$",
"message",
"->",
"to",
"(",
"$",
"subscribe",
"->",
"email",
",",
"$",
"subscribe",
"->",
"email",
")",
"->",
"subject",
"(",
"'Inscription!'",
")",
";",
"}",
")",
";",
"alert",
"(",
")",
"->",
"success",
"(",
"'<strong>Lien d\\'activation envoyé</strong>')",
";",
"",
"return",
"redirect",
"(",
"'/'",
")",
";",
"}"
] | Resend activation link email
POST /inscription/resend/email
@return Response | [
"Resend",
"activation",
"link",
"email",
"POST",
"/",
"inscription",
"/",
"resend",
"/",
"email"
] | train | https://github.com/DesignPond/newsletter/blob/0bf0e7a8a42fa4b90a5e937771bb80058e0a91c3/src/Http/Controllers/Frontend/InscriptionController.php#L169-L181 |
songshenzong/log | src/DataCollector/EventCollector.php | EventCollector.prepareParams | protected function prepareParams($params)
{
$data = [];
foreach ($params as $key => $value) {
if (is_object($value) && Str::is('Illuminate\*\Events\*', get_class($value))) {
$value = $this->prepareParams(get_object_vars($value));
}
$data[$key] = htmlentities($this->exporter->exportValue($value), ENT_QUOTES, 'UTF-8', false);
}
return $data;
} | php | protected function prepareParams($params)
{
$data = [];
foreach ($params as $key => $value) {
if (is_object($value) && Str::is('Illuminate\*\Events\*', get_class($value))) {
$value = $this->prepareParams(get_object_vars($value));
}
$data[$key] = htmlentities($this->exporter->exportValue($value), ENT_QUOTES, 'UTF-8', false);
}
return $data;
} | [
"protected",
"function",
"prepareParams",
"(",
"$",
"params",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"Str",
"::",
"is",
"(",
"'Illuminate\\*\\Events\\*'",
",",
"get_class",
"(",
"$",
"value",
")",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"prepareParams",
"(",
"get_object_vars",
"(",
"$",
"value",
")",
")",
";",
"}",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"htmlentities",
"(",
"$",
"this",
"->",
"exporter",
"->",
"exportValue",
"(",
"$",
"value",
")",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
",",
"false",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | @param $params
@return array | [
"@param",
"$params"
] | train | https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/DataCollector/EventCollector.php#L102-L113 |
thecodingmachine/mvc.splash-common | src/Mouf/Mvc/Splash/Routers/NotFoundRouter.php | NotFoundRouter.process | public function process(Request $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($this->log) {
$this->log->info('404 - Page not found on URL: '.$request->getUri()->getPath());
}
$response = SplashUtils::buildControllerResponse(
function () use ($request) {
return $this->pageNotFoundController->pageNotFound($request);
}
);
return $response;
} | php | public function process(Request $request, RequestHandlerInterface $handler): ResponseInterface
{
if ($this->log) {
$this->log->info('404 - Page not found on URL: '.$request->getUri()->getPath());
}
$response = SplashUtils::buildControllerResponse(
function () use ($request) {
return $this->pageNotFoundController->pageNotFound($request);
}
);
return $response;
} | [
"public",
"function",
"process",
"(",
"Request",
"$",
"request",
",",
"RequestHandlerInterface",
"$",
"handler",
")",
":",
"ResponseInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"log",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"'404 - Page not found on URL: '",
".",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
")",
";",
"}",
"$",
"response",
"=",
"SplashUtils",
"::",
"buildControllerResponse",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"request",
")",
"{",
"return",
"$",
"this",
"->",
"pageNotFoundController",
"->",
"pageNotFound",
"(",
"$",
"request",
")",
";",
"}",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Process an incoming server request and return a response, optionally delegating
to the next middleware component to create the response.
@param Request $request
@param RequestHandlerInterface $handler
@return ResponseInterface | [
"Process",
"an",
"incoming",
"server",
"request",
"and",
"return",
"a",
"response",
"optionally",
"delegating",
"to",
"the",
"next",
"middleware",
"component",
"to",
"create",
"the",
"response",
"."
] | train | https://github.com/thecodingmachine/mvc.splash-common/blob/eed0269ceda4d7d090a330a220490906a7aa60bd/src/Mouf/Mvc/Splash/Routers/NotFoundRouter.php#L49-L62 |
prooph/link-monitor | src/Controller/ProcessViewController.php | ProcessViewController.populateTaskEvents | private function populateTaskEvents(array &$process)
{
foreach ($process['tasks'] as &$task) {
$task['events'] = [];
foreach ($process['events'] as $event) {
if ($event['task_id'] == $task['id']) {
$task['events'][] = $event;
}
}
}
} | php | private function populateTaskEvents(array &$process)
{
foreach ($process['tasks'] as &$task) {
$task['events'] = [];
foreach ($process['events'] as $event) {
if ($event['task_id'] == $task['id']) {
$task['events'][] = $event;
}
}
}
} | [
"private",
"function",
"populateTaskEvents",
"(",
"array",
"&",
"$",
"process",
")",
"{",
"foreach",
"(",
"$",
"process",
"[",
"'tasks'",
"]",
"as",
"&",
"$",
"task",
")",
"{",
"$",
"task",
"[",
"'events'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"process",
"[",
"'events'",
"]",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"[",
"'task_id'",
"]",
"==",
"$",
"task",
"[",
"'id'",
"]",
")",
"{",
"$",
"task",
"[",
"'events'",
"]",
"[",
"]",
"=",
"$",
"event",
";",
"}",
"}",
"}",
"}"
] | Copy each task event to its task
@param array $process | [
"Copy",
"each",
"task",
"event",
"to",
"its",
"task"
] | train | https://github.com/prooph/link-monitor/blob/5dd12a4bda48eb05471181bf4dab43938cf39df8/src/Controller/ProcessViewController.php#L185-L195 |
seagoj/devtools | FileLogger.php | FileLogger.write | public function write($content, $result = null)
{
return file_put_contents(
self::$filename,
self::$formatter->format($content, $result) . PHP_EOL,
FILE_APPEND
);
} | php | public function write($content, $result = null)
{
return file_put_contents(
self::$filename,
self::$formatter->format($content, $result) . PHP_EOL,
FILE_APPEND
);
} | [
"public",
"function",
"write",
"(",
"$",
"content",
",",
"$",
"result",
"=",
"null",
")",
"{",
"return",
"file_put_contents",
"(",
"self",
"::",
"$",
"filename",
",",
"self",
"::",
"$",
"formatter",
"->",
"format",
"(",
"$",
"content",
",",
"$",
"result",
")",
".",
"PHP_EOL",
",",
"FILE_APPEND",
")",
";",
"}"
] | /* } | [
"/",
"*",
"}"
] | train | https://github.com/seagoj/devtools/blob/15dd451a0b00c272d3e1961f114342d5e0f526ba/FileLogger.php#L20-L27 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Core/Transformer/Writer/Statistics.php | Statistics.getDeprecatedCounter | protected function getDeprecatedCounter(ProjectDescriptor $project)
{
$deprecatedCounter = 0;
/** @var DescriptorAbstract $element */
foreach ($project->getIndexes()->get('elements') as $element) {
if ($element->isDeprecated()) {
$deprecatedCounter += 1;
}
}
return $deprecatedCounter;
} | php | protected function getDeprecatedCounter(ProjectDescriptor $project)
{
$deprecatedCounter = 0;
/** @var DescriptorAbstract $element */
foreach ($project->getIndexes()->get('elements') as $element) {
if ($element->isDeprecated()) {
$deprecatedCounter += 1;
}
}
return $deprecatedCounter;
} | [
"protected",
"function",
"getDeprecatedCounter",
"(",
"ProjectDescriptor",
"$",
"project",
")",
"{",
"$",
"deprecatedCounter",
"=",
"0",
";",
"/** @var DescriptorAbstract $element */",
"foreach",
"(",
"$",
"project",
"->",
"getIndexes",
"(",
")",
"->",
"get",
"(",
"'elements'",
")",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"isDeprecated",
"(",
")",
")",
"{",
"$",
"deprecatedCounter",
"+=",
"1",
";",
"}",
"}",
"return",
"$",
"deprecatedCounter",
";",
"}"
] | Get number of deprecated elements.
@param ProjectDescriptor $project
@return int | [
"Get",
"number",
"of",
"deprecated",
"elements",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Core/Transformer/Writer/Statistics.php#L135-L147 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Security/Policy.php | Dwoo_Security_Policy.allowPhpFunction | public function allowPhpFunction($func)
{
if (is_array($func))
foreach ($func as $fname)
$this->allowedPhpFunctions[strtolower($fname)] = true;
else
$this->allowedPhpFunctions[strtolower($func)] = true;
} | php | public function allowPhpFunction($func)
{
if (is_array($func))
foreach ($func as $fname)
$this->allowedPhpFunctions[strtolower($fname)] = true;
else
$this->allowedPhpFunctions[strtolower($func)] = true;
} | [
"public",
"function",
"allowPhpFunction",
"(",
"$",
"func",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"func",
")",
")",
"foreach",
"(",
"$",
"func",
"as",
"$",
"fname",
")",
"$",
"this",
"->",
"allowedPhpFunctions",
"[",
"strtolower",
"(",
"$",
"fname",
")",
"]",
"=",
"true",
";",
"else",
"$",
"this",
"->",
"allowedPhpFunctions",
"[",
"strtolower",
"(",
"$",
"func",
")",
"]",
"=",
"true",
";",
"}"
] | adds a php function to the allowed list
@param mixed $func function name or array of function names | [
"adds",
"a",
"php",
"function",
"to",
"the",
"allowed",
"list"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Security/Policy.php#L84-L91 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Security/Policy.php | Dwoo_Security_Policy.allowDirectory | public function allowDirectory($path)
{
if (is_array($path))
foreach ($path as $dir)
$this->allowedDirectories[realpath($dir)] = true;
else
$this->allowedDirectories[realpath($path)] = true;
} | php | public function allowDirectory($path)
{
if (is_array($path))
foreach ($path as $dir)
$this->allowedDirectories[realpath($dir)] = true;
else
$this->allowedDirectories[realpath($path)] = true;
} | [
"public",
"function",
"allowDirectory",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"path",
")",
")",
"foreach",
"(",
"$",
"path",
"as",
"$",
"dir",
")",
"$",
"this",
"->",
"allowedDirectories",
"[",
"realpath",
"(",
"$",
"dir",
")",
"]",
"=",
"true",
";",
"else",
"$",
"this",
"->",
"allowedDirectories",
"[",
"realpath",
"(",
"$",
"path",
")",
"]",
"=",
"true",
";",
"}"
] | adds a directory to the safelist for includes and other file-access plugins
note that all the includePath directories you provide to the Dwoo_Template_File class
are automatically marked as safe
@param mixed $path a path name or an array of paths | [
"adds",
"a",
"directory",
"to",
"the",
"safelist",
"for",
"includes",
"and",
"other",
"file",
"-",
"access",
"plugins"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Security/Policy.php#L126-L133 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Security/Policy.php | Dwoo_Security_Policy.disallowDirectory | public function disallowDirectory($path)
{
if (is_array($path))
foreach ($path as $dir)
unset($this->allowedDirectories[realpath($dir)]);
else
unset($this->allowedDirectories[realpath($path)]);
} | php | public function disallowDirectory($path)
{
if (is_array($path))
foreach ($path as $dir)
unset($this->allowedDirectories[realpath($dir)]);
else
unset($this->allowedDirectories[realpath($path)]);
} | [
"public",
"function",
"disallowDirectory",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"path",
")",
")",
"foreach",
"(",
"$",
"path",
"as",
"$",
"dir",
")",
"unset",
"(",
"$",
"this",
"->",
"allowedDirectories",
"[",
"realpath",
"(",
"$",
"dir",
")",
"]",
")",
";",
"else",
"unset",
"(",
"$",
"this",
"->",
"allowedDirectories",
"[",
"realpath",
"(",
"$",
"path",
")",
"]",
")",
";",
"}"
] | removes a directory from the safelist
@param mixed $path a path name or an array of paths | [
"removes",
"a",
"directory",
"from",
"the",
"safelist"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Security/Policy.php#L140-L147 |
fkooman/php-lib-http | src/fkooman/Http/Request.php | Request.getHeader | public function getHeader($keyName)
{
$headers = $this->getHeaders();
$keyName = self::normalizeHeaderKeyName($keyName);
if (array_key_exists($keyName, $headers)) {
return $headers[$keyName];
}
return;
} | php | public function getHeader($keyName)
{
$headers = $this->getHeaders();
$keyName = self::normalizeHeaderKeyName($keyName);
if (array_key_exists($keyName, $headers)) {
return $headers[$keyName];
}
return;
} | [
"public",
"function",
"getHeader",
"(",
"$",
"keyName",
")",
"{",
"$",
"headers",
"=",
"$",
"this",
"->",
"getHeaders",
"(",
")",
";",
"$",
"keyName",
"=",
"self",
"::",
"normalizeHeaderKeyName",
"(",
"$",
"keyName",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"keyName",
",",
"$",
"headers",
")",
")",
"{",
"return",
"$",
"headers",
"[",
"$",
"keyName",
"]",
";",
"}",
"return",
";",
"}"
] | Get the value of the request header keyname.
@param string $keyName the HTTP header keyname
@return mixed the value of the header keyname as string or null if the
header key is not set | [
"Get",
"the",
"value",
"of",
"the",
"request",
"header",
"keyname",
"."
] | train | https://github.com/fkooman/php-lib-http/blob/94956a480459b7f6b880d61f21ef03e683deb995/src/fkooman/Http/Request.php#L130-L139 |
fkooman/php-lib-http | src/fkooman/Http/Request.php | Request.getHeaders | public function getHeaders()
{
$headers = [];
foreach ($this->srv as $k => $v) {
$headers[self::normalizeHeaderKeyName($k)] = $v;
}
return $headers;
} | php | public function getHeaders()
{
$headers = [];
foreach ($this->srv as $k => $v) {
$headers[self::normalizeHeaderKeyName($k)] = $v;
}
return $headers;
} | [
"public",
"function",
"getHeaders",
"(",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"srv",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"headers",
"[",
"self",
"::",
"normalizeHeaderKeyName",
"(",
"$",
"k",
")",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] | Get the HTTP headers.
@return array the HTTP headers as a key-value array | [
"Get",
"the",
"HTTP",
"headers",
"."
] | train | https://github.com/fkooman/php-lib-http/blob/94956a480459b7f6b880d61f21ef03e683deb995/src/fkooman/Http/Request.php#L146-L154 |
fkooman/php-lib-http | src/fkooman/Http/Request.php | Request.normalizeHeaderKeyName | public static function normalizeHeaderKeyName($keyName)
{
if (0 === mb_stripos($keyName, 'HTTP_') || 0 === mb_stripos($keyName, 'HTTP-')) {
$keyName = mb_substr($keyName, 5);
}
return str_replace(
' ',
'-',
mb_convert_case(
mb_convert_case(
str_replace(
['_', '-'],
' ',
$keyName
),
MB_CASE_LOWER
),
MB_CASE_TITLE
)
);
} | php | public static function normalizeHeaderKeyName($keyName)
{
if (0 === mb_stripos($keyName, 'HTTP_') || 0 === mb_stripos($keyName, 'HTTP-')) {
$keyName = mb_substr($keyName, 5);
}
return str_replace(
' ',
'-',
mb_convert_case(
mb_convert_case(
str_replace(
['_', '-'],
' ',
$keyName
),
MB_CASE_LOWER
),
MB_CASE_TITLE
)
);
} | [
"public",
"static",
"function",
"normalizeHeaderKeyName",
"(",
"$",
"keyName",
")",
"{",
"if",
"(",
"0",
"===",
"mb_stripos",
"(",
"$",
"keyName",
",",
"'HTTP_'",
")",
"||",
"0",
"===",
"mb_stripos",
"(",
"$",
"keyName",
",",
"'HTTP-'",
")",
")",
"{",
"$",
"keyName",
"=",
"mb_substr",
"(",
"$",
"keyName",
",",
"5",
")",
";",
"}",
"return",
"str_replace",
"(",
"' '",
",",
"'-'",
",",
"mb_convert_case",
"(",
"mb_convert_case",
"(",
"str_replace",
"(",
"[",
"'_'",
",",
"'-'",
"]",
",",
"' '",
",",
"$",
"keyName",
")",
",",
"MB_CASE_LOWER",
")",
",",
"MB_CASE_TITLE",
")",
")",
";",
"}"
] | Normalize a HTTP request header keyname. It will remove any HTTP_ or
HTTP- prefix, replace all underscores with dashes and capitalize the
first letter(s). For example:.
HTTP_ACCEPT: Accept
CONTENT_TYPE: Content-Type
@param string $keyName the keyname to normalize
@return string the normalized keyname | [
"Normalize",
"a",
"HTTP",
"request",
"header",
"keyname",
".",
"It",
"will",
"remove",
"any",
"HTTP_",
"or",
"HTTP",
"-",
"prefix",
"replace",
"all",
"underscores",
"with",
"dashes",
"and",
"capitalize",
"the",
"first",
"letter",
"(",
"s",
")",
".",
"For",
"example",
":",
"."
] | train | https://github.com/fkooman/php-lib-http/blob/94956a480459b7f6b880d61f21ef03e683deb995/src/fkooman/Http/Request.php#L178-L199 |
thelia-modules/CustomerGroup | Model/Map/CustomerCustomerGroupTableMap.php | CustomerCustomerGroupTableMap.addInstanceToPool | public static function addInstanceToPool($obj, $key = null)
{
if (Propel::isInstancePoolingEnabled()) {
if (null === $key) {
$key = serialize(array((string) $obj->getCustomerId(), (string) $obj->getCustomerGroupId()));
} // if key === null
self::$instances[$key] = $obj;
}
} | php | public static function addInstanceToPool($obj, $key = null)
{
if (Propel::isInstancePoolingEnabled()) {
if (null === $key) {
$key = serialize(array((string) $obj->getCustomerId(), (string) $obj->getCustomerGroupId()));
} // if key === null
self::$instances[$key] = $obj;
}
} | [
"public",
"static",
"function",
"addInstanceToPool",
"(",
"$",
"obj",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"Propel",
"::",
"isInstancePoolingEnabled",
"(",
")",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"key",
")",
"{",
"$",
"key",
"=",
"serialize",
"(",
"array",
"(",
"(",
"string",
")",
"$",
"obj",
"->",
"getCustomerId",
"(",
")",
",",
"(",
"string",
")",
"$",
"obj",
"->",
"getCustomerGroupId",
"(",
")",
")",
")",
";",
"}",
"// if key === null",
"self",
"::",
"$",
"instances",
"[",
"$",
"key",
"]",
"=",
"$",
"obj",
";",
"}",
"}"
] | Adds an object to the instance pool.
Propel keeps cached copies of objects in an instance pool when they are retrieved
from the database. In some cases you may need to explicitly add objects
to the cache in order to ensure that the same objects are always returned by find*()
and findPk*() calls.
@param \CustomerGroup\Model\CustomerCustomerGroup $obj A \CustomerGroup\Model\CustomerCustomerGroup object.
@param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). | [
"Adds",
"an",
"object",
"to",
"the",
"instance",
"pool",
"."
] | train | https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Model/Map/CustomerCustomerGroupTableMap.php#L159-L167 |
thelia-modules/CustomerGroup | Model/Map/CustomerCustomerGroupTableMap.php | CustomerCustomerGroupTableMap.removeInstanceFromPool | public static function removeInstanceFromPool($value)
{
if (Propel::isInstancePoolingEnabled() && null !== $value) {
if (is_object($value) && $value instanceof \CustomerGroup\Model\CustomerCustomerGroup) {
$key = serialize(array((string) $value->getCustomerId(), (string) $value->getCustomerGroupId()));
} elseif (is_array($value) && count($value) === 2) {
// assume we've been passed a primary key";
$key = serialize(array((string) $value[0], (string) $value[1]));
} elseif ($value instanceof Criteria) {
self::$instances = [];
return;
} else {
$e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \CustomerGroup\Model\CustomerCustomerGroup object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true)));
throw $e;
}
unset(self::$instances[$key]);
}
} | php | public static function removeInstanceFromPool($value)
{
if (Propel::isInstancePoolingEnabled() && null !== $value) {
if (is_object($value) && $value instanceof \CustomerGroup\Model\CustomerCustomerGroup) {
$key = serialize(array((string) $value->getCustomerId(), (string) $value->getCustomerGroupId()));
} elseif (is_array($value) && count($value) === 2) {
// assume we've been passed a primary key";
$key = serialize(array((string) $value[0], (string) $value[1]));
} elseif ($value instanceof Criteria) {
self::$instances = [];
return;
} else {
$e = new PropelException("Invalid value passed to removeInstanceFromPool(). Expected primary key or \CustomerGroup\Model\CustomerCustomerGroup object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true)));
throw $e;
}
unset(self::$instances[$key]);
}
} | [
"public",
"static",
"function",
"removeInstanceFromPool",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"Propel",
"::",
"isInstancePoolingEnabled",
"(",
")",
"&&",
"null",
"!==",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"instanceof",
"\\",
"CustomerGroup",
"\\",
"Model",
"\\",
"CustomerCustomerGroup",
")",
"{",
"$",
"key",
"=",
"serialize",
"(",
"array",
"(",
"(",
"string",
")",
"$",
"value",
"->",
"getCustomerId",
"(",
")",
",",
"(",
"string",
")",
"$",
"value",
"->",
"getCustomerGroupId",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"count",
"(",
"$",
"value",
")",
"===",
"2",
")",
"{",
"// assume we've been passed a primary key\";",
"$",
"key",
"=",
"serialize",
"(",
"array",
"(",
"(",
"string",
")",
"$",
"value",
"[",
"0",
"]",
",",
"(",
"string",
")",
"$",
"value",
"[",
"1",
"]",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"instanceof",
"Criteria",
")",
"{",
"self",
"::",
"$",
"instances",
"=",
"[",
"]",
";",
"return",
";",
"}",
"else",
"{",
"$",
"e",
"=",
"new",
"PropelException",
"(",
"\"Invalid value passed to removeInstanceFromPool(). Expected primary key or \\CustomerGroup\\Model\\CustomerCustomerGroup object; got \"",
".",
"(",
"is_object",
"(",
"$",
"value",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
".",
"' object.'",
":",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
")",
")",
";",
"throw",
"$",
"e",
";",
"}",
"unset",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] | Removes an object from the instance pool.
Propel keeps cached copies of objects in an instance pool when they are retrieved
from the database. In some cases -- especially when you override doDelete
methods in your stub classes -- you may need to explicitly remove objects
from the cache in order to prevent returning objects that no longer exist.
@param mixed $value A \CustomerGroup\Model\CustomerCustomerGroup object or a primary key value. | [
"Removes",
"an",
"object",
"from",
"the",
"instance",
"pool",
"."
] | train | https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Model/Map/CustomerCustomerGroupTableMap.php#L179-L199 |
thelia-modules/CustomerGroup | Model/Map/CustomerCustomerGroupTableMap.php | CustomerCustomerGroupTableMap.addSelectColumns | public static function addSelectColumns(Criteria $criteria, $alias = null)
{
if (null === $alias) {
$criteria->addSelectColumn(CustomerCustomerGroupTableMap::CUSTOMER_ID);
$criteria->addSelectColumn(CustomerCustomerGroupTableMap::CUSTOMER_GROUP_ID);
} else {
$criteria->addSelectColumn($alias . '.CUSTOMER_ID');
$criteria->addSelectColumn($alias . '.CUSTOMER_GROUP_ID');
}
} | php | public static function addSelectColumns(Criteria $criteria, $alias = null)
{
if (null === $alias) {
$criteria->addSelectColumn(CustomerCustomerGroupTableMap::CUSTOMER_ID);
$criteria->addSelectColumn(CustomerCustomerGroupTableMap::CUSTOMER_GROUP_ID);
} else {
$criteria->addSelectColumn($alias . '.CUSTOMER_ID');
$criteria->addSelectColumn($alias . '.CUSTOMER_GROUP_ID');
}
} | [
"public",
"static",
"function",
"addSelectColumns",
"(",
"Criteria",
"$",
"criteria",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"alias",
")",
"{",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"CustomerCustomerGroupTableMap",
"::",
"CUSTOMER_ID",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"CustomerCustomerGroupTableMap",
"::",
"CUSTOMER_GROUP_ID",
")",
";",
"}",
"else",
"{",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"$",
"alias",
".",
"'.CUSTOMER_ID'",
")",
";",
"$",
"criteria",
"->",
"addSelectColumn",
"(",
"$",
"alias",
".",
"'.CUSTOMER_GROUP_ID'",
")",
";",
"}",
"}"
] | Add all the columns needed to create a new object.
Note: any columns that were marked with lazyLoad="true" in the
XML schema will not be added to the select list and only loaded
on demand.
@param Criteria $criteria object containing the columns to add.
@param string $alias optional table alias
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException. | [
"Add",
"all",
"the",
"columns",
"needed",
"to",
"create",
"a",
"new",
"object",
"."
] | train | https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Model/Map/CustomerCustomerGroupTableMap.php#L332-L341 |
thelia-modules/CustomerGroup | Model/Map/CustomerCustomerGroupTableMap.php | CustomerCustomerGroupTableMap.buildTableMap | public static function buildTableMap()
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap(CustomerCustomerGroupTableMap::DATABASE_NAME);
if (!$dbMap->hasTable(CustomerCustomerGroupTableMap::TABLE_NAME)) {
$dbMap->addTableObject(new CustomerCustomerGroupTableMap());
}
} | php | public static function buildTableMap()
{
$dbMap = Propel::getServiceContainer()->getDatabaseMap(CustomerCustomerGroupTableMap::DATABASE_NAME);
if (!$dbMap->hasTable(CustomerCustomerGroupTableMap::TABLE_NAME)) {
$dbMap->addTableObject(new CustomerCustomerGroupTableMap());
}
} | [
"public",
"static",
"function",
"buildTableMap",
"(",
")",
"{",
"$",
"dbMap",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getDatabaseMap",
"(",
"CustomerCustomerGroupTableMap",
"::",
"DATABASE_NAME",
")",
";",
"if",
"(",
"!",
"$",
"dbMap",
"->",
"hasTable",
"(",
"CustomerCustomerGroupTableMap",
"::",
"TABLE_NAME",
")",
")",
"{",
"$",
"dbMap",
"->",
"addTableObject",
"(",
"new",
"CustomerCustomerGroupTableMap",
"(",
")",
")",
";",
"}",
"}"
] | Add a TableMap instance to the database for this tableMap class. | [
"Add",
"a",
"TableMap",
"instance",
"to",
"the",
"database",
"for",
"this",
"tableMap",
"class",
"."
] | train | https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Model/Map/CustomerCustomerGroupTableMap.php#L358-L364 |
thelia-modules/CustomerGroup | Model/Map/CustomerCustomerGroupTableMap.php | CustomerCustomerGroupTableMap.doDelete | public static function doDelete($values, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(CustomerCustomerGroupTableMap::DATABASE_NAME);
}
if ($values instanceof Criteria) {
// rename for clarity
$criteria = $values;
} elseif ($values instanceof \CustomerGroup\Model\CustomerCustomerGroup) { // it's a model object
// create criteria based on pk values
$criteria = $values->buildPkeyCriteria();
} else { // it's a primary key, or an array of pks
$criteria = new Criteria(CustomerCustomerGroupTableMap::DATABASE_NAME);
// primary key is composite; we therefore, expect
// the primary key passed to be an array of pkey values
if (count($values) == count($values, COUNT_RECURSIVE)) {
// array is not multi-dimensional
$values = array($values);
}
foreach ($values as $value) {
$criterion = $criteria->getNewCriterion(CustomerCustomerGroupTableMap::CUSTOMER_ID, $value[0]);
$criterion->addAnd($criteria->getNewCriterion(CustomerCustomerGroupTableMap::CUSTOMER_GROUP_ID, $value[1]));
$criteria->addOr($criterion);
}
}
$query = CustomerCustomerGroupQuery::create()->mergeWith($criteria);
if ($values instanceof Criteria) { CustomerCustomerGroupTableMap::clearInstancePool();
} elseif (!is_object($values)) { // it's a primary key, or an array of pks
foreach ((array) $values as $singleval) { CustomerCustomerGroupTableMap::removeInstanceFromPool($singleval);
}
}
return $query->delete($con);
} | php | public static function doDelete($values, ConnectionInterface $con = null)
{
if (null === $con) {
$con = Propel::getServiceContainer()->getWriteConnection(CustomerCustomerGroupTableMap::DATABASE_NAME);
}
if ($values instanceof Criteria) {
// rename for clarity
$criteria = $values;
} elseif ($values instanceof \CustomerGroup\Model\CustomerCustomerGroup) { // it's a model object
// create criteria based on pk values
$criteria = $values->buildPkeyCriteria();
} else { // it's a primary key, or an array of pks
$criteria = new Criteria(CustomerCustomerGroupTableMap::DATABASE_NAME);
// primary key is composite; we therefore, expect
// the primary key passed to be an array of pkey values
if (count($values) == count($values, COUNT_RECURSIVE)) {
// array is not multi-dimensional
$values = array($values);
}
foreach ($values as $value) {
$criterion = $criteria->getNewCriterion(CustomerCustomerGroupTableMap::CUSTOMER_ID, $value[0]);
$criterion->addAnd($criteria->getNewCriterion(CustomerCustomerGroupTableMap::CUSTOMER_GROUP_ID, $value[1]));
$criteria->addOr($criterion);
}
}
$query = CustomerCustomerGroupQuery::create()->mergeWith($criteria);
if ($values instanceof Criteria) { CustomerCustomerGroupTableMap::clearInstancePool();
} elseif (!is_object($values)) { // it's a primary key, or an array of pks
foreach ((array) $values as $singleval) { CustomerCustomerGroupTableMap::removeInstanceFromPool($singleval);
}
}
return $query->delete($con);
} | [
"public",
"static",
"function",
"doDelete",
"(",
"$",
"values",
",",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"con",
")",
"{",
"$",
"con",
"=",
"Propel",
"::",
"getServiceContainer",
"(",
")",
"->",
"getWriteConnection",
"(",
"CustomerCustomerGroupTableMap",
"::",
"DATABASE_NAME",
")",
";",
"}",
"if",
"(",
"$",
"values",
"instanceof",
"Criteria",
")",
"{",
"// rename for clarity",
"$",
"criteria",
"=",
"$",
"values",
";",
"}",
"elseif",
"(",
"$",
"values",
"instanceof",
"\\",
"CustomerGroup",
"\\",
"Model",
"\\",
"CustomerCustomerGroup",
")",
"{",
"// it's a model object",
"// create criteria based on pk values",
"$",
"criteria",
"=",
"$",
"values",
"->",
"buildPkeyCriteria",
"(",
")",
";",
"}",
"else",
"{",
"// it's a primary key, or an array of pks",
"$",
"criteria",
"=",
"new",
"Criteria",
"(",
"CustomerCustomerGroupTableMap",
"::",
"DATABASE_NAME",
")",
";",
"// primary key is composite; we therefore, expect",
"// the primary key passed to be an array of pkey values",
"if",
"(",
"count",
"(",
"$",
"values",
")",
"==",
"count",
"(",
"$",
"values",
",",
"COUNT_RECURSIVE",
")",
")",
"{",
"// array is not multi-dimensional",
"$",
"values",
"=",
"array",
"(",
"$",
"values",
")",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"criterion",
"=",
"$",
"criteria",
"->",
"getNewCriterion",
"(",
"CustomerCustomerGroupTableMap",
"::",
"CUSTOMER_ID",
",",
"$",
"value",
"[",
"0",
"]",
")",
";",
"$",
"criterion",
"->",
"addAnd",
"(",
"$",
"criteria",
"->",
"getNewCriterion",
"(",
"CustomerCustomerGroupTableMap",
"::",
"CUSTOMER_GROUP_ID",
",",
"$",
"value",
"[",
"1",
"]",
")",
")",
";",
"$",
"criteria",
"->",
"addOr",
"(",
"$",
"criterion",
")",
";",
"}",
"}",
"$",
"query",
"=",
"CustomerCustomerGroupQuery",
"::",
"create",
"(",
")",
"->",
"mergeWith",
"(",
"$",
"criteria",
")",
";",
"if",
"(",
"$",
"values",
"instanceof",
"Criteria",
")",
"{",
"CustomerCustomerGroupTableMap",
"::",
"clearInstancePool",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"is_object",
"(",
"$",
"values",
")",
")",
"{",
"// it's a primary key, or an array of pks",
"foreach",
"(",
"(",
"array",
")",
"$",
"values",
"as",
"$",
"singleval",
")",
"{",
"CustomerCustomerGroupTableMap",
"::",
"removeInstanceFromPool",
"(",
"$",
"singleval",
")",
";",
"}",
"}",
"return",
"$",
"query",
"->",
"delete",
"(",
"$",
"con",
")",
";",
"}"
] | Performs a DELETE on the database, given a CustomerCustomerGroup or Criteria object OR a primary key value.
@param mixed $values Criteria or CustomerCustomerGroup object or primary key or array of primary keys
which is used to create the DELETE statement
@param ConnectionInterface $con the connection to use
@return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows
if supported by native driver or if emulated using Propel.
@throws PropelException Any exceptions caught during processing will be
rethrown wrapped into a PropelException. | [
"Performs",
"a",
"DELETE",
"on",
"the",
"database",
"given",
"a",
"CustomerCustomerGroup",
"or",
"Criteria",
"object",
"OR",
"a",
"primary",
"key",
"value",
"."
] | train | https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Model/Map/CustomerCustomerGroupTableMap.php#L377-L413 |
mothership-ec/composer | src/Composer/Factory.php | Factory.getCacheDir | protected static function getCacheDir($home)
{
$cacheDir = getenv('COMPOSER_CACHE_DIR');
if (!$cacheDir) {
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ($cacheDir = getenv('LOCALAPPDATA')) {
$cacheDir .= '/Composer';
} else {
$cacheDir = $home . '/cache';
}
$cacheDir = strtr($cacheDir, '\\', '/');
} else {
$cacheDir = $home.'/cache';
}
}
return $cacheDir;
} | php | protected static function getCacheDir($home)
{
$cacheDir = getenv('COMPOSER_CACHE_DIR');
if (!$cacheDir) {
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if ($cacheDir = getenv('LOCALAPPDATA')) {
$cacheDir .= '/Composer';
} else {
$cacheDir = $home . '/cache';
}
$cacheDir = strtr($cacheDir, '\\', '/');
} else {
$cacheDir = $home.'/cache';
}
}
return $cacheDir;
} | [
"protected",
"static",
"function",
"getCacheDir",
"(",
"$",
"home",
")",
"{",
"$",
"cacheDir",
"=",
"getenv",
"(",
"'COMPOSER_CACHE_DIR'",
")",
";",
"if",
"(",
"!",
"$",
"cacheDir",
")",
"{",
"if",
"(",
"defined",
"(",
"'PHP_WINDOWS_VERSION_MAJOR'",
")",
")",
"{",
"if",
"(",
"$",
"cacheDir",
"=",
"getenv",
"(",
"'LOCALAPPDATA'",
")",
")",
"{",
"$",
"cacheDir",
".=",
"'/Composer'",
";",
"}",
"else",
"{",
"$",
"cacheDir",
"=",
"$",
"home",
".",
"'/cache'",
";",
"}",
"$",
"cacheDir",
"=",
"strtr",
"(",
"$",
"cacheDir",
",",
"'\\\\'",
",",
"'/'",
")",
";",
"}",
"else",
"{",
"$",
"cacheDir",
"=",
"$",
"home",
".",
"'/cache'",
";",
"}",
"}",
"return",
"$",
"cacheDir",
";",
"}"
] | @param string $home
@return string | [
"@param",
"string",
"$home"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Factory.php#L67-L84 |
mothership-ec/composer | src/Composer/Factory.php | Factory.createComposer | public function createComposer(IOInterface $io, $localConfig = null, $disablePlugins = false, $cwd = null, $fullLoad = true)
{
$cwd = $cwd ?: getcwd();
// load Composer configuration
if (null === $localConfig) {
$localConfig = static::getComposerFile();
}
if (is_string($localConfig)) {
$composerFile = $localConfig;
$file = new JsonFile($localConfig, new RemoteFilesystem($io));
if (!$file->exists()) {
if ($localConfig === './composer.json' || $localConfig === 'composer.json') {
$message = 'Composer could not find a composer.json file in '.$cwd;
} else {
$message = 'Composer could not find the config file: '.$localConfig;
}
$instructions = 'To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section';
throw new \InvalidArgumentException($message.PHP_EOL.$instructions);
}
$file->validateSchema(JsonFile::LAX_SCHEMA);
$localConfig = $file->read();
}
// Load config and override with local config/auth config
$config = static::createConfig($io, $cwd);
$config->merge($localConfig);
if (isset($composerFile)) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $composerFile);
}
$localAuthFile = new JsonFile(dirname(realpath($composerFile)) . '/auth.json');
if ($localAuthFile->exists()) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $localAuthFile->getPath());
}
$config->merge(array('config' => $localAuthFile->read()));
$config->setAuthConfigSource(new JsonConfigSource($localAuthFile, true));
}
}
$vendorDir = $config->get('vendor-dir');
$binDir = $config->get('bin-dir');
// initialize composer
$composer = new Composer();
$composer->setConfig($config);
if ($fullLoad) {
// load auth configs into the IO instance
$io->loadConfiguration($config);
}
// initialize event dispatcher
$dispatcher = new EventDispatcher($composer, $io);
$composer->setEventDispatcher($dispatcher);
// initialize repository manager
$rm = $this->createRepositoryManager($io, $config, $dispatcher);
$composer->setRepositoryManager($rm);
// load local repository
$this->addLocalRepository($rm, $vendorDir);
// load package
$parser = new VersionParser;
$loader = new Package\Loader\RootPackageLoader($rm, $config, $parser, new ProcessExecutor($io));
$package = $loader->load($localConfig);
$composer->setPackage($package);
// initialize installation manager
$im = $this->createInstallationManager();
$composer->setInstallationManager($im);
if ($fullLoad) {
// initialize download manager
$dm = $this->createDownloadManager($io, $config, $dispatcher);
$composer->setDownloadManager($dm);
// initialize autoload generator
$generator = new AutoloadGenerator($dispatcher, $io);
$composer->setAutoloadGenerator($generator);
}
// add installers to the manager (must happen after download manager is created since they read it out of $composer)
$this->createDefaultInstallers($im, $composer, $io);
if ($fullLoad) {
$globalComposer = $this->createGlobalComposer($io, $config, $disablePlugins);
$pm = $this->createPluginManager($io, $composer, $globalComposer);
$composer->setPluginManager($pm);
if (!$disablePlugins) {
$pm->loadInstalledPlugins();
}
// once we have plugins and custom installers we can
// purge packages from local repos if they have been deleted on the filesystem
if ($rm->getLocalRepository()) {
$this->purgePackages($rm->getLocalRepository(), $im);
}
}
// init locker if possible
if ($fullLoad && isset($composerFile)) {
$lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION)
? substr($composerFile, 0, -4).'lock'
: $composerFile . '.lock';
$locker = new Package\Locker($io, new JsonFile($lockFile, new RemoteFilesystem($io, $config)), $rm, $im, md5_file($composerFile));
$composer->setLocker($locker);
}
return $composer;
} | php | public function createComposer(IOInterface $io, $localConfig = null, $disablePlugins = false, $cwd = null, $fullLoad = true)
{
$cwd = $cwd ?: getcwd();
// load Composer configuration
if (null === $localConfig) {
$localConfig = static::getComposerFile();
}
if (is_string($localConfig)) {
$composerFile = $localConfig;
$file = new JsonFile($localConfig, new RemoteFilesystem($io));
if (!$file->exists()) {
if ($localConfig === './composer.json' || $localConfig === 'composer.json') {
$message = 'Composer could not find a composer.json file in '.$cwd;
} else {
$message = 'Composer could not find the config file: '.$localConfig;
}
$instructions = 'To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section';
throw new \InvalidArgumentException($message.PHP_EOL.$instructions);
}
$file->validateSchema(JsonFile::LAX_SCHEMA);
$localConfig = $file->read();
}
// Load config and override with local config/auth config
$config = static::createConfig($io, $cwd);
$config->merge($localConfig);
if (isset($composerFile)) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $composerFile);
}
$localAuthFile = new JsonFile(dirname(realpath($composerFile)) . '/auth.json');
if ($localAuthFile->exists()) {
if ($io && $io->isDebug()) {
$io->writeError('Loading config file ' . $localAuthFile->getPath());
}
$config->merge(array('config' => $localAuthFile->read()));
$config->setAuthConfigSource(new JsonConfigSource($localAuthFile, true));
}
}
$vendorDir = $config->get('vendor-dir');
$binDir = $config->get('bin-dir');
// initialize composer
$composer = new Composer();
$composer->setConfig($config);
if ($fullLoad) {
// load auth configs into the IO instance
$io->loadConfiguration($config);
}
// initialize event dispatcher
$dispatcher = new EventDispatcher($composer, $io);
$composer->setEventDispatcher($dispatcher);
// initialize repository manager
$rm = $this->createRepositoryManager($io, $config, $dispatcher);
$composer->setRepositoryManager($rm);
// load local repository
$this->addLocalRepository($rm, $vendorDir);
// load package
$parser = new VersionParser;
$loader = new Package\Loader\RootPackageLoader($rm, $config, $parser, new ProcessExecutor($io));
$package = $loader->load($localConfig);
$composer->setPackage($package);
// initialize installation manager
$im = $this->createInstallationManager();
$composer->setInstallationManager($im);
if ($fullLoad) {
// initialize download manager
$dm = $this->createDownloadManager($io, $config, $dispatcher);
$composer->setDownloadManager($dm);
// initialize autoload generator
$generator = new AutoloadGenerator($dispatcher, $io);
$composer->setAutoloadGenerator($generator);
}
// add installers to the manager (must happen after download manager is created since they read it out of $composer)
$this->createDefaultInstallers($im, $composer, $io);
if ($fullLoad) {
$globalComposer = $this->createGlobalComposer($io, $config, $disablePlugins);
$pm = $this->createPluginManager($io, $composer, $globalComposer);
$composer->setPluginManager($pm);
if (!$disablePlugins) {
$pm->loadInstalledPlugins();
}
// once we have plugins and custom installers we can
// purge packages from local repos if they have been deleted on the filesystem
if ($rm->getLocalRepository()) {
$this->purgePackages($rm->getLocalRepository(), $im);
}
}
// init locker if possible
if ($fullLoad && isset($composerFile)) {
$lockFile = "json" === pathinfo($composerFile, PATHINFO_EXTENSION)
? substr($composerFile, 0, -4).'lock'
: $composerFile . '.lock';
$locker = new Package\Locker($io, new JsonFile($lockFile, new RemoteFilesystem($io, $config)), $rm, $im, md5_file($composerFile));
$composer->setLocker($locker);
}
return $composer;
} | [
"public",
"function",
"createComposer",
"(",
"IOInterface",
"$",
"io",
",",
"$",
"localConfig",
"=",
"null",
",",
"$",
"disablePlugins",
"=",
"false",
",",
"$",
"cwd",
"=",
"null",
",",
"$",
"fullLoad",
"=",
"true",
")",
"{",
"$",
"cwd",
"=",
"$",
"cwd",
"?",
":",
"getcwd",
"(",
")",
";",
"// load Composer configuration",
"if",
"(",
"null",
"===",
"$",
"localConfig",
")",
"{",
"$",
"localConfig",
"=",
"static",
"::",
"getComposerFile",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"localConfig",
")",
")",
"{",
"$",
"composerFile",
"=",
"$",
"localConfig",
";",
"$",
"file",
"=",
"new",
"JsonFile",
"(",
"$",
"localConfig",
",",
"new",
"RemoteFilesystem",
"(",
"$",
"io",
")",
")",
";",
"if",
"(",
"!",
"$",
"file",
"->",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"$",
"localConfig",
"===",
"'./composer.json'",
"||",
"$",
"localConfig",
"===",
"'composer.json'",
")",
"{",
"$",
"message",
"=",
"'Composer could not find a composer.json file in '",
".",
"$",
"cwd",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"'Composer could not find the config file: '",
".",
"$",
"localConfig",
";",
"}",
"$",
"instructions",
"=",
"'To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ \"Getting Started\" section'",
";",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"message",
".",
"PHP_EOL",
".",
"$",
"instructions",
")",
";",
"}",
"$",
"file",
"->",
"validateSchema",
"(",
"JsonFile",
"::",
"LAX_SCHEMA",
")",
";",
"$",
"localConfig",
"=",
"$",
"file",
"->",
"read",
"(",
")",
";",
"}",
"// Load config and override with local config/auth config",
"$",
"config",
"=",
"static",
"::",
"createConfig",
"(",
"$",
"io",
",",
"$",
"cwd",
")",
";",
"$",
"config",
"->",
"merge",
"(",
"$",
"localConfig",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"composerFile",
")",
")",
"{",
"if",
"(",
"$",
"io",
"&&",
"$",
"io",
"->",
"isDebug",
"(",
")",
")",
"{",
"$",
"io",
"->",
"writeError",
"(",
"'Loading config file '",
".",
"$",
"composerFile",
")",
";",
"}",
"$",
"localAuthFile",
"=",
"new",
"JsonFile",
"(",
"dirname",
"(",
"realpath",
"(",
"$",
"composerFile",
")",
")",
".",
"'/auth.json'",
")",
";",
"if",
"(",
"$",
"localAuthFile",
"->",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"$",
"io",
"&&",
"$",
"io",
"->",
"isDebug",
"(",
")",
")",
"{",
"$",
"io",
"->",
"writeError",
"(",
"'Loading config file '",
".",
"$",
"localAuthFile",
"->",
"getPath",
"(",
")",
")",
";",
"}",
"$",
"config",
"->",
"merge",
"(",
"array",
"(",
"'config'",
"=>",
"$",
"localAuthFile",
"->",
"read",
"(",
")",
")",
")",
";",
"$",
"config",
"->",
"setAuthConfigSource",
"(",
"new",
"JsonConfigSource",
"(",
"$",
"localAuthFile",
",",
"true",
")",
")",
";",
"}",
"}",
"$",
"vendorDir",
"=",
"$",
"config",
"->",
"get",
"(",
"'vendor-dir'",
")",
";",
"$",
"binDir",
"=",
"$",
"config",
"->",
"get",
"(",
"'bin-dir'",
")",
";",
"// initialize composer",
"$",
"composer",
"=",
"new",
"Composer",
"(",
")",
";",
"$",
"composer",
"->",
"setConfig",
"(",
"$",
"config",
")",
";",
"if",
"(",
"$",
"fullLoad",
")",
"{",
"// load auth configs into the IO instance",
"$",
"io",
"->",
"loadConfiguration",
"(",
"$",
"config",
")",
";",
"}",
"// initialize event dispatcher",
"$",
"dispatcher",
"=",
"new",
"EventDispatcher",
"(",
"$",
"composer",
",",
"$",
"io",
")",
";",
"$",
"composer",
"->",
"setEventDispatcher",
"(",
"$",
"dispatcher",
")",
";",
"// initialize repository manager",
"$",
"rm",
"=",
"$",
"this",
"->",
"createRepositoryManager",
"(",
"$",
"io",
",",
"$",
"config",
",",
"$",
"dispatcher",
")",
";",
"$",
"composer",
"->",
"setRepositoryManager",
"(",
"$",
"rm",
")",
";",
"// load local repository",
"$",
"this",
"->",
"addLocalRepository",
"(",
"$",
"rm",
",",
"$",
"vendorDir",
")",
";",
"// load package",
"$",
"parser",
"=",
"new",
"VersionParser",
";",
"$",
"loader",
"=",
"new",
"Package",
"\\",
"Loader",
"\\",
"RootPackageLoader",
"(",
"$",
"rm",
",",
"$",
"config",
",",
"$",
"parser",
",",
"new",
"ProcessExecutor",
"(",
"$",
"io",
")",
")",
";",
"$",
"package",
"=",
"$",
"loader",
"->",
"load",
"(",
"$",
"localConfig",
")",
";",
"$",
"composer",
"->",
"setPackage",
"(",
"$",
"package",
")",
";",
"// initialize installation manager",
"$",
"im",
"=",
"$",
"this",
"->",
"createInstallationManager",
"(",
")",
";",
"$",
"composer",
"->",
"setInstallationManager",
"(",
"$",
"im",
")",
";",
"if",
"(",
"$",
"fullLoad",
")",
"{",
"// initialize download manager",
"$",
"dm",
"=",
"$",
"this",
"->",
"createDownloadManager",
"(",
"$",
"io",
",",
"$",
"config",
",",
"$",
"dispatcher",
")",
";",
"$",
"composer",
"->",
"setDownloadManager",
"(",
"$",
"dm",
")",
";",
"// initialize autoload generator",
"$",
"generator",
"=",
"new",
"AutoloadGenerator",
"(",
"$",
"dispatcher",
",",
"$",
"io",
")",
";",
"$",
"composer",
"->",
"setAutoloadGenerator",
"(",
"$",
"generator",
")",
";",
"}",
"// add installers to the manager (must happen after download manager is created since they read it out of $composer)",
"$",
"this",
"->",
"createDefaultInstallers",
"(",
"$",
"im",
",",
"$",
"composer",
",",
"$",
"io",
")",
";",
"if",
"(",
"$",
"fullLoad",
")",
"{",
"$",
"globalComposer",
"=",
"$",
"this",
"->",
"createGlobalComposer",
"(",
"$",
"io",
",",
"$",
"config",
",",
"$",
"disablePlugins",
")",
";",
"$",
"pm",
"=",
"$",
"this",
"->",
"createPluginManager",
"(",
"$",
"io",
",",
"$",
"composer",
",",
"$",
"globalComposer",
")",
";",
"$",
"composer",
"->",
"setPluginManager",
"(",
"$",
"pm",
")",
";",
"if",
"(",
"!",
"$",
"disablePlugins",
")",
"{",
"$",
"pm",
"->",
"loadInstalledPlugins",
"(",
")",
";",
"}",
"// once we have plugins and custom installers we can",
"// purge packages from local repos if they have been deleted on the filesystem",
"if",
"(",
"$",
"rm",
"->",
"getLocalRepository",
"(",
")",
")",
"{",
"$",
"this",
"->",
"purgePackages",
"(",
"$",
"rm",
"->",
"getLocalRepository",
"(",
")",
",",
"$",
"im",
")",
";",
"}",
"}",
"// init locker if possible",
"if",
"(",
"$",
"fullLoad",
"&&",
"isset",
"(",
"$",
"composerFile",
")",
")",
"{",
"$",
"lockFile",
"=",
"\"json\"",
"===",
"pathinfo",
"(",
"$",
"composerFile",
",",
"PATHINFO_EXTENSION",
")",
"?",
"substr",
"(",
"$",
"composerFile",
",",
"0",
",",
"-",
"4",
")",
".",
"'lock'",
":",
"$",
"composerFile",
".",
"'.lock'",
";",
"$",
"locker",
"=",
"new",
"Package",
"\\",
"Locker",
"(",
"$",
"io",
",",
"new",
"JsonFile",
"(",
"$",
"lockFile",
",",
"new",
"RemoteFilesystem",
"(",
"$",
"io",
",",
"$",
"config",
")",
")",
",",
"$",
"rm",
",",
"$",
"im",
",",
"md5_file",
"(",
"$",
"composerFile",
")",
")",
";",
"$",
"composer",
"->",
"setLocker",
"(",
"$",
"locker",
")",
";",
"}",
"return",
"$",
"composer",
";",
"}"
] | Creates a Composer instance
@param IOInterface $io IO instance
@param array|string|null $localConfig either a configuration array or a filename to read from, if null it will
read from the default filename
@param bool $disablePlugins Whether plugins should not be loaded
@param bool $fullLoad Whether to initialize everything or only main project stuff (used when loading the global composer)
@throws \InvalidArgumentException
@throws \UnexpectedValueException
@return Composer | [
"Creates",
"a",
"Composer",
"instance"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Factory.php#L198-L314 |
mothership-ec/composer | src/Composer/Factory.php | Factory.createArchiveManager | public function createArchiveManager(Config $config, Downloader\DownloadManager $dm = null)
{
if (null === $dm) {
$io = new IO\NullIO();
$io->loadConfiguration($config);
$dm = $this->createDownloadManager($io, $config);
}
$am = new Archiver\ArchiveManager($dm);
$am->addArchiver(new Archiver\PharArchiver);
return $am;
} | php | public function createArchiveManager(Config $config, Downloader\DownloadManager $dm = null)
{
if (null === $dm) {
$io = new IO\NullIO();
$io->loadConfiguration($config);
$dm = $this->createDownloadManager($io, $config);
}
$am = new Archiver\ArchiveManager($dm);
$am->addArchiver(new Archiver\PharArchiver);
return $am;
} | [
"public",
"function",
"createArchiveManager",
"(",
"Config",
"$",
"config",
",",
"Downloader",
"\\",
"DownloadManager",
"$",
"dm",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"dm",
")",
"{",
"$",
"io",
"=",
"new",
"IO",
"\\",
"NullIO",
"(",
")",
";",
"$",
"io",
"->",
"loadConfiguration",
"(",
"$",
"config",
")",
";",
"$",
"dm",
"=",
"$",
"this",
"->",
"createDownloadManager",
"(",
"$",
"io",
",",
"$",
"config",
")",
";",
"}",
"$",
"am",
"=",
"new",
"Archiver",
"\\",
"ArchiveManager",
"(",
"$",
"dm",
")",
";",
"$",
"am",
"->",
"addArchiver",
"(",
"new",
"Archiver",
"\\",
"PharArchiver",
")",
";",
"return",
"$",
"am",
";",
"}"
] | @param Config $config The configuration
@param Downloader\DownloadManager $dm Manager use to download sources
@return Archiver\ArchiveManager | [
"@param",
"Config",
"$config",
"The",
"configuration",
"@param",
"Downloader",
"\\",
"DownloadManager",
"$dm",
"Manager",
"use",
"to",
"download",
"sources"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Factory.php#L416-L428 |
fapi-cz/http-client | src/Fapi/HttpClient/Utils/Callback.php | Callback.invokeSafe | public static function invokeSafe(callable $function, array $args, callable $onError)
{
/** @noinspection PhpUnusedLocalVariableInspection */
$prev = \set_error_handler(static function ($severity, $message, $file) use ($onError, & $prev) {
if ($file === __FILE__ && $onError($message, $severity) !== false) {
return null;
}
if ($prev) {
return \call_user_func_array($prev, \func_get_args());
}
return false;
});
try {
$res = \call_user_func_array($function, $args);
\restore_error_handler();
return $res;
} catch (\Throwable $e) {
\restore_error_handler();
throw $e;
}
} | php | public static function invokeSafe(callable $function, array $args, callable $onError)
{
/** @noinspection PhpUnusedLocalVariableInspection */
$prev = \set_error_handler(static function ($severity, $message, $file) use ($onError, & $prev) {
if ($file === __FILE__ && $onError($message, $severity) !== false) {
return null;
}
if ($prev) {
return \call_user_func_array($prev, \func_get_args());
}
return false;
});
try {
$res = \call_user_func_array($function, $args);
\restore_error_handler();
return $res;
} catch (\Throwable $e) {
\restore_error_handler();
throw $e;
}
} | [
"public",
"static",
"function",
"invokeSafe",
"(",
"callable",
"$",
"function",
",",
"array",
"$",
"args",
",",
"callable",
"$",
"onError",
")",
"{",
"/** @noinspection PhpUnusedLocalVariableInspection */",
"$",
"prev",
"=",
"\\",
"set_error_handler",
"(",
"static",
"function",
"(",
"$",
"severity",
",",
"$",
"message",
",",
"$",
"file",
")",
"use",
"(",
"$",
"onError",
",",
"&",
"$",
"prev",
")",
"{",
"if",
"(",
"$",
"file",
"===",
"__FILE__",
"&&",
"$",
"onError",
"(",
"$",
"message",
",",
"$",
"severity",
")",
"!==",
"false",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"prev",
")",
"{",
"return",
"\\",
"call_user_func_array",
"(",
"$",
"prev",
",",
"\\",
"func_get_args",
"(",
")",
")",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"try",
"{",
"$",
"res",
"=",
"\\",
"call_user_func_array",
"(",
"$",
"function",
",",
"$",
"args",
")",
";",
"\\",
"restore_error_handler",
"(",
")",
";",
"return",
"$",
"res",
";",
"}",
"catch",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"\\",
"restore_error_handler",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] | Invokes internal PHP function with own error handler.
@param callable $function
@param mixed[] $args
@param callable $onError function($message, $severity)
@return mixed
@throws \Throwable | [
"Invokes",
"internal",
"PHP",
"function",
"with",
"own",
"error",
"handler",
"."
] | train | https://github.com/fapi-cz/http-client/blob/5aeed581c5c115fb4d2f72b46e2ce27f91a1c999/src/Fapi/HttpClient/Utils/Callback.php#L25-L50 |
ouropencode/dachi | src/Configuration.php | Configuration.get | public static function get($key, $default = "default") {
if(self::$config == array())
self::load();
$env = Kernel::getEnvironment();
$position = self::$config[$env];
$token = strtok($key, '.');
while($token !== false) {
$nextToken = strtok('.');
if(!isset($position[$token]))
return $default;
if($nextToken === false)
return $position[$token];
$position = &$position[$token];
$token = $nextToken;
}
return $default;
} | php | public static function get($key, $default = "default") {
if(self::$config == array())
self::load();
$env = Kernel::getEnvironment();
$position = self::$config[$env];
$token = strtok($key, '.');
while($token !== false) {
$nextToken = strtok('.');
if(!isset($position[$token]))
return $default;
if($nextToken === false)
return $position[$token];
$position = &$position[$token];
$token = $nextToken;
}
return $default;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"\"default\"",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"config",
"==",
"array",
"(",
")",
")",
"self",
"::",
"load",
"(",
")",
";",
"$",
"env",
"=",
"Kernel",
"::",
"getEnvironment",
"(",
")",
";",
"$",
"position",
"=",
"self",
"::",
"$",
"config",
"[",
"$",
"env",
"]",
";",
"$",
"token",
"=",
"strtok",
"(",
"$",
"key",
",",
"'.'",
")",
";",
"while",
"(",
"$",
"token",
"!==",
"false",
")",
"{",
"$",
"nextToken",
"=",
"strtok",
"(",
"'.'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"position",
"[",
"$",
"token",
"]",
")",
")",
"return",
"$",
"default",
";",
"if",
"(",
"$",
"nextToken",
"===",
"false",
")",
"return",
"$",
"position",
"[",
"$",
"token",
"]",
";",
"$",
"position",
"=",
"&",
"$",
"position",
"[",
"$",
"token",
"]",
";",
"$",
"token",
"=",
"$",
"nextToken",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Get a configuration entry
@param string $key The configuration key to retrieve (e.g. dachi.siteName or api.twitter.publicKey)
@param string $default The default value to return if the key was not found
@return mixed | [
"Get",
"a",
"configuration",
"entry"
] | train | https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Configuration.php#L51-L71 |
heidelpay/PhpDoc | src/phpDocumentor/Descriptor/Builder/Reflector/Tags/ThrowsAssembler.php | ThrowsAssembler.create | public function create($data)
{
$descriptor = new ThrowsDescriptor($data->getName());
$descriptor->setDescription($data->getDescription());
$descriptor->setTypes(
$this->builder->buildDescriptor(new Collection($data->getTypes()))
);
return $descriptor;
} | php | public function create($data)
{
$descriptor = new ThrowsDescriptor($data->getName());
$descriptor->setDescription($data->getDescription());
$descriptor->setTypes(
$this->builder->buildDescriptor(new Collection($data->getTypes()))
);
return $descriptor;
} | [
"public",
"function",
"create",
"(",
"$",
"data",
")",
"{",
"$",
"descriptor",
"=",
"new",
"ThrowsDescriptor",
"(",
"$",
"data",
"->",
"getName",
"(",
")",
")",
";",
"$",
"descriptor",
"->",
"setDescription",
"(",
"$",
"data",
"->",
"getDescription",
"(",
")",
")",
";",
"$",
"descriptor",
"->",
"setTypes",
"(",
"$",
"this",
"->",
"builder",
"->",
"buildDescriptor",
"(",
"new",
"Collection",
"(",
"$",
"data",
"->",
"getTypes",
"(",
")",
")",
")",
")",
";",
"return",
"$",
"descriptor",
";",
"}"
] | Creates a new Descriptor from the given Reflector.
@param ThrowsTag $data
@return ThrowsDescriptor | [
"Creates",
"a",
"new",
"Descriptor",
"from",
"the",
"given",
"Reflector",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/ThrowsAssembler.php#L34-L43 |
xiewulong/yii2-fileupload | oss/libs/guzzle/http/Guzzle/Http/Message/RequestFactory.php | RequestFactory.cloneRequestWithMethod | public function cloneRequestWithMethod(RequestInterface $request, $method)
{
// Create the request with the same client if possible
if ($client = $request->getClient()) {
$cloned = $request->getClient()->createRequest($method, $request->getUrl(), $request->getHeaders());
} else {
$cloned = $this->create($method, $request->getUrl(), $request->getHeaders());
}
$cloned->getCurlOptions()->replace($request->getCurlOptions()->toArray());
$cloned->setEventDispatcher(clone $request->getEventDispatcher());
// Ensure that that the Content-Length header is not copied if changing to GET or HEAD
if (!($cloned instanceof EntityEnclosingRequestInterface)) {
$cloned->removeHeader('Content-Length');
} elseif ($request instanceof EntityEnclosingRequestInterface) {
$cloned->setBody($request->getBody());
}
$cloned->getParams()->replace($request->getParams()->toArray());
$cloned->dispatch('request.clone', array('request' => $cloned));
return $cloned;
} | php | public function cloneRequestWithMethod(RequestInterface $request, $method)
{
// Create the request with the same client if possible
if ($client = $request->getClient()) {
$cloned = $request->getClient()->createRequest($method, $request->getUrl(), $request->getHeaders());
} else {
$cloned = $this->create($method, $request->getUrl(), $request->getHeaders());
}
$cloned->getCurlOptions()->replace($request->getCurlOptions()->toArray());
$cloned->setEventDispatcher(clone $request->getEventDispatcher());
// Ensure that that the Content-Length header is not copied if changing to GET or HEAD
if (!($cloned instanceof EntityEnclosingRequestInterface)) {
$cloned->removeHeader('Content-Length');
} elseif ($request instanceof EntityEnclosingRequestInterface) {
$cloned->setBody($request->getBody());
}
$cloned->getParams()->replace($request->getParams()->toArray());
$cloned->dispatch('request.clone', array('request' => $cloned));
return $cloned;
} | [
"public",
"function",
"cloneRequestWithMethod",
"(",
"RequestInterface",
"$",
"request",
",",
"$",
"method",
")",
"{",
"// Create the request with the same client if possible",
"if",
"(",
"$",
"client",
"=",
"$",
"request",
"->",
"getClient",
"(",
")",
")",
"{",
"$",
"cloned",
"=",
"$",
"request",
"->",
"getClient",
"(",
")",
"->",
"createRequest",
"(",
"$",
"method",
",",
"$",
"request",
"->",
"getUrl",
"(",
")",
",",
"$",
"request",
"->",
"getHeaders",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"cloned",
"=",
"$",
"this",
"->",
"create",
"(",
"$",
"method",
",",
"$",
"request",
"->",
"getUrl",
"(",
")",
",",
"$",
"request",
"->",
"getHeaders",
"(",
")",
")",
";",
"}",
"$",
"cloned",
"->",
"getCurlOptions",
"(",
")",
"->",
"replace",
"(",
"$",
"request",
"->",
"getCurlOptions",
"(",
")",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"cloned",
"->",
"setEventDispatcher",
"(",
"clone",
"$",
"request",
"->",
"getEventDispatcher",
"(",
")",
")",
";",
"// Ensure that that the Content-Length header is not copied if changing to GET or HEAD",
"if",
"(",
"!",
"(",
"$",
"cloned",
"instanceof",
"EntityEnclosingRequestInterface",
")",
")",
"{",
"$",
"cloned",
"->",
"removeHeader",
"(",
"'Content-Length'",
")",
";",
"}",
"elseif",
"(",
"$",
"request",
"instanceof",
"EntityEnclosingRequestInterface",
")",
"{",
"$",
"cloned",
"->",
"setBody",
"(",
"$",
"request",
"->",
"getBody",
"(",
")",
")",
";",
"}",
"$",
"cloned",
"->",
"getParams",
"(",
")",
"->",
"replace",
"(",
"$",
"request",
"->",
"getParams",
"(",
")",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"cloned",
"->",
"dispatch",
"(",
"'request.clone'",
",",
"array",
"(",
"'request'",
"=>",
"$",
"cloned",
")",
")",
";",
"return",
"$",
"cloned",
";",
"}"
] | Clone a request while changing the method. Emulates the behavior of
{@see Guzzle\Http\Message\Request::clone}, but can change the HTTP method.
@param RequestInterface $request Request to clone
@param string $method Method to set
@return RequestInterface | [
"Clone",
"a",
"request",
"while",
"changing",
"the",
"method",
".",
"Emulates",
"the",
"behavior",
"of",
"{",
"@see",
"Guzzle",
"\\",
"Http",
"\\",
"Message",
"\\",
"Request",
"::",
"clone",
"}",
"but",
"can",
"change",
"the",
"HTTP",
"method",
"."
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Message/RequestFactory.php#L139-L160 |
DataDo/data | src/main/php/DataDo/Data/Query/DefaultQueryBuilder.php | DefaultQueryBuilder.build | public function build($tokens, $tableName, $namingConvention, $class)
{
$resultMode = $this->getMode($tokens);
$fields = $this->getFields($tokens, $namingConvention, $class);
$constraints = $this->getConstraints($tokens, $namingConvention, $class);
switch ($resultMode) {
case QueryBuilderResult::RESULT_SELECT_SINGLE:
case QueryBuilderResult::RESULT_SELECT_MULTIPLE:
$sql = "SELECT $fields FROM $tableName $constraints";
break;
case QueryBuilderResult::RESULT_DELETE:
$sql = "DELETE FROM $tableName $constraints";
break;
default:
throw new DslSyntaxException("Unknown result mode: $resultMode", DATADO_ILLEGAL_RESULT_MODE);
}
return new QueryBuilderResult($sql, $resultMode);
} | php | public function build($tokens, $tableName, $namingConvention, $class)
{
$resultMode = $this->getMode($tokens);
$fields = $this->getFields($tokens, $namingConvention, $class);
$constraints = $this->getConstraints($tokens, $namingConvention, $class);
switch ($resultMode) {
case QueryBuilderResult::RESULT_SELECT_SINGLE:
case QueryBuilderResult::RESULT_SELECT_MULTIPLE:
$sql = "SELECT $fields FROM $tableName $constraints";
break;
case QueryBuilderResult::RESULT_DELETE:
$sql = "DELETE FROM $tableName $constraints";
break;
default:
throw new DslSyntaxException("Unknown result mode: $resultMode", DATADO_ILLEGAL_RESULT_MODE);
}
return new QueryBuilderResult($sql, $resultMode);
} | [
"public",
"function",
"build",
"(",
"$",
"tokens",
",",
"$",
"tableName",
",",
"$",
"namingConvention",
",",
"$",
"class",
")",
"{",
"$",
"resultMode",
"=",
"$",
"this",
"->",
"getMode",
"(",
"$",
"tokens",
")",
";",
"$",
"fields",
"=",
"$",
"this",
"->",
"getFields",
"(",
"$",
"tokens",
",",
"$",
"namingConvention",
",",
"$",
"class",
")",
";",
"$",
"constraints",
"=",
"$",
"this",
"->",
"getConstraints",
"(",
"$",
"tokens",
",",
"$",
"namingConvention",
",",
"$",
"class",
")",
";",
"switch",
"(",
"$",
"resultMode",
")",
"{",
"case",
"QueryBuilderResult",
"::",
"RESULT_SELECT_SINGLE",
":",
"case",
"QueryBuilderResult",
"::",
"RESULT_SELECT_MULTIPLE",
":",
"$",
"sql",
"=",
"\"SELECT $fields FROM $tableName $constraints\"",
";",
"break",
";",
"case",
"QueryBuilderResult",
"::",
"RESULT_DELETE",
":",
"$",
"sql",
"=",
"\"DELETE FROM $tableName $constraints\"",
";",
"break",
";",
"default",
":",
"throw",
"new",
"DslSyntaxException",
"(",
"\"Unknown result mode: $resultMode\"",
",",
"DATADO_ILLEGAL_RESULT_MODE",
")",
";",
"}",
"return",
"new",
"QueryBuilderResult",
"(",
"$",
"sql",
",",
"$",
"resultMode",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/DataDo/data/blob/555b02a27755032fcd53e165b0674e81a68067c0/src/main/php/DataDo/Data/Query/DefaultQueryBuilder.php#L26-L45 |
DataDo/data | src/main/php/DataDo/Data/Query/DefaultQueryBuilder.php | DefaultQueryBuilder.getMode | private function getMode($tokens)
{
switch ($tokens->getQueryMode()) {
case 'find':
return QueryBuilderResult::RESULT_SELECT_MULTIPLE;
case 'get':
return QueryBuilderResult::RESULT_SELECT_SINGLE;
case 'delete':
return QueryBuilderResult::RESULT_DELETE;
}
throw new DslSyntaxException('No query could be built for ' . $tokens->getMethodName() . ': Unknown query mode [' . $tokens->getQueryMode() . ']', DATADO_ILLEGAL_RESULT_MODE);
} | php | private function getMode($tokens)
{
switch ($tokens->getQueryMode()) {
case 'find':
return QueryBuilderResult::RESULT_SELECT_MULTIPLE;
case 'get':
return QueryBuilderResult::RESULT_SELECT_SINGLE;
case 'delete':
return QueryBuilderResult::RESULT_DELETE;
}
throw new DslSyntaxException('No query could be built for ' . $tokens->getMethodName() . ': Unknown query mode [' . $tokens->getQueryMode() . ']', DATADO_ILLEGAL_RESULT_MODE);
} | [
"private",
"function",
"getMode",
"(",
"$",
"tokens",
")",
"{",
"switch",
"(",
"$",
"tokens",
"->",
"getQueryMode",
"(",
")",
")",
"{",
"case",
"'find'",
":",
"return",
"QueryBuilderResult",
"::",
"RESULT_SELECT_MULTIPLE",
";",
"case",
"'get'",
":",
"return",
"QueryBuilderResult",
"::",
"RESULT_SELECT_SINGLE",
";",
"case",
"'delete'",
":",
"return",
"QueryBuilderResult",
"::",
"RESULT_DELETE",
";",
"}",
"throw",
"new",
"DslSyntaxException",
"(",
"'No query could be built for '",
".",
"$",
"tokens",
"->",
"getMethodName",
"(",
")",
".",
"': Unknown query mode ['",
".",
"$",
"tokens",
"->",
"getQueryMode",
"(",
")",
".",
"']'",
",",
"DATADO_ILLEGAL_RESULT_MODE",
")",
";",
"}"
] | Get the result type for a MethodNameToken.
@param MethodNameToken $tokens
@return int The result type
@throws DslSyntaxException if no supported mode was found | [
"Get",
"the",
"result",
"type",
"for",
"a",
"MethodNameToken",
"."
] | train | https://github.com/DataDo/data/blob/555b02a27755032fcd53e165b0674e81a68067c0/src/main/php/DataDo/Data/Query/DefaultQueryBuilder.php#L55-L67 |
DataDo/data | src/main/php/DataDo/Data/Query/DefaultQueryBuilder.php | DefaultQueryBuilder.getFields | private function getFields($tokens, $namingConvention, $class)
{
$fields = [];
$prefix = '';
foreach ($tokens->getTokens() as $token) {
if ($token instanceof ByToken) {
return $prefix . $this->fieldsToSQL($fields, $class, $namingConvention);
}
if ($token instanceof AllToken) {
return $prefix . $this->fieldsToSQL([], $class, $namingConvention);
}
if($token instanceof DistinctToken) {
$prefix .= 'DISTINCT ';
continue;
}
if ($token instanceof AndToken) {
// Ignore and tokens as they do nothing
continue;
}
if (!($token instanceof ValueToken)) {
throw new DslSyntaxException('Unexpected token ' . $token->getName() . ' in field selector', DATADO_UNEXPECTED_TOKEN);
}
$fields[] = lcfirst($token->getSource());
}
return $prefix . $this->fieldsToSQL($fields, $class, $namingConvention);
} | php | private function getFields($tokens, $namingConvention, $class)
{
$fields = [];
$prefix = '';
foreach ($tokens->getTokens() as $token) {
if ($token instanceof ByToken) {
return $prefix . $this->fieldsToSQL($fields, $class, $namingConvention);
}
if ($token instanceof AllToken) {
return $prefix . $this->fieldsToSQL([], $class, $namingConvention);
}
if($token instanceof DistinctToken) {
$prefix .= 'DISTINCT ';
continue;
}
if ($token instanceof AndToken) {
// Ignore and tokens as they do nothing
continue;
}
if (!($token instanceof ValueToken)) {
throw new DslSyntaxException('Unexpected token ' . $token->getName() . ' in field selector', DATADO_UNEXPECTED_TOKEN);
}
$fields[] = lcfirst($token->getSource());
}
return $prefix . $this->fieldsToSQL($fields, $class, $namingConvention);
} | [
"private",
"function",
"getFields",
"(",
"$",
"tokens",
",",
"$",
"namingConvention",
",",
"$",
"class",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"$",
"prefix",
"=",
"''",
";",
"foreach",
"(",
"$",
"tokens",
"->",
"getTokens",
"(",
")",
"as",
"$",
"token",
")",
"{",
"if",
"(",
"$",
"token",
"instanceof",
"ByToken",
")",
"{",
"return",
"$",
"prefix",
".",
"$",
"this",
"->",
"fieldsToSQL",
"(",
"$",
"fields",
",",
"$",
"class",
",",
"$",
"namingConvention",
")",
";",
"}",
"if",
"(",
"$",
"token",
"instanceof",
"AllToken",
")",
"{",
"return",
"$",
"prefix",
".",
"$",
"this",
"->",
"fieldsToSQL",
"(",
"[",
"]",
",",
"$",
"class",
",",
"$",
"namingConvention",
")",
";",
"}",
"if",
"(",
"$",
"token",
"instanceof",
"DistinctToken",
")",
"{",
"$",
"prefix",
".=",
"'DISTINCT '",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"token",
"instanceof",
"AndToken",
")",
"{",
"// Ignore and tokens as they do nothing",
"continue",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"token",
"instanceof",
"ValueToken",
")",
")",
"{",
"throw",
"new",
"DslSyntaxException",
"(",
"'Unexpected token '",
".",
"$",
"token",
"->",
"getName",
"(",
")",
".",
"' in field selector'",
",",
"DATADO_UNEXPECTED_TOKEN",
")",
";",
"}",
"$",
"fields",
"[",
"]",
"=",
"lcfirst",
"(",
"$",
"token",
"->",
"getSource",
"(",
")",
")",
";",
"}",
"return",
"$",
"prefix",
".",
"$",
"this",
"->",
"fieldsToSQL",
"(",
"$",
"fields",
",",
"$",
"class",
",",
"$",
"namingConvention",
")",
";",
"}"
] | Build the SQL string for the fields from a MethodNameToken
@param MethodNameToken $tokens
@param NamingConvention $namingConvention
@param ReflectionClass $class
@return string
@throws DslSyntaxException if an unexpected token is found | [
"Build",
"the",
"SQL",
"string",
"for",
"the",
"fields",
"from",
"a",
"MethodNameToken"
] | train | https://github.com/DataDo/data/blob/555b02a27755032fcd53e165b0674e81a68067c0/src/main/php/DataDo/Data/Query/DefaultQueryBuilder.php#L77-L109 |
DataDo/data | src/main/php/DataDo/Data/Query/DefaultQueryBuilder.php | DefaultQueryBuilder.tokenToColumn | private function tokenToColumn($token, $namingConvention, $class)
{
// Find a matching property
$property = null;
foreach ($class->getProperties() as $prop) {
if (strcasecmp($token->getSource(), $prop->getName()) === 0) {
$property = $prop;
break;
}
}
if ($property === null) {
throw new DslSyntaxException('No matching property found for ' . $token->getSource());
}
return $namingConvention->propertyToColumnName($property);
} | php | private function tokenToColumn($token, $namingConvention, $class)
{
// Find a matching property
$property = null;
foreach ($class->getProperties() as $prop) {
if (strcasecmp($token->getSource(), $prop->getName()) === 0) {
$property = $prop;
break;
}
}
if ($property === null) {
throw new DslSyntaxException('No matching property found for ' . $token->getSource());
}
return $namingConvention->propertyToColumnName($property);
} | [
"private",
"function",
"tokenToColumn",
"(",
"$",
"token",
",",
"$",
"namingConvention",
",",
"$",
"class",
")",
"{",
"// Find a matching property",
"$",
"property",
"=",
"null",
";",
"foreach",
"(",
"$",
"class",
"->",
"getProperties",
"(",
")",
"as",
"$",
"prop",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"token",
"->",
"getSource",
"(",
")",
",",
"$",
"prop",
"->",
"getName",
"(",
")",
")",
"===",
"0",
")",
"{",
"$",
"property",
"=",
"$",
"prop",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"property",
"===",
"null",
")",
"{",
"throw",
"new",
"DslSyntaxException",
"(",
"'No matching property found for '",
".",
"$",
"token",
"->",
"getSource",
"(",
")",
")",
";",
"}",
"return",
"$",
"namingConvention",
"->",
"propertyToColumnName",
"(",
"$",
"property",
")",
";",
"}"
] | Get the column name for a token.
@param ValueToken $token
@param NamingConvention $namingConvention
@param ReflectionClass $class
@return string
@throws DslSyntaxException when no matching property could be found | [
"Get",
"the",
"column",
"name",
"for",
"a",
"token",
"."
] | train | https://github.com/DataDo/data/blob/555b02a27755032fcd53e165b0674e81a68067c0/src/main/php/DataDo/Data/Query/DefaultQueryBuilder.php#L206-L222 |
caffeinated/beverage | src/Arr.php | Arr.unflatten | public static function unflatten(array $array, $delimiter = '.')
{
$unflattenedArray = array();
foreach ($array as $key => $value) {
$keyList = explode($delimiter, $key);
$firstKey = array_shift($keyList);
if (sizeof($keyList) > 0) {
$subArray = static::unflatten(array( implode($delimiter, $keyList) => $value ), $delimiter);
foreach ($subArray as $subArrayKey => $subArrayValue) {
$unflattenedArray[ $firstKey ][ $subArrayKey ] = $subArrayValue;
}
} else {
$unflattenedArray[ $firstKey ] = $value;
}
}
return $unflattenedArray;
} | php | public static function unflatten(array $array, $delimiter = '.')
{
$unflattenedArray = array();
foreach ($array as $key => $value) {
$keyList = explode($delimiter, $key);
$firstKey = array_shift($keyList);
if (sizeof($keyList) > 0) {
$subArray = static::unflatten(array( implode($delimiter, $keyList) => $value ), $delimiter);
foreach ($subArray as $subArrayKey => $subArrayValue) {
$unflattenedArray[ $firstKey ][ $subArrayKey ] = $subArrayValue;
}
} else {
$unflattenedArray[ $firstKey ] = $value;
}
}
return $unflattenedArray;
} | [
"public",
"static",
"function",
"unflatten",
"(",
"array",
"$",
"array",
",",
"$",
"delimiter",
"=",
"'.'",
")",
"{",
"$",
"unflattenedArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"keyList",
"=",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"key",
")",
";",
"$",
"firstKey",
"=",
"array_shift",
"(",
"$",
"keyList",
")",
";",
"if",
"(",
"sizeof",
"(",
"$",
"keyList",
")",
">",
"0",
")",
"{",
"$",
"subArray",
"=",
"static",
"::",
"unflatten",
"(",
"array",
"(",
"implode",
"(",
"$",
"delimiter",
",",
"$",
"keyList",
")",
"=>",
"$",
"value",
")",
",",
"$",
"delimiter",
")",
";",
"foreach",
"(",
"$",
"subArray",
"as",
"$",
"subArrayKey",
"=>",
"$",
"subArrayValue",
")",
"{",
"$",
"unflattenedArray",
"[",
"$",
"firstKey",
"]",
"[",
"$",
"subArrayKey",
"]",
"=",
"$",
"subArrayValue",
";",
"}",
"}",
"else",
"{",
"$",
"unflattenedArray",
"[",
"$",
"firstKey",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"unflattenedArray",
";",
"}"
] | Unflattens a single stacked array back into a multidimensional array.
@param array $array
@param string $delimiter
@return array | [
"Unflattens",
"a",
"single",
"stacked",
"array",
"back",
"into",
"a",
"multidimensional",
"array",
"."
] | train | https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Arr.php#L28-L48 |
Speicher210/monsum-api | src/Service/Coupon/CouponService.php | CouponService.getCoupons | public function getCoupons($code = null)
{
$requestData = new Get\RequestData($code);
$request = new Get\Request($requestData);
$apiResponse = $this->sendRequest($request, Get\ApiResponse::class);
/** @var Get\Response $response */
$response = $apiResponse->getResponse();
foreach ($response->getCoupons() as $coupon) {
$validFrom = $coupon->getValidFrom();
if ($validFrom !== null) {
$validFrom->setTime(0, 0, 0);
}
$validTo = $coupon->getValidTo();
if ($validTo !== null) {
$validTo->setTime(0, 0, 0);
}
}
return $apiResponse;
} | php | public function getCoupons($code = null)
{
$requestData = new Get\RequestData($code);
$request = new Get\Request($requestData);
$apiResponse = $this->sendRequest($request, Get\ApiResponse::class);
/** @var Get\Response $response */
$response = $apiResponse->getResponse();
foreach ($response->getCoupons() as $coupon) {
$validFrom = $coupon->getValidFrom();
if ($validFrom !== null) {
$validFrom->setTime(0, 0, 0);
}
$validTo = $coupon->getValidTo();
if ($validTo !== null) {
$validTo->setTime(0, 0, 0);
}
}
return $apiResponse;
} | [
"public",
"function",
"getCoupons",
"(",
"$",
"code",
"=",
"null",
")",
"{",
"$",
"requestData",
"=",
"new",
"Get",
"\\",
"RequestData",
"(",
"$",
"code",
")",
";",
"$",
"request",
"=",
"new",
"Get",
"\\",
"Request",
"(",
"$",
"requestData",
")",
";",
"$",
"apiResponse",
"=",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"request",
",",
"Get",
"\\",
"ApiResponse",
"::",
"class",
")",
";",
"/** @var Get\\Response $response */",
"$",
"response",
"=",
"$",
"apiResponse",
"->",
"getResponse",
"(",
")",
";",
"foreach",
"(",
"$",
"response",
"->",
"getCoupons",
"(",
")",
"as",
"$",
"coupon",
")",
"{",
"$",
"validFrom",
"=",
"$",
"coupon",
"->",
"getValidFrom",
"(",
")",
";",
"if",
"(",
"$",
"validFrom",
"!==",
"null",
")",
"{",
"$",
"validFrom",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"$",
"validTo",
"=",
"$",
"coupon",
"->",
"getValidTo",
"(",
")",
";",
"if",
"(",
"$",
"validTo",
"!==",
"null",
")",
"{",
"$",
"validTo",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"}",
"return",
"$",
"apiResponse",
";",
"}"
] | Get the coupons.
@param string $code The code to get.
@return Get\ApiResponse | [
"Get",
"the",
"coupons",
"."
] | train | https://github.com/Speicher210/monsum-api/blob/4611a048097de5d2b0efe9d4426779c783c0af4d/src/Service/Coupon/CouponService.php#L18-L39 |
Speicher210/monsum-api | src/Service/Coupon/CouponService.php | CouponService.checkCoupon | public function checkCoupon($code, $articleNumber)
{
$requestData = new Check\RequestData($code, $articleNumber);
$request = new Check\Request($requestData);
return $this->sendRequest($request, Check\ApiResponse::class);
} | php | public function checkCoupon($code, $articleNumber)
{
$requestData = new Check\RequestData($code, $articleNumber);
$request = new Check\Request($requestData);
return $this->sendRequest($request, Check\ApiResponse::class);
} | [
"public",
"function",
"checkCoupon",
"(",
"$",
"code",
",",
"$",
"articleNumber",
")",
"{",
"$",
"requestData",
"=",
"new",
"Check",
"\\",
"RequestData",
"(",
"$",
"code",
",",
"$",
"articleNumber",
")",
";",
"$",
"request",
"=",
"new",
"Check",
"\\",
"Request",
"(",
"$",
"requestData",
")",
";",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"$",
"request",
",",
"Check",
"\\",
"ApiResponse",
"::",
"class",
")",
";",
"}"
] | Check a coupon.
@param string $code The code to check.
@param string $articleNumber The article number.
@return Check\ApiResponse | [
"Check",
"a",
"coupon",
"."
] | train | https://github.com/Speicher210/monsum-api/blob/4611a048097de5d2b0efe9d4426779c783c0af4d/src/Service/Coupon/CouponService.php#L48-L54 |
surebert/surebert-framework | src/sb/Socket/Client.php | Client.open | public function open()
{
$this->log('open socket connection');
$this->socket = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
if ($this->socket) {
socket_set_blocking($this->socket, 1);
return true;
} else {
throw(new \Exception("{$errstr} (#{$errno})"));
}
} | php | public function open()
{
$this->log('open socket connection');
$this->socket = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
if ($this->socket) {
socket_set_blocking($this->socket, 1);
return true;
} else {
throw(new \Exception("{$errstr} (#{$errno})"));
}
} | [
"public",
"function",
"open",
"(",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'open socket connection'",
")",
";",
"$",
"this",
"->",
"socket",
"=",
"fsockopen",
"(",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"this",
"->",
"timeout",
")",
";",
"if",
"(",
"$",
"this",
"->",
"socket",
")",
"{",
"socket_set_blocking",
"(",
"$",
"this",
"->",
"socket",
",",
"1",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"throw",
"(",
"new",
"\\",
"Exception",
"(",
"\"{$errstr} (#{$errno})\"",
")",
")",
";",
"}",
"}"
] | Open the connection
@return boolean Throws exception on error | [
"Open",
"the",
"connection"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Socket/Client.php#L74-L86 |
surebert/surebert-framework | src/sb/Socket/Client.php | Client.close | public function close()
{
$this->log('close socket connection');
$state = fclose($this->socket);
if ($state) {
$this->socket = null;
}
return $state;
} | php | public function close()
{
$this->log('close socket connection');
$state = fclose($this->socket);
if ($state) {
$this->socket = null;
}
return $state;
} | [
"public",
"function",
"close",
"(",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'close socket connection'",
")",
";",
"$",
"state",
"=",
"fclose",
"(",
"$",
"this",
"->",
"socket",
")",
";",
"if",
"(",
"$",
"state",
")",
"{",
"$",
"this",
"->",
"socket",
"=",
"null",
";",
"}",
"return",
"$",
"state",
";",
"}"
] | Closes the connection. Automatically is called on __destruct
@return boolean | [
"Closes",
"the",
"connection",
".",
"Automatically",
"is",
"called",
"on",
"__destruct"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Socket/Client.php#L92-L102 |
wplibs/rules | src/Variable.php | Variable.get_property | public function get_property( $name, $value = null ) {
if ( ! array_key_exists( $name, $this->properties ) ) {
$this->properties[ $name ] = new Variable_Property( $this, $name, $value );
}
return $this->properties[ $name ];
} | php | public function get_property( $name, $value = null ) {
if ( ! array_key_exists( $name, $this->properties ) ) {
$this->properties[ $name ] = new Variable_Property( $this, $name, $value );
}
return $this->properties[ $name ];
} | [
"public",
"function",
"get_property",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"properties",
")",
")",
"{",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
"=",
"new",
"Variable_Property",
"(",
"$",
"this",
",",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
";",
"}"
] | Get a property (create new if not exists).
@param string $name The property name.
@param mixed $value The default value.
@return \WPLibs\Rules\Variable_Property | [
"Get",
"a",
"property",
"(",
"create",
"new",
"if",
"not",
"exists",
")",
"."
] | train | https://github.com/wplibs/rules/blob/29b4495e2ae87349fd64fcd844f3ba96cc268e3d/src/Variable.php#L102-L108 |
wplibs/rules | src/Variable.php | Variable.set_property | public function set_property( $name, $value ) {
$property = $this->get_property( $name );
$property->setValue( $value );
return $property;
} | php | public function set_property( $name, $value ) {
$property = $this->get_property( $name );
$property->setValue( $value );
return $property;
} | [
"public",
"function",
"set_property",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"get_property",
"(",
"$",
"name",
")",
";",
"$",
"property",
"->",
"setValue",
"(",
"$",
"value",
")",
";",
"return",
"$",
"property",
";",
"}"
] | Set a property value.
@param string $name The property name.
@param mixed $value The property value.
@return \WPLibs\Rules\Variable_Property | [
"Set",
"a",
"property",
"value",
"."
] | train | https://github.com/wplibs/rules/blob/29b4495e2ae87349fd64fcd844f3ba96cc268e3d/src/Variable.php#L117-L123 |
giftcards/Encryption | CipherText/Rotator/RotatorBuilder.php | RotatorBuilder.addStore | public function addStore($storeName, $builderName, array $options = array())
{
$this->storeRegistryBuilder->addStore($storeName, $builderName, $options);
} | php | public function addStore($storeName, $builderName, array $options = array())
{
$this->storeRegistryBuilder->addStore($storeName, $builderName, $options);
} | [
"public",
"function",
"addStore",
"(",
"$",
"storeName",
",",
"$",
"builderName",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"storeRegistryBuilder",
"->",
"addStore",
"(",
"$",
"storeName",
",",
"$",
"builderName",
",",
"$",
"options",
")",
";",
"}"
] | Adds a store to the builder
@param $storeName
@param $builderName
@param array $options | [
"Adds",
"a",
"store",
"to",
"the",
"builder"
] | train | https://github.com/giftcards/Encryption/blob/a48f92408538e2ffe1c8603f168d57803aad7100/CipherText/Rotator/RotatorBuilder.php#L60-L63 |
semibreve/minim | src/Authenticator.php | Authenticator.dispenseToken | private function dispenseToken()
{
$token = bin2hex(random_bytes($this->config->getTokenLength())); // Generate token.
$arr = array(
'token' => $token,
'expires' => time() + $this->config->getTokenTtl()
); // Prepare array containing token and expiry.
$plain = Spyc::YAMLDump($arr); // Encode as YAML.
$encrypted = Encryption::encrypt($plain, $this->config->getSecretKey()); // Apply symmetric encryption.
file_put_contents($this->config->getSessionFileName(), $encrypted); // Write to disk.
return $token;
} | php | private function dispenseToken()
{
$token = bin2hex(random_bytes($this->config->getTokenLength())); // Generate token.
$arr = array(
'token' => $token,
'expires' => time() + $this->config->getTokenTtl()
); // Prepare array containing token and expiry.
$plain = Spyc::YAMLDump($arr); // Encode as YAML.
$encrypted = Encryption::encrypt($plain, $this->config->getSecretKey()); // Apply symmetric encryption.
file_put_contents($this->config->getSessionFileName(), $encrypted); // Write to disk.
return $token;
} | [
"private",
"function",
"dispenseToken",
"(",
")",
"{",
"$",
"token",
"=",
"bin2hex",
"(",
"random_bytes",
"(",
"$",
"this",
"->",
"config",
"->",
"getTokenLength",
"(",
")",
")",
")",
";",
"// Generate token.",
"$",
"arr",
"=",
"array",
"(",
"'token'",
"=>",
"$",
"token",
",",
"'expires'",
"=>",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"config",
"->",
"getTokenTtl",
"(",
")",
")",
";",
"// Prepare array containing token and expiry.",
"$",
"plain",
"=",
"Spyc",
"::",
"YAMLDump",
"(",
"$",
"arr",
")",
";",
"// Encode as YAML.",
"$",
"encrypted",
"=",
"Encryption",
"::",
"encrypt",
"(",
"$",
"plain",
",",
"$",
"this",
"->",
"config",
"->",
"getSecretKey",
"(",
")",
")",
";",
"// Apply symmetric encryption.",
"file_put_contents",
"(",
"$",
"this",
"->",
"config",
"->",
"getSessionFileName",
"(",
")",
",",
"$",
"encrypted",
")",
";",
"// Write to disk.",
"return",
"$",
"token",
";",
"}"
] | Dispenses a randomly generated authentication token.
@return string | [
"Dispenses",
"a",
"randomly",
"generated",
"authentication",
"token",
"."
] | train | https://github.com/semibreve/minim/blob/c74353754f19ef0f3427fb7246b4474a24623cdd/src/Authenticator.php#L35-L50 |
semibreve/minim | src/Authenticator.php | Authenticator.validateToken | private function validateToken($token)
{
// Without a session file, no token will validate.
if (!file_exists($this->config->getSessionFileName()))
{
return false;
}
$encrypted = file_get_contents($this->config->getSessionFileName()); // Read encrypted session file.
$plain = Encryption::decrypt($encrypted, $this->config->getSecretKey()); // Decrypt data.
$file = Spyc::YAMLLoadString($plain); // Parse YAML.
return $token == $file['token'] && time() < $file['expires']; // Token must be valid and not expired.
} | php | private function validateToken($token)
{
// Without a session file, no token will validate.
if (!file_exists($this->config->getSessionFileName()))
{
return false;
}
$encrypted = file_get_contents($this->config->getSessionFileName()); // Read encrypted session file.
$plain = Encryption::decrypt($encrypted, $this->config->getSecretKey()); // Decrypt data.
$file = Spyc::YAMLLoadString($plain); // Parse YAML.
return $token == $file['token'] && time() < $file['expires']; // Token must be valid and not expired.
} | [
"private",
"function",
"validateToken",
"(",
"$",
"token",
")",
"{",
"// Without a session file, no token will validate.",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"config",
"->",
"getSessionFileName",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"encrypted",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"config",
"->",
"getSessionFileName",
"(",
")",
")",
";",
"// Read encrypted session file.",
"$",
"plain",
"=",
"Encryption",
"::",
"decrypt",
"(",
"$",
"encrypted",
",",
"$",
"this",
"->",
"config",
"->",
"getSecretKey",
"(",
")",
")",
";",
"// Decrypt data.",
"$",
"file",
"=",
"Spyc",
"::",
"YAMLLoadString",
"(",
"$",
"plain",
")",
";",
"// Parse YAML.",
"return",
"$",
"token",
"==",
"$",
"file",
"[",
"'token'",
"]",
"&&",
"time",
"(",
")",
"<",
"$",
"file",
"[",
"'expires'",
"]",
";",
"// Token must be valid and not expired.",
"}"
] | Returns true if the given authentication token is valid, otherwise returns false.
@param string $token the authentication token to validate
@return bool | [
"Returns",
"true",
"if",
"the",
"given",
"authentication",
"token",
"is",
"valid",
"otherwise",
"returns",
"false",
"."
] | train | https://github.com/semibreve/minim/blob/c74353754f19ef0f3427fb7246b4474a24623cdd/src/Authenticator.php#L58-L72 |
semibreve/minim | src/Authenticator.php | Authenticator.getCookieToken | public function getCookieToken()
{
// If we have accessed the cookie token this request already.
if ($this->cookieToken !== null) {
return $this->cookieToken;
}
$name = $this->config->getCookieName();
$plain = '';
if (isset($_COOKIE[$name])) {
$encrypted = $_COOKIE[$name]; // Read encrypted cookie.
$plain = Encryption::decrypt($encrypted, $this->config->getSecretKey()); // Decrypt cookie.
}
$this->cookieToken = $plain; // Don't access cookie again.
return $plain;
} | php | public function getCookieToken()
{
// If we have accessed the cookie token this request already.
if ($this->cookieToken !== null) {
return $this->cookieToken;
}
$name = $this->config->getCookieName();
$plain = '';
if (isset($_COOKIE[$name])) {
$encrypted = $_COOKIE[$name]; // Read encrypted cookie.
$plain = Encryption::decrypt($encrypted, $this->config->getSecretKey()); // Decrypt cookie.
}
$this->cookieToken = $plain; // Don't access cookie again.
return $plain;
} | [
"public",
"function",
"getCookieToken",
"(",
")",
"{",
"// If we have accessed the cookie token this request already.",
"if",
"(",
"$",
"this",
"->",
"cookieToken",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"cookieToken",
";",
"}",
"$",
"name",
"=",
"$",
"this",
"->",
"config",
"->",
"getCookieName",
"(",
")",
";",
"$",
"plain",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"encrypted",
"=",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
";",
"// Read encrypted cookie.",
"$",
"plain",
"=",
"Encryption",
"::",
"decrypt",
"(",
"$",
"encrypted",
",",
"$",
"this",
"->",
"config",
"->",
"getSecretKey",
"(",
")",
")",
";",
"// Decrypt cookie.",
"}",
"$",
"this",
"->",
"cookieToken",
"=",
"$",
"plain",
";",
"// Don't access cookie again.",
"return",
"$",
"plain",
";",
"}"
] | Decrypts the stored authentication token out of the authentication cookie and returns it.
@return string | [
"Decrypts",
"the",
"stored",
"authentication",
"token",
"out",
"of",
"the",
"authentication",
"cookie",
"and",
"returns",
"it",
"."
] | train | https://github.com/semibreve/minim/blob/c74353754f19ef0f3427fb7246b4474a24623cdd/src/Authenticator.php#L79-L95 |
semibreve/minim | src/Authenticator.php | Authenticator.setCookieToken | public function setCookieToken($token)
{
$this->cookieToken = $token; // Remember this for this request.
$encrypted = Encryption::encrypt($token, $this->config->getSecretKey()); // Encrypt token.
// Set cookie on client.
setcookie($this->config->getCookieName(),
$encrypted,
time() + $this->config->getTokenTtl(),
'/',
'',
$this->config->getCookieSslOnly(),
$this->config->getCookieHttpOnly()); // Store in cookie.
} | php | public function setCookieToken($token)
{
$this->cookieToken = $token; // Remember this for this request.
$encrypted = Encryption::encrypt($token, $this->config->getSecretKey()); // Encrypt token.
// Set cookie on client.
setcookie($this->config->getCookieName(),
$encrypted,
time() + $this->config->getTokenTtl(),
'/',
'',
$this->config->getCookieSslOnly(),
$this->config->getCookieHttpOnly()); // Store in cookie.
} | [
"public",
"function",
"setCookieToken",
"(",
"$",
"token",
")",
"{",
"$",
"this",
"->",
"cookieToken",
"=",
"$",
"token",
";",
"// Remember this for this request.",
"$",
"encrypted",
"=",
"Encryption",
"::",
"encrypt",
"(",
"$",
"token",
",",
"$",
"this",
"->",
"config",
"->",
"getSecretKey",
"(",
")",
")",
";",
"// Encrypt token.",
"// Set cookie on client.",
"setcookie",
"(",
"$",
"this",
"->",
"config",
"->",
"getCookieName",
"(",
")",
",",
"$",
"encrypted",
",",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"config",
"->",
"getTokenTtl",
"(",
")",
",",
"'/'",
",",
"''",
",",
"$",
"this",
"->",
"config",
"->",
"getCookieSslOnly",
"(",
")",
",",
"$",
"this",
"->",
"config",
"->",
"getCookieHttpOnly",
"(",
")",
")",
";",
"// Store in cookie.",
"}"
] | Encrypts an authentication token into the authentication cookie.
@param string $token the token to store in the cookie | [
"Encrypts",
"an",
"authentication",
"token",
"into",
"the",
"authentication",
"cookie",
"."
] | train | https://github.com/semibreve/minim/blob/c74353754f19ef0f3427fb7246b4474a24623cdd/src/Authenticator.php#L102-L115 |
semibreve/minim | src/Authenticator.php | Authenticator.authenticate | public function authenticate($email, $password)
{
// If we're operating in secure-only mode.
if ($this->config->getCookieSslOnly() && !isset($_SERVER['HTTPS'])) {
echo 'Connection is insecure, login cannot proceed.';
die();
}
// Check credentials.
if ($this->config->getAdminEmail() != $email
|| !Encryption::verify($password, $this->config->getAdminPasswordHash()))
{
return false; // Authentication failure.
}
// Set cookie to newly dispensed token.
$this->setCookieToken($this->dispenseToken());
return true;
} | php | public function authenticate($email, $password)
{
// If we're operating in secure-only mode.
if ($this->config->getCookieSslOnly() && !isset($_SERVER['HTTPS'])) {
echo 'Connection is insecure, login cannot proceed.';
die();
}
// Check credentials.
if ($this->config->getAdminEmail() != $email
|| !Encryption::verify($password, $this->config->getAdminPasswordHash()))
{
return false; // Authentication failure.
}
// Set cookie to newly dispensed token.
$this->setCookieToken($this->dispenseToken());
return true;
} | [
"public",
"function",
"authenticate",
"(",
"$",
"email",
",",
"$",
"password",
")",
"{",
"// If we're operating in secure-only mode.",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"getCookieSslOnly",
"(",
")",
"&&",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
")",
"{",
"echo",
"'Connection is insecure, login cannot proceed.'",
";",
"die",
"(",
")",
";",
"}",
"// Check credentials.",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"getAdminEmail",
"(",
")",
"!=",
"$",
"email",
"||",
"!",
"Encryption",
"::",
"verify",
"(",
"$",
"password",
",",
"$",
"this",
"->",
"config",
"->",
"getAdminPasswordHash",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"// Authentication failure.",
"}",
"// Set cookie to newly dispensed token.",
"$",
"this",
"->",
"setCookieToken",
"(",
"$",
"this",
"->",
"dispenseToken",
"(",
")",
")",
";",
"return",
"true",
";",
"}"
] | Authenticates the given e-mail address password pair.
@param string $email the e-mail address to authenticate
@param string $password the password to authenticate
@return bool | [
"Authenticates",
"the",
"given",
"e",
"-",
"mail",
"address",
"password",
"pair",
"."
] | train | https://github.com/semibreve/minim/blob/c74353754f19ef0f3427fb7246b4474a24623cdd/src/Authenticator.php#L124-L143 |
semibreve/minim | src/Authenticator.php | Authenticator.isAuthenticated | public function isAuthenticated()
{
// Validate token.
$authenticated = $this->validateToken($this->getCookieToken());
if ($authenticated) {
$this->setCookieToken($this->dispenseToken()); // Dispense a new token.
}
return $authenticated;
} | php | public function isAuthenticated()
{
// Validate token.
$authenticated = $this->validateToken($this->getCookieToken());
if ($authenticated) {
$this->setCookieToken($this->dispenseToken()); // Dispense a new token.
}
return $authenticated;
} | [
"public",
"function",
"isAuthenticated",
"(",
")",
"{",
"// Validate token.",
"$",
"authenticated",
"=",
"$",
"this",
"->",
"validateToken",
"(",
"$",
"this",
"->",
"getCookieToken",
"(",
")",
")",
";",
"if",
"(",
"$",
"authenticated",
")",
"{",
"$",
"this",
"->",
"setCookieToken",
"(",
"$",
"this",
"->",
"dispenseToken",
"(",
")",
")",
";",
"// Dispense a new token.",
"}",
"return",
"$",
"authenticated",
";",
"}"
] | Checks whether or not the current user is authenticated.
@return bool | [
"Checks",
"whether",
"or",
"not",
"the",
"current",
"user",
"is",
"authenticated",
"."
] | train | https://github.com/semibreve/minim/blob/c74353754f19ef0f3427fb7246b4474a24623cdd/src/Authenticator.php#L150-L158 |
semibreve/minim | src/Authenticator.php | Authenticator.logout | public function logout()
{
setcookie($this->config->getCookieName(), '', time() - 3600); // Remove client-side cookie.
unlink($this->config->getSessionFileName()); // Delete session file.
} | php | public function logout()
{
setcookie($this->config->getCookieName(), '', time() - 3600); // Remove client-side cookie.
unlink($this->config->getSessionFileName()); // Delete session file.
} | [
"public",
"function",
"logout",
"(",
")",
"{",
"setcookie",
"(",
"$",
"this",
"->",
"config",
"->",
"getCookieName",
"(",
")",
",",
"''",
",",
"time",
"(",
")",
"-",
"3600",
")",
";",
"// Remove client-side cookie.",
"unlink",
"(",
"$",
"this",
"->",
"config",
"->",
"getSessionFileName",
"(",
")",
")",
";",
"// Delete session file.",
"}"
] | Logs the currently authenticated user out. | [
"Logs",
"the",
"currently",
"authenticated",
"user",
"out",
"."
] | train | https://github.com/semibreve/minim/blob/c74353754f19ef0f3427fb7246b4474a24623cdd/src/Authenticator.php#L163-L167 |
yeaha/owl-core | src/Parameter/Validator.php | Validator.is | public function is(array $values, array $rules)
{
try {
$this->execute($values, $rules);
} catch (\Exception $ex) {
return false;
}
return true;
} | php | public function is(array $values, array $rules)
{
try {
$this->execute($values, $rules);
} catch (\Exception $ex) {
return false;
}
return true;
} | [
"public",
"function",
"is",
"(",
"array",
"$",
"values",
",",
"array",
"$",
"rules",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"execute",
"(",
"$",
"values",
",",
"$",
"rules",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | 数据是否符合检查规则,不抛出异常而是返回boolean.
@param array $values
@param array $rules
@return bool | [
"数据是否符合检查规则,不抛出异常而是返回boolean",
"."
] | train | https://github.com/yeaha/owl-core/blob/fd7531c0a5c0142300a96160bd079f2e2d92fe4c/src/Parameter/Validator.php#L152-L161 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.boot | public static function boot()
{
NodeSource::saving(function (NodeSourceContract $nodeSource)
{
if (empty($nodeSource->getNodeName()) || is_null($nodeSource->getNodeName()))
{
$nodeSource->setNodeNameFromTitle();
}
});
} | php | public static function boot()
{
NodeSource::saving(function (NodeSourceContract $nodeSource)
{
if (empty($nodeSource->getNodeName()) || is_null($nodeSource->getNodeName()))
{
$nodeSource->setNodeNameFromTitle();
}
});
} | [
"public",
"static",
"function",
"boot",
"(",
")",
"{",
"NodeSource",
"::",
"saving",
"(",
"function",
"(",
"NodeSourceContract",
"$",
"nodeSource",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"nodeSource",
"->",
"getNodeName",
"(",
")",
")",
"||",
"is_null",
"(",
"$",
"nodeSource",
"->",
"getNodeName",
"(",
")",
")",
")",
"{",
"$",
"nodeSource",
"->",
"setNodeNameFromTitle",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Boot the model | [
"Boot",
"the",
"model"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L45-L54 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.getSourceModelName | public function getSourceModelName($type = null)
{
$type = $type ?: $this->source_type;
return source_model_name($type, true);
} | php | public function getSourceModelName($type = null)
{
$type = $type ?: $this->source_type;
return source_model_name($type, true);
} | [
"public",
"function",
"getSourceModelName",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"type",
"=",
"$",
"type",
"?",
":",
"$",
"this",
"->",
"source_type",
";",
"return",
"source_model_name",
"(",
"$",
"type",
",",
"true",
")",
";",
"}"
] | Returns the source model name
@param string|null $type
@return string | [
"Returns",
"the",
"source",
"model",
"name"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L85-L90 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.newWithType | public static function newWithType($locale, $type)
{
$nodeSource = new static();
$sourceModel = $nodeSource->getNewSourceModel($type);
// We temporarily cache the model since Eloquent does not
// have a way to attach hasOne relations without saving them.
// So we are providing a customized way to emulate that.
// We will always access the source model through getSource() method.
$nodeSource->setTemporarySource($sourceModel);
// We first fill special attributes.
// These have to be done after we have added the temporary source
// since the setAttribute will look at the temporary source as well.
$nodeSource->setAttribute('locale', $locale);
$nodeSource->setAttribute('source_type', $type);
return $nodeSource;
} | php | public static function newWithType($locale, $type)
{
$nodeSource = new static();
$sourceModel = $nodeSource->getNewSourceModel($type);
// We temporarily cache the model since Eloquent does not
// have a way to attach hasOne relations without saving them.
// So we are providing a customized way to emulate that.
// We will always access the source model through getSource() method.
$nodeSource->setTemporarySource($sourceModel);
// We first fill special attributes.
// These have to be done after we have added the temporary source
// since the setAttribute will look at the temporary source as well.
$nodeSource->setAttribute('locale', $locale);
$nodeSource->setAttribute('source_type', $type);
return $nodeSource;
} | [
"public",
"static",
"function",
"newWithType",
"(",
"$",
"locale",
",",
"$",
"type",
")",
"{",
"$",
"nodeSource",
"=",
"new",
"static",
"(",
")",
";",
"$",
"sourceModel",
"=",
"$",
"nodeSource",
"->",
"getNewSourceModel",
"(",
"$",
"type",
")",
";",
"// We temporarily cache the model since Eloquent does not",
"// have a way to attach hasOne relations without saving them.",
"// So we are providing a customized way to emulate that.",
"// We will always access the source model through getSource() method.",
"$",
"nodeSource",
"->",
"setTemporarySource",
"(",
"$",
"sourceModel",
")",
";",
"// We first fill special attributes.",
"// These have to be done after we have added the temporary source",
"// since the setAttribute will look at the temporary source as well.",
"$",
"nodeSource",
"->",
"setAttribute",
"(",
"'locale'",
",",
"$",
"locale",
")",
";",
"$",
"nodeSource",
"->",
"setAttribute",
"(",
"'source_type'",
",",
"$",
"type",
")",
";",
"return",
"$",
"nodeSource",
";",
"}"
] | Create new node source with locale and type
@param string $locale
@param string $type
@return NodeSource | [
"Create",
"new",
"node",
"source",
"with",
"locale",
"and",
"type"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L99-L118 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.getSource | public function getSource()
{
if ( ! is_null($this->tempSource))
{
return $this->tempSource;
}
if ( ! $this->isSourceRelationLoaded())
{
$this->load('source');
}
return $this->relations['source'];
} | php | public function getSource()
{
if ( ! is_null($this->tempSource))
{
return $this->tempSource;
}
if ( ! $this->isSourceRelationLoaded())
{
$this->load('source');
}
return $this->relations['source'];
} | [
"public",
"function",
"getSource",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"tempSource",
")",
")",
"{",
"return",
"$",
"this",
"->",
"tempSource",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isSourceRelationLoaded",
"(",
")",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"'source'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"relations",
"[",
"'source'",
"]",
";",
"}"
] | Getter for source data
@return mixed | [
"Getter",
"for",
"source",
"data"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L154-L167 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.saveSource | protected function saveSource()
{
// This part is only for the first save
// as we temporarily keep the source model before
// the parent saves.
if ( ! is_null($this->tempSource))
{
$saved = $this->source()->save(
$this->tempSource);
// Reload the relation
$this->load('source');
$this->flushTemporarySource();
return ! is_null($saved);
}
return $this->source->save();
} | php | protected function saveSource()
{
// This part is only for the first save
// as we temporarily keep the source model before
// the parent saves.
if ( ! is_null($this->tempSource))
{
$saved = $this->source()->save(
$this->tempSource);
// Reload the relation
$this->load('source');
$this->flushTemporarySource();
return ! is_null($saved);
}
return $this->source->save();
} | [
"protected",
"function",
"saveSource",
"(",
")",
"{",
"// This part is only for the first save",
"// as we temporarily keep the source model before",
"// the parent saves.",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"tempSource",
")",
")",
"{",
"$",
"saved",
"=",
"$",
"this",
"->",
"source",
"(",
")",
"->",
"save",
"(",
"$",
"this",
"->",
"tempSource",
")",
";",
"// Reload the relation",
"$",
"this",
"->",
"load",
"(",
"'source'",
")",
";",
"$",
"this",
"->",
"flushTemporarySource",
"(",
")",
";",
"return",
"!",
"is_null",
"(",
"$",
"saved",
")",
";",
"}",
"return",
"$",
"this",
"->",
"source",
"->",
"save",
"(",
")",
";",
"}"
] | Saves the source model
@return bool | [
"Saves",
"the",
"source",
"model"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L224-L243 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.getAttribute | public function getAttribute($key)
{
if ($this->isBaseAttribute($key))
{
return parent::getAttribute($key);
} else
{
return $this->getSource()->getAttribute($key);
}
} | php | public function getAttribute($key)
{
if ($this->isBaseAttribute($key))
{
return parent::getAttribute($key);
} else
{
return $this->getSource()->getAttribute($key);
}
} | [
"public",
"function",
"getAttribute",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isBaseAttribute",
"(",
"$",
"key",
")",
")",
"{",
"return",
"parent",
"::",
"getAttribute",
"(",
"$",
"key",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"getSource",
"(",
")",
"->",
"getAttribute",
"(",
"$",
"key",
")",
";",
"}",
"}"
] | Gets a model attribute
@param string $key
@return mixed | [
"Gets",
"a",
"model",
"attribute"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L251-L260 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.getUnmutatedAttribute | public function getUnmutatedAttribute($key)
{
if ($this->isBaseAttribute($key))
{
return parent::getAttribute($key);
} else
{
return $this->getSource()->getAttributeFromArray($key);
}
} | php | public function getUnmutatedAttribute($key)
{
if ($this->isBaseAttribute($key))
{
return parent::getAttribute($key);
} else
{
return $this->getSource()->getAttributeFromArray($key);
}
} | [
"public",
"function",
"getUnmutatedAttribute",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isBaseAttribute",
"(",
"$",
"key",
")",
")",
"{",
"return",
"parent",
"::",
"getAttribute",
"(",
"$",
"key",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"getSource",
"(",
")",
"->",
"getAttributeFromArray",
"(",
"$",
"key",
")",
";",
"}",
"}"
] | Gets a model attribute
@param string $key
@return mixed | [
"Gets",
"a",
"model",
"attribute"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L268-L277 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.setAttribute | public function setAttribute($key, $value)
{
if ($this->isBaseAttribute($key))
{
return parent::setAttribute($key, $value);
} else
{
return $this->getSource()->setAttribute($key, $value);
}
} | php | public function setAttribute($key, $value)
{
if ($this->isBaseAttribute($key))
{
return parent::setAttribute($key, $value);
} else
{
return $this->getSource()->setAttribute($key, $value);
}
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isBaseAttribute",
"(",
"$",
"key",
")",
")",
"{",
"return",
"parent",
"::",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"getSource",
"(",
")",
"->",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Sets a model attribute
@param string $key
@param mixed $value
@return void | [
"Sets",
"a",
"model",
"attribute"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L286-L295 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.isDirty | public function isDirty($attributes = null)
{
return parent::isDirty($attributes) or
$this->getSource()->isDirty($attributes);
} | php | public function isDirty($attributes = null)
{
return parent::isDirty($attributes) or
$this->getSource()->isDirty($attributes);
} | [
"public",
"function",
"isDirty",
"(",
"$",
"attributes",
"=",
"null",
")",
"{",
"return",
"parent",
"::",
"isDirty",
"(",
"$",
"attributes",
")",
"or",
"$",
"this",
"->",
"getSource",
"(",
")",
"->",
"isDirty",
"(",
"$",
"attributes",
")",
";",
"}"
] | Determine if the model or given attribute(s) have been modified.
@param array|string|null $attributes
@return bool | [
"Determine",
"if",
"the",
"model",
"or",
"given",
"attribute",
"(",
"s",
")",
"have",
"been",
"modified",
"."
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L315-L319 |
NuclearCMS/Hierarchy | src/NodeSource.php | NodeSource.setExtensionNodeId | public function setExtensionNodeId($id, $save = true)
{
$source = $this->getSource()->setNodeId($id);
if ($save)
{
$source->save();
}
} | php | public function setExtensionNodeId($id, $save = true)
{
$source = $this->getSource()->setNodeId($id);
if ($save)
{
$source->save();
}
} | [
"public",
"function",
"setExtensionNodeId",
"(",
"$",
"id",
",",
"$",
"save",
"=",
"true",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"getSource",
"(",
")",
"->",
"setNodeId",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"save",
")",
"{",
"$",
"source",
"->",
"save",
"(",
")",
";",
"}",
"}"
] | Sets the extension node id
@param bool $save
@param int $id | [
"Sets",
"the",
"extension",
"node",
"id"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeSource.php#L400-L408 |
colorium/web | src/Colorium/Web/Kernel.php | Kernel.setup | protected function setup()
{
set_error_handler(function($level, $message, $file = null, $line = null) {
$fatal = E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING;
if(($level & $fatal) > 0) {
throw new \ErrorException($message, $level, $level, $file, $line);
}
});
} | php | protected function setup()
{
set_error_handler(function($level, $message, $file = null, $line = null) {
$fatal = E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING;
if(($level & $fatal) > 0) {
throw new \ErrorException($message, $level, $level, $file, $line);
}
});
} | [
"protected",
"function",
"setup",
"(",
")",
"{",
"set_error_handler",
"(",
"function",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"file",
"=",
"null",
",",
"$",
"line",
"=",
"null",
")",
"{",
"$",
"fatal",
"=",
"E_ERROR",
"|",
"E_PARSE",
"|",
"E_CORE_ERROR",
"|",
"E_CORE_WARNING",
"|",
"E_COMPILE_ERROR",
"|",
"E_COMPILE_WARNING",
";",
"if",
"(",
"(",
"$",
"level",
"&",
"$",
"fatal",
")",
">",
"0",
")",
"{",
"throw",
"new",
"\\",
"ErrorException",
"(",
"$",
"message",
",",
"$",
"level",
",",
"$",
"level",
",",
"$",
"file",
",",
"$",
"line",
")",
";",
"}",
"}",
")",
";",
"}"
] | Setup app | [
"Setup",
"app"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Kernel.php#L39-L47 |
colorium/web | src/Colorium/Web/Kernel.php | Kernel.run | public function run(Context $context = null)
{
$start = microtime(true);
try {
try {
$this->logger->debug('kernel: start');
$context = $context ?: $this->context();
$context = $this->before($context);
return $this->proceed($context);
}
catch(HttpException $event) {
return $this->event($event, $context);
}
}
catch(\Exception $error) {
return $this->error($error, $context);
}
finally {
$this->after($context);
$this->logger->debug('kernel: end (' . number_format(microtime(true) - $start, 4) . 's)');
}
} | php | public function run(Context $context = null)
{
$start = microtime(true);
try {
try {
$this->logger->debug('kernel: start');
$context = $context ?: $this->context();
$context = $this->before($context);
return $this->proceed($context);
}
catch(HttpException $event) {
return $this->event($event, $context);
}
}
catch(\Exception $error) {
return $this->error($error, $context);
}
finally {
$this->after($context);
$this->logger->debug('kernel: end (' . number_format(microtime(true) - $start, 4) . 's)');
}
} | [
"public",
"function",
"run",
"(",
"Context",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"start",
"=",
"microtime",
"(",
"true",
")",
";",
"try",
"{",
"try",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel: start'",
")",
";",
"$",
"context",
"=",
"$",
"context",
"?",
":",
"$",
"this",
"->",
"context",
"(",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"before",
"(",
"$",
"context",
")",
";",
"return",
"$",
"this",
"->",
"proceed",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"HttpException",
"$",
"event",
")",
"{",
"return",
"$",
"this",
"->",
"event",
"(",
"$",
"event",
",",
"$",
"context",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"error",
")",
"{",
"return",
"$",
"this",
"->",
"error",
"(",
"$",
"error",
",",
"$",
"context",
")",
";",
"}",
"finally",
"{",
"$",
"this",
"->",
"after",
"(",
"$",
"context",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel: end ('",
".",
"number_format",
"(",
"microtime",
"(",
"true",
")",
"-",
"$",
"start",
",",
"4",
")",
".",
"'s)'",
")",
";",
"}",
"}"
] | Run handler
@param Context $context
@return Context
@throws \Exception
@throws HttpException | [
"Run",
"handler"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Kernel.php#L59-L81 |
colorium/web | src/Colorium/Web/Kernel.php | Kernel.event | protected function event(HttpException $event, Context $context = null)
{
$code = $event->getCode();
if(isset($this->events[$code])) {
$context->error = $event;
$context->response->code = $event->getCode();
$this->logger->debug('kernel.event: http ' . $code . ' event raised, has callback');
return $context->forward($this->events[$code], $event);
}
$this->logger->debug('kernel.event: http ' . $code . ' event raised, no callback');
throw $event;
} | php | protected function event(HttpException $event, Context $context = null)
{
$code = $event->getCode();
if(isset($this->events[$code])) {
$context->error = $event;
$context->response->code = $event->getCode();
$this->logger->debug('kernel.event: http ' . $code . ' event raised, has callback');
return $context->forward($this->events[$code], $event);
}
$this->logger->debug('kernel.event: http ' . $code . ' event raised, no callback');
throw $event;
} | [
"protected",
"function",
"event",
"(",
"HttpException",
"$",
"event",
",",
"Context",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"code",
"=",
"$",
"event",
"->",
"getCode",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"code",
"]",
")",
")",
"{",
"$",
"context",
"->",
"error",
"=",
"$",
"event",
";",
"$",
"context",
"->",
"response",
"->",
"code",
"=",
"$",
"event",
"->",
"getCode",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.event: http '",
".",
"$",
"code",
".",
"' event raised, has callback'",
")",
";",
"return",
"$",
"context",
"->",
"forward",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"code",
"]",
",",
"$",
"event",
")",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.event: http '",
".",
"$",
"code",
".",
"' event raised, no callback'",
")",
";",
"throw",
"$",
"event",
";",
"}"
] | Handle http event
@param HttpException $event
@param Context $context
@return Context
@throws HttpException | [
"Handle",
"http",
"event"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Kernel.php#L125-L137 |
colorium/web | src/Colorium/Web/Kernel.php | Kernel.error | protected function error(\Exception $error, Context $context = null)
{
$exception = get_class($error);
$this->logger->error($error);
if($this->catch) {
foreach($this->errors as $class => $callback) {
if(is_string($class) and $error instanceof $class) {
$context->error = $error;
$this->logger->debug('kernel.error: ' . $exception . ' raised, has callback');
return $context->forward($callback, $error);
}
}
}
$this->logger->debug('kernel.error: ' . $exception . ' raised, no callback');
throw $error;
} | php | protected function error(\Exception $error, Context $context = null)
{
$exception = get_class($error);
$this->logger->error($error);
if($this->catch) {
foreach($this->errors as $class => $callback) {
if(is_string($class) and $error instanceof $class) {
$context->error = $error;
$this->logger->debug('kernel.error: ' . $exception . ' raised, has callback');
return $context->forward($callback, $error);
}
}
}
$this->logger->debug('kernel.error: ' . $exception . ' raised, no callback');
throw $error;
} | [
"protected",
"function",
"error",
"(",
"\\",
"Exception",
"$",
"error",
",",
"Context",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"exception",
"=",
"get_class",
"(",
"$",
"error",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"$",
"error",
")",
";",
"if",
"(",
"$",
"this",
"->",
"catch",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"errors",
"as",
"$",
"class",
"=>",
"$",
"callback",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"class",
")",
"and",
"$",
"error",
"instanceof",
"$",
"class",
")",
"{",
"$",
"context",
"->",
"error",
"=",
"$",
"error",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.error: '",
".",
"$",
"exception",
".",
"' raised, has callback'",
")",
";",
"return",
"$",
"context",
"->",
"forward",
"(",
"$",
"callback",
",",
"$",
"error",
")",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.error: '",
".",
"$",
"exception",
".",
"' raised, no callback'",
")",
";",
"throw",
"$",
"error",
";",
"}"
] | Handle exception
@param \Exception $error
@param Context $context
@return Context
@throws \Exception | [
"Handle",
"exception"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Kernel.php#L149-L166 |
phergie/phergie-irc-plugin-react-autojoin | src/Plugin.php | Plugin.joinChannels | public function joinChannels($dummy, EventQueueInterface $queue)
{
$queue->ircJoin($this->channels, $this->keys);
} | php | public function joinChannels($dummy, EventQueueInterface $queue)
{
$queue->ircJoin($this->channels, $this->keys);
} | [
"public",
"function",
"joinChannels",
"(",
"$",
"dummy",
",",
"EventQueueInterface",
"$",
"queue",
")",
"{",
"$",
"queue",
"->",
"ircJoin",
"(",
"$",
"this",
"->",
"channels",
",",
"$",
"this",
"->",
"keys",
")",
";",
"}"
] | Joins the provided list of channels.
@param mixed $dummy Unused, as it only matters that one of the
subscribed events has occurred, not what it is
@param \Phergie\Irc\Bot\React\EventQueueInterface $queue | [
"Joins",
"the",
"provided",
"list",
"of",
"channels",
"."
] | train | https://github.com/phergie/phergie-irc-plugin-react-autojoin/blob/b0e98fc2b503ddcdaf199375e9bcdc62e774036b/src/Plugin.php#L112-L115 |
DeprecatedPackages/EventDispatcher | src/DI/NetteEventListFactory.php | NetteEventListFactory.create | public function create()
{
$list = [];
$list = $this->addApplicationEventItems($list);
$list = $this->addPresenterEventItems($list);
return $list;
} | php | public function create()
{
$list = [];
$list = $this->addApplicationEventItems($list);
$list = $this->addPresenterEventItems($list);
return $list;
} | [
"public",
"function",
"create",
"(",
")",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"addApplicationEventItems",
"(",
"$",
"list",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"addPresenterEventItems",
"(",
"$",
"list",
")",
";",
"return",
"$",
"list",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/DeprecatedPackages/EventDispatcher/blob/1359bb86e208626578bd7049b48bfb8a25d57b64/src/DI/NetteEventListFactory.php#L29-L35 |
WellCommerce/StandardEditionBundle | DataFixtures/ORM/LoadDelivererData.php | LoadDelivererData.load | public function load(ObjectManager $manager)
{
if (!$this->isEnabled()) {
return;
}
$fakerGenerator = $this->getFakerGenerator();
$deliverer = new Deliverer();
$name = $fakerGenerator->company;
foreach ($this->getLocales() as $locale) {
$deliverer->translate($locale->getCode())->setName($name);
}
$deliverer->mergeNewTranslations();
$manager->persist($deliverer);
$manager->flush();
$this->setReference('deliverer', $deliverer);
} | php | public function load(ObjectManager $manager)
{
if (!$this->isEnabled()) {
return;
}
$fakerGenerator = $this->getFakerGenerator();
$deliverer = new Deliverer();
$name = $fakerGenerator->company;
foreach ($this->getLocales() as $locale) {
$deliverer->translate($locale->getCode())->setName($name);
}
$deliverer->mergeNewTranslations();
$manager->persist($deliverer);
$manager->flush();
$this->setReference('deliverer', $deliverer);
} | [
"public",
"function",
"load",
"(",
"ObjectManager",
"$",
"manager",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isEnabled",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"fakerGenerator",
"=",
"$",
"this",
"->",
"getFakerGenerator",
"(",
")",
";",
"$",
"deliverer",
"=",
"new",
"Deliverer",
"(",
")",
";",
"$",
"name",
"=",
"$",
"fakerGenerator",
"->",
"company",
";",
"foreach",
"(",
"$",
"this",
"->",
"getLocales",
"(",
")",
"as",
"$",
"locale",
")",
"{",
"$",
"deliverer",
"->",
"translate",
"(",
"$",
"locale",
"->",
"getCode",
"(",
")",
")",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"}",
"$",
"deliverer",
"->",
"mergeNewTranslations",
"(",
")",
";",
"$",
"manager",
"->",
"persist",
"(",
"$",
"deliverer",
")",
";",
"$",
"manager",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"setReference",
"(",
"'deliverer'",
",",
"$",
"deliverer",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/WellCommerce/StandardEditionBundle/blob/6367bd20bbb6bde37c710a6ba87ae72b5f05f61e/DataFixtures/ORM/LoadDelivererData.php#L29-L47 |
bobfridley/laravel-vonage | src/VonageFactory.php | VonageFactory.getClient | protected function getClient(array $auth)
{
$this->cookieFile = storage_path() . '/guzzlehttp/cookies/vonage/' . $auth['username'] . '.txt';
$cookieJar = new FileCookieJar($this->cookieFile, true);
$this->client = new Client(array('base_uri' => $this->base_uri, 'cookies' => $cookieJar));
$response = $this->client->get($this->base_uri . '/appserver/rest/user/null', [
'cookies' => $cookieJar,
'query' => [
'htmlLogin' => $auth['username'],
'htmlPassword' => $auth['password']
],
'headers' => ['X-Vonage' => 'vonage']
]);
return $this->client;
} | php | protected function getClient(array $auth)
{
$this->cookieFile = storage_path() . '/guzzlehttp/cookies/vonage/' . $auth['username'] . '.txt';
$cookieJar = new FileCookieJar($this->cookieFile, true);
$this->client = new Client(array('base_uri' => $this->base_uri, 'cookies' => $cookieJar));
$response = $this->client->get($this->base_uri . '/appserver/rest/user/null', [
'cookies' => $cookieJar,
'query' => [
'htmlLogin' => $auth['username'],
'htmlPassword' => $auth['password']
],
'headers' => ['X-Vonage' => 'vonage']
]);
return $this->client;
} | [
"protected",
"function",
"getClient",
"(",
"array",
"$",
"auth",
")",
"{",
"$",
"this",
"->",
"cookieFile",
"=",
"storage_path",
"(",
")",
".",
"'/guzzlehttp/cookies/vonage/'",
".",
"$",
"auth",
"[",
"'username'",
"]",
".",
"'.txt'",
";",
"$",
"cookieJar",
"=",
"new",
"FileCookieJar",
"(",
"$",
"this",
"->",
"cookieFile",
",",
"true",
")",
";",
"$",
"this",
"->",
"client",
"=",
"new",
"Client",
"(",
"array",
"(",
"'base_uri'",
"=>",
"$",
"this",
"->",
"base_uri",
",",
"'cookies'",
"=>",
"$",
"cookieJar",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"get",
"(",
"$",
"this",
"->",
"base_uri",
".",
"'/appserver/rest/user/null'",
",",
"[",
"'cookies'",
"=>",
"$",
"cookieJar",
",",
"'query'",
"=>",
"[",
"'htmlLogin'",
"=>",
"$",
"auth",
"[",
"'username'",
"]",
",",
"'htmlPassword'",
"=>",
"$",
"auth",
"[",
"'password'",
"]",
"]",
",",
"'headers'",
"=>",
"[",
"'X-Vonage'",
"=>",
"'vonage'",
"]",
"]",
")",
";",
"return",
"$",
"this",
"->",
"client",
";",
"}"
] | Get the vonage client.
@param array[] $auth
@return \Vonage\Client | [
"Get",
"the",
"vonage",
"client",
"."
] | train | https://github.com/bobfridley/laravel-vonage/blob/e422af44a449c3147878c317b865508b1afa50e6/src/VonageFactory.php#L88-L106 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/Agavi/DwooRenderer.php | DwooRenderer.initialize | public function initialize(AgaviContext $context, array $parameters = array())
{
parent::initialize($context, $parameters);
$this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir);
} | php | public function initialize(AgaviContext $context, array $parameters = array())
{
parent::initialize($context, $parameters);
$this->plugin_dir = $this->getParameter('plugin_dir', $this->plugin_dir);
} | [
"public",
"function",
"initialize",
"(",
"AgaviContext",
"$",
"context",
",",
"array",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"parent",
"::",
"initialize",
"(",
"$",
"context",
",",
"$",
"parameters",
")",
";",
"$",
"this",
"->",
"plugin_dir",
"=",
"$",
"this",
"->",
"getParameter",
"(",
"'plugin_dir'",
",",
"$",
"this",
"->",
"plugin_dir",
")",
";",
"}"
] | Initialize this Renderer.
@param AgaviContext The current application context.
@param array An associative array of initialization parameters. | [
"Initialize",
"this",
"Renderer",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/Agavi/DwooRenderer.php#L97-L102 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/Agavi/DwooRenderer.php | DwooRenderer.compilerFactory | public function compilerFactory()
{
if (class_exists('Dwoo_Compiler', false) === false) {
include DWOO_DIRECTORY . 'Dwoo/Compiler.php';
}
$compiler = Dwoo_Compiler::compilerFactory();
$compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false));
return $compiler;
} | php | public function compilerFactory()
{
if (class_exists('Dwoo_Compiler', false) === false) {
include DWOO_DIRECTORY . 'Dwoo/Compiler.php';
}
$compiler = Dwoo_Compiler::compilerFactory();
$compiler->setAutoEscape((bool) $this->getParameter('auto_escape', false));
return $compiler;
} | [
"public",
"function",
"compilerFactory",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'Dwoo_Compiler'",
",",
"false",
")",
"===",
"false",
")",
"{",
"include",
"DWOO_DIRECTORY",
".",
"'Dwoo/Compiler.php'",
";",
"}",
"$",
"compiler",
"=",
"Dwoo_Compiler",
"::",
"compilerFactory",
"(",
")",
";",
"$",
"compiler",
"->",
"setAutoEscape",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"getParameter",
"(",
"'auto_escape'",
",",
"false",
")",
")",
";",
"return",
"$",
"compiler",
";",
"}"
] | provides a custom compiler to the dwoo renderer with optional settings
you can set in the agavi output_types.xml config file
@return Dwoo_Compiler | [
"provides",
"a",
"custom",
"compiler",
"to",
"the",
"dwoo",
"renderer",
"with",
"optional",
"settings",
"you",
"can",
"set",
"in",
"the",
"agavi",
"output_types",
".",
"xml",
"config",
"file"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/Agavi/DwooRenderer.php#L110-L118 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/Agavi/DwooRenderer.php | DwooRenderer.getEngine | protected function getEngine()
{
if($this->dwoo) {
return $this->dwoo;
}
if(!class_exists('Dwoo')) {
if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) {
// file was dropped with the entire dwoo package
require dirname(__FILE__).'/../../../dwooAutoload.php';
} else {
// assume the dwoo package is in the include path
require 'dwooAutoload.php';
}
}
$parentMode = fileperms(AgaviConfig::get('core.cache_dir'));
$compileDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::COMPILE_DIR . DIRECTORY_SEPARATOR . self::COMPILE_SUBDIR;
AgaviToolkit::mkdir($compileDir, $parentMode, true);
$cacheDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_DIR;
AgaviToolkit::mkdir($cacheDir, $parentMode, true);
$this->dwoo = new Dwoo($compileDir, $cacheDir);
if (!empty($this->plugin_dir)) {
$this->dwoo->getLoader()->addDirectory($this->plugin_dir);
}
$this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
return $this->dwoo;
} | php | protected function getEngine()
{
if($this->dwoo) {
return $this->dwoo;
}
if(!class_exists('Dwoo')) {
if (file_exists(dirname(__FILE__).'/../../../dwooAutoload.php')) {
// file was dropped with the entire dwoo package
require dirname(__FILE__).'/../../../dwooAutoload.php';
} else {
// assume the dwoo package is in the include path
require 'dwooAutoload.php';
}
}
$parentMode = fileperms(AgaviConfig::get('core.cache_dir'));
$compileDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::COMPILE_DIR . DIRECTORY_SEPARATOR . self::COMPILE_SUBDIR;
AgaviToolkit::mkdir($compileDir, $parentMode, true);
$cacheDir = AgaviConfig::get('core.cache_dir') . DIRECTORY_SEPARATOR . self::CACHE_DIR;
AgaviToolkit::mkdir($cacheDir, $parentMode, true);
$this->dwoo = new Dwoo($compileDir, $cacheDir);
if (!empty($this->plugin_dir)) {
$this->dwoo->getLoader()->addDirectory($this->plugin_dir);
}
$this->dwoo->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
return $this->dwoo;
} | [
"protected",
"function",
"getEngine",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dwoo",
")",
"{",
"return",
"$",
"this",
"->",
"dwoo",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"'Dwoo'",
")",
")",
"{",
"if",
"(",
"file_exists",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"'/../../../dwooAutoload.php'",
")",
")",
"{",
"// file was dropped with the entire dwoo package",
"require",
"dirname",
"(",
"__FILE__",
")",
".",
"'/../../../dwooAutoload.php'",
";",
"}",
"else",
"{",
"// assume the dwoo package is in the include path",
"require",
"'dwooAutoload.php'",
";",
"}",
"}",
"$",
"parentMode",
"=",
"fileperms",
"(",
"AgaviConfig",
"::",
"get",
"(",
"'core.cache_dir'",
")",
")",
";",
"$",
"compileDir",
"=",
"AgaviConfig",
"::",
"get",
"(",
"'core.cache_dir'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"self",
"::",
"COMPILE_DIR",
".",
"DIRECTORY_SEPARATOR",
".",
"self",
"::",
"COMPILE_SUBDIR",
";",
"AgaviToolkit",
"::",
"mkdir",
"(",
"$",
"compileDir",
",",
"$",
"parentMode",
",",
"true",
")",
";",
"$",
"cacheDir",
"=",
"AgaviConfig",
"::",
"get",
"(",
"'core.cache_dir'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"self",
"::",
"CACHE_DIR",
";",
"AgaviToolkit",
"::",
"mkdir",
"(",
"$",
"cacheDir",
",",
"$",
"parentMode",
",",
"true",
")",
";",
"$",
"this",
"->",
"dwoo",
"=",
"new",
"Dwoo",
"(",
"$",
"compileDir",
",",
"$",
"cacheDir",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"plugin_dir",
")",
")",
"{",
"$",
"this",
"->",
"dwoo",
"->",
"getLoader",
"(",
")",
"->",
"addDirectory",
"(",
"$",
"this",
"->",
"plugin_dir",
")",
";",
"}",
"$",
"this",
"->",
"dwoo",
"->",
"setDefaultCompilerFactory",
"(",
"'file'",
",",
"array",
"(",
"$",
"this",
",",
"'compilerFactory'",
")",
")",
";",
"return",
"$",
"this",
"->",
"dwoo",
";",
"}"
] | Grab a cleaned up dwoo instance.
@return Dwoo A Dwoo instance. | [
"Grab",
"a",
"cleaned",
"up",
"dwoo",
"instance",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/Agavi/DwooRenderer.php#L125-L158 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/Agavi/DwooRenderer.php | DwooRenderer.render | public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array())
{
$engine = $this->getEngine();
$data = array();
if($this->extractVars) {
$data = $attributes;
} else {
$data[$this->varName] = &$attributes;
}
$data[$this->slotsVarName] =& $slots;
foreach($this->assigns as $key => $getter) {
$data[$key] = $this->context->$getter();
}
foreach($moreAssigns as $key => &$value) {
if(isset($this->moreAssignNames[$key])) {
$key = $this->moreAssignNames[$key];
}
$data[$key] =& $value;
}
return $engine->get($layer->getResourceStreamIdentifier(), $data);
} | php | public function render(AgaviTemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array())
{
$engine = $this->getEngine();
$data = array();
if($this->extractVars) {
$data = $attributes;
} else {
$data[$this->varName] = &$attributes;
}
$data[$this->slotsVarName] =& $slots;
foreach($this->assigns as $key => $getter) {
$data[$key] = $this->context->$getter();
}
foreach($moreAssigns as $key => &$value) {
if(isset($this->moreAssignNames[$key])) {
$key = $this->moreAssignNames[$key];
}
$data[$key] =& $value;
}
return $engine->get($layer->getResourceStreamIdentifier(), $data);
} | [
"public",
"function",
"render",
"(",
"AgaviTemplateLayer",
"$",
"layer",
",",
"array",
"&",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"array",
"&",
"$",
"slots",
"=",
"array",
"(",
")",
",",
"array",
"&",
"$",
"moreAssigns",
"=",
"array",
"(",
")",
")",
"{",
"$",
"engine",
"=",
"$",
"this",
"->",
"getEngine",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"extractVars",
")",
"{",
"$",
"data",
"=",
"$",
"attributes",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"this",
"->",
"varName",
"]",
"=",
"&",
"$",
"attributes",
";",
"}",
"$",
"data",
"[",
"$",
"this",
"->",
"slotsVarName",
"]",
"=",
"&",
"$",
"slots",
";",
"foreach",
"(",
"$",
"this",
"->",
"assigns",
"as",
"$",
"key",
"=>",
"$",
"getter",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"context",
"->",
"$",
"getter",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"moreAssigns",
"as",
"$",
"key",
"=>",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"moreAssignNames",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"moreAssignNames",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"&",
"$",
"value",
";",
"}",
"return",
"$",
"engine",
"->",
"get",
"(",
"$",
"layer",
"->",
"getResourceStreamIdentifier",
"(",
")",
",",
"$",
"data",
")",
";",
"}"
] | Render the presentation and return the result.
@param AgaviTemplateLayer The template layer to render.
@param array The template variables.
@param array The slots.
@param array Associative array of additional assigns.
@return string A rendered result. | [
"Render",
"the",
"presentation",
"and",
"return",
"the",
"result",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/dwoo/Dwoo/Adapters/Agavi/DwooRenderer.php#L170-L195 |
heidelpay/PhpDoc | src/phpDocumentor/Transformer/Transformer.php | Transformer.execute | public function execute(ProjectDescriptor $project)
{
Dispatcher::getInstance()->dispatch(
self::EVENT_PRE_TRANSFORM,
PreTransformEvent::createInstance($this)->setProject($project)
);
$transformations = $this->getTemplates()->getTransformations();
$this->initializeWriters($project, $transformations);
$this->transformProject($project, $transformations);
Dispatcher::getInstance()->dispatch(self::EVENT_POST_TRANSFORM, PostTransformEvent::createInstance($this));
$this->log('Finished transformation process');
} | php | public function execute(ProjectDescriptor $project)
{
Dispatcher::getInstance()->dispatch(
self::EVENT_PRE_TRANSFORM,
PreTransformEvent::createInstance($this)->setProject($project)
);
$transformations = $this->getTemplates()->getTransformations();
$this->initializeWriters($project, $transformations);
$this->transformProject($project, $transformations);
Dispatcher::getInstance()->dispatch(self::EVENT_POST_TRANSFORM, PostTransformEvent::createInstance($this));
$this->log('Finished transformation process');
} | [
"public",
"function",
"execute",
"(",
"ProjectDescriptor",
"$",
"project",
")",
"{",
"Dispatcher",
"::",
"getInstance",
"(",
")",
"->",
"dispatch",
"(",
"self",
"::",
"EVENT_PRE_TRANSFORM",
",",
"PreTransformEvent",
"::",
"createInstance",
"(",
"$",
"this",
")",
"->",
"setProject",
"(",
"$",
"project",
")",
")",
";",
"$",
"transformations",
"=",
"$",
"this",
"->",
"getTemplates",
"(",
")",
"->",
"getTransformations",
"(",
")",
";",
"$",
"this",
"->",
"initializeWriters",
"(",
"$",
"project",
",",
"$",
"transformations",
")",
";",
"$",
"this",
"->",
"transformProject",
"(",
"$",
"project",
",",
"$",
"transformations",
")",
";",
"Dispatcher",
"::",
"getInstance",
"(",
")",
"->",
"dispatch",
"(",
"self",
"::",
"EVENT_POST_TRANSFORM",
",",
"PostTransformEvent",
"::",
"createInstance",
"(",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"log",
"(",
"'Finished transformation process'",
")",
";",
"}"
] | Transforms the given project into a series of artifacts as provided by the templates.
@param ProjectDescriptor $project
@return void | [
"Transforms",
"the",
"given",
"project",
"into",
"a",
"series",
"of",
"artifacts",
"as",
"provided",
"by",
"the",
"templates",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Transformer.php#L132-L146 |
heidelpay/PhpDoc | src/phpDocumentor/Transformer/Transformer.php | Transformer.generateFilename | public function generateFilename($name)
{
if (substr($name, -4) == '.php') {
$name = substr($name, 0, -4);
}
return trim(str_replace(array(DIRECTORY_SEPARATOR, '\\'), '.', trim($name, DIRECTORY_SEPARATOR . '.')), '.')
. '.html';
} | php | public function generateFilename($name)
{
if (substr($name, -4) == '.php') {
$name = substr($name, 0, -4);
}
return trim(str_replace(array(DIRECTORY_SEPARATOR, '\\'), '.', trim($name, DIRECTORY_SEPARATOR . '.')), '.')
. '.html';
} | [
"public",
"function",
"generateFilename",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"name",
",",
"-",
"4",
")",
"==",
"'.php'",
")",
"{",
"$",
"name",
"=",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"-",
"4",
")",
";",
"}",
"return",
"trim",
"(",
"str_replace",
"(",
"array",
"(",
"DIRECTORY_SEPARATOR",
",",
"'\\\\'",
")",
",",
"'.'",
",",
"trim",
"(",
"$",
"name",
",",
"DIRECTORY_SEPARATOR",
".",
"'.'",
")",
")",
",",
"'.'",
")",
".",
"'.html'",
";",
"}"
] | Converts a source file name to the name used for generating the end result.
This method strips down the given $name using the following rules:
* if the $name is suffixed with .php then that is removed
* any occurrence of \ or DIRECTORY_SEPARATOR is replaced with .
* any dots that the name starts or ends with is removed
* the result is suffixed with .html
@param string $name Name to convert.
@return string | [
"Converts",
"a",
"source",
"file",
"name",
"to",
"the",
"name",
"used",
"for",
"generating",
"the",
"end",
"result",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Transformer.php#L162-L170 |
heidelpay/PhpDoc | src/phpDocumentor/Transformer/Transformer.php | Transformer.debug | public function debug($message)
{
Dispatcher::getInstance()->dispatch(
'system.debug',
DebugEvent::createInstance($this)
->setMessage($message)
);
} | php | public function debug($message)
{
Dispatcher::getInstance()->dispatch(
'system.debug',
DebugEvent::createInstance($this)
->setMessage($message)
);
} | [
"public",
"function",
"debug",
"(",
"$",
"message",
")",
"{",
"Dispatcher",
"::",
"getInstance",
"(",
")",
"->",
"dispatch",
"(",
"'system.debug'",
",",
"DebugEvent",
"::",
"createInstance",
"(",
"$",
"this",
")",
"->",
"setMessage",
"(",
"$",
"message",
")",
")",
";",
"}"
] | Dispatches a logging request to log a debug message.
@param string $message The message to log.
@return void | [
"Dispatches",
"a",
"logging",
"request",
"to",
"log",
"a",
"debug",
"message",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Transformer.php#L197-L204 |
heidelpay/PhpDoc | src/phpDocumentor/Transformer/Transformer.php | Transformer.initializeWriters | private function initializeWriters(ProjectDescriptor $project, $transformations)
{
$isInitialized = array();
foreach ($transformations as $transformation) {
$writerName = $transformation->getWriter();
if (in_array($writerName, $isInitialized)) {
continue;
}
$isInitialized[] = $writerName;
$writer = $this->writers[$writerName];
$this->initializeWriter($writer, $project);
}
} | php | private function initializeWriters(ProjectDescriptor $project, $transformations)
{
$isInitialized = array();
foreach ($transformations as $transformation) {
$writerName = $transformation->getWriter();
if (in_array($writerName, $isInitialized)) {
continue;
}
$isInitialized[] = $writerName;
$writer = $this->writers[$writerName];
$this->initializeWriter($writer, $project);
}
} | [
"private",
"function",
"initializeWriters",
"(",
"ProjectDescriptor",
"$",
"project",
",",
"$",
"transformations",
")",
"{",
"$",
"isInitialized",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"transformations",
"as",
"$",
"transformation",
")",
"{",
"$",
"writerName",
"=",
"$",
"transformation",
"->",
"getWriter",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"writerName",
",",
"$",
"isInitialized",
")",
")",
"{",
"continue",
";",
"}",
"$",
"isInitialized",
"[",
"]",
"=",
"$",
"writerName",
";",
"$",
"writer",
"=",
"$",
"this",
"->",
"writers",
"[",
"$",
"writerName",
"]",
";",
"$",
"this",
"->",
"initializeWriter",
"(",
"$",
"writer",
",",
"$",
"project",
")",
";",
"}",
"}"
] | Initializes all writers that are used during this transformation.
@param ProjectDescriptor $project
@param Transformation[] $transformations
@return void | [
"Initializes",
"all",
"writers",
"that",
"are",
"used",
"during",
"this",
"transformation",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Transformer.php#L214-L228 |
heidelpay/PhpDoc | src/phpDocumentor/Transformer/Transformer.php | Transformer.initializeWriter | private function initializeWriter(WriterAbstract $writer, ProjectDescriptor $project)
{
$event = WriterInitializationEvent::createInstance($this)->setWriter($writer);
Dispatcher::getInstance()->dispatch(self::EVENT_PRE_INITIALIZATION, $event);
if ($writer instanceof Initializable) {
$writer->initialize($project);
}
Dispatcher::getInstance()->dispatch(self::EVENT_POST_INITIALIZATION, $event);
} | php | private function initializeWriter(WriterAbstract $writer, ProjectDescriptor $project)
{
$event = WriterInitializationEvent::createInstance($this)->setWriter($writer);
Dispatcher::getInstance()->dispatch(self::EVENT_PRE_INITIALIZATION, $event);
if ($writer instanceof Initializable) {
$writer->initialize($project);
}
Dispatcher::getInstance()->dispatch(self::EVENT_POST_INITIALIZATION, $event);
} | [
"private",
"function",
"initializeWriter",
"(",
"WriterAbstract",
"$",
"writer",
",",
"ProjectDescriptor",
"$",
"project",
")",
"{",
"$",
"event",
"=",
"WriterInitializationEvent",
"::",
"createInstance",
"(",
"$",
"this",
")",
"->",
"setWriter",
"(",
"$",
"writer",
")",
";",
"Dispatcher",
"::",
"getInstance",
"(",
")",
"->",
"dispatch",
"(",
"self",
"::",
"EVENT_PRE_INITIALIZATION",
",",
"$",
"event",
")",
";",
"if",
"(",
"$",
"writer",
"instanceof",
"Initializable",
")",
"{",
"$",
"writer",
"->",
"initialize",
"(",
"$",
"project",
")",
";",
"}",
"Dispatcher",
"::",
"getInstance",
"(",
")",
"->",
"dispatch",
"(",
"self",
"::",
"EVENT_POST_INITIALIZATION",
",",
"$",
"event",
")",
";",
"}"
] | Initializes the given writer using the provided project meta-data.
This method wil call for the initialization of each writer that supports an initialization routine (as defined by
the `Initializable` interface).
In addition to this, the following events emitted for each writer that is present in the collected list of
transformations, even those that do not implement the `Initializable` interface.
Emitted events:
- transformer.writer.initialization.pre, before the initialization of a single writer.
- transformer.writer.initialization.post, after the initialization of a single writer.
@param WriterAbstract $writer
@param ProjectDescriptor $project
@uses Dispatcher to emit the events surrounding an initialization.
@return void | [
"Initializes",
"the",
"given",
"writer",
"using",
"the",
"provided",
"project",
"meta",
"-",
"data",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Transformer.php#L251-L261 |
heidelpay/PhpDoc | src/phpDocumentor/Transformer/Transformer.php | Transformer.transformProject | private function transformProject(ProjectDescriptor $project, $transformations)
{
foreach ($transformations as $transformation) {
$transformation->setTransformer($this);
$this->applyTransformationToProject($transformation, $project);
}
} | php | private function transformProject(ProjectDescriptor $project, $transformations)
{
foreach ($transformations as $transformation) {
$transformation->setTransformer($this);
$this->applyTransformationToProject($transformation, $project);
}
} | [
"private",
"function",
"transformProject",
"(",
"ProjectDescriptor",
"$",
"project",
",",
"$",
"transformations",
")",
"{",
"foreach",
"(",
"$",
"transformations",
"as",
"$",
"transformation",
")",
"{",
"$",
"transformation",
"->",
"setTransformer",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"applyTransformationToProject",
"(",
"$",
"transformation",
",",
"$",
"project",
")",
";",
"}",
"}"
] | Applies all given transformations to the provided project.
@param ProjectDescriptor $project
@param Transformation[] $transformations
@return void | [
"Applies",
"all",
"given",
"transformations",
"to",
"the",
"provided",
"project",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Transformer.php#L271-L277 |
heidelpay/PhpDoc | src/phpDocumentor/Transformer/Transformer.php | Transformer.applyTransformationToProject | private function applyTransformationToProject(Transformation $transformation, ProjectDescriptor $project)
{
$this->log(
sprintf(
' Writer %s %s on %s',
$transformation->getWriter(),
($transformation->getQuery() ? ' using query "' . $transformation->getQuery() . '"' : ''),
$transformation->getArtifact()
)
);
$preTransformationEvent = PreTransformationEvent::createInstance($this)->setTransformation($transformation);
Dispatcher::getInstance()->dispatch(self::EVENT_PRE_TRANSFORMATION, $preTransformationEvent);
$writer = $this->writers[$transformation->getWriter()];
$writer->transform($project, $transformation);
$postTransformationEvent = PostTransformationEvent::createInstance($this);
Dispatcher::getInstance()->dispatch(self::EVENT_POST_TRANSFORMATION, $postTransformationEvent);
} | php | private function applyTransformationToProject(Transformation $transformation, ProjectDescriptor $project)
{
$this->log(
sprintf(
' Writer %s %s on %s',
$transformation->getWriter(),
($transformation->getQuery() ? ' using query "' . $transformation->getQuery() . '"' : ''),
$transformation->getArtifact()
)
);
$preTransformationEvent = PreTransformationEvent::createInstance($this)->setTransformation($transformation);
Dispatcher::getInstance()->dispatch(self::EVENT_PRE_TRANSFORMATION, $preTransformationEvent);
$writer = $this->writers[$transformation->getWriter()];
$writer->transform($project, $transformation);
$postTransformationEvent = PostTransformationEvent::createInstance($this);
Dispatcher::getInstance()->dispatch(self::EVENT_POST_TRANSFORMATION, $postTransformationEvent);
} | [
"private",
"function",
"applyTransformationToProject",
"(",
"Transformation",
"$",
"transformation",
",",
"ProjectDescriptor",
"$",
"project",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"sprintf",
"(",
"' Writer %s %s on %s'",
",",
"$",
"transformation",
"->",
"getWriter",
"(",
")",
",",
"(",
"$",
"transformation",
"->",
"getQuery",
"(",
")",
"?",
"' using query \"'",
".",
"$",
"transformation",
"->",
"getQuery",
"(",
")",
".",
"'\"'",
":",
"''",
")",
",",
"$",
"transformation",
"->",
"getArtifact",
"(",
")",
")",
")",
";",
"$",
"preTransformationEvent",
"=",
"PreTransformationEvent",
"::",
"createInstance",
"(",
"$",
"this",
")",
"->",
"setTransformation",
"(",
"$",
"transformation",
")",
";",
"Dispatcher",
"::",
"getInstance",
"(",
")",
"->",
"dispatch",
"(",
"self",
"::",
"EVENT_PRE_TRANSFORMATION",
",",
"$",
"preTransformationEvent",
")",
";",
"$",
"writer",
"=",
"$",
"this",
"->",
"writers",
"[",
"$",
"transformation",
"->",
"getWriter",
"(",
")",
"]",
";",
"$",
"writer",
"->",
"transform",
"(",
"$",
"project",
",",
"$",
"transformation",
")",
";",
"$",
"postTransformationEvent",
"=",
"PostTransformationEvent",
"::",
"createInstance",
"(",
"$",
"this",
")",
";",
"Dispatcher",
"::",
"getInstance",
"(",
")",
"->",
"dispatch",
"(",
"self",
"::",
"EVENT_POST_TRANSFORMATION",
",",
"$",
"postTransformationEvent",
")",
";",
"}"
] | Applies the given transformation to the provided project.
This method will attempt to find an appropriate writer for the given transformation and invoke that with the
transformation and project so that an artifact can be generated that matches the intended transformation.
In addition this method will emit the following events:
- transformer.transformation.pre, before the project has been transformed with this transformation.
- transformer.transformation.post, after the project has been transformed with this transformation
@param Transformation $transformation
@param ProjectDescriptor $project
@uses Dispatcher to emit the events surrounding a transformation.
@return void | [
"Applies",
"the",
"given",
"transformation",
"to",
"the",
"provided",
"project",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Transformer.php#L297-L316 |
VincentChalnot/SidusDataGridBundle | Twig/RendererExtension.php | RendererExtension.renderDataGrid | public function renderDataGrid(DataGrid $dataGrid, array $viewParameters = []): string
{
$viewParameters = array_merge($dataGrid->getTemplateVars(), $viewParameters);
$viewParameters['datagrid'] = $dataGrid;
return $this->twig->render($dataGrid->getTemplate(), $viewParameters);
} | php | public function renderDataGrid(DataGrid $dataGrid, array $viewParameters = []): string
{
$viewParameters = array_merge($dataGrid->getTemplateVars(), $viewParameters);
$viewParameters['datagrid'] = $dataGrid;
return $this->twig->render($dataGrid->getTemplate(), $viewParameters);
} | [
"public",
"function",
"renderDataGrid",
"(",
"DataGrid",
"$",
"dataGrid",
",",
"array",
"$",
"viewParameters",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"viewParameters",
"=",
"array_merge",
"(",
"$",
"dataGrid",
"->",
"getTemplateVars",
"(",
")",
",",
"$",
"viewParameters",
")",
";",
"$",
"viewParameters",
"[",
"'datagrid'",
"]",
"=",
"$",
"dataGrid",
";",
"return",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"$",
"dataGrid",
"->",
"getTemplate",
"(",
")",
",",
"$",
"viewParameters",
")",
";",
"}"
] | @param DataGrid $dataGrid
@param array $viewParameters
@throws \Twig_Error_Loader
@throws \Twig_Error_Runtime
@throws \Twig_Error_Syntax
@return string | [
"@param",
"DataGrid",
"$dataGrid",
"@param",
"array",
"$viewParameters"
] | train | https://github.com/VincentChalnot/SidusDataGridBundle/blob/aa929113e2208ed335f514d2891affaf7fddf3f6/Twig/RendererExtension.php#L66-L72 |
VincentChalnot/SidusDataGridBundle | Twig/RendererExtension.php | RendererExtension.getFilterColumns | public function getFilterColumns(FormView $formView, int $numColumns = 3): array
{
$columns = [];
$i = 0;
foreach ($formView as $formItem) {
$columns[$i % $numColumns][] = $formItem;
++$i;
}
return $columns;
} | php | public function getFilterColumns(FormView $formView, int $numColumns = 3): array
{
$columns = [];
$i = 0;
foreach ($formView as $formItem) {
$columns[$i % $numColumns][] = $formItem;
++$i;
}
return $columns;
} | [
"public",
"function",
"getFilterColumns",
"(",
"FormView",
"$",
"formView",
",",
"int",
"$",
"numColumns",
"=",
"3",
")",
":",
"array",
"{",
"$",
"columns",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"formView",
"as",
"$",
"formItem",
")",
"{",
"$",
"columns",
"[",
"$",
"i",
"%",
"$",
"numColumns",
"]",
"[",
"]",
"=",
"$",
"formItem",
";",
"++",
"$",
"i",
";",
"}",
"return",
"$",
"columns",
";",
"}"
] | Simple function to split form widgets in as many columns as wanted
@param FormView $formView
@param int $numColumns
@return array | [
"Simple",
"function",
"to",
"split",
"form",
"widgets",
"in",
"as",
"many",
"columns",
"as",
"wanted"
] | train | https://github.com/VincentChalnot/SidusDataGridBundle/blob/aa929113e2208ed335f514d2891affaf7fddf3f6/Twig/RendererExtension.php#L82-L92 |
wenbin1989/yii2-curl | Curl.php | Curl.get | public function get($url, $options = [], $body = null, $raw = true)
{
return $this->httpRequest('GET', $this->createUrl($url, $options), $body, $raw);
} | php | public function get($url, $options = [], $body = null, $raw = true)
{
return $this->httpRequest('GET', $this->createUrl($url, $options), $body, $raw);
} | [
"public",
"function",
"get",
"(",
"$",
"url",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"null",
",",
"$",
"raw",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"httpRequest",
"(",
"'GET'",
",",
"$",
"this",
"->",
"createUrl",
"(",
"$",
"url",
",",
"$",
"options",
")",
",",
"$",
"body",
",",
"$",
"raw",
")",
";",
"}"
] | Performs GET HTTP request
@param string $url URL
@param array $options URL options
@param string $body request body
@param boolean $raw if response body contains JSON and should be decoded
@return mixed response | [
"Performs",
"GET",
"HTTP",
"request"
] | train | https://github.com/wenbin1989/yii2-curl/blob/e30730dc685ec10118f982eab518b49761f6cd3a/Curl.php#L48-L51 |
wenbin1989/yii2-curl | Curl.php | Curl.head | public function head($url, $options = [], $body = null)
{
return $this->httpRequest('HEAD', $this->createUrl($url, $options), $body);
} | php | public function head($url, $options = [], $body = null)
{
return $this->httpRequest('HEAD', $this->createUrl($url, $options), $body);
} | [
"public",
"function",
"head",
"(",
"$",
"url",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"httpRequest",
"(",
"'HEAD'",
",",
"$",
"this",
"->",
"createUrl",
"(",
"$",
"url",
",",
"$",
"options",
")",
",",
"$",
"body",
")",
";",
"}"
] | Performs HEAD HTTP request
@param string $url URL
@param array $options URL options
@param string $body request body
@return mixed response | [
"Performs",
"HEAD",
"HTTP",
"request"
] | train | https://github.com/wenbin1989/yii2-curl/blob/e30730dc685ec10118f982eab518b49761f6cd3a/Curl.php#L61-L64 |
wenbin1989/yii2-curl | Curl.php | Curl.createUrl | private function createUrl($path, $options = [])
{
if (!is_string($path)) {
$url = implode('/', array_map(function ($a) {
return urlencode(is_array($a) ? implode(',', $a) : $a);
}, $path));
if (!empty($options)) {
$url .= '?' . http_build_query($options);
}
} else {
$url = $path;
if (!empty($options)) {
$url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($options);
}
}
return $url;
} | php | private function createUrl($path, $options = [])
{
if (!is_string($path)) {
$url = implode('/', array_map(function ($a) {
return urlencode(is_array($a) ? implode(',', $a) : $a);
}, $path));
if (!empty($options)) {
$url .= '?' . http_build_query($options);
}
} else {
$url = $path;
if (!empty($options)) {
$url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($options);
}
}
return $url;
} | [
"private",
"function",
"createUrl",
"(",
"$",
"path",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"$",
"url",
"=",
"implode",
"(",
"'/'",
",",
"array_map",
"(",
"function",
"(",
"$",
"a",
")",
"{",
"return",
"urlencode",
"(",
"is_array",
"(",
"$",
"a",
")",
"?",
"implode",
"(",
"','",
",",
"$",
"a",
")",
":",
"$",
"a",
")",
";",
"}",
",",
"$",
"path",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
")",
")",
"{",
"$",
"url",
".=",
"'?'",
".",
"http_build_query",
"(",
"$",
"options",
")",
";",
"}",
"}",
"else",
"{",
"$",
"url",
"=",
"$",
"path",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
")",
")",
"{",
"$",
"url",
".=",
"(",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
"===",
"false",
"?",
"'?'",
":",
"'&'",
")",
".",
"http_build_query",
"(",
"$",
"options",
")",
";",
"}",
"}",
"return",
"$",
"url",
";",
"}"
] | Creates URL
@param mixed $path path
@param array $options URL options
@return string | [
"Creates",
"URL"
] | train | https://github.com/wenbin1989/yii2-curl/blob/e30730dc685ec10118f982eab518b49761f6cd3a/Curl.php#L115-L132 |
wenbin1989/yii2-curl | Curl.php | Curl.httpRequest | protected function httpRequest($method, $url, $requestBody = null, $raw = false)
{
$method = strtoupper($method);
// response body
$body = '';
$options = [
CURLOPT_USERAGENT => 'Yii Framework 2 ' . __CLASS__,
CURLOPT_RETURNTRANSFER => false,
CURLOPT_HEADER => false,
// http://www.php.net/manual/en/function.curl-setopt.php#82418
CURLOPT_HTTPHEADER => ['Expect:'],
CURLOPT_WRITEFUNCTION => function ($curl, $data) use (&$body) {
$body .= $data;
return mb_strlen($data, '8bit');
},
CURLOPT_CUSTOMREQUEST => $method,
];
if ($this->connectionTimeout !== null) {
$options[CURLOPT_CONNECTTIMEOUT] = $this->connectionTimeout;
}
if ($this->dataTimeout !== null) {
$options[CURLOPT_TIMEOUT] = $this->dataTimeout;
}
if ($requestBody !== null) {
$options[CURLOPT_POSTFIELDS] = $requestBody;
}
if ($method == 'HEAD') {
$options[CURLOPT_NOBODY] = true;
unset($options[CURLOPT_WRITEFUNCTION]);
}
$bodyProfile = serialize($requestBody);
$profile = $method . ' ' . $url . '#' . md5($bodyProfile);
Yii::trace("Sending request: $url\n" . $bodyProfile, __METHOD__);
Yii::beginProfile($profile, __METHOD__);
$curl = curl_init($url);
curl_setopt_array($curl, $options);
if (curl_exec($curl) === false) {
throw new Exception('curl request failed: ' . curl_error($curl) , curl_errno($curl));
}
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
Yii::endProfile($profile, __METHOD__);
if ($responseCode >= 200 && $responseCode < 300) {
if ($method == 'HEAD') {
return true;
} else {
return $raw ? $body : Json::decode($body);
}
} elseif ($responseCode == 404) {
return false;
} else {
throw new HttpException($responseCode, $body);
}
} | php | protected function httpRequest($method, $url, $requestBody = null, $raw = false)
{
$method = strtoupper($method);
// response body
$body = '';
$options = [
CURLOPT_USERAGENT => 'Yii Framework 2 ' . __CLASS__,
CURLOPT_RETURNTRANSFER => false,
CURLOPT_HEADER => false,
// http://www.php.net/manual/en/function.curl-setopt.php#82418
CURLOPT_HTTPHEADER => ['Expect:'],
CURLOPT_WRITEFUNCTION => function ($curl, $data) use (&$body) {
$body .= $data;
return mb_strlen($data, '8bit');
},
CURLOPT_CUSTOMREQUEST => $method,
];
if ($this->connectionTimeout !== null) {
$options[CURLOPT_CONNECTTIMEOUT] = $this->connectionTimeout;
}
if ($this->dataTimeout !== null) {
$options[CURLOPT_TIMEOUT] = $this->dataTimeout;
}
if ($requestBody !== null) {
$options[CURLOPT_POSTFIELDS] = $requestBody;
}
if ($method == 'HEAD') {
$options[CURLOPT_NOBODY] = true;
unset($options[CURLOPT_WRITEFUNCTION]);
}
$bodyProfile = serialize($requestBody);
$profile = $method . ' ' . $url . '#' . md5($bodyProfile);
Yii::trace("Sending request: $url\n" . $bodyProfile, __METHOD__);
Yii::beginProfile($profile, __METHOD__);
$curl = curl_init($url);
curl_setopt_array($curl, $options);
if (curl_exec($curl) === false) {
throw new Exception('curl request failed: ' . curl_error($curl) , curl_errno($curl));
}
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
Yii::endProfile($profile, __METHOD__);
if ($responseCode >= 200 && $responseCode < 300) {
if ($method == 'HEAD') {
return true;
} else {
return $raw ? $body : Json::decode($body);
}
} elseif ($responseCode == 404) {
return false;
} else {
throw new HttpException($responseCode, $body);
}
} | [
"protected",
"function",
"httpRequest",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"requestBody",
"=",
"null",
",",
"$",
"raw",
"=",
"false",
")",
"{",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"method",
")",
";",
"// response body",
"$",
"body",
"=",
"''",
";",
"$",
"options",
"=",
"[",
"CURLOPT_USERAGENT",
"=>",
"'Yii Framework 2 '",
".",
"__CLASS__",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"false",
",",
"CURLOPT_HEADER",
"=>",
"false",
",",
"// http://www.php.net/manual/en/function.curl-setopt.php#82418",
"CURLOPT_HTTPHEADER",
"=>",
"[",
"'Expect:'",
"]",
",",
"CURLOPT_WRITEFUNCTION",
"=>",
"function",
"(",
"$",
"curl",
",",
"$",
"data",
")",
"use",
"(",
"&",
"$",
"body",
")",
"{",
"$",
"body",
".=",
"$",
"data",
";",
"return",
"mb_strlen",
"(",
"$",
"data",
",",
"'8bit'",
")",
";",
"}",
",",
"CURLOPT_CUSTOMREQUEST",
"=>",
"$",
"method",
",",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"connectionTimeout",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"CURLOPT_CONNECTTIMEOUT",
"]",
"=",
"$",
"this",
"->",
"connectionTimeout",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"dataTimeout",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"CURLOPT_TIMEOUT",
"]",
"=",
"$",
"this",
"->",
"dataTimeout",
";",
"}",
"if",
"(",
"$",
"requestBody",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"CURLOPT_POSTFIELDS",
"]",
"=",
"$",
"requestBody",
";",
"}",
"if",
"(",
"$",
"method",
"==",
"'HEAD'",
")",
"{",
"$",
"options",
"[",
"CURLOPT_NOBODY",
"]",
"=",
"true",
";",
"unset",
"(",
"$",
"options",
"[",
"CURLOPT_WRITEFUNCTION",
"]",
")",
";",
"}",
"$",
"bodyProfile",
"=",
"serialize",
"(",
"$",
"requestBody",
")",
";",
"$",
"profile",
"=",
"$",
"method",
".",
"' '",
".",
"$",
"url",
".",
"'#'",
".",
"md5",
"(",
"$",
"bodyProfile",
")",
";",
"Yii",
"::",
"trace",
"(",
"\"Sending request: $url\\n\"",
".",
"$",
"bodyProfile",
",",
"__METHOD__",
")",
";",
"Yii",
"::",
"beginProfile",
"(",
"$",
"profile",
",",
"__METHOD__",
")",
";",
"$",
"curl",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt_array",
"(",
"$",
"curl",
",",
"$",
"options",
")",
";",
"if",
"(",
"curl_exec",
"(",
"$",
"curl",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'curl request failed: '",
".",
"curl_error",
"(",
"$",
"curl",
")",
",",
"curl_errno",
"(",
"$",
"curl",
")",
")",
";",
"}",
"$",
"responseCode",
"=",
"curl_getinfo",
"(",
"$",
"curl",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"curl",
")",
";",
"Yii",
"::",
"endProfile",
"(",
"$",
"profile",
",",
"__METHOD__",
")",
";",
"if",
"(",
"$",
"responseCode",
">=",
"200",
"&&",
"$",
"responseCode",
"<",
"300",
")",
"{",
"if",
"(",
"$",
"method",
"==",
"'HEAD'",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"$",
"raw",
"?",
"$",
"body",
":",
"Json",
"::",
"decode",
"(",
"$",
"body",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"responseCode",
"==",
"404",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"new",
"HttpException",
"(",
"$",
"responseCode",
",",
"$",
"body",
")",
";",
"}",
"}"
] | Performs HTTP request
@param string $method method name
@param string $url URL
@param string $requestBody request body
@param boolean $raw if response body contains JSON and should be decoded
@throws Exception if request failed
@throws HttpException
@return mixed if response http code is 404, return false; if http code >= 200 and < 300, return response body;
throws HttpException for other http code. | [
"Performs",
"HTTP",
"request"
] | train | https://github.com/wenbin1989/yii2-curl/blob/e30730dc685ec10118f982eab518b49761f6cd3a/Curl.php#L146-L208 |
LIN3S/Distribution | src/Php/Composer/Symfony.php | Symfony.installRequiredFiles | public static function installRequiredFiles()
{
$htaccess = [
__DIR__ . '/../../../../../../app/.htaccess',
__DIR__ . '/../../../../../../src/.htaccess',
__DIR__ . '/../../../../../../web/.htaccess',
];
$fileSystem = new Filesystem();
try {
if (false === $fileSystem->exists($htaccess)) {
$fileSystem->copy($htaccess[0] . '.dist', $htaccess[0]);
$fileSystem->copy($htaccess[1] . '.dist', $htaccess[1]);
$fileSystem->copy($htaccess[2] . '.dist', $htaccess[2]);
}
} catch (\Exception $exception) {
echo sprintf("Something wrong happens during process: \n%s\n", $exception->getMessage());
}
} | php | public static function installRequiredFiles()
{
$htaccess = [
__DIR__ . '/../../../../../../app/.htaccess',
__DIR__ . '/../../../../../../src/.htaccess',
__DIR__ . '/../../../../../../web/.htaccess',
];
$fileSystem = new Filesystem();
try {
if (false === $fileSystem->exists($htaccess)) {
$fileSystem->copy($htaccess[0] . '.dist', $htaccess[0]);
$fileSystem->copy($htaccess[1] . '.dist', $htaccess[1]);
$fileSystem->copy($htaccess[2] . '.dist', $htaccess[2]);
}
} catch (\Exception $exception) {
echo sprintf("Something wrong happens during process: \n%s\n", $exception->getMessage());
}
} | [
"public",
"static",
"function",
"installRequiredFiles",
"(",
")",
"{",
"$",
"htaccess",
"=",
"[",
"__DIR__",
".",
"'/../../../../../../app/.htaccess'",
",",
"__DIR__",
".",
"'/../../../../../../src/.htaccess'",
",",
"__DIR__",
".",
"'/../../../../../../web/.htaccess'",
",",
"]",
";",
"$",
"fileSystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"try",
"{",
"if",
"(",
"false",
"===",
"$",
"fileSystem",
"->",
"exists",
"(",
"$",
"htaccess",
")",
")",
"{",
"$",
"fileSystem",
"->",
"copy",
"(",
"$",
"htaccess",
"[",
"0",
"]",
".",
"'.dist'",
",",
"$",
"htaccess",
"[",
"0",
"]",
")",
";",
"$",
"fileSystem",
"->",
"copy",
"(",
"$",
"htaccess",
"[",
"1",
"]",
".",
"'.dist'",
",",
"$",
"htaccess",
"[",
"1",
"]",
")",
";",
"$",
"fileSystem",
"->",
"copy",
"(",
"$",
"htaccess",
"[",
"2",
"]",
".",
"'.dist'",
",",
"$",
"htaccess",
"[",
"2",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"echo",
"sprintf",
"(",
"\"Something wrong happens during process: \\n%s\\n\"",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Static method that creates .htaccess, files if they do not exist. | [
"Static",
"method",
"that",
"creates",
".",
"htaccess",
"files",
"if",
"they",
"do",
"not",
"exist",
"."
] | train | https://github.com/LIN3S/Distribution/blob/294cda1c2128fa967b3b316f01f202e4e46d2e5b/src/Php/Composer/Symfony.php#L26-L44 |
m4grio/bangkok-insurance-php | src/SoapClient/Factory.php | Factory.getClient | public function getClient($wsdl, array $options = [])
{
$defaults = [
'trace' => true,
//'features' => \SOAP_SINGLE_ELEMENT_ARRAYS,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'soap_version' => SOAP_1_1,
];
$options = array_merge($defaults, $options);
$client = new SoapClient($wsdl, $options);
return $client;
} | php | public function getClient($wsdl, array $options = [])
{
$defaults = [
'trace' => true,
//'features' => \SOAP_SINGLE_ELEMENT_ARRAYS,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'soap_version' => SOAP_1_1,
];
$options = array_merge($defaults, $options);
$client = new SoapClient($wsdl, $options);
return $client;
} | [
"public",
"function",
"getClient",
"(",
"$",
"wsdl",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'trace'",
"=>",
"true",
",",
"//'features' => \\SOAP_SINGLE_ELEMENT_ARRAYS,",
"'compression'",
"=>",
"SOAP_COMPRESSION_ACCEPT",
"|",
"SOAP_COMPRESSION_GZIP",
",",
"'soap_version'",
"=>",
"SOAP_1_1",
",",
"]",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"$",
"client",
"=",
"new",
"SoapClient",
"(",
"$",
"wsdl",
",",
"$",
"options",
")",
";",
"return",
"$",
"client",
";",
"}"
] | @param $wsdl
@param array $options
@return SoapClient | [
"@param",
"$wsdl",
"@param",
"array",
"$options"
] | train | https://github.com/m4grio/bangkok-insurance-php/blob/400266d043abe6b7cacb9da36064cbb169149c2a/src/SoapClient/Factory.php#L21-L33 |
KodiComponents/Support | src/Upload.php | Upload.getAttribute | public function getAttribute($key)
{
$this->findUploadFields();
if ($this->isUploadField($key)) {
list($method, $originalKey) = $this->uploadGetKeys[$key];
$value = $this->getAttribute($originalKey);
if ($this->hasGetMutator($key)) {
return $this->mutateAttribute($key, $value);
}
return $this->{$method}($originalKey, $value);
}
return parent::getAttribute($key);
} | php | public function getAttribute($key)
{
$this->findUploadFields();
if ($this->isUploadField($key)) {
list($method, $originalKey) = $this->uploadGetKeys[$key];
$value = $this->getAttribute($originalKey);
if ($this->hasGetMutator($key)) {
return $this->mutateAttribute($key, $value);
}
return $this->{$method}($originalKey, $value);
}
return parent::getAttribute($key);
} | [
"public",
"function",
"getAttribute",
"(",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"findUploadFields",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isUploadField",
"(",
"$",
"key",
")",
")",
"{",
"list",
"(",
"$",
"method",
",",
"$",
"originalKey",
")",
"=",
"$",
"this",
"->",
"uploadGetKeys",
"[",
"$",
"key",
"]",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getAttribute",
"(",
"$",
"originalKey",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasGetMutator",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"mutateAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"originalKey",
",",
"$",
"value",
")",
";",
"}",
"return",
"parent",
"::",
"getAttribute",
"(",
"$",
"key",
")",
";",
"}"
] | Get an attribute from the model.
@param string $key
@return mixed | [
"Get",
"an",
"attribute",
"from",
"the",
"model",
"."
] | train | https://github.com/KodiComponents/Support/blob/9090543605a2354c7454d707650a0abdb815b60a/src/Upload.php#L134-L151 |
KodiComponents/Support | src/Upload.php | Upload.mutateAttribute | protected function mutateAttribute($key, $value)
{
$this->findUploadFields();
if ($this->isUploadField($key)) {
return $this->getAttribute($key);
}
return parent::mutateAttribute($key, $value);
} | php | protected function mutateAttribute($key, $value)
{
$this->findUploadFields();
if ($this->isUploadField($key)) {
return $this->getAttribute($key);
}
return parent::mutateAttribute($key, $value);
} | [
"protected",
"function",
"mutateAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"findUploadFields",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isUploadField",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getAttribute",
"(",
"$",
"key",
")",
";",
"}",
"return",
"parent",
"::",
"mutateAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | Get the value of an attribute using its mutator.
@param string $key
@param mixed $value
@return mixed | [
"Get",
"the",
"value",
"of",
"an",
"attribute",
"using",
"its",
"mutator",
"."
] | train | https://github.com/KodiComponents/Support/blob/9090543605a2354c7454d707650a0abdb815b60a/src/Upload.php#L161-L170 |
KodiComponents/Support | src/Upload.php | Upload.setAttribute | public function setAttribute($key, $value)
{
$this->findUploadFields();
if ($this->isUploadField($key)) {
list($method, $originalKey) = $this->uploadSetKeys[$key];
if ($this->hasSetMutator($key)) {
$method = 'set'.Str::studly($key).'Attribute';
return $this->{$method}($value);
}
return $this->{$method}($originalKey, $value);
}
return parent::setAttribute($key, $value);
} | php | public function setAttribute($key, $value)
{
$this->findUploadFields();
if ($this->isUploadField($key)) {
list($method, $originalKey) = $this->uploadSetKeys[$key];
if ($this->hasSetMutator($key)) {
$method = 'set'.Str::studly($key).'Attribute';
return $this->{$method}($value);
}
return $this->{$method}($originalKey, $value);
}
return parent::setAttribute($key, $value);
} | [
"public",
"function",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"findUploadFields",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isUploadField",
"(",
"$",
"key",
")",
")",
"{",
"list",
"(",
"$",
"method",
",",
"$",
"originalKey",
")",
"=",
"$",
"this",
"->",
"uploadSetKeys",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"hasSetMutator",
"(",
"$",
"key",
")",
")",
"{",
"$",
"method",
"=",
"'set'",
".",
"Str",
"::",
"studly",
"(",
"$",
"key",
")",
".",
"'Attribute'",
";",
"return",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"originalKey",
",",
"$",
"value",
")",
";",
"}",
"return",
"parent",
"::",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | Set a given attribute on the model.
@param string $key
@param mixed $value
@return $this | [
"Set",
"a",
"given",
"attribute",
"on",
"the",
"model",
"."
] | train | https://github.com/KodiComponents/Support/blob/9090543605a2354c7454d707650a0abdb815b60a/src/Upload.php#L180-L197 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.