repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
eureka-framework/component-http | src/Http/File.php | File.move | public function move($toDir, $fileName = null, $mode = 0775)
{
if ($this->hasError()) {
throw new \Exception('Cannot move file, the file has not been correctly uploaded!');
}
$fileName = (empty($fileName) ? $this->get('name') : $fileName);
if (!file_exists($toDir) && !mkdir($toDir, $mode, true)) {
throw new \Exception(__METHOD__ . '|Cannot create directory "' . $toDir . '" !', 1000);
}
return move_uploaded_file($this->get('tmp_name'), $toDir . $fileName);
} | php | public function move($toDir, $fileName = null, $mode = 0775)
{
if ($this->hasError()) {
throw new \Exception('Cannot move file, the file has not been correctly uploaded!');
}
$fileName = (empty($fileName) ? $this->get('name') : $fileName);
if (!file_exists($toDir) && !mkdir($toDir, $mode, true)) {
throw new \Exception(__METHOD__ . '|Cannot create directory "' . $toDir . '" !', 1000);
}
return move_uploaded_file($this->get('tmp_name'), $toDir . $fileName);
} | [
"public",
"function",
"move",
"(",
"$",
"toDir",
",",
"$",
"fileName",
"=",
"null",
",",
"$",
"mode",
"=",
"0775",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasError",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Cannot move file, the file has not been correctly uploaded!'",
")",
";",
"}",
"$",
"fileName",
"=",
"(",
"empty",
"(",
"$",
"fileName",
")",
"?",
"$",
"this",
"->",
"get",
"(",
"'name'",
")",
":",
"$",
"fileName",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"toDir",
")",
"&&",
"!",
"mkdir",
"(",
"$",
"toDir",
",",
"$",
"mode",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"__METHOD__",
".",
"'|Cannot create directory \"'",
".",
"$",
"toDir",
".",
"'\" !'",
",",
"1000",
")",
";",
"}",
"return",
"move_uploaded_file",
"(",
"$",
"this",
"->",
"get",
"(",
"'tmp_name'",
")",
",",
"$",
"toDir",
".",
"$",
"fileName",
")",
";",
"}"
] | Move uploaded file.
@param string $toDir
@param string $fileName
@param int $mode Right mode on directory to create (if not exists)
@return bool
@throws \Exception | [
"Move",
"uploaded",
"file",
"."
] | 698c3b73581a9703a9c932890c57e50f8774607a | https://github.com/eureka-framework/component-http/blob/698c3b73581a9703a9c932890c57e50f8774607a/src/Http/File.php#L78-L91 | train |
black-lamp/blcms-cart | backend/controllers/OrderController.php | OrderController.actionView | public function actionView($id)
{
if (!empty($id)) {
$model = Order::findOne($id);
if (empty($model)) {
$model = new Order();
}
if (Yii::$app->user->can('changeOrderStatus')) {
if ($model->load(Yii::$app->request->post())) {
$this->trigger(self::EVENT_BEFORE_CHANGE_ORDER_STATUS);
if ($model->save()) {
$this->trigger(self::EVENT_AFTER_CHANGE_ORDER_STATUS, new OrderEvent([
'model' => $model
]));
\Yii::$app->session->setFlash('success', \Yii::t('cart', 'The record was successfully saved.'));
} else {
\Yii::$app->session->setFlash('error', \Yii::t('cart', 'An error occurred when saving the record.'));
}
return $this->redirect(['view', 'id' => $id]);
} else {
$orderProducts = $model->orderProducts;
return $this->render('view', [
'model' => $this->findModel($id),
'statuses' => OrderStatus::find()->all(),
'orderProducts' => $orderProducts,
]);
}
} else throw new ForbiddenHttpException();
} else throw new NotFoundHttpException();
} | php | public function actionView($id)
{
if (!empty($id)) {
$model = Order::findOne($id);
if (empty($model)) {
$model = new Order();
}
if (Yii::$app->user->can('changeOrderStatus')) {
if ($model->load(Yii::$app->request->post())) {
$this->trigger(self::EVENT_BEFORE_CHANGE_ORDER_STATUS);
if ($model->save()) {
$this->trigger(self::EVENT_AFTER_CHANGE_ORDER_STATUS, new OrderEvent([
'model' => $model
]));
\Yii::$app->session->setFlash('success', \Yii::t('cart', 'The record was successfully saved.'));
} else {
\Yii::$app->session->setFlash('error', \Yii::t('cart', 'An error occurred when saving the record.'));
}
return $this->redirect(['view', 'id' => $id]);
} else {
$orderProducts = $model->orderProducts;
return $this->render('view', [
'model' => $this->findModel($id),
'statuses' => OrderStatus::find()->all(),
'orderProducts' => $orderProducts,
]);
}
} else throw new ForbiddenHttpException();
} else throw new NotFoundHttpException();
} | [
"public",
"function",
"actionView",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"model",
"=",
"Order",
"::",
"findOne",
"(",
"$",
"id",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"model",
")",
")",
"{",
"$",
"model",
"=",
"new",
"Order",
"(",
")",
";",
"}",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"can",
"(",
"'changeOrderStatus'",
")",
")",
"{",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_BEFORE_CHANGE_ORDER_STATUS",
")",
";",
"if",
"(",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_AFTER_CHANGE_ORDER_STATUS",
",",
"new",
"OrderEvent",
"(",
"[",
"'model'",
"=>",
"$",
"model",
"]",
")",
")",
";",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'success'",
",",
"\\",
"Yii",
"::",
"t",
"(",
"'cart'",
",",
"'The record was successfully saved.'",
")",
")",
";",
"}",
"else",
"{",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'error'",
",",
"\\",
"Yii",
"::",
"t",
"(",
"'cart'",
",",
"'An error occurred when saving the record.'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'view'",
",",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"}",
"else",
"{",
"$",
"orderProducts",
"=",
"$",
"model",
"->",
"orderProducts",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'view'",
",",
"[",
"'model'",
"=>",
"$",
"this",
"->",
"findModel",
"(",
"$",
"id",
")",
",",
"'statuses'",
"=>",
"OrderStatus",
"::",
"find",
"(",
")",
"->",
"all",
"(",
")",
",",
"'orderProducts'",
"=>",
"$",
"orderProducts",
",",
"]",
")",
";",
"}",
"}",
"else",
"throw",
"new",
"ForbiddenHttpException",
"(",
")",
";",
"}",
"else",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}"
] | Displays a single Order model and changes status for this model.
@param integer $id
@return mixed
@throws NotFoundHttpException
@throws ForbiddenHttpException | [
"Displays",
"a",
"single",
"Order",
"model",
"and",
"changes",
"status",
"for",
"this",
"model",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/backend/controllers/OrderController.php#L84-L118 | train |
black-lamp/blcms-cart | backend/controllers/OrderController.php | OrderController.actionDeleteProduct | public function actionDeleteProduct($id)
{
if (($model = OrderProduct::findOne($id)) !== null) {
$model->delete();
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
return $this->redirect(\Yii::$app->request->referrer);
} | php | public function actionDeleteProduct($id)
{
if (($model = OrderProduct::findOne($id)) !== null) {
$model->delete();
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
return $this->redirect(\Yii::$app->request->referrer);
} | [
"public",
"function",
"actionDeleteProduct",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"(",
"$",
"model",
"=",
"OrderProduct",
"::",
"findOne",
"(",
"$",
"id",
")",
")",
"!==",
"null",
")",
"{",
"$",
"model",
"->",
"delete",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'The requested page does not exist.'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"referrer",
")",
";",
"}"
] | Deletes product from existing Order model.
If deletion is successful, the browser will be redirected to the 'view' page.
@param integer $id
@return mixed
@throws NotFoundHttpException | [
"Deletes",
"product",
"from",
"existing",
"Order",
"model",
".",
"If",
"deletion",
"is",
"successful",
"the",
"browser",
"will",
"be",
"redirected",
"to",
"the",
"view",
"page",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/backend/controllers/OrderController.php#L140-L149 | train |
danielgp/common-lib | source/DomDynamicSelectByDanielGP.php | DomDynamicSelectByDanielGP.calculateSelectOptionsSize | private function calculateSelectOptionsSize($aElements, $aFeatures = [])
{
$selectSize = $this->calculateSelectOptionsSizeForced($aElements, $aFeatures);
if ((in_array('include_null', $aFeatures)) && ($selectSize != '1')) {
$selectSize++;
}
return $selectSize;
} | php | private function calculateSelectOptionsSize($aElements, $aFeatures = [])
{
$selectSize = $this->calculateSelectOptionsSizeForced($aElements, $aFeatures);
if ((in_array('include_null', $aFeatures)) && ($selectSize != '1')) {
$selectSize++;
}
return $selectSize;
} | [
"private",
"function",
"calculateSelectOptionsSize",
"(",
"$",
"aElements",
",",
"$",
"aFeatures",
"=",
"[",
"]",
")",
"{",
"$",
"selectSize",
"=",
"$",
"this",
"->",
"calculateSelectOptionsSizeForced",
"(",
"$",
"aElements",
",",
"$",
"aFeatures",
")",
";",
"if",
"(",
"(",
"in_array",
"(",
"'include_null'",
",",
"$",
"aFeatures",
")",
")",
"&&",
"(",
"$",
"selectSize",
"!=",
"'1'",
")",
")",
"{",
"$",
"selectSize",
"++",
";",
"}",
"return",
"$",
"selectSize",
";",
"}"
] | Calculate the optimal for all options within a select tag
@param array $aElements
@param array $aFeatures
@return string|int | [
"Calculate",
"the",
"optimal",
"for",
"all",
"options",
"within",
"a",
"select",
"tag"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomDynamicSelectByDanielGP.php#L61-L68 | train |
danielgp/common-lib | source/DomDynamicSelectByDanielGP.php | DomDynamicSelectByDanielGP.setOptionsForSelect | private function setOptionsForSelect($aElements, $sDefaultValue, $featArray = null)
{
if (is_null($featArray)) {
$featArray = [];
}
$sReturn = [];
$crtGroup = null;
foreach ($aElements as $key => $value) {
$aFH = $this->setOptionGroupFooterHeader($featArray, $value, $crtGroup);
$crtGroup = $aFH['crtGroup'];
$sReturn[] = $aFH['groupFooterHeader']
. '<option value="' . $key . '"' . $this->setOptionSelected($key, $sDefaultValue)
. $this->featureArraySimpleTranslated($featArray, 'styleForOption') . '>'
. str_replace(['&', $crtGroup], ['&', ''], $value) . '</option>';
}
$sReturn[] = $this->setOptionGroupEnd($crtGroup, $featArray);
return $this->featureArraySimpleTranslated($featArray, 'include_null') . implode('', $sReturn);
} | php | private function setOptionsForSelect($aElements, $sDefaultValue, $featArray = null)
{
if (is_null($featArray)) {
$featArray = [];
}
$sReturn = [];
$crtGroup = null;
foreach ($aElements as $key => $value) {
$aFH = $this->setOptionGroupFooterHeader($featArray, $value, $crtGroup);
$crtGroup = $aFH['crtGroup'];
$sReturn[] = $aFH['groupFooterHeader']
. '<option value="' . $key . '"' . $this->setOptionSelected($key, $sDefaultValue)
. $this->featureArraySimpleTranslated($featArray, 'styleForOption') . '>'
. str_replace(['&', $crtGroup], ['&', ''], $value) . '</option>';
}
$sReturn[] = $this->setOptionGroupEnd($crtGroup, $featArray);
return $this->featureArraySimpleTranslated($featArray, 'include_null') . implode('', $sReturn);
} | [
"private",
"function",
"setOptionsForSelect",
"(",
"$",
"aElements",
",",
"$",
"sDefaultValue",
",",
"$",
"featArray",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"featArray",
")",
")",
"{",
"$",
"featArray",
"=",
"[",
"]",
";",
"}",
"$",
"sReturn",
"=",
"[",
"]",
";",
"$",
"crtGroup",
"=",
"null",
";",
"foreach",
"(",
"$",
"aElements",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"aFH",
"=",
"$",
"this",
"->",
"setOptionGroupFooterHeader",
"(",
"$",
"featArray",
",",
"$",
"value",
",",
"$",
"crtGroup",
")",
";",
"$",
"crtGroup",
"=",
"$",
"aFH",
"[",
"'crtGroup'",
"]",
";",
"$",
"sReturn",
"[",
"]",
"=",
"$",
"aFH",
"[",
"'groupFooterHeader'",
"]",
".",
"'<option value=\"'",
".",
"$",
"key",
".",
"'\"'",
".",
"$",
"this",
"->",
"setOptionSelected",
"(",
"$",
"key",
",",
"$",
"sDefaultValue",
")",
".",
"$",
"this",
"->",
"featureArraySimpleTranslated",
"(",
"$",
"featArray",
",",
"'styleForOption'",
")",
".",
"'>'",
".",
"str_replace",
"(",
"[",
"'&'",
",",
"$",
"crtGroup",
"]",
",",
"[",
"'&'",
",",
"''",
"]",
",",
"$",
"value",
")",
".",
"'</option>'",
";",
"}",
"$",
"sReturn",
"[",
"]",
"=",
"$",
"this",
"->",
"setOptionGroupEnd",
"(",
"$",
"crtGroup",
",",
"$",
"featArray",
")",
";",
"return",
"$",
"this",
"->",
"featureArraySimpleTranslated",
"(",
"$",
"featArray",
",",
"'include_null'",
")",
".",
"implode",
"(",
"''",
",",
"$",
"sReturn",
")",
";",
"}"
] | Creates all the child tags required to populate a SELECT tag
@param array $aElements
@param string|array $sDefaultValue
@param array $featArray
@return string | [
"Creates",
"all",
"the",
"child",
"tags",
"required",
"to",
"populate",
"a",
"SELECT",
"tag"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomDynamicSelectByDanielGP.php#L199-L216 | train |
Programie/JsonConfig | src/main/php/com/selfcoders/jsonconfig/ValueByPath.php | ValueByPath.getValueByPath | public static function getValueByPath($dataTree, $path)
{
$pathParts = explode(".", $path);
foreach ($pathParts as $name)
{
if (!isset($dataTree->{$name}))
{
return null;
}
$dataTree = $dataTree->{$name};
}
return $dataTree;
} | php | public static function getValueByPath($dataTree, $path)
{
$pathParts = explode(".", $path);
foreach ($pathParts as $name)
{
if (!isset($dataTree->{$name}))
{
return null;
}
$dataTree = $dataTree->{$name};
}
return $dataTree;
} | [
"public",
"static",
"function",
"getValueByPath",
"(",
"$",
"dataTree",
",",
"$",
"path",
")",
"{",
"$",
"pathParts",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"pathParts",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"dataTree",
"=",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
";",
"}",
"return",
"$",
"dataTree",
";",
"}"
] | Get the value of the property in the data tree specified by the dotted path.
@param \StdClass $dataTree A tree of StdClass objects
@param string $path The dotted path to the property which should be returned
@return null|mixed The value of the property or null if not found | [
"Get",
"the",
"value",
"of",
"the",
"property",
"in",
"the",
"data",
"tree",
"specified",
"by",
"the",
"dotted",
"path",
"."
] | 51314ec4f00fb14c6eb17b36f322b723681a7d36 | https://github.com/Programie/JsonConfig/blob/51314ec4f00fb14c6eb17b36f322b723681a7d36/src/main/php/com/selfcoders/jsonconfig/ValueByPath.php#L13-L28 | train |
Programie/JsonConfig | src/main/php/com/selfcoders/jsonconfig/ValueByPath.php | ValueByPath.setValueByPath | public static function setValueByPath($dataTree, $path, $value, $add)
{
$pathParts = explode(".", $path);
$name = $pathParts[0];
if (!$add and !isset($dataTree->{$name}))
{
return false;
}
if (count($pathParts) == 1)
{
$dataTree->{$name} = $value;
return true;
}
if (isset($dataTree->{$name}))
{
$object = $dataTree->{$name};
}
else
{
$object = new \StdClass;
$dataTree->{$name} = $object;
}
return ValueByPath::setValueByPath($object, implode(".", array_slice($pathParts, 1)), $value, $add);
} | php | public static function setValueByPath($dataTree, $path, $value, $add)
{
$pathParts = explode(".", $path);
$name = $pathParts[0];
if (!$add and !isset($dataTree->{$name}))
{
return false;
}
if (count($pathParts) == 1)
{
$dataTree->{$name} = $value;
return true;
}
if (isset($dataTree->{$name}))
{
$object = $dataTree->{$name};
}
else
{
$object = new \StdClass;
$dataTree->{$name} = $object;
}
return ValueByPath::setValueByPath($object, implode(".", array_slice($pathParts, 1)), $value, $add);
} | [
"public",
"static",
"function",
"setValueByPath",
"(",
"$",
"dataTree",
",",
"$",
"path",
",",
"$",
"value",
",",
"$",
"add",
")",
"{",
"$",
"pathParts",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"path",
")",
";",
"$",
"name",
"=",
"$",
"pathParts",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"$",
"add",
"and",
"!",
"isset",
"(",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"pathParts",
")",
"==",
"1",
")",
"{",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
"=",
"$",
"value",
";",
"return",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
")",
")",
"{",
"$",
"object",
"=",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
";",
"}",
"else",
"{",
"$",
"object",
"=",
"new",
"\\",
"StdClass",
";",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
"=",
"$",
"object",
";",
"}",
"return",
"ValueByPath",
"::",
"setValueByPath",
"(",
"$",
"object",
",",
"implode",
"(",
"\".\"",
",",
"array_slice",
"(",
"$",
"pathParts",
",",
"1",
")",
")",
",",
"$",
"value",
",",
"$",
"add",
")",
";",
"}"
] | Set the value of the property specified by the given path in the data tree.
@param \StdClass $dataTree A tree of StdClass objects
@param string $path The path to the property which should be set
@param mixed $value The value for the property
@param bool $add Whether to add a new property if not existing or only set if existing
@return bool true if the property has been set successfully, false if not (e.g. property not existing in tree and $add is set to false) | [
"Set",
"the",
"value",
"of",
"the",
"property",
"specified",
"by",
"the",
"given",
"path",
"in",
"the",
"data",
"tree",
"."
] | 51314ec4f00fb14c6eb17b36f322b723681a7d36 | https://github.com/Programie/JsonConfig/blob/51314ec4f00fb14c6eb17b36f322b723681a7d36/src/main/php/com/selfcoders/jsonconfig/ValueByPath.php#L40-L70 | train |
Programie/JsonConfig | src/main/php/com/selfcoders/jsonconfig/ValueByPath.php | ValueByPath.removeValueByPath | public static function removeValueByPath($dataTree, $path)
{
$pathParts = explode(".", $path);
$name = $pathParts[0];
if (!isset($dataTree->{$name}))
{
return false;
}
if (count($pathParts) == 1)
{
unset($dataTree->{$name});
return true;
}
return ValueByPath::removeValueByPath($dataTree->{$name}, implode(".", array_slice($pathParts, 1)));
} | php | public static function removeValueByPath($dataTree, $path)
{
$pathParts = explode(".", $path);
$name = $pathParts[0];
if (!isset($dataTree->{$name}))
{
return false;
}
if (count($pathParts) == 1)
{
unset($dataTree->{$name});
return true;
}
return ValueByPath::removeValueByPath($dataTree->{$name}, implode(".", array_slice($pathParts, 1)));
} | [
"public",
"static",
"function",
"removeValueByPath",
"(",
"$",
"dataTree",
",",
"$",
"path",
")",
"{",
"$",
"pathParts",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"path",
")",
";",
"$",
"name",
"=",
"$",
"pathParts",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"pathParts",
")",
"==",
"1",
")",
"{",
"unset",
"(",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
")",
";",
"return",
"true",
";",
"}",
"return",
"ValueByPath",
"::",
"removeValueByPath",
"(",
"$",
"dataTree",
"->",
"{",
"$",
"name",
"}",
",",
"implode",
"(",
"\".\"",
",",
"array_slice",
"(",
"$",
"pathParts",
",",
"1",
")",
")",
")",
";",
"}"
] | Remove the value of the property specified by the given path in the data tree.
@param \StdClass $dataTree A tree of StdClass objects
@param string $path The path to the property which should be removed
@return bool true if the property has been removed successfully, false if not (e.g. property not existing in tree) | [
"Remove",
"the",
"value",
"of",
"the",
"property",
"specified",
"by",
"the",
"given",
"path",
"in",
"the",
"data",
"tree",
"."
] | 51314ec4f00fb14c6eb17b36f322b723681a7d36 | https://github.com/Programie/JsonConfig/blob/51314ec4f00fb14c6eb17b36f322b723681a7d36/src/main/php/com/selfcoders/jsonconfig/ValueByPath.php#L80-L98 | train |
FuzeWorks/Core | src/FuzeWorks/Libraries.php | Libraries.getDriver | public function getDriver($libraryName, array $parameters = null, array $directory = null, $newInstance = false)
{
if (empty($libraryName))
{
throw new LibraryException("Could not load driver. No name provided", 1);
}
// Load the driver class if it is not yet loaded
if ( ! class_exists('FuzeWorks\FW_Driver_Library', false))
{
require_once(Core::$coreDir . DS . 'Libraries'.DS.'Driver.php');
}
// And then load and return the library
return $this->loadLibrary($libraryName, $parameters, $directory, $newInstance);
} | php | public function getDriver($libraryName, array $parameters = null, array $directory = null, $newInstance = false)
{
if (empty($libraryName))
{
throw new LibraryException("Could not load driver. No name provided", 1);
}
// Load the driver class if it is not yet loaded
if ( ! class_exists('FuzeWorks\FW_Driver_Library', false))
{
require_once(Core::$coreDir . DS . 'Libraries'.DS.'Driver.php');
}
// And then load and return the library
return $this->loadLibrary($libraryName, $parameters, $directory, $newInstance);
} | [
"public",
"function",
"getDriver",
"(",
"$",
"libraryName",
",",
"array",
"$",
"parameters",
"=",
"null",
",",
"array",
"$",
"directory",
"=",
"null",
",",
"$",
"newInstance",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"libraryName",
")",
")",
"{",
"throw",
"new",
"LibraryException",
"(",
"\"Could not load driver. No name provided\"",
",",
"1",
")",
";",
"}",
"// Load the driver class if it is not yet loaded",
"if",
"(",
"!",
"class_exists",
"(",
"'FuzeWorks\\FW_Driver_Library'",
",",
"false",
")",
")",
"{",
"require_once",
"(",
"Core",
"::",
"$",
"coreDir",
".",
"DS",
".",
"'Libraries'",
".",
"DS",
".",
"'Driver.php'",
")",
";",
"}",
"// And then load and return the library",
"return",
"$",
"this",
"->",
"loadLibrary",
"(",
"$",
"libraryName",
",",
"$",
"parameters",
",",
"$",
"directory",
",",
"$",
"newInstance",
")",
";",
"}"
] | Driver Library Loader
Loads, instantiates and returns driver libraries.
@param string $library Driver Library name
@param array $params Optional parameters to pass to the library class constructor
@param array $directory Optional list of directories where the library can be found. Overrides default list
@param bool $newInstance Whether to return a new instance of the library or the same one
@return object
@throws LibraryException | [
"Driver",
"Library",
"Loader"
] | 051c64fdaa3a648174cbd54557d05ad553dd826b | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Libraries.php#L132-L147 | train |
FuzeWorks/Core | src/FuzeWorks/Libraries.php | Libraries.loadLibrary | protected function loadLibrary($libraryName, $parameters = null, array $directory = null, $newInstance = false)
{
// First get the directories where the library can be located
$directories = (is_null($directory) ? $this->libraryPaths : $directory);
// Now figure out the className and subdir
$class = trim($libraryName, '/');
if (($last_slash = strrpos($class, '/')) !== FALSE)
{
// Extract the path
$subdir = substr($class, 0, ++$last_slash);
// Get the filename from the path
$class = substr($class, $last_slash);
}
else
{
$subdir = '';
}
$class = ucfirst($class);
// Is the library a core library, then load a core library
if (file_exists(Core::$coreDir . DS . 'Libraries'.DS.$subdir.$class.'.php'))
{
// Load base library
return $this->loadCoreLibrary($class, $subdir, $parameters, $directories, $newInstance);
}
// Otherwise try and load an Application Library
return $this->loadAppLibrary($class, $subdir, $parameters, $directories, $newInstance);
} | php | protected function loadLibrary($libraryName, $parameters = null, array $directory = null, $newInstance = false)
{
// First get the directories where the library can be located
$directories = (is_null($directory) ? $this->libraryPaths : $directory);
// Now figure out the className and subdir
$class = trim($libraryName, '/');
if (($last_slash = strrpos($class, '/')) !== FALSE)
{
// Extract the path
$subdir = substr($class, 0, ++$last_slash);
// Get the filename from the path
$class = substr($class, $last_slash);
}
else
{
$subdir = '';
}
$class = ucfirst($class);
// Is the library a core library, then load a core library
if (file_exists(Core::$coreDir . DS . 'Libraries'.DS.$subdir.$class.'.php'))
{
// Load base library
return $this->loadCoreLibrary($class, $subdir, $parameters, $directories, $newInstance);
}
// Otherwise try and load an Application Library
return $this->loadAppLibrary($class, $subdir, $parameters, $directories, $newInstance);
} | [
"protected",
"function",
"loadLibrary",
"(",
"$",
"libraryName",
",",
"$",
"parameters",
"=",
"null",
",",
"array",
"$",
"directory",
"=",
"null",
",",
"$",
"newInstance",
"=",
"false",
")",
"{",
"// First get the directories where the library can be located",
"$",
"directories",
"=",
"(",
"is_null",
"(",
"$",
"directory",
")",
"?",
"$",
"this",
"->",
"libraryPaths",
":",
"$",
"directory",
")",
";",
"// Now figure out the className and subdir",
"$",
"class",
"=",
"trim",
"(",
"$",
"libraryName",
",",
"'/'",
")",
";",
"if",
"(",
"(",
"$",
"last_slash",
"=",
"strrpos",
"(",
"$",
"class",
",",
"'/'",
")",
")",
"!==",
"FALSE",
")",
"{",
"// Extract the path",
"$",
"subdir",
"=",
"substr",
"(",
"$",
"class",
",",
"0",
",",
"++",
"$",
"last_slash",
")",
";",
"// Get the filename from the path",
"$",
"class",
"=",
"substr",
"(",
"$",
"class",
",",
"$",
"last_slash",
")",
";",
"}",
"else",
"{",
"$",
"subdir",
"=",
"''",
";",
"}",
"$",
"class",
"=",
"ucfirst",
"(",
"$",
"class",
")",
";",
"// Is the library a core library, then load a core library",
"if",
"(",
"file_exists",
"(",
"Core",
"::",
"$",
"coreDir",
".",
"DS",
".",
"'Libraries'",
".",
"DS",
".",
"$",
"subdir",
".",
"$",
"class",
".",
"'.php'",
")",
")",
"{",
"// Load base library",
"return",
"$",
"this",
"->",
"loadCoreLibrary",
"(",
"$",
"class",
",",
"$",
"subdir",
",",
"$",
"parameters",
",",
"$",
"directories",
",",
"$",
"newInstance",
")",
";",
"}",
"// Otherwise try and load an Application Library",
"return",
"$",
"this",
"->",
"loadAppLibrary",
"(",
"$",
"class",
",",
"$",
"subdir",
",",
"$",
"parameters",
",",
"$",
"directories",
",",
"$",
"newInstance",
")",
";",
"}"
] | Internal Library Loader
Determines what type of library needs to be loaded
@param string $library Library name
@param array $params Optional parameters to pass to the library class constructor
@param array $directory Optional list of directories where the library can be found. Overrides default list
@param bool $newInstance Whether to return a new instance of the library or the same one
@return object
@throws LibraryException | [
"Internal",
"Library",
"Loader"
] | 051c64fdaa3a648174cbd54557d05ad553dd826b | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Libraries.php#L161-L192 | train |
FuzeWorks/Core | src/FuzeWorks/Libraries.php | Libraries.loadAppLibrary | protected function loadAppLibrary($class, $subdir, array $parameters = null, array $directories, $newInstance = false)
{
// First check if the input is correct
if (!is_array($directories))
{
throw new LibraryException("Could not load library. \$directory variable was not an array", 1);
}
// Search for the file
foreach ($directories as $directory)
{
// Skip the core directory
if ($directory === Core::$coreDir . DS . 'Libraries')
{
continue;
}
// Determine the file
$file = $directory . DS . $subdir . $class . '.php';
$className = '\Application\Library\\'.$class;
// Check if the file was already loaded
if (class_exists($className, false))
{
// Return existing instance
if (!isset($this->libraries[$className]))
{
return $this->initLibrary($className, $parameters);
}
// If required to do so, return the existing instance or load a new one
if ($newInstance)
{
$this->factory->logger->log("Library '".$className."' already loaded. Returning existing instance");
return $this->libraries[$prefix.$class];
}
$this->factory->logger->log("Library '".$className."' already loaded. Returning new instance");
return $this->initLibrary($className, $parameters);
}
// Otherwise load the file first
if (file_exists($file))
{
include_once($file);
return $this->initLibrary($className, $parameters);
}
}
// Maybe it's in a subdirectory with the same name as the class
if ($subdir === '')
{
return $this->loadLibrary($class."/".$class, $parameters, $directories, $newInstance);
}
throw new LibraryException("Could not load library. Library was not found", 1);
} | php | protected function loadAppLibrary($class, $subdir, array $parameters = null, array $directories, $newInstance = false)
{
// First check if the input is correct
if (!is_array($directories))
{
throw new LibraryException("Could not load library. \$directory variable was not an array", 1);
}
// Search for the file
foreach ($directories as $directory)
{
// Skip the core directory
if ($directory === Core::$coreDir . DS . 'Libraries')
{
continue;
}
// Determine the file
$file = $directory . DS . $subdir . $class . '.php';
$className = '\Application\Library\\'.$class;
// Check if the file was already loaded
if (class_exists($className, false))
{
// Return existing instance
if (!isset($this->libraries[$className]))
{
return $this->initLibrary($className, $parameters);
}
// If required to do so, return the existing instance or load a new one
if ($newInstance)
{
$this->factory->logger->log("Library '".$className."' already loaded. Returning existing instance");
return $this->libraries[$prefix.$class];
}
$this->factory->logger->log("Library '".$className."' already loaded. Returning new instance");
return $this->initLibrary($className, $parameters);
}
// Otherwise load the file first
if (file_exists($file))
{
include_once($file);
return $this->initLibrary($className, $parameters);
}
}
// Maybe it's in a subdirectory with the same name as the class
if ($subdir === '')
{
return $this->loadLibrary($class."/".$class, $parameters, $directories, $newInstance);
}
throw new LibraryException("Could not load library. Library was not found", 1);
} | [
"protected",
"function",
"loadAppLibrary",
"(",
"$",
"class",
",",
"$",
"subdir",
",",
"array",
"$",
"parameters",
"=",
"null",
",",
"array",
"$",
"directories",
",",
"$",
"newInstance",
"=",
"false",
")",
"{",
"// First check if the input is correct",
"if",
"(",
"!",
"is_array",
"(",
"$",
"directories",
")",
")",
"{",
"throw",
"new",
"LibraryException",
"(",
"\"Could not load library. \\$directory variable was not an array\"",
",",
"1",
")",
";",
"}",
"// Search for the file",
"foreach",
"(",
"$",
"directories",
"as",
"$",
"directory",
")",
"{",
"// Skip the core directory",
"if",
"(",
"$",
"directory",
"===",
"Core",
"::",
"$",
"coreDir",
".",
"DS",
".",
"'Libraries'",
")",
"{",
"continue",
";",
"}",
"// Determine the file",
"$",
"file",
"=",
"$",
"directory",
".",
"DS",
".",
"$",
"subdir",
".",
"$",
"class",
".",
"'.php'",
";",
"$",
"className",
"=",
"'\\Application\\Library\\\\'",
".",
"$",
"class",
";",
"// Check if the file was already loaded",
"if",
"(",
"class_exists",
"(",
"$",
"className",
",",
"false",
")",
")",
"{",
"// Return existing instance",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"libraries",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"initLibrary",
"(",
"$",
"className",
",",
"$",
"parameters",
")",
";",
"}",
"// If required to do so, return the existing instance or load a new one",
"if",
"(",
"$",
"newInstance",
")",
"{",
"$",
"this",
"->",
"factory",
"->",
"logger",
"->",
"log",
"(",
"\"Library '\"",
".",
"$",
"className",
".",
"\"' already loaded. Returning existing instance\"",
")",
";",
"return",
"$",
"this",
"->",
"libraries",
"[",
"$",
"prefix",
".",
"$",
"class",
"]",
";",
"}",
"$",
"this",
"->",
"factory",
"->",
"logger",
"->",
"log",
"(",
"\"Library '\"",
".",
"$",
"className",
".",
"\"' already loaded. Returning new instance\"",
")",
";",
"return",
"$",
"this",
"->",
"initLibrary",
"(",
"$",
"className",
",",
"$",
"parameters",
")",
";",
"}",
"// Otherwise load the file first",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"include_once",
"(",
"$",
"file",
")",
";",
"return",
"$",
"this",
"->",
"initLibrary",
"(",
"$",
"className",
",",
"$",
"parameters",
")",
";",
"}",
"}",
"// Maybe it's in a subdirectory with the same name as the class",
"if",
"(",
"$",
"subdir",
"===",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"loadLibrary",
"(",
"$",
"class",
".",
"\"/\"",
".",
"$",
"class",
",",
"$",
"parameters",
",",
"$",
"directories",
",",
"$",
"newInstance",
")",
";",
"}",
"throw",
"new",
"LibraryException",
"(",
"\"Could not load library. Library was not found\"",
",",
"1",
")",
";",
"}"
] | Application Library Loader
Loads, instantiates and returns an application library.
Could possibly extend a core library if requested.
@param string $class Classname
@param string $subdir Sub directory in which the final class can be found
@param array $params Optional parameters to pass to the library class constructor
@param array $directory Optional list of directories where the library can be found. Overrides default list
@param bool $newInstance Whether to return a new instance of the library or the same one
@return object
@throws LibraryException | [
"Application",
"Library",
"Loader"
] | 051c64fdaa3a648174cbd54557d05ad553dd826b | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Libraries.php#L320-L376 | train |
FuzeWorks/Core | src/FuzeWorks/Libraries.php | Libraries.removeLibraryPath | public function removeLibraryPath($directory)
{
if (($key = array_search($directory, $this->libraryPaths)) !== false)
{
unset($this->libraryPaths[$key]);
}
} | php | public function removeLibraryPath($directory)
{
if (($key = array_search($directory, $this->libraryPaths)) !== false)
{
unset($this->libraryPaths[$key]);
}
} | [
"public",
"function",
"removeLibraryPath",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"directory",
",",
"$",
"this",
"->",
"libraryPaths",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"libraryPaths",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}"
] | Remove a path where libraries can be found
@param string $directory The directory
@return void | [
"Remove",
"a",
"path",
"where",
"libraries",
"can",
"be",
"found"
] | 051c64fdaa3a648174cbd54557d05ad553dd826b | https://github.com/FuzeWorks/Core/blob/051c64fdaa3a648174cbd54557d05ad553dd826b/src/FuzeWorks/Libraries.php#L445-L451 | train |
freialib/fenrir.system | src/Trait/MysqlRepo.php | MysqlRepoTrait.find | function find(array $logic = null) {
$logic != null or $logic = [];
$opt = [];
foreach (['%fields', '%order_by', '%limit', '%offset'] as $key) {
if (isset($logic[$key])) {
$opt[$key] = $logic[$key];
unset($logic[$key]);
}
else { // %filter not set
$opt[$key] = [];
}
}
$entries = $this->sqlfind
(
$logic,
$opt['%fields'],
$opt['%order_by'],
$opt['%limit'],
$opt['%offset']
);
return $this->toModels($entries);
} | php | function find(array $logic = null) {
$logic != null or $logic = [];
$opt = [];
foreach (['%fields', '%order_by', '%limit', '%offset'] as $key) {
if (isset($logic[$key])) {
$opt[$key] = $logic[$key];
unset($logic[$key]);
}
else { // %filter not set
$opt[$key] = [];
}
}
$entries = $this->sqlfind
(
$logic,
$opt['%fields'],
$opt['%order_by'],
$opt['%limit'],
$opt['%offset']
);
return $this->toModels($entries);
} | [
"function",
"find",
"(",
"array",
"$",
"logic",
"=",
"null",
")",
"{",
"$",
"logic",
"!=",
"null",
"or",
"$",
"logic",
"=",
"[",
"]",
";",
"$",
"opt",
"=",
"[",
"]",
";",
"foreach",
"(",
"[",
"'%fields'",
",",
"'%order_by'",
",",
"'%limit'",
",",
"'%offset'",
"]",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"logic",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"opt",
"[",
"$",
"key",
"]",
"=",
"$",
"logic",
"[",
"$",
"key",
"]",
";",
"unset",
"(",
"$",
"logic",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"// %filter not set",
"$",
"opt",
"[",
"$",
"key",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"$",
"entries",
"=",
"$",
"this",
"->",
"sqlfind",
"(",
"$",
"logic",
",",
"$",
"opt",
"[",
"'%fields'",
"]",
",",
"$",
"opt",
"[",
"'%order_by'",
"]",
",",
"$",
"opt",
"[",
"'%limit'",
"]",
",",
"$",
"opt",
"[",
"'%offset'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"toModels",
"(",
"$",
"entries",
")",
";",
"}"
] | You can specify fields via %fields
You can specify limit via %limit and offset via %offset
You can specify order rules via %order_by
Everything else is interpreted as constraints on the entries.
@return array [ models ] | [
"You",
"can",
"specify",
"fields",
"via",
"%fields",
"You",
"can",
"specify",
"limit",
"via",
"%limit",
"and",
"offset",
"via",
"%offset",
"You",
"can",
"specify",
"order",
"rules",
"via",
"%order_by"
] | 388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8 | https://github.com/freialib/fenrir.system/blob/388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8/src/Trait/MysqlRepo.php#L81-L106 | train |
freialib/fenrir.system | src/Trait/MysqlRepo.php | MysqlRepoTrait.sqlinsert | protected function sqlinsert(array $fields, array $nums = null, array $bools = null) {
$db = $this->db;
$nums != null or $nums = [];
$bools != null or $bools = [];
$keys = array_keys($fields);
$strs = array_diff($keys, $bools, $nums);
$key_fields = \hlin\Arr::join(', ', $keys, function ($_, $val) {
return "`$val`";
});
$value_fields = \hlin\Arr::join(', ', $keys, function ($_, $val) {
return ":$val ";
});
$db->prepare
(
" INSERT INTO `[table]`
($key_fields)
VALUES ($value_fields)
",
[ 'table' => $this->constants()['table'] ]
)
->strs($fields, $strs)
->bools($fields, $bools)
->nums($fields, $nums)
->execute();
return $db->lastInsertId();
} | php | protected function sqlinsert(array $fields, array $nums = null, array $bools = null) {
$db = $this->db;
$nums != null or $nums = [];
$bools != null or $bools = [];
$keys = array_keys($fields);
$strs = array_diff($keys, $bools, $nums);
$key_fields = \hlin\Arr::join(', ', $keys, function ($_, $val) {
return "`$val`";
});
$value_fields = \hlin\Arr::join(', ', $keys, function ($_, $val) {
return ":$val ";
});
$db->prepare
(
" INSERT INTO `[table]`
($key_fields)
VALUES ($value_fields)
",
[ 'table' => $this->constants()['table'] ]
)
->strs($fields, $strs)
->bools($fields, $bools)
->nums($fields, $nums)
->execute();
return $db->lastInsertId();
} | [
"protected",
"function",
"sqlinsert",
"(",
"array",
"$",
"fields",
",",
"array",
"$",
"nums",
"=",
"null",
",",
"array",
"$",
"bools",
"=",
"null",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"db",
";",
"$",
"nums",
"!=",
"null",
"or",
"$",
"nums",
"=",
"[",
"]",
";",
"$",
"bools",
"!=",
"null",
"or",
"$",
"bools",
"=",
"[",
"]",
";",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"fields",
")",
";",
"$",
"strs",
"=",
"array_diff",
"(",
"$",
"keys",
",",
"$",
"bools",
",",
"$",
"nums",
")",
";",
"$",
"key_fields",
"=",
"\\",
"hlin",
"\\",
"Arr",
"::",
"join",
"(",
"', '",
",",
"$",
"keys",
",",
"function",
"(",
"$",
"_",
",",
"$",
"val",
")",
"{",
"return",
"\"`$val`\"",
";",
"}",
")",
";",
"$",
"value_fields",
"=",
"\\",
"hlin",
"\\",
"Arr",
"::",
"join",
"(",
"', '",
",",
"$",
"keys",
",",
"function",
"(",
"$",
"_",
",",
"$",
"val",
")",
"{",
"return",
"\":$val \"",
";",
"}",
")",
";",
"$",
"db",
"->",
"prepare",
"(",
"\"\tINSERT INTO `[table]`\n\t\t\t\t\t\t ($key_fields)\n\t\t\t\t\tVALUES ($value_fields)\n\t\t\t\t\"",
",",
"[",
"'table'",
"=>",
"$",
"this",
"->",
"constants",
"(",
")",
"[",
"'table'",
"]",
"]",
")",
"->",
"strs",
"(",
"$",
"fields",
",",
"$",
"strs",
")",
"->",
"bools",
"(",
"$",
"fields",
",",
"$",
"bools",
")",
"->",
"nums",
"(",
"$",
"fields",
",",
"$",
"nums",
")",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"db",
"->",
"lastInsertId",
"(",
")",
";",
"}"
] | Inserts fields, if bools or nums are specified the fields mentioned are
treated as strings.
@return int new entry id | [
"Inserts",
"fields",
"if",
"bools",
"or",
"nums",
"are",
"specified",
"the",
"fields",
"mentioned",
"are",
"treated",
"as",
"strings",
"."
] | 388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8 | https://github.com/freialib/fenrir.system/blob/388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8/src/Trait/MysqlRepo.php#L200-L231 | train |
freialib/fenrir.system | src/Trait/MysqlRepo.php | MysqlRepoTrait.sqlupdate | protected function sqlupdate(array $fields, array $nums = null, array $bools = null) {
$db = $this->db;
$idfield = $this->idfield();
$nums != null or $nums = [];
$bools != null or $bools = [];
$keys = array_diff(array_keys($fields), [ $idfield ]);
$strs = array_diff(array_keys($fields), $bools, $nums);
$setters = \hlin\Arr::join(",\n\t\t\t\t\t ", $keys, function ($_, $val) {
return "`$val` = :$val";
});
$db->prepare
(
" UPDATE `[table]`
SET $setters
WHERE `$idfield` = :$idfield
",
[ 'table' => $this->constants()['table'] ]
)
->strs($fields, $strs)
->bools($fields, $bools)
->nums($fields, $nums)
->execute();
return $fields[$idfield];
} | php | protected function sqlupdate(array $fields, array $nums = null, array $bools = null) {
$db = $this->db;
$idfield = $this->idfield();
$nums != null or $nums = [];
$bools != null or $bools = [];
$keys = array_diff(array_keys($fields), [ $idfield ]);
$strs = array_diff(array_keys($fields), $bools, $nums);
$setters = \hlin\Arr::join(",\n\t\t\t\t\t ", $keys, function ($_, $val) {
return "`$val` = :$val";
});
$db->prepare
(
" UPDATE `[table]`
SET $setters
WHERE `$idfield` = :$idfield
",
[ 'table' => $this->constants()['table'] ]
)
->strs($fields, $strs)
->bools($fields, $bools)
->nums($fields, $nums)
->execute();
return $fields[$idfield];
} | [
"protected",
"function",
"sqlupdate",
"(",
"array",
"$",
"fields",
",",
"array",
"$",
"nums",
"=",
"null",
",",
"array",
"$",
"bools",
"=",
"null",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"db",
";",
"$",
"idfield",
"=",
"$",
"this",
"->",
"idfield",
"(",
")",
";",
"$",
"nums",
"!=",
"null",
"or",
"$",
"nums",
"=",
"[",
"]",
";",
"$",
"bools",
"!=",
"null",
"or",
"$",
"bools",
"=",
"[",
"]",
";",
"$",
"keys",
"=",
"array_diff",
"(",
"array_keys",
"(",
"$",
"fields",
")",
",",
"[",
"$",
"idfield",
"]",
")",
";",
"$",
"strs",
"=",
"array_diff",
"(",
"array_keys",
"(",
"$",
"fields",
")",
",",
"$",
"bools",
",",
"$",
"nums",
")",
";",
"$",
"setters",
"=",
"\\",
"hlin",
"\\",
"Arr",
"::",
"join",
"(",
"\",\\n\\t\\t\\t\\t\\t \"",
",",
"$",
"keys",
",",
"function",
"(",
"$",
"_",
",",
"$",
"val",
")",
"{",
"return",
"\"`$val` = :$val\"",
";",
"}",
")",
";",
"$",
"db",
"->",
"prepare",
"(",
"\"\tUPDATE `[table]`\n\t\t\t\t\t SET $setters\n\t\t\t\t\t WHERE `$idfield` = :$idfield\n\t\t\t\t\"",
",",
"[",
"'table'",
"=>",
"$",
"this",
"->",
"constants",
"(",
")",
"[",
"'table'",
"]",
"]",
")",
"->",
"strs",
"(",
"$",
"fields",
",",
"$",
"strs",
")",
"->",
"bools",
"(",
"$",
"fields",
",",
"$",
"bools",
")",
"->",
"nums",
"(",
"$",
"fields",
",",
"$",
"nums",
")",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"fields",
"[",
"$",
"idfield",
"]",
";",
"}"
] | Update fields, if bools or nums are specified the fields mentioned are
treated as strings
@return int updated entry id | [
"Update",
"fields",
"if",
"bools",
"or",
"nums",
"are",
"specified",
"the",
"fields",
"mentioned",
"are",
"treated",
"as",
"strings"
] | 388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8 | https://github.com/freialib/fenrir.system/blob/388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8/src/Trait/MysqlRepo.php#L239-L268 | train |
freialib/fenrir.system | src/Trait/MysqlRepo.php | MysqlRepoTrait.sqlentry | protected function sqlentry($entry_id) {
$res = $this->sqlfind([ $this->idfield() => $entry_id ], null, null, 1);
if (empty($res)) {
return null;
}
else { // found entry
return $res[0];
}
} | php | protected function sqlentry($entry_id) {
$res = $this->sqlfind([ $this->idfield() => $entry_id ], null, null, 1);
if (empty($res)) {
return null;
}
else { // found entry
return $res[0];
}
} | [
"protected",
"function",
"sqlentry",
"(",
"$",
"entry_id",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"sqlfind",
"(",
"[",
"$",
"this",
"->",
"idfield",
"(",
")",
"=>",
"$",
"entry_id",
"]",
",",
"null",
",",
"null",
",",
"1",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"res",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"// found entry",
"return",
"$",
"res",
"[",
"0",
"]",
";",
"}",
"}"
] | Mostly an alias to sqlsearch on id with limit of 1.
@return array|null | [
"Mostly",
"an",
"alias",
"to",
"sqlsearch",
"on",
"id",
"with",
"limit",
"of",
"1",
"."
] | 388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8 | https://github.com/freialib/fenrir.system/blob/388d360dbc3bc6dcf85b09bb06e08a2dce8f3ec8/src/Trait/MysqlRepo.php#L337-L345 | train |
jyokum/healthgraph | src/HealthGraph/HealthGraphClient.php | HealthGraphClient.factory | public static function factory($config = array())
{
$default = array(
'base_url' => 'https://api.runkeeper.com',
'logger' => FALSE,
);
$required = array('base_url');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'));
$client->setConfig($config);
$client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'client.json'));
// Set the iterator resource factory based on the provided iterators config
$clientClass = get_class();
$prefix = substr($clientClass, 0, strrpos($clientClass, '\\'));
$client->setResourceIteratorFactory(
new HealthGraphIteratorFactory(array("{$prefix}\\Common\\Iterator"))
);
if ($config->get('logger')) {
$adapter = new \Guzzle\Log\PsrLogAdapter($config->get('logger'));
$logPlugin = new \Guzzle\Plugin\Log\LogPlugin(
$adapter,
\Guzzle\Log\MessageFormatter::DEBUG_FORMAT
);
$client->addSubscriber($logPlugin);
}
return $client;
} | php | public static function factory($config = array())
{
$default = array(
'base_url' => 'https://api.runkeeper.com',
'logger' => FALSE,
);
$required = array('base_url');
$config = Collection::fromConfig($config, $default, $required);
$client = new self($config->get('base_url'));
$client->setConfig($config);
$client->setDescription(ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . 'client.json'));
// Set the iterator resource factory based on the provided iterators config
$clientClass = get_class();
$prefix = substr($clientClass, 0, strrpos($clientClass, '\\'));
$client->setResourceIteratorFactory(
new HealthGraphIteratorFactory(array("{$prefix}\\Common\\Iterator"))
);
if ($config->get('logger')) {
$adapter = new \Guzzle\Log\PsrLogAdapter($config->get('logger'));
$logPlugin = new \Guzzle\Plugin\Log\LogPlugin(
$adapter,
\Guzzle\Log\MessageFormatter::DEBUG_FORMAT
);
$client->addSubscriber($logPlugin);
}
return $client;
} | [
"public",
"static",
"function",
"factory",
"(",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"$",
"default",
"=",
"array",
"(",
"'base_url'",
"=>",
"'https://api.runkeeper.com'",
",",
"'logger'",
"=>",
"FALSE",
",",
")",
";",
"$",
"required",
"=",
"array",
"(",
"'base_url'",
")",
";",
"$",
"config",
"=",
"Collection",
"::",
"fromConfig",
"(",
"$",
"config",
",",
"$",
"default",
",",
"$",
"required",
")",
";",
"$",
"client",
"=",
"new",
"self",
"(",
"$",
"config",
"->",
"get",
"(",
"'base_url'",
")",
")",
";",
"$",
"client",
"->",
"setConfig",
"(",
"$",
"config",
")",
";",
"$",
"client",
"->",
"setDescription",
"(",
"ServiceDescription",
"::",
"factory",
"(",
"__DIR__",
".",
"DIRECTORY_SEPARATOR",
".",
"'client.json'",
")",
")",
";",
"// Set the iterator resource factory based on the provided iterators config",
"$",
"clientClass",
"=",
"get_class",
"(",
")",
";",
"$",
"prefix",
"=",
"substr",
"(",
"$",
"clientClass",
",",
"0",
",",
"strrpos",
"(",
"$",
"clientClass",
",",
"'\\\\'",
")",
")",
";",
"$",
"client",
"->",
"setResourceIteratorFactory",
"(",
"new",
"HealthGraphIteratorFactory",
"(",
"array",
"(",
"\"{$prefix}\\\\Common\\\\Iterator\"",
")",
")",
")",
";",
"if",
"(",
"$",
"config",
"->",
"get",
"(",
"'logger'",
")",
")",
"{",
"$",
"adapter",
"=",
"new",
"\\",
"Guzzle",
"\\",
"Log",
"\\",
"PsrLogAdapter",
"(",
"$",
"config",
"->",
"get",
"(",
"'logger'",
")",
")",
";",
"$",
"logPlugin",
"=",
"new",
"\\",
"Guzzle",
"\\",
"Plugin",
"\\",
"Log",
"\\",
"LogPlugin",
"(",
"$",
"adapter",
",",
"\\",
"Guzzle",
"\\",
"Log",
"\\",
"MessageFormatter",
"::",
"DEBUG_FORMAT",
")",
";",
"$",
"client",
"->",
"addSubscriber",
"(",
"$",
"logPlugin",
")",
";",
"}",
"return",
"$",
"client",
";",
"}"
] | Factory method to create a new HealthGraphClient
@param array|Collection $config Configuration data. Array keys:
base_url - Base URL of web service
@return HealthGraphClient
@TODO update factory method and docblock for parameters | [
"Factory",
"method",
"to",
"create",
"a",
"new",
"HealthGraphClient"
] | 6b3b4c4eb797f1fcf056024c8b15a16665bf8758 | https://github.com/jyokum/healthgraph/blob/6b3b4c4eb797f1fcf056024c8b15a16665bf8758/src/HealthGraph/HealthGraphClient.php#L23-L55 | train |
faustbrian/HTTP | src/HttpRequest.php | HttpRequest.headers | public function headers(): array
{
return collect($this->request->getHeaders())->mapWithKeys(function ($values, $header) {
return [$header => $values[0]];
})->all();
} | php | public function headers(): array
{
return collect($this->request->getHeaders())->mapWithKeys(function ($values, $header) {
return [$header => $values[0]];
})->all();
} | [
"public",
"function",
"headers",
"(",
")",
":",
"array",
"{",
"return",
"collect",
"(",
"$",
"this",
"->",
"request",
"->",
"getHeaders",
"(",
")",
")",
"->",
"mapWithKeys",
"(",
"function",
"(",
"$",
"values",
",",
"$",
"header",
")",
"{",
"return",
"[",
"$",
"header",
"=>",
"$",
"values",
"[",
"0",
"]",
"]",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Gets all header values.
@return array | [
"Gets",
"all",
"header",
"values",
"."
] | ab24b37ea211eb106237a813ec8d47ec1d4fe199 | https://github.com/faustbrian/HTTP/blob/ab24b37ea211eb106237a813ec8d47ec1d4fe199/src/HttpRequest.php#L65-L70 | train |
stubbles/stubbles-peer | src/main/php/QueryString.php | QueryString.build | public function build(): string
{
if (count($this->parameters) === 0) {
return '';
}
$queryString = '';
foreach ($this->parameters as $name => $value) {
$queryString .= $this->buildQuery($name, $value);
}
return substr($queryString, 1);
} | php | public function build(): string
{
if (count($this->parameters) === 0) {
return '';
}
$queryString = '';
foreach ($this->parameters as $name => $value) {
$queryString .= $this->buildQuery($name, $value);
}
return substr($queryString, 1);
} | [
"public",
"function",
"build",
"(",
")",
":",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"parameters",
")",
"===",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"queryString",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"parameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"queryString",
".=",
"$",
"this",
"->",
"buildQuery",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"return",
"substr",
"(",
"$",
"queryString",
",",
"1",
")",
";",
"}"
] | build the query from parameters
@return string | [
"build",
"the",
"query",
"from",
"parameters"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/QueryString.php#L85-L97 | train |
stubbles/stubbles-peer | src/main/php/QueryString.php | QueryString.buildQuery | protected function buildQuery(string $name, $value, string $postfix= ''): string
{
$query = '';
if (is_array($value)) {
foreach ($value as $k => $v) {
if (is_int($k)) {
$query .= $this->buildQuery('', $v, $postfix . $name .'[]');
} else {
$query .= $this->buildQuery('', $v, $postfix . $name . '[' . $k . ']');
}
}
} elseif (null === $value) {
$query .= '&' . urlencode($name) . $postfix;
} elseif (false === $value) {
$query .= '&' . urlencode($name) . $postfix . '=0';
} elseif (true === $value) {
$query .= '&' . urlencode($name) . $postfix . '=1';
} else {
$query .= '&' . urlencode($name) . $postfix . '=' . urlencode($value);
}
return $query;
} | php | protected function buildQuery(string $name, $value, string $postfix= ''): string
{
$query = '';
if (is_array($value)) {
foreach ($value as $k => $v) {
if (is_int($k)) {
$query .= $this->buildQuery('', $v, $postfix . $name .'[]');
} else {
$query .= $this->buildQuery('', $v, $postfix . $name . '[' . $k . ']');
}
}
} elseif (null === $value) {
$query .= '&' . urlencode($name) . $postfix;
} elseif (false === $value) {
$query .= '&' . urlencode($name) . $postfix . '=0';
} elseif (true === $value) {
$query .= '&' . urlencode($name) . $postfix . '=1';
} else {
$query .= '&' . urlencode($name) . $postfix . '=' . urlencode($value);
}
return $query;
} | [
"protected",
"function",
"buildQuery",
"(",
"string",
"$",
"name",
",",
"$",
"value",
",",
"string",
"$",
"postfix",
"=",
"''",
")",
":",
"string",
"{",
"$",
"query",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"k",
")",
")",
"{",
"$",
"query",
".=",
"$",
"this",
"->",
"buildQuery",
"(",
"''",
",",
"$",
"v",
",",
"$",
"postfix",
".",
"$",
"name",
".",
"'[]'",
")",
";",
"}",
"else",
"{",
"$",
"query",
".=",
"$",
"this",
"->",
"buildQuery",
"(",
"''",
",",
"$",
"v",
",",
"$",
"postfix",
".",
"$",
"name",
".",
"'['",
".",
"$",
"k",
".",
"']'",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"$",
"query",
".=",
"'&'",
".",
"urlencode",
"(",
"$",
"name",
")",
".",
"$",
"postfix",
";",
"}",
"elseif",
"(",
"false",
"===",
"$",
"value",
")",
"{",
"$",
"query",
".=",
"'&'",
".",
"urlencode",
"(",
"$",
"name",
")",
".",
"$",
"postfix",
".",
"'=0'",
";",
"}",
"elseif",
"(",
"true",
"===",
"$",
"value",
")",
"{",
"$",
"query",
".=",
"'&'",
".",
"urlencode",
"(",
"$",
"name",
")",
".",
"$",
"postfix",
".",
"'=1'",
";",
"}",
"else",
"{",
"$",
"query",
".=",
"'&'",
".",
"urlencode",
"(",
"$",
"name",
")",
".",
"$",
"postfix",
".",
"'='",
".",
"urlencode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Calculates query string
@param string $name
@param mixed $value
@param string $postfix The postfix to use for each variable (defaults to '')
@return string | [
"Calculates",
"query",
"string"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/QueryString.php#L107-L129 | train |
stubbles/stubbles-peer | src/main/php/QueryString.php | QueryString.addParam | public function addParam(string $name, $value): self
{
if (!is_array($value) && !is_scalar($value) && null !== $value) {
if (is_object($value) && method_exists($value, '__toString')) {
$value = (string) $value;
} else {
throw new \InvalidArgumentException(
'Argument 2 passed to ' . __METHOD__ . '() must be'
. ' a string, array, object with __toString() method'
. ' or any other scalar value.'
);
}
}
$this->parameters[$name] = $value;
return $this;
} | php | public function addParam(string $name, $value): self
{
if (!is_array($value) && !is_scalar($value) && null !== $value) {
if (is_object($value) && method_exists($value, '__toString')) {
$value = (string) $value;
} else {
throw new \InvalidArgumentException(
'Argument 2 passed to ' . __METHOD__ . '() must be'
. ' a string, array, object with __toString() method'
. ' or any other scalar value.'
);
}
}
$this->parameters[$name] = $value;
return $this;
} | [
"public",
"function",
"addParam",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"self",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
"&&",
"!",
"is_scalar",
"(",
"$",
"value",
")",
"&&",
"null",
"!==",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"method_exists",
"(",
"$",
"value",
",",
"'__toString'",
")",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Argument 2 passed to '",
".",
"__METHOD__",
".",
"'() must be'",
".",
"' a string, array, object with __toString() method'",
".",
"' or any other scalar value.'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | add a parameter
@param string $name name of parameter
@param mixed $value value of parameter
@return \stubbles\peer\QueryString
@throws \InvalidArgumentException | [
"add",
"a",
"parameter"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/QueryString.php#L149-L165 | train |
stubbles/stubbles-peer | src/main/php/QueryString.php | QueryString.removeParam | public function removeParam(string $name): self
{
if (array_key_exists($name, $this->parameters)) {
unset($this->parameters[$name]);
}
return $this;
} | php | public function removeParam(string $name): self
{
if (array_key_exists($name, $this->parameters)) {
unset($this->parameters[$name]);
}
return $this;
} | [
"public",
"function",
"removeParam",
"(",
"string",
"$",
"name",
")",
":",
"self",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"parameters",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"parameters",
"[",
"$",
"name",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | remove a param
@param string $name name of parameter
@return \stubbles\peer\QueryString | [
"remove",
"a",
"param"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/QueryString.php#L173-L180 | train |
shgysk8zer0/core_api | traits/magic/is_set.php | Is_Set.__isset | final public function __isset($prop)
{
$this->magicPropConvert($prop);
return is_array($this->{$this::MAGIC_PROPERTY})
? array_key_exists($prop, $this->{$this::MAGIC_PROPERTY})
: isset($this->{$this::MAGIC_PROPERTY}->$prop);
} | php | final public function __isset($prop)
{
$this->magicPropConvert($prop);
return is_array($this->{$this::MAGIC_PROPERTY})
? array_key_exists($prop, $this->{$this::MAGIC_PROPERTY})
: isset($this->{$this::MAGIC_PROPERTY}->$prop);
} | [
"final",
"public",
"function",
"__isset",
"(",
"$",
"prop",
")",
"{",
"$",
"this",
"->",
"magicPropConvert",
"(",
"$",
"prop",
")",
";",
"return",
"is_array",
"(",
"$",
"this",
"->",
"{",
"$",
"this",
"::",
"MAGIC_PROPERTY",
"}",
")",
"?",
"array_key_exists",
"(",
"$",
"prop",
",",
"$",
"this",
"->",
"{",
"$",
"this",
"::",
"MAGIC_PROPERTY",
"}",
")",
":",
"isset",
"(",
"$",
"this",
"->",
"{",
"$",
"this",
"::",
"MAGIC_PROPERTY",
"}",
"->",
"$",
"prop",
")",
";",
"}"
] | Magic isset metod.
@param string $prop The property to work with
@return bool Whether or not it is set.
@example isset($magic_class->$prop) ? 'True' : 'False'; | [
"Magic",
"isset",
"metod",
"."
] | 9e9b8baf761af874b95256ad2462e55fbb2b2e58 | https://github.com/shgysk8zer0/core_api/blob/9e9b8baf761af874b95256ad2462e55fbb2b2e58/traits/magic/is_set.php#L32-L38 | train |
stubbles/stubbles-streams | src/main/php/InputStreamIterator.php | InputStreamIterator.next | public function next()
{
$this->valid = !$this->inputStream->eof();
$this->currentLine = $this->inputStream->readLine();
$this->lineNumber++;
} | php | public function next()
{
$this->valid = !$this->inputStream->eof();
$this->currentLine = $this->inputStream->readLine();
$this->lineNumber++;
} | [
"public",
"function",
"next",
"(",
")",
"{",
"$",
"this",
"->",
"valid",
"=",
"!",
"$",
"this",
"->",
"inputStream",
"->",
"eof",
"(",
")",
";",
"$",
"this",
"->",
"currentLine",
"=",
"$",
"this",
"->",
"inputStream",
"->",
"readLine",
"(",
")",
";",
"$",
"this",
"->",
"lineNumber",
"++",
";",
"}"
] | moves forward to next line | [
"moves",
"forward",
"to",
"next",
"line"
] | 99b0dace5fcf71584d1456b4b5408017b896bdf5 | https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/InputStreamIterator.php#L78-L83 | train |
stubbles/stubbles-streams | src/main/php/InputStreamIterator.php | InputStreamIterator.rewind | public function rewind()
{
if (!($this->inputStream instanceof Seekable)) {
return;
}
$this->inputStream->seek(0, Seekable::SET);
$this->lineNumber = 0;
$this->currentLine = null;
$this->next();
} | php | public function rewind()
{
if (!($this->inputStream instanceof Seekable)) {
return;
}
$this->inputStream->seek(0, Seekable::SET);
$this->lineNumber = 0;
$this->currentLine = null;
$this->next();
} | [
"public",
"function",
"rewind",
"(",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"inputStream",
"instanceof",
"Seekable",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"inputStream",
"->",
"seek",
"(",
"0",
",",
"Seekable",
"::",
"SET",
")",
";",
"$",
"this",
"->",
"lineNumber",
"=",
"0",
";",
"$",
"this",
"->",
"currentLine",
"=",
"null",
";",
"$",
"this",
"->",
"next",
"(",
")",
";",
"}"
] | rewinds to first line | [
"rewinds",
"to",
"first",
"line"
] | 99b0dace5fcf71584d1456b4b5408017b896bdf5 | https://github.com/stubbles/stubbles-streams/blob/99b0dace5fcf71584d1456b4b5408017b896bdf5/src/main/php/InputStreamIterator.php#L88-L98 | train |
shampeak/GraceServer | src/Log/Log.php | Log.addDebug | public function addDebug($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::DEBUG, $message, $context);
} | php | public function addDebug($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::DEBUG, $message, $context);
} | [
"public",
"function",
"addDebug",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_instance",
"->",
"addRecord",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"DEBUG",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Adds a log record at the DEBUG level.
@param string $message The log message
@param array $context The log context
@return Boolean Whether the record has been processed | [
"Adds",
"a",
"log",
"record",
"at",
"the",
"DEBUG",
"level",
"."
] | e69891de3daae7d228c803c06213eb248fc88594 | https://github.com/shampeak/GraceServer/blob/e69891de3daae7d228c803c06213eb248fc88594/src/Log/Log.php#L115-L118 | train |
shampeak/GraceServer | src/Log/Log.php | Log.addInfo | public function addInfo($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::INFO, $message, $context);
} | php | public function addInfo($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::INFO, $message, $context);
} | [
"public",
"function",
"addInfo",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_instance",
"->",
"addRecord",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"INFO",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Adds a log record at the INFO level.
@param string $message The log message
@param array $context The log context
@return Boolean Whether the record has been processed | [
"Adds",
"a",
"log",
"record",
"at",
"the",
"INFO",
"level",
"."
] | e69891de3daae7d228c803c06213eb248fc88594 | https://github.com/shampeak/GraceServer/blob/e69891de3daae7d228c803c06213eb248fc88594/src/Log/Log.php#L128-L131 | train |
shampeak/GraceServer | src/Log/Log.php | Log.addNotice | public function addNotice($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::NOTICE, $message, $context);
} | php | public function addNotice($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::NOTICE, $message, $context);
} | [
"public",
"function",
"addNotice",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_instance",
"->",
"addRecord",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"NOTICE",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Adds a log record at the NOTICE level.
@param string $message The log message
@param array $context The log context
@return Boolean Whether the record has been processed | [
"Adds",
"a",
"log",
"record",
"at",
"the",
"NOTICE",
"level",
"."
] | e69891de3daae7d228c803c06213eb248fc88594 | https://github.com/shampeak/GraceServer/blob/e69891de3daae7d228c803c06213eb248fc88594/src/Log/Log.php#L141-L144 | train |
shampeak/GraceServer | src/Log/Log.php | Log.addCritical | public function addCritical($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::CRITICAL, $message, $context);
} | php | public function addCritical($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::CRITICAL, $message, $context);
} | [
"public",
"function",
"addCritical",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_instance",
"->",
"addRecord",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"CRITICAL",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Adds a log record at the CRITICAL level.
@param string $message The log message
@param array $context The log context
@return Boolean Whether the record has been processed | [
"Adds",
"a",
"log",
"record",
"at",
"the",
"CRITICAL",
"level",
"."
] | e69891de3daae7d228c803c06213eb248fc88594 | https://github.com/shampeak/GraceServer/blob/e69891de3daae7d228c803c06213eb248fc88594/src/Log/Log.php#L180-L183 | train |
shampeak/GraceServer | src/Log/Log.php | Log.addAlert | public function addAlert($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::ALERT, $message, $context);
} | php | public function addAlert($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::ALERT, $message, $context);
} | [
"public",
"function",
"addAlert",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_instance",
"->",
"addRecord",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"ALERT",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Adds a log record at the ALERT level.
@param string $message The log message
@param array $context The log context
@return Boolean Whether the record has been processed | [
"Adds",
"a",
"log",
"record",
"at",
"the",
"ALERT",
"level",
"."
] | e69891de3daae7d228c803c06213eb248fc88594 | https://github.com/shampeak/GraceServer/blob/e69891de3daae7d228c803c06213eb248fc88594/src/Log/Log.php#L193-L196 | train |
shampeak/GraceServer | src/Log/Log.php | Log.warn | public function warn($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::WARNING, $message, $context);
} | php | public function warn($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::WARNING, $message, $context);
} | [
"public",
"function",
"warn",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_instance",
"->",
"addRecord",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"WARNING",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Adds a log record at the WARNING level.
This method allows for compatibility with common interfaces.
@param string $message The log message
@param array $context The log context
@return Boolean Whether the record has been processed | [
"Adds",
"a",
"log",
"record",
"at",
"the",
"WARNING",
"level",
"."
] | e69891de3daae7d228c803c06213eb248fc88594 | https://github.com/shampeak/GraceServer/blob/e69891de3daae7d228c803c06213eb248fc88594/src/Log/Log.php#L295-L298 | train |
shampeak/GraceServer | src/Log/Log.php | Log.err | public function err($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::ERROR, $message, $context);
} | php | public function err($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::ERROR, $message, $context);
} | [
"public",
"function",
"err",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_instance",
"->",
"addRecord",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"ERROR",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Adds a log record at the ERROR level.
This method allows for compatibility with common interfaces.
@param string $message The log message
@param array $context The log context
@return Boolean Whether the record has been processed | [
"Adds",
"a",
"log",
"record",
"at",
"the",
"ERROR",
"level",
"."
] | e69891de3daae7d228c803c06213eb248fc88594 | https://github.com/shampeak/GraceServer/blob/e69891de3daae7d228c803c06213eb248fc88594/src/Log/Log.php#L325-L328 | train |
shampeak/GraceServer | src/Log/Log.php | Log.emergency | public function emergency($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::EMERGENCY, $message, $context);
} | php | public function emergency($message, array $context = array())
{
return $this->_instance->addRecord(\Monolog\Logger::EMERGENCY, $message, $context);
} | [
"public",
"function",
"emergency",
"(",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_instance",
"->",
"addRecord",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"EMERGENCY",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] | Adds a log record at the EMERGENCY level.
This method allows for compatibility with common interfaces.
@param string $message The log message
@param array $context The log context
@return Boolean Whether the record has been processed | [
"Adds",
"a",
"log",
"record",
"at",
"the",
"EMERGENCY",
"level",
"."
] | e69891de3daae7d228c803c06213eb248fc88594 | https://github.com/shampeak/GraceServer/blob/e69891de3daae7d228c803c06213eb248fc88594/src/Log/Log.php#L415-L418 | train |
Panigale/laravel5-Points | src/Traits/AddPoint.php | AddPoint.addPointToUser | protected function addPointToUser($number, $beforePoint, $afterPoint)
{
if($this->pointNotIsset())
$point = $this->createPointToUser();
else
$point = Point::where('user_id' ,$this->id)
->where('rule_id' ,$this->ruleId)
->first();
$this->logPoint($point->id, $number, $beforePoint, $afterPoint);
$point->number = $afterPoint;
return $point->save();
} | php | protected function addPointToUser($number, $beforePoint, $afterPoint)
{
if($this->pointNotIsset())
$point = $this->createPointToUser();
else
$point = Point::where('user_id' ,$this->id)
->where('rule_id' ,$this->ruleId)
->first();
$this->logPoint($point->id, $number, $beforePoint, $afterPoint);
$point->number = $afterPoint;
return $point->save();
} | [
"protected",
"function",
"addPointToUser",
"(",
"$",
"number",
",",
"$",
"beforePoint",
",",
"$",
"afterPoint",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pointNotIsset",
"(",
")",
")",
"$",
"point",
"=",
"$",
"this",
"->",
"createPointToUser",
"(",
")",
";",
"else",
"$",
"point",
"=",
"Point",
"::",
"where",
"(",
"'user_id'",
",",
"$",
"this",
"->",
"id",
")",
"->",
"where",
"(",
"'rule_id'",
",",
"$",
"this",
"->",
"ruleId",
")",
"->",
"first",
"(",
")",
";",
"$",
"this",
"->",
"logPoint",
"(",
"$",
"point",
"->",
"id",
",",
"$",
"number",
",",
"$",
"beforePoint",
",",
"$",
"afterPoint",
")",
";",
"$",
"point",
"->",
"number",
"=",
"$",
"afterPoint",
";",
"return",
"$",
"point",
"->",
"save",
"(",
")",
";",
"}"
] | update user point
@param int $ruleId
@param $number
@param $beforePoint
@param $afterPoint
@return mixed | [
"update",
"user",
"point"
] | 6fb559d91694a336f5a11d8408348a85395b4ff3 | https://github.com/Panigale/laravel5-Points/blob/6fb559d91694a336f5a11d8408348a85395b4ff3/src/Traits/AddPoint.php#L49-L62 | train |
Panigale/laravel5-Points | src/Traits/AddPoint.php | AddPoint.createPointToUser | private function createPointToUser($number = null)
{
return Point::create([
'user_id' => $this->id,
'rule_id' => $this->ruleId,
'number' => $number
]);
} | php | private function createPointToUser($number = null)
{
return Point::create([
'user_id' => $this->id,
'rule_id' => $this->ruleId,
'number' => $number
]);
} | [
"private",
"function",
"createPointToUser",
"(",
"$",
"number",
"=",
"null",
")",
"{",
"return",
"Point",
"::",
"create",
"(",
"[",
"'user_id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'rule_id'",
"=>",
"$",
"this",
"->",
"ruleId",
",",
"'number'",
"=>",
"$",
"number",
"]",
")",
";",
"}"
] | create point to user
@param null $number | [
"create",
"point",
"to",
"user"
] | 6fb559d91694a336f5a11d8408348a85395b4ff3 | https://github.com/Panigale/laravel5-Points/blob/6fb559d91694a336f5a11d8408348a85395b4ff3/src/Traits/AddPoint.php#L69-L76 | train |
N0rthernL1ghts/Command | src/Exec.php | Exec.command | public static function command(string $command, bool $passThrough = false): CommandResultInterface
{
return new CommandResult(
new static(
$command,
$passThrough
)
);
} | php | public static function command(string $command, bool $passThrough = false): CommandResultInterface
{
return new CommandResult(
new static(
$command,
$passThrough
)
);
} | [
"public",
"static",
"function",
"command",
"(",
"string",
"$",
"command",
",",
"bool",
"$",
"passThrough",
"=",
"false",
")",
":",
"CommandResultInterface",
"{",
"return",
"new",
"CommandResult",
"(",
"new",
"static",
"(",
"$",
"command",
",",
"$",
"passThrough",
")",
")",
";",
"}"
] | Creates new instance of self, and passes it to new instance of CommandResult
@param string $command
@param bool $passThrough
@return CommandResultInterface | [
"Creates",
"new",
"instance",
"of",
"self",
"and",
"passes",
"it",
"to",
"new",
"instance",
"of",
"CommandResult"
] | 52877330a1b150f2e410d1ef6eff8f404da01481 | https://github.com/N0rthernL1ghts/Command/blob/52877330a1b150f2e410d1ef6eff8f404da01481/src/Exec.php#L50-L58 | train |
romm/configuration_object | Classes/TypeConverter/ArrayConverter.php | ArrayConverter.convertFrom | public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
{
$result = [];
$array = ('array' === $targetType)
? $source
: $convertedChildProperties;
foreach ($array as $name => $subProperty) {
$result[$name] = $subProperty;
if (is_object($subProperty)
&& in_array(StoreArrayIndexTrait::class, class_uses($subProperty))
) {
/** @var StoreArrayIndexTrait $subProperty */
$subProperty->setArrayIndex($name);
}
}
return $result;
} | php | public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
{
$result = [];
$array = ('array' === $targetType)
? $source
: $convertedChildProperties;
foreach ($array as $name => $subProperty) {
$result[$name] = $subProperty;
if (is_object($subProperty)
&& in_array(StoreArrayIndexTrait::class, class_uses($subProperty))
) {
/** @var StoreArrayIndexTrait $subProperty */
$subProperty->setArrayIndex($name);
}
}
return $result;
} | [
"public",
"function",
"convertFrom",
"(",
"$",
"source",
",",
"$",
"targetType",
",",
"array",
"$",
"convertedChildProperties",
"=",
"[",
"]",
",",
"PropertyMappingConfigurationInterface",
"$",
"configuration",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"array",
"=",
"(",
"'array'",
"===",
"$",
"targetType",
")",
"?",
"$",
"source",
":",
"$",
"convertedChildProperties",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"name",
"=>",
"$",
"subProperty",
")",
"{",
"$",
"result",
"[",
"$",
"name",
"]",
"=",
"$",
"subProperty",
";",
"if",
"(",
"is_object",
"(",
"$",
"subProperty",
")",
"&&",
"in_array",
"(",
"StoreArrayIndexTrait",
"::",
"class",
",",
"class_uses",
"(",
"$",
"subProperty",
")",
")",
")",
"{",
"/** @var StoreArrayIndexTrait $subProperty */",
"$",
"subProperty",
"->",
"setArrayIndex",
"(",
"$",
"name",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Converts into an array, leaving child properties types.
@inheritdoc | [
"Converts",
"into",
"an",
"array",
"leaving",
"child",
"properties",
"types",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/TypeConverter/ArrayConverter.php#L49-L68 | train |
devlabmtl/haven-cms | Controller/LayoutController.php | LayoutController.showAction | public function showAction($id, $extra) {
$entity = $this->container->get("layout.read_handler")->get($id);
$delete_form = $this->container->get("layout.form_handler")->createDeleteForm($id);
// $route_collection = $this->container->get('router')->getRouteCollection()->all();
// echo '<pre>';
// if(is_object($route_collection))
// print_r(get_class_methods($route_collection));
// print_r($route_collection);
//
// echo '</pre>';
$layout = str_replace(":show.html.twig", ":display.html.twig", $this->container->get("request")->get('_layout'));
$params = array(
"entity" => $entity
, "extra" => $extra
);
return new Response($this->container->get('templating')->render($layout, $params));
} | php | public function showAction($id, $extra) {
$entity = $this->container->get("layout.read_handler")->get($id);
$delete_form = $this->container->get("layout.form_handler")->createDeleteForm($id);
// $route_collection = $this->container->get('router')->getRouteCollection()->all();
// echo '<pre>';
// if(is_object($route_collection))
// print_r(get_class_methods($route_collection));
// print_r($route_collection);
//
// echo '</pre>';
$layout = str_replace(":show.html.twig", ":display.html.twig", $this->container->get("request")->get('_layout'));
$params = array(
"entity" => $entity
, "extra" => $extra
);
return new Response($this->container->get('templating')->render($layout, $params));
} | [
"public",
"function",
"showAction",
"(",
"$",
"id",
",",
"$",
"extra",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"\"layout.read_handler\"",
")",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"delete_form",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"\"layout.form_handler\"",
")",
"->",
"createDeleteForm",
"(",
"$",
"id",
")",
";",
"// $route_collection = $this->container->get('router')->getRouteCollection()->all();",
"// echo '<pre>';",
"// if(is_object($route_collection))",
"// print_r(get_class_methods($route_collection));",
"// print_r($route_collection);",
"// ",
"// echo '</pre>';",
"$",
"layout",
"=",
"str_replace",
"(",
"\":show.html.twig\"",
",",
"\":display.html.twig\"",
",",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"\"request\"",
")",
"->",
"get",
"(",
"'_layout'",
")",
")",
";",
"$",
"params",
"=",
"array",
"(",
"\"entity\"",
"=>",
"$",
"entity",
",",
"\"extra\"",
"=>",
"$",
"extra",
")",
";",
"return",
"new",
"Response",
"(",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'templating'",
")",
"->",
"render",
"(",
"$",
"layout",
",",
"$",
"params",
")",
")",
";",
"}"
] | Finds and displays a layout entity.
@Route("/admin/{show}/layout/{id}/{extra}", requirements={"id" = "\d+", "extra" = ".+"}, defaults={"extra" = ""})
@Method("GET")
@Template() | [
"Finds",
"and",
"displays",
"a",
"layout",
"entity",
"."
] | c20761a07c201a966dbda1f3eae33617f80e1ece | https://github.com/devlabmtl/haven-cms/blob/c20761a07c201a966dbda1f3eae33617f80e1ece/Controller/LayoutController.php#L67-L88 | train |
martinlindhe/php-debughelper | src/HexPrinter.php | HexPrinter.render | public static function render($m, $rowLength = 16, $fillChar = ' ', $showOffset = true)
{
$res = '';
$rowOffset = 0;
$bytes = '';
$hex = '';
$j = 0;
for ($i = 0; $i < strlen($m); $i++) {
$x = substr($m, $i, 1);
$bytes .= self::decodeReadable($x);
$hex .= bin2hex($x).$fillChar;
if (++$j == $rowLength) {
$res .=
($showOffset ? sprintf("%06x", $rowOffset).": " : '')
.$hex.' '.$bytes.PHP_EOL;
$rowOffset += $rowLength;
$bytes = '';
$hex = '';
$j = 0;
}
}
if ($j) {
$res .=
($showOffset ? sprintf("%06x", $rowOffset).": " : '')
.$hex.' '
.str_repeat(' ', ($rowLength - strlen($bytes)) * 3)
.$bytes.PHP_EOL;
}
return $res;
} | php | public static function render($m, $rowLength = 16, $fillChar = ' ', $showOffset = true)
{
$res = '';
$rowOffset = 0;
$bytes = '';
$hex = '';
$j = 0;
for ($i = 0; $i < strlen($m); $i++) {
$x = substr($m, $i, 1);
$bytes .= self::decodeReadable($x);
$hex .= bin2hex($x).$fillChar;
if (++$j == $rowLength) {
$res .=
($showOffset ? sprintf("%06x", $rowOffset).": " : '')
.$hex.' '.$bytes.PHP_EOL;
$rowOffset += $rowLength;
$bytes = '';
$hex = '';
$j = 0;
}
}
if ($j) {
$res .=
($showOffset ? sprintf("%06x", $rowOffset).": " : '')
.$hex.' '
.str_repeat(' ', ($rowLength - strlen($bytes)) * 3)
.$bytes.PHP_EOL;
}
return $res;
} | [
"public",
"static",
"function",
"render",
"(",
"$",
"m",
",",
"$",
"rowLength",
"=",
"16",
",",
"$",
"fillChar",
"=",
"' '",
",",
"$",
"showOffset",
"=",
"true",
")",
"{",
"$",
"res",
"=",
"''",
";",
"$",
"rowOffset",
"=",
"0",
";",
"$",
"bytes",
"=",
"''",
";",
"$",
"hex",
"=",
"''",
";",
"$",
"j",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"m",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"x",
"=",
"substr",
"(",
"$",
"m",
",",
"$",
"i",
",",
"1",
")",
";",
"$",
"bytes",
".=",
"self",
"::",
"decodeReadable",
"(",
"$",
"x",
")",
";",
"$",
"hex",
".=",
"bin2hex",
"(",
"$",
"x",
")",
".",
"$",
"fillChar",
";",
"if",
"(",
"++",
"$",
"j",
"==",
"$",
"rowLength",
")",
"{",
"$",
"res",
".=",
"(",
"$",
"showOffset",
"?",
"sprintf",
"(",
"\"%06x\"",
",",
"$",
"rowOffset",
")",
".",
"\": \"",
":",
"''",
")",
".",
"$",
"hex",
".",
"' '",
".",
"$",
"bytes",
".",
"PHP_EOL",
";",
"$",
"rowOffset",
"+=",
"$",
"rowLength",
";",
"$",
"bytes",
"=",
"''",
";",
"$",
"hex",
"=",
"''",
";",
"$",
"j",
"=",
"0",
";",
"}",
"}",
"if",
"(",
"$",
"j",
")",
"{",
"$",
"res",
".=",
"(",
"$",
"showOffset",
"?",
"sprintf",
"(",
"\"%06x\"",
",",
"$",
"rowOffset",
")",
".",
"\": \"",
":",
"''",
")",
".",
"$",
"hex",
".",
"' '",
".",
"str_repeat",
"(",
"' '",
",",
"(",
"$",
"rowLength",
"-",
"strlen",
"(",
"$",
"bytes",
")",
")",
"*",
"3",
")",
".",
"$",
"bytes",
".",
"PHP_EOL",
";",
"}",
"return",
"$",
"res",
";",
"}"
] | Prints hex dump of a binary string, similar to xxd
@param string $m
@param int $rowLength
@param string $fillChar
@param bool $showOffset
@return string of hex + ascii values | [
"Prints",
"hex",
"dump",
"of",
"a",
"binary",
"string",
"similar",
"to",
"xxd"
] | 8fde5bbfd77d71f3f0990829f235242232094734 | https://github.com/martinlindhe/php-debughelper/blob/8fde5bbfd77d71f3f0990829f235242232094734/src/HexPrinter.php#L13-L49 | train |
danielgp/common-lib | source/DomHeaderFooterByDanielGP.php | DomHeaderFooterByDanielGP.setFooterCommon | protected function setFooterCommon($footerInjected = null)
{
$sHK = $this->tCmnSuperGlobals->get('specialHook');
if (!is_null($sHK) && (in_array('noHeader', $sHK))) {
return '';
}
return $this->setFooterCommonInjected($footerInjected) . '</body></html>';
} | php | protected function setFooterCommon($footerInjected = null)
{
$sHK = $this->tCmnSuperGlobals->get('specialHook');
if (!is_null($sHK) && (in_array('noHeader', $sHK))) {
return '';
}
return $this->setFooterCommonInjected($footerInjected) . '</body></html>';
} | [
"protected",
"function",
"setFooterCommon",
"(",
"$",
"footerInjected",
"=",
"null",
")",
"{",
"$",
"sHK",
"=",
"$",
"this",
"->",
"tCmnSuperGlobals",
"->",
"get",
"(",
"'specialHook'",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"sHK",
")",
"&&",
"(",
"in_array",
"(",
"'noHeader'",
",",
"$",
"sHK",
")",
")",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"this",
"->",
"setFooterCommonInjected",
"(",
"$",
"footerInjected",
")",
".",
"'</body></html>'",
";",
"}"
] | Outputs an HTML footer
@param array $footerInjected
@return string | [
"Outputs",
"an",
"HTML",
"footer"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomHeaderFooterByDanielGP.php#L76-L83 | train |
danielgp/common-lib | source/DomHeaderFooterByDanielGP.php | DomHeaderFooterByDanielGP.setHeaderCommon | protected function setHeaderCommon($headerFeatures = [])
{
$sReturn = [];
$this->initializeSprGlbAndSession();
$sHK = $this->tCmnSuperGlobals->get('specialHook');
if (!is_null($sHK) && (in_array('noHeader', $sHK))) {
return ''; // no Header
}
$fixedHeaderElements = [
'start' => '<!DOCTYPE html>',
'lang' => $this->setHeaderLanguage($headerFeatures),
'head' => '<head>',
'charset' => '<meta charset="utf-8" />',
'viewport' => '<meta name="viewport" content="width=device-width height=device-height initial-scale=1" />',
];
if ($headerFeatures !== []) {
$aFeatures = [];
foreach ($headerFeatures as $key => $value) {
$aFeatures[] = $this->setHeaderFeatures($key, $value);
}
return implode('', $fixedHeaderElements) . implode('', $aFeatures) . '</head>' . '<body>';
}
$sReturn[] = implode('', $fixedHeaderElements) . '</head>' . '<body>'
. '<p style="background-color:red;color:#FFF;">The parameter sent to '
. __FUNCTION__ . ' must be a non-empty array</p>' . $this->setFooterCommon();
throw new \Exception(implode('', $sReturn));
} | php | protected function setHeaderCommon($headerFeatures = [])
{
$sReturn = [];
$this->initializeSprGlbAndSession();
$sHK = $this->tCmnSuperGlobals->get('specialHook');
if (!is_null($sHK) && (in_array('noHeader', $sHK))) {
return ''; // no Header
}
$fixedHeaderElements = [
'start' => '<!DOCTYPE html>',
'lang' => $this->setHeaderLanguage($headerFeatures),
'head' => '<head>',
'charset' => '<meta charset="utf-8" />',
'viewport' => '<meta name="viewport" content="width=device-width height=device-height initial-scale=1" />',
];
if ($headerFeatures !== []) {
$aFeatures = [];
foreach ($headerFeatures as $key => $value) {
$aFeatures[] = $this->setHeaderFeatures($key, $value);
}
return implode('', $fixedHeaderElements) . implode('', $aFeatures) . '</head>' . '<body>';
}
$sReturn[] = implode('', $fixedHeaderElements) . '</head>' . '<body>'
. '<p style="background-color:red;color:#FFF;">The parameter sent to '
. __FUNCTION__ . ' must be a non-empty array</p>' . $this->setFooterCommon();
throw new \Exception(implode('', $sReturn));
} | [
"protected",
"function",
"setHeaderCommon",
"(",
"$",
"headerFeatures",
"=",
"[",
"]",
")",
"{",
"$",
"sReturn",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"initializeSprGlbAndSession",
"(",
")",
";",
"$",
"sHK",
"=",
"$",
"this",
"->",
"tCmnSuperGlobals",
"->",
"get",
"(",
"'specialHook'",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"sHK",
")",
"&&",
"(",
"in_array",
"(",
"'noHeader'",
",",
"$",
"sHK",
")",
")",
")",
"{",
"return",
"''",
";",
"// no Header",
"}",
"$",
"fixedHeaderElements",
"=",
"[",
"'start'",
"=>",
"'<!DOCTYPE html>'",
",",
"'lang'",
"=>",
"$",
"this",
"->",
"setHeaderLanguage",
"(",
"$",
"headerFeatures",
")",
",",
"'head'",
"=>",
"'<head>'",
",",
"'charset'",
"=>",
"'<meta charset=\"utf-8\" />'",
",",
"'viewport'",
"=>",
"'<meta name=\"viewport\" content=\"width=device-width height=device-height initial-scale=1\" />'",
",",
"]",
";",
"if",
"(",
"$",
"headerFeatures",
"!==",
"[",
"]",
")",
"{",
"$",
"aFeatures",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"headerFeatures",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"aFeatures",
"[",
"]",
"=",
"$",
"this",
"->",
"setHeaderFeatures",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"fixedHeaderElements",
")",
".",
"implode",
"(",
"''",
",",
"$",
"aFeatures",
")",
".",
"'</head>'",
".",
"'<body>'",
";",
"}",
"$",
"sReturn",
"[",
"]",
"=",
"implode",
"(",
"''",
",",
"$",
"fixedHeaderElements",
")",
".",
"'</head>'",
".",
"'<body>'",
".",
"'<p style=\"background-color:red;color:#FFF;\">The parameter sent to '",
".",
"__FUNCTION__",
".",
"' must be a non-empty array</p>'",
".",
"$",
"this",
"->",
"setFooterCommon",
"(",
")",
";",
"throw",
"new",
"\\",
"Exception",
"(",
"implode",
"(",
"''",
",",
"$",
"sReturn",
")",
")",
";",
"}"
] | Outputs an HTML header
@param array $headerFeatures
@return string | [
"Outputs",
"an",
"HTML",
"header"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/DomHeaderFooterByDanielGP.php#L103-L129 | train |
AmericanCouncils/MediaInfoBundle | MediaInfo.php | MediaInfo.scan | public function scan($filepath)
{
$proc = new Process(sprintf('%s %s --Output=XML --Full', $this->path, $filepath));
$proc->run();
if (!$proc->isSuccessful()) {
throw new \RuntimeException($proc->getErrorOutput());
}
$result = $proc->getOutput();
//parse structure to turn into raw php array
$xml = simplexml_load_string($result);
$data = array();
$data['version'] = (string) $xml['version'];
foreach ($xml->File->track as $track) {
$trackType = strtolower($track['type']);
$trackId = isset($track['streamid']) ? $track['streamid'] : 1;
$trackId = (string)$trackId;
$trackData = [];
foreach ($track as $rawKey => $rawVal) {
$key = strtolower($rawKey);
$val = (string)$rawVal;
# This sometimes doesn't match streamid, so let's ignore it
if ($key == 'stream_identifier') { continue; }
if (!array_key_exists($key, $trackData)) {
$trackData[$key] = array($val);
} elseif (!in_array($val, $trackData[$key])) {
$trackData[$key][] = $val;
}
}
if ($trackType == 'general') {
$data['file']['general'] = $trackData;
} else {
$data['file'][$trackType][$trackId] = $trackData;
}
}
return $data;
} | php | public function scan($filepath)
{
$proc = new Process(sprintf('%s %s --Output=XML --Full', $this->path, $filepath));
$proc->run();
if (!$proc->isSuccessful()) {
throw new \RuntimeException($proc->getErrorOutput());
}
$result = $proc->getOutput();
//parse structure to turn into raw php array
$xml = simplexml_load_string($result);
$data = array();
$data['version'] = (string) $xml['version'];
foreach ($xml->File->track as $track) {
$trackType = strtolower($track['type']);
$trackId = isset($track['streamid']) ? $track['streamid'] : 1;
$trackId = (string)$trackId;
$trackData = [];
foreach ($track as $rawKey => $rawVal) {
$key = strtolower($rawKey);
$val = (string)$rawVal;
# This sometimes doesn't match streamid, so let's ignore it
if ($key == 'stream_identifier') { continue; }
if (!array_key_exists($key, $trackData)) {
$trackData[$key] = array($val);
} elseif (!in_array($val, $trackData[$key])) {
$trackData[$key][] = $val;
}
}
if ($trackType == 'general') {
$data['file']['general'] = $trackData;
} else {
$data['file'][$trackType][$trackId] = $trackData;
}
}
return $data;
} | [
"public",
"function",
"scan",
"(",
"$",
"filepath",
")",
"{",
"$",
"proc",
"=",
"new",
"Process",
"(",
"sprintf",
"(",
"'%s %s --Output=XML --Full'",
",",
"$",
"this",
"->",
"path",
",",
"$",
"filepath",
")",
")",
";",
"$",
"proc",
"->",
"run",
"(",
")",
";",
"if",
"(",
"!",
"$",
"proc",
"->",
"isSuccessful",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"$",
"proc",
"->",
"getErrorOutput",
"(",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"proc",
"->",
"getOutput",
"(",
")",
";",
"//parse structure to turn into raw php array",
"$",
"xml",
"=",
"simplexml_load_string",
"(",
"$",
"result",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"data",
"[",
"'version'",
"]",
"=",
"(",
"string",
")",
"$",
"xml",
"[",
"'version'",
"]",
";",
"foreach",
"(",
"$",
"xml",
"->",
"File",
"->",
"track",
"as",
"$",
"track",
")",
"{",
"$",
"trackType",
"=",
"strtolower",
"(",
"$",
"track",
"[",
"'type'",
"]",
")",
";",
"$",
"trackId",
"=",
"isset",
"(",
"$",
"track",
"[",
"'streamid'",
"]",
")",
"?",
"$",
"track",
"[",
"'streamid'",
"]",
":",
"1",
";",
"$",
"trackId",
"=",
"(",
"string",
")",
"$",
"trackId",
";",
"$",
"trackData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"track",
"as",
"$",
"rawKey",
"=>",
"$",
"rawVal",
")",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"rawKey",
")",
";",
"$",
"val",
"=",
"(",
"string",
")",
"$",
"rawVal",
";",
"# This sometimes doesn't match streamid, so let's ignore it",
"if",
"(",
"$",
"key",
"==",
"'stream_identifier'",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"trackData",
")",
")",
"{",
"$",
"trackData",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"$",
"val",
")",
";",
"}",
"elseif",
"(",
"!",
"in_array",
"(",
"$",
"val",
",",
"$",
"trackData",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"trackData",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"if",
"(",
"$",
"trackType",
"==",
"'general'",
")",
"{",
"$",
"data",
"[",
"'file'",
"]",
"[",
"'general'",
"]",
"=",
"$",
"trackData",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'file'",
"]",
"[",
"$",
"trackType",
"]",
"[",
"$",
"trackId",
"]",
"=",
"$",
"trackData",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Scans a file to return any structured metadata.
@param string $filepath Path to file to analyze
@return array | [
"Scans",
"a",
"file",
"to",
"return",
"any",
"structured",
"metadata",
"."
] | c1a37134c3e1c56282c115abfd53caaea7c97201 | https://github.com/AmericanCouncils/MediaInfoBundle/blob/c1a37134c3e1c56282c115abfd53caaea7c97201/MediaInfo.php#L33-L77 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/URLUtils.php | URLUtils.fullUrl | public static function fullUrl()
{
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = StringUtils::strLeft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80" || $_SERVER["SERVER_PORT"] == "443") ? "" : (":".$_SERVER["SERVER_PORT"]);
$uri = (isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:"");
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$uri;
} | php | public static function fullUrl()
{
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = StringUtils::strLeft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80" || $_SERVER["SERVER_PORT"] == "443") ? "" : (":".$_SERVER["SERVER_PORT"]);
$uri = (isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:"");
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$uri;
} | [
"public",
"static",
"function",
"fullUrl",
"(",
")",
"{",
"$",
"s",
"=",
"empty",
"(",
"$",
"_SERVER",
"[",
"\"HTTPS\"",
"]",
")",
"?",
"''",
":",
"(",
"$",
"_SERVER",
"[",
"\"HTTPS\"",
"]",
"==",
"\"on\"",
")",
"?",
"\"s\"",
":",
"\"\"",
";",
"$",
"protocol",
"=",
"StringUtils",
"::",
"strLeft",
"(",
"strtolower",
"(",
"$",
"_SERVER",
"[",
"\"SERVER_PROTOCOL\"",
"]",
")",
",",
"\"/\"",
")",
".",
"$",
"s",
";",
"$",
"port",
"=",
"(",
"$",
"_SERVER",
"[",
"\"SERVER_PORT\"",
"]",
"==",
"\"80\"",
"||",
"$",
"_SERVER",
"[",
"\"SERVER_PORT\"",
"]",
"==",
"\"443\"",
")",
"?",
"\"\"",
":",
"(",
"\":\"",
".",
"$",
"_SERVER",
"[",
"\"SERVER_PORT\"",
"]",
")",
";",
"$",
"uri",
"=",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
":",
"\"\"",
")",
";",
"return",
"$",
"protocol",
".",
"\"://\"",
".",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
".",
"$",
"port",
".",
"$",
"uri",
";",
"}"
] | Returns the current, full url
@return string the current url | [
"Returns",
"the",
"current",
"full",
"url"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/URLUtils.php#L328-L335 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/URLUtils.php | URLUtils.safeUrl | public static function safeUrl($url)
{
// Strip invalid characters (anything but [a-zA-Z0-9=?&:;#_\/.-])
// $url = preg_replace("/[^a-zA-Z0-9=?&:;#_\/.-]/", '', $url);
if (empty($url))
return '';
// Prepend http:// if no scheme is specified
if (!preg_match("/^(https?):\/\//", $url))
$url = 'http://' . $url;
if (!self::isURL($url))
$url = '';
return filter_var($url, FILTER_SANITIZE_URL);
} | php | public static function safeUrl($url)
{
// Strip invalid characters (anything but [a-zA-Z0-9=?&:;#_\/.-])
// $url = preg_replace("/[^a-zA-Z0-9=?&:;#_\/.-]/", '', $url);
if (empty($url))
return '';
// Prepend http:// if no scheme is specified
if (!preg_match("/^(https?):\/\//", $url))
$url = 'http://' . $url;
if (!self::isURL($url))
$url = '';
return filter_var($url, FILTER_SANITIZE_URL);
} | [
"public",
"static",
"function",
"safeUrl",
"(",
"$",
"url",
")",
"{",
"// Strip invalid characters (anything but [a-zA-Z0-9=?&:;#_\\/.-])",
"// $url = preg_replace(\"/[^a-zA-Z0-9=?&:;#_\\/.-]/\", '', $url);",
"if",
"(",
"empty",
"(",
"$",
"url",
")",
")",
"return",
"''",
";",
"// Prepend http:// if no scheme is specified",
"if",
"(",
"!",
"preg_match",
"(",
"\"/^(https?):\\/\\//\"",
",",
"$",
"url",
")",
")",
"$",
"url",
"=",
"'http://'",
".",
"$",
"url",
";",
"if",
"(",
"!",
"self",
"::",
"isURL",
"(",
"$",
"url",
")",
")",
"$",
"url",
"=",
"''",
";",
"return",
"filter_var",
"(",
"$",
"url",
",",
"FILTER_SANITIZE_URL",
")",
";",
"}"
] | Outputs a "safe" url, stripped of xss, autolink on domain, and stripped of invalid chars
@param string $url The url to process
@return string Safe and happy URL | [
"Outputs",
"a",
"safe",
"url",
"stripped",
"of",
"xss",
"autolink",
"on",
"domain",
"and",
"stripped",
"of",
"invalid",
"chars"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/URLUtils.php#L393-L410 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/URLUtils.php | URLUtils.resolveContextVariables | public static function resolveContextVariables($value, $object)
{
$value = str_replace(
array('%PATH_BUILD%', '%CONTEXT%', '%REWRITE_BASE%', '%SERVER_NAME%', '%DEVICE_VIEW%', '%DESIGN%', '%DOMAIN%', '%DOMAIN_BASE_URI%', '%DEPLOYMENT_BASE_PATH%'),
array(PATH_BUILD, ($object instanceof ContextObject?$object->Slug:$_SERVER['CONTEXT']), $_SERVER['REWRITE_BASE'], $_SERVER['SERVER_NAME'], $_SERVER['DEVICE_VIEW'], $_SERVER['DESIGN'], $object->Domain, $object->DomainBaseURI, isset($object->DeploymentBasePath)?$object->DeploymentBasePath:''),
$value
);
$value = preg_replace("/\/[\/]+/", "/", $value);
return $value;
} | php | public static function resolveContextVariables($value, $object)
{
$value = str_replace(
array('%PATH_BUILD%', '%CONTEXT%', '%REWRITE_BASE%', '%SERVER_NAME%', '%DEVICE_VIEW%', '%DESIGN%', '%DOMAIN%', '%DOMAIN_BASE_URI%', '%DEPLOYMENT_BASE_PATH%'),
array(PATH_BUILD, ($object instanceof ContextObject?$object->Slug:$_SERVER['CONTEXT']), $_SERVER['REWRITE_BASE'], $_SERVER['SERVER_NAME'], $_SERVER['DEVICE_VIEW'], $_SERVER['DESIGN'], $object->Domain, $object->DomainBaseURI, isset($object->DeploymentBasePath)?$object->DeploymentBasePath:''),
$value
);
$value = preg_replace("/\/[\/]+/", "/", $value);
return $value;
} | [
"public",
"static",
"function",
"resolveContextVariables",
"(",
"$",
"value",
",",
"$",
"object",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"array",
"(",
"'%PATH_BUILD%'",
",",
"'%CONTEXT%'",
",",
"'%REWRITE_BASE%'",
",",
"'%SERVER_NAME%'",
",",
"'%DEVICE_VIEW%'",
",",
"'%DESIGN%'",
",",
"'%DOMAIN%'",
",",
"'%DOMAIN_BASE_URI%'",
",",
"'%DEPLOYMENT_BASE_PATH%'",
")",
",",
"array",
"(",
"PATH_BUILD",
",",
"(",
"$",
"object",
"instanceof",
"ContextObject",
"?",
"$",
"object",
"->",
"Slug",
":",
"$",
"_SERVER",
"[",
"'CONTEXT'",
"]",
")",
",",
"$",
"_SERVER",
"[",
"'REWRITE_BASE'",
"]",
",",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
",",
"$",
"_SERVER",
"[",
"'DEVICE_VIEW'",
"]",
",",
"$",
"_SERVER",
"[",
"'DESIGN'",
"]",
",",
"$",
"object",
"->",
"Domain",
",",
"$",
"object",
"->",
"DomainBaseURI",
",",
"isset",
"(",
"$",
"object",
"->",
"DeploymentBasePath",
")",
"?",
"$",
"object",
"->",
"DeploymentBasePath",
":",
"''",
")",
",",
"$",
"value",
")",
";",
"$",
"value",
"=",
"preg_replace",
"(",
"\"/\\/[\\/]+/\"",
",",
"\"/\"",
",",
"$",
"value",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Replace variables inside a value using the object as an originating reference
@static
@param $value
@param $object
@return mixed | [
"Replace",
"variables",
"inside",
"a",
"value",
"using",
"the",
"object",
"as",
"an",
"originating",
"reference"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/URLUtils.php#L579-L591 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/URLUtils.php | URLUtils.resolveSiteFromArray | public static function resolveSiteFromArray($siteArray, $useDomainAlias = false)
{
$site = new Site();
return self::resolveSiteContextObject($site, $siteArray, $useDomainAlias);
} | php | public static function resolveSiteFromArray($siteArray, $useDomainAlias = false)
{
$site = new Site();
return self::resolveSiteContextObject($site, $siteArray, $useDomainAlias);
} | [
"public",
"static",
"function",
"resolveSiteFromArray",
"(",
"$",
"siteArray",
",",
"$",
"useDomainAlias",
"=",
"false",
")",
"{",
"$",
"site",
"=",
"new",
"Site",
"(",
")",
";",
"return",
"self",
"::",
"resolveSiteContextObject",
"(",
"$",
"site",
",",
"$",
"siteArray",
",",
"$",
"useDomainAlias",
")",
";",
"}"
] | Creates a Site object from an array originating from the environments.xml
@static
@param $siteArray
@param bool $useDomainAlias
@return | [
"Creates",
"a",
"Site",
"object",
"from",
"an",
"array",
"originating",
"from",
"the",
"environments",
".",
"xml"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/URLUtils.php#L601-L607 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/URLUtils.php | URLUtils.resolveContextFromArray | public static function resolveContextFromArray($contextArray, $useDomainAlias = false)
{
$context = new ContextObject();
return self::resolveSiteContextObject($context, $contextArray, $useDomainAlias);
} | php | public static function resolveContextFromArray($contextArray, $useDomainAlias = false)
{
$context = new ContextObject();
return self::resolveSiteContextObject($context, $contextArray, $useDomainAlias);
} | [
"public",
"static",
"function",
"resolveContextFromArray",
"(",
"$",
"contextArray",
",",
"$",
"useDomainAlias",
"=",
"false",
")",
"{",
"$",
"context",
"=",
"new",
"ContextObject",
"(",
")",
";",
"return",
"self",
"::",
"resolveSiteContextObject",
"(",
"$",
"context",
",",
"$",
"contextArray",
",",
"$",
"useDomainAlias",
")",
";",
"}"
] | Creates a ContextObject object from an array originating from the environments.xml
@static
@param $contextArray
@param bool $useDomainAlias
@return | [
"Creates",
"a",
"ContextObject",
"object",
"from",
"an",
"array",
"originating",
"from",
"the",
"environments",
".",
"xml"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/URLUtils.php#L617-L622 | train |
pluf/collection | src/Collection/Views/Document.php | Collection_Views_Document.create | public function create ($request, $match, $p)
{
// check collection
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
$request->REQUEST['collection'] = $collectionId;
} else {
$collectionId = $request->REQUEST['collection'];
}
Pluf_Shortcuts_GetObjectOr404('Collection_Collection', $collectionId);
// create document
$object = new Collection_Document();
$form = Pluf_Shortcuts_GetFormForModel($object, $request->REQUEST, array());
$object = $form->save();
$this->putDocumentMap($object, $request->REQUEST);
return new Pluf_HTTP_Response_Json($this->getDocumentMap($object));
} | php | public function create ($request, $match, $p)
{
// check collection
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
$request->REQUEST['collection'] = $collectionId;
} else {
$collectionId = $request->REQUEST['collection'];
}
Pluf_Shortcuts_GetObjectOr404('Collection_Collection', $collectionId);
// create document
$object = new Collection_Document();
$form = Pluf_Shortcuts_GetFormForModel($object, $request->REQUEST, array());
$object = $form->save();
$this->putDocumentMap($object, $request->REQUEST);
return new Pluf_HTTP_Response_Json($this->getDocumentMap($object));
} | [
"public",
"function",
"create",
"(",
"$",
"request",
",",
"$",
"match",
",",
"$",
"p",
")",
"{",
"// check collection",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'collectionId'",
"]",
")",
")",
"{",
"$",
"collectionId",
"=",
"$",
"match",
"[",
"'collectionId'",
"]",
";",
"$",
"request",
"->",
"REQUEST",
"[",
"'collection'",
"]",
"=",
"$",
"collectionId",
";",
"}",
"else",
"{",
"$",
"collectionId",
"=",
"$",
"request",
"->",
"REQUEST",
"[",
"'collection'",
"]",
";",
"}",
"Pluf_Shortcuts_GetObjectOr404",
"(",
"'Collection_Collection'",
",",
"$",
"collectionId",
")",
";",
"// create document",
"$",
"object",
"=",
"new",
"Collection_Document",
"(",
")",
";",
"$",
"form",
"=",
"Pluf_Shortcuts_GetFormForModel",
"(",
"$",
"object",
",",
"$",
"request",
"->",
"REQUEST",
",",
"array",
"(",
")",
")",
";",
"$",
"object",
"=",
"$",
"form",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"putDocumentMap",
"(",
"$",
"object",
",",
"$",
"request",
"->",
"REQUEST",
")",
";",
"return",
"new",
"Pluf_HTTP_Response_Json",
"(",
"$",
"this",
"->",
"getDocumentMap",
"(",
"$",
"object",
")",
")",
";",
"}"
] | Creates new instance of a document
@param Pluf_HTTP_Request $request
@param array $match
@param array $p
@return Pluf_HTTP_Response | [
"Creates",
"new",
"instance",
"of",
"a",
"document"
] | ae229d12e5ec352c66b31d5f89752f91f1342920 | https://github.com/pluf/collection/blob/ae229d12e5ec352c66b31d5f89752f91f1342920/src/Collection/Views/Document.php#L23-L39 | train |
pluf/collection | src/Collection/Views/Document.php | Collection_Views_Document.get | public function get ($request, $match)
{
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
} else {
$collectionId = $request->REQUEST['collectionId'];
}
$collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
$collectionId);
$document = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$match['documentId']);
if ($document->collection !== $collection->id) {
throw new Pluf_Exception_DoesNotExist(
'Document with id (' . $document->id .
') does not exist in collection with id (' .
$collection->id . ')');
}
return new Pluf_HTTP_Response_Json($document);
} | php | public function get ($request, $match)
{
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
} else {
$collectionId = $request->REQUEST['collectionId'];
}
$collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
$collectionId);
$document = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$match['documentId']);
if ($document->collection !== $collection->id) {
throw new Pluf_Exception_DoesNotExist(
'Document with id (' . $document->id .
') does not exist in collection with id (' .
$collection->id . ')');
}
return new Pluf_HTTP_Response_Json($document);
} | [
"public",
"function",
"get",
"(",
"$",
"request",
",",
"$",
"match",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'collectionId'",
"]",
")",
")",
"{",
"$",
"collectionId",
"=",
"$",
"match",
"[",
"'collectionId'",
"]",
";",
"}",
"else",
"{",
"$",
"collectionId",
"=",
"$",
"request",
"->",
"REQUEST",
"[",
"'collectionId'",
"]",
";",
"}",
"$",
"collection",
"=",
"Pluf_Shortcuts_GetObjectOr404",
"(",
"'Collection_Collection'",
",",
"$",
"collectionId",
")",
";",
"$",
"document",
"=",
"Pluf_Shortcuts_GetObjectOr404",
"(",
"'Collection_Document'",
",",
"$",
"match",
"[",
"'documentId'",
"]",
")",
";",
"if",
"(",
"$",
"document",
"->",
"collection",
"!==",
"$",
"collection",
"->",
"id",
")",
"{",
"throw",
"new",
"Pluf_Exception_DoesNotExist",
"(",
"'Document with id ('",
".",
"$",
"document",
"->",
"id",
".",
"') does not exist in collection with id ('",
".",
"$",
"collection",
"->",
"id",
".",
"')'",
")",
";",
"}",
"return",
"new",
"Pluf_HTTP_Response_Json",
"(",
"$",
"document",
")",
";",
"}"
] | Gets a document
@param Pluf_HTTP_Request $request
@param array $match
@throws Pluf_Exception_DoesNotExist
@return Pluf_HTTP_Response_Json | [
"Gets",
"a",
"document"
] | ae229d12e5ec352c66b31d5f89752f91f1342920 | https://github.com/pluf/collection/blob/ae229d12e5ec352c66b31d5f89752f91f1342920/src/Collection/Views/Document.php#L49-L67 | train |
pluf/collection | src/Collection/Views/Document.php | Collection_Views_Document.find | public function find ($request, $match)
{
// check for collection
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
} elseif (isset($request->REQUEST['collectionId'])) {
$collectionId = $request->REQUEST['collectionId'];
}
$document = new Collection_Document();
$paginator = new Pluf_Paginator($document);
if (isset($collectionId)) {
$sql = new Pluf_SQL('collection=%s',
array(
$collectionId
));
$paginator->forced_where = $sql;
}
$paginator->list_filters = array(
'id'
);
$search_fields = array(
'id'
);
$sort_fields = array(
'id',
'collection'
);
$paginator->configure(array(), $search_fields, $sort_fields);
$paginator->items_per_page = Collection_Shortcuts_NormalizeItemPerPage(
$request);
$paginator->setFromRequest($request);
$docs = $paginator->render_object();
// TODO: maso, 2017: pass list of attributes
foreach ($docs['items'] as $key => $value) {
$docs['items'][$key] = $this->getDocumentMap($value);
}
return new Pluf_HTTP_Response_Json($docs);
} | php | public function find ($request, $match)
{
// check for collection
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
} elseif (isset($request->REQUEST['collectionId'])) {
$collectionId = $request->REQUEST['collectionId'];
}
$document = new Collection_Document();
$paginator = new Pluf_Paginator($document);
if (isset($collectionId)) {
$sql = new Pluf_SQL('collection=%s',
array(
$collectionId
));
$paginator->forced_where = $sql;
}
$paginator->list_filters = array(
'id'
);
$search_fields = array(
'id'
);
$sort_fields = array(
'id',
'collection'
);
$paginator->configure(array(), $search_fields, $sort_fields);
$paginator->items_per_page = Collection_Shortcuts_NormalizeItemPerPage(
$request);
$paginator->setFromRequest($request);
$docs = $paginator->render_object();
// TODO: maso, 2017: pass list of attributes
foreach ($docs['items'] as $key => $value) {
$docs['items'][$key] = $this->getDocumentMap($value);
}
return new Pluf_HTTP_Response_Json($docs);
} | [
"public",
"function",
"find",
"(",
"$",
"request",
",",
"$",
"match",
")",
"{",
"// check for collection",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'collectionId'",
"]",
")",
")",
"{",
"$",
"collectionId",
"=",
"$",
"match",
"[",
"'collectionId'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"request",
"->",
"REQUEST",
"[",
"'collectionId'",
"]",
")",
")",
"{",
"$",
"collectionId",
"=",
"$",
"request",
"->",
"REQUEST",
"[",
"'collectionId'",
"]",
";",
"}",
"$",
"document",
"=",
"new",
"Collection_Document",
"(",
")",
";",
"$",
"paginator",
"=",
"new",
"Pluf_Paginator",
"(",
"$",
"document",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"collectionId",
")",
")",
"{",
"$",
"sql",
"=",
"new",
"Pluf_SQL",
"(",
"'collection=%s'",
",",
"array",
"(",
"$",
"collectionId",
")",
")",
";",
"$",
"paginator",
"->",
"forced_where",
"=",
"$",
"sql",
";",
"}",
"$",
"paginator",
"->",
"list_filters",
"=",
"array",
"(",
"'id'",
")",
";",
"$",
"search_fields",
"=",
"array",
"(",
"'id'",
")",
";",
"$",
"sort_fields",
"=",
"array",
"(",
"'id'",
",",
"'collection'",
")",
";",
"$",
"paginator",
"->",
"configure",
"(",
"array",
"(",
")",
",",
"$",
"search_fields",
",",
"$",
"sort_fields",
")",
";",
"$",
"paginator",
"->",
"items_per_page",
"=",
"Collection_Shortcuts_NormalizeItemPerPage",
"(",
"$",
"request",
")",
";",
"$",
"paginator",
"->",
"setFromRequest",
"(",
"$",
"request",
")",
";",
"$",
"docs",
"=",
"$",
"paginator",
"->",
"render_object",
"(",
")",
";",
"// TODO: maso, 2017: pass list of attributes",
"foreach",
"(",
"$",
"docs",
"[",
"'items'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"docs",
"[",
"'items'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getDocumentMap",
"(",
"$",
"value",
")",
";",
"}",
"return",
"new",
"Pluf_HTTP_Response_Json",
"(",
"$",
"docs",
")",
";",
"}"
] | Search for an document
@param Pluf_HTTP_Request $request
@param array $match
@return Pluf_HTTP_Response_Json | [
"Search",
"for",
"an",
"document"
] | ae229d12e5ec352c66b31d5f89752f91f1342920 | https://github.com/pluf/collection/blob/ae229d12e5ec352c66b31d5f89752f91f1342920/src/Collection/Views/Document.php#L76-L114 | train |
pluf/collection | src/Collection/Views/Document.php | Collection_Views_Document.remove | public function remove ($request, $match)
{
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
} else {
$collectionId = $request->REQUEST['collectionId'];
}
$collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
$collectionId);
if (isset($match['documentId'])) {
$documentId = $match['documentId'];
} else {
$documentId = $request->REQUEST['documentId'];
}
$document = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$documentId);
if ($document->collection !== $collection->id) {
throw new Pluf_Exception_DoesNotExist(
'Document with id (' . $documentId .
') does not exist in collection with id (' .
$collectionId . ')');
}
$documentCopy = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$documentId);
$document->delete();
return new Pluf_HTTP_Response_Json($documentCopy);
} | php | public function remove ($request, $match)
{
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
} else {
$collectionId = $request->REQUEST['collectionId'];
}
$collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
$collectionId);
if (isset($match['documentId'])) {
$documentId = $match['documentId'];
} else {
$documentId = $request->REQUEST['documentId'];
}
$document = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$documentId);
if ($document->collection !== $collection->id) {
throw new Pluf_Exception_DoesNotExist(
'Document with id (' . $documentId .
') does not exist in collection with id (' .
$collectionId . ')');
}
$documentCopy = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$documentId);
$document->delete();
return new Pluf_HTTP_Response_Json($documentCopy);
} | [
"public",
"function",
"remove",
"(",
"$",
"request",
",",
"$",
"match",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'collectionId'",
"]",
")",
")",
"{",
"$",
"collectionId",
"=",
"$",
"match",
"[",
"'collectionId'",
"]",
";",
"}",
"else",
"{",
"$",
"collectionId",
"=",
"$",
"request",
"->",
"REQUEST",
"[",
"'collectionId'",
"]",
";",
"}",
"$",
"collection",
"=",
"Pluf_Shortcuts_GetObjectOr404",
"(",
"'Collection_Collection'",
",",
"$",
"collectionId",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'documentId'",
"]",
")",
")",
"{",
"$",
"documentId",
"=",
"$",
"match",
"[",
"'documentId'",
"]",
";",
"}",
"else",
"{",
"$",
"documentId",
"=",
"$",
"request",
"->",
"REQUEST",
"[",
"'documentId'",
"]",
";",
"}",
"$",
"document",
"=",
"Pluf_Shortcuts_GetObjectOr404",
"(",
"'Collection_Document'",
",",
"$",
"documentId",
")",
";",
"if",
"(",
"$",
"document",
"->",
"collection",
"!==",
"$",
"collection",
"->",
"id",
")",
"{",
"throw",
"new",
"Pluf_Exception_DoesNotExist",
"(",
"'Document with id ('",
".",
"$",
"documentId",
".",
"') does not exist in collection with id ('",
".",
"$",
"collectionId",
".",
"')'",
")",
";",
"}",
"$",
"documentCopy",
"=",
"Pluf_Shortcuts_GetObjectOr404",
"(",
"'Collection_Document'",
",",
"$",
"documentId",
")",
";",
"$",
"document",
"->",
"delete",
"(",
")",
";",
"return",
"new",
"Pluf_HTTP_Response_Json",
"(",
"$",
"documentCopy",
")",
";",
"}"
] | Removes a document
@param Pluf_HTTP_Request $request
@param array $match
@throws Pluf_Exception_DoesNotExist
@return Pluf_HTTP_Response_Json | [
"Removes",
"a",
"document"
] | ae229d12e5ec352c66b31d5f89752f91f1342920 | https://github.com/pluf/collection/blob/ae229d12e5ec352c66b31d5f89752f91f1342920/src/Collection/Views/Document.php#L124-L151 | train |
pluf/collection | src/Collection/Views/Document.php | Collection_Views_Document.update | public function update ($request, $match, $p)
{
// check collection
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
$request->REQUEST['collection'] = $collectionId;
} else {
$collectionId = $request->REQUEST['collection'];
}
$collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
$collectionId);
$document = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$match['modelId']);
if ($document->collection !== $collection->id) {
throw new Pluf_Exception_DoesNotExist(
'Document with id (' . $document->id .
') does not exist in collection with id (' .
$collection->id . ')');
}
// update document
$plufService = new Pluf_Views();
return $plufService->updateObject($request, $match, $p);
} | php | public function update ($request, $match, $p)
{
// check collection
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
$request->REQUEST['collection'] = $collectionId;
} else {
$collectionId = $request->REQUEST['collection'];
}
$collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
$collectionId);
$document = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$match['modelId']);
if ($document->collection !== $collection->id) {
throw new Pluf_Exception_DoesNotExist(
'Document with id (' . $document->id .
') does not exist in collection with id (' .
$collection->id . ')');
}
// update document
$plufService = new Pluf_Views();
return $plufService->updateObject($request, $match, $p);
} | [
"public",
"function",
"update",
"(",
"$",
"request",
",",
"$",
"match",
",",
"$",
"p",
")",
"{",
"// check collection",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'collectionId'",
"]",
")",
")",
"{",
"$",
"collectionId",
"=",
"$",
"match",
"[",
"'collectionId'",
"]",
";",
"$",
"request",
"->",
"REQUEST",
"[",
"'collection'",
"]",
"=",
"$",
"collectionId",
";",
"}",
"else",
"{",
"$",
"collectionId",
"=",
"$",
"request",
"->",
"REQUEST",
"[",
"'collection'",
"]",
";",
"}",
"$",
"collection",
"=",
"Pluf_Shortcuts_GetObjectOr404",
"(",
"'Collection_Collection'",
",",
"$",
"collectionId",
")",
";",
"$",
"document",
"=",
"Pluf_Shortcuts_GetObjectOr404",
"(",
"'Collection_Document'",
",",
"$",
"match",
"[",
"'modelId'",
"]",
")",
";",
"if",
"(",
"$",
"document",
"->",
"collection",
"!==",
"$",
"collection",
"->",
"id",
")",
"{",
"throw",
"new",
"Pluf_Exception_DoesNotExist",
"(",
"'Document with id ('",
".",
"$",
"document",
"->",
"id",
".",
"') does not exist in collection with id ('",
".",
"$",
"collection",
"->",
"id",
".",
"')'",
")",
";",
"}",
"// update document",
"$",
"plufService",
"=",
"new",
"Pluf_Views",
"(",
")",
";",
"return",
"$",
"plufService",
"->",
"updateObject",
"(",
"$",
"request",
",",
"$",
"match",
",",
"$",
"p",
")",
";",
"}"
] | Updates a document
@param Pluf_HTTP_Request $request
@param array $match
@param array $p
@throws Pluf_Exception_DoesNotExist
@return Pluf_HTTP_Response | [
"Updates",
"a",
"document"
] | ae229d12e5ec352c66b31d5f89752f91f1342920 | https://github.com/pluf/collection/blob/ae229d12e5ec352c66b31d5f89752f91f1342920/src/Collection/Views/Document.php#L162-L184 | train |
pluf/collection | src/Collection/Views/Document.php | Collection_Views_Document.putMap | public function putMap ($request, $match)
{
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
} else {
$collectionId = $request->REQUEST['collectionId'];
}
// $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
// $collectionId);
if (isset($match['documentId'])) {
$documentId = $match['documentId'];
} else {
$documentId = $request->REQUEST['documentId'];
}
$document = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$documentId);
if ($document->collection != $collectionId) {
throw new Pluf_Exception_DoesNotExist(
'Document with id (' . $documentId .
') does not exist in collection with id (' .
$collectionId . ')');
}
$this->putDocumentMap($document, $request->REQUEST);
return new Pluf_HTTP_Response_Json($this->getDocumentMap($document));
} | php | public function putMap ($request, $match)
{
if (isset($match['collectionId'])) {
$collectionId = $match['collectionId'];
} else {
$collectionId = $request->REQUEST['collectionId'];
}
// $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
// $collectionId);
if (isset($match['documentId'])) {
$documentId = $match['documentId'];
} else {
$documentId = $request->REQUEST['documentId'];
}
$document = Pluf_Shortcuts_GetObjectOr404('Collection_Document',
$documentId);
if ($document->collection != $collectionId) {
throw new Pluf_Exception_DoesNotExist(
'Document with id (' . $documentId .
') does not exist in collection with id (' .
$collectionId . ')');
}
$this->putDocumentMap($document, $request->REQUEST);
return new Pluf_HTTP_Response_Json($this->getDocumentMap($document));
} | [
"public",
"function",
"putMap",
"(",
"$",
"request",
",",
"$",
"match",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'collectionId'",
"]",
")",
")",
"{",
"$",
"collectionId",
"=",
"$",
"match",
"[",
"'collectionId'",
"]",
";",
"}",
"else",
"{",
"$",
"collectionId",
"=",
"$",
"request",
"->",
"REQUEST",
"[",
"'collectionId'",
"]",
";",
"}",
"// $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',",
"// $collectionId);",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"'documentId'",
"]",
")",
")",
"{",
"$",
"documentId",
"=",
"$",
"match",
"[",
"'documentId'",
"]",
";",
"}",
"else",
"{",
"$",
"documentId",
"=",
"$",
"request",
"->",
"REQUEST",
"[",
"'documentId'",
"]",
";",
"}",
"$",
"document",
"=",
"Pluf_Shortcuts_GetObjectOr404",
"(",
"'Collection_Document'",
",",
"$",
"documentId",
")",
";",
"if",
"(",
"$",
"document",
"->",
"collection",
"!=",
"$",
"collectionId",
")",
"{",
"throw",
"new",
"Pluf_Exception_DoesNotExist",
"(",
"'Document with id ('",
".",
"$",
"documentId",
".",
"') does not exist in collection with id ('",
".",
"$",
"collectionId",
".",
"')'",
")",
";",
"}",
"$",
"this",
"->",
"putDocumentMap",
"(",
"$",
"document",
",",
"$",
"request",
"->",
"REQUEST",
")",
";",
"return",
"new",
"Pluf_HTTP_Response_Json",
"(",
"$",
"this",
"->",
"getDocumentMap",
"(",
"$",
"document",
")",
")",
";",
"}"
] | Puts attributes of a document
@param Pluf_HTTP_Request $request
@param array $match | [
"Puts",
"attributes",
"of",
"a",
"document"
] | ae229d12e5ec352c66b31d5f89752f91f1342920 | https://github.com/pluf/collection/blob/ae229d12e5ec352c66b31d5f89752f91f1342920/src/Collection/Views/Document.php#L225-L251 | train |
opensourcerefinery/vicus | src/Storage/Handler/DeglobalizedMySQLSessionHandler.php | DeglobalizedMySQLSessionHandler.connect | private function connect()
{
$this->sessionLink = mysqli_connect($this->host_master,$this->user,$this->password,$this->name) or die("Error " . mysqli_error($this->sessionLink));
// $this->pdo = new \PDO($dsn, $this->username, $this->password, $this->connectionOptions);
// $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
// $this->driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
} | php | private function connect()
{
$this->sessionLink = mysqli_connect($this->host_master,$this->user,$this->password,$this->name) or die("Error " . mysqli_error($this->sessionLink));
// $this->pdo = new \PDO($dsn, $this->username, $this->password, $this->connectionOptions);
// $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
// $this->driver = $this->pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
} | [
"private",
"function",
"connect",
"(",
")",
"{",
"$",
"this",
"->",
"sessionLink",
"=",
"mysqli_connect",
"(",
"$",
"this",
"->",
"host_master",
",",
"$",
"this",
"->",
"user",
",",
"$",
"this",
"->",
"password",
",",
"$",
"this",
"->",
"name",
")",
"or",
"die",
"(",
"\"Error \"",
".",
"mysqli_error",
"(",
"$",
"this",
"->",
"sessionLink",
")",
")",
";",
"// $this->pdo = new \\PDO($dsn, $this->username, $this->password, $this->connectionOptions);",
"// $this->pdo->setAttribute(\\PDO::ATTR_ERRMODE, \\PDO::ERRMODE_EXCEPTION);",
"// $this->driver = $this->pdo->getAttribute(\\PDO::ATTR_DRIVER_NAME);",
"}"
] | NOT WORKING!!!
Lazy-connects to the database.
@param string $dsn DSN string | [
"NOT",
"WORKING!!!",
"Lazy",
"-",
"connects",
"to",
"the",
"database",
"."
] | 5be93d75bf6ab8009a299e9946c8333f0017fa3e | https://github.com/opensourcerefinery/vicus/blob/5be93d75bf6ab8009a299e9946c8333f0017fa3e/src/Storage/Handler/DeglobalizedMySQLSessionHandler.php#L218-L225 | train |
mwyatt/core | src/Iterator/Model.php | Model.getKeyedByPropertyMulti | public function getKeyedByPropertyMulti($property)
{
$keyed = [];
foreach ($this as $model) {
if (empty($keyed[$model->$property])) {
$keyed[$model->$property] = [];
}
$keyed[$model->$property][] = $model;
}
return $keyed;
} | php | public function getKeyedByPropertyMulti($property)
{
$keyed = [];
foreach ($this as $model) {
if (empty($keyed[$model->$property])) {
$keyed[$model->$property] = [];
}
$keyed[$model->$property][] = $model;
}
return $keyed;
} | [
"public",
"function",
"getKeyedByPropertyMulti",
"(",
"$",
"property",
")",
"{",
"$",
"keyed",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"model",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"keyed",
"[",
"$",
"model",
"->",
"$",
"property",
"]",
")",
")",
"{",
"$",
"keyed",
"[",
"$",
"model",
"->",
"$",
"property",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"keyed",
"[",
"$",
"model",
"->",
"$",
"property",
"]",
"[",
"]",
"=",
"$",
"model",
";",
"}",
"return",
"$",
"keyed",
";",
"}"
] | key the iterator by the specified property
but go 2 levels
@param string $property
@return array | [
"key",
"the",
"iterator",
"by",
"the",
"specified",
"property",
"but",
"go",
"2",
"levels"
] | 8ea9d67cc84fe6aff17a469c703d5492dbcd93ed | https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Iterator/Model.php#L78-L88 | train |
raulfraile/ladybug-plugin-extra | Type/CollectionType.php | CollectionType.loadFromArray | public function loadFromArray(array $data, $useKeys = true)
{
$this->items = array();
foreach ($data as $key => $item) {
$this->items[] = $item;
}
} | php | public function loadFromArray(array $data, $useKeys = true)
{
$this->items = array();
foreach ($data as $key => $item) {
$this->items[] = $item;
}
} | [
"public",
"function",
"loadFromArray",
"(",
"array",
"$",
"data",
",",
"$",
"useKeys",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"items",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}"
] | Loads collection values from the given array
@param array $data
@param bool $useKeys | [
"Loads",
"collection",
"values",
"from",
"the",
"given",
"array"
] | 0d569c28eb4706506f0057d95a1da9dd2c76c329 | https://github.com/raulfraile/ladybug-plugin-extra/blob/0d569c28eb4706506f0057d95a1da9dd2c76c329/Type/CollectionType.php#L40-L47 | train |
geniv/nette-general-form | src/GeneralForm.php | GeneralForm.getDefinitionFormContainer | public static function getDefinitionFormContainer(CompilerExtension $compilerExtension, $indexConfig = 'formContainer', $prefixName = 'formContainer'): ServiceDefinition
{
$builder = $compilerExtension->getContainerBuilder();
$config = $compilerExtension->getConfig();
return $builder->addDefinition($compilerExtension->prefix($prefixName))
->setFactory($config[$indexConfig])
->setAutowired($config['autowired']);
} | php | public static function getDefinitionFormContainer(CompilerExtension $compilerExtension, $indexConfig = 'formContainer', $prefixName = 'formContainer'): ServiceDefinition
{
$builder = $compilerExtension->getContainerBuilder();
$config = $compilerExtension->getConfig();
return $builder->addDefinition($compilerExtension->prefix($prefixName))
->setFactory($config[$indexConfig])
->setAutowired($config['autowired']);
} | [
"public",
"static",
"function",
"getDefinitionFormContainer",
"(",
"CompilerExtension",
"$",
"compilerExtension",
",",
"$",
"indexConfig",
"=",
"'formContainer'",
",",
"$",
"prefixName",
"=",
"'formContainer'",
")",
":",
"ServiceDefinition",
"{",
"$",
"builder",
"=",
"$",
"compilerExtension",
"->",
"getContainerBuilder",
"(",
")",
";",
"$",
"config",
"=",
"$",
"compilerExtension",
"->",
"getConfig",
"(",
")",
";",
"return",
"$",
"builder",
"->",
"addDefinition",
"(",
"$",
"compilerExtension",
"->",
"prefix",
"(",
"$",
"prefixName",
")",
")",
"->",
"setFactory",
"(",
"$",
"config",
"[",
"$",
"indexConfig",
"]",
")",
"->",
"setAutowired",
"(",
"$",
"config",
"[",
"'autowired'",
"]",
")",
";",
"}"
] | Get definition form container.
@param CompilerExtension $compilerExtension
@param string $indexConfig
@param string $prefixName
@return ServiceDefinition | [
"Get",
"definition",
"form",
"container",
"."
] | 0d0548b63cf7db58c17ee12d6933f2dd995a64e6 | https://github.com/geniv/nette-general-form/blob/0d0548b63cf7db58c17ee12d6933f2dd995a64e6/src/GeneralForm.php#L30-L38 | train |
geniv/nette-general-form | src/GeneralForm.php | GeneralForm.getDefinitionEventContainer | public static function getDefinitionEventContainer(CompilerExtension $compilerExtension, $indexConfig = 'events'): array
{
$builder = $compilerExtension->getContainerBuilder();
$config = $compilerExtension->getConfig();
$events = [];
foreach ($config[$indexConfig] as $index => $event) {
// get name from event/statement
$name = $event;
if ($event instanceof Statement) {
$name = $event->getEntity();
}
// get part name
$exp = explode('\\', $name);
if (count($exp) > 1) {
$name = $exp[count($exp) - 1]; // get last index
}
$definitionName = $compilerExtension->prefix($name);
if (!$builder->hasDefinition($definitionName)) {
$events[$index] = $builder->addDefinition($compilerExtension->prefix($name))
->setFactory($event)
->setAutowired($config['autowired']);
} else {
$events[$index] = $builder->getDefinition($definitionName);
}
}
return $events;
} | php | public static function getDefinitionEventContainer(CompilerExtension $compilerExtension, $indexConfig = 'events'): array
{
$builder = $compilerExtension->getContainerBuilder();
$config = $compilerExtension->getConfig();
$events = [];
foreach ($config[$indexConfig] as $index => $event) {
// get name from event/statement
$name = $event;
if ($event instanceof Statement) {
$name = $event->getEntity();
}
// get part name
$exp = explode('\\', $name);
if (count($exp) > 1) {
$name = $exp[count($exp) - 1]; // get last index
}
$definitionName = $compilerExtension->prefix($name);
if (!$builder->hasDefinition($definitionName)) {
$events[$index] = $builder->addDefinition($compilerExtension->prefix($name))
->setFactory($event)
->setAutowired($config['autowired']);
} else {
$events[$index] = $builder->getDefinition($definitionName);
}
}
return $events;
} | [
"public",
"static",
"function",
"getDefinitionEventContainer",
"(",
"CompilerExtension",
"$",
"compilerExtension",
",",
"$",
"indexConfig",
"=",
"'events'",
")",
":",
"array",
"{",
"$",
"builder",
"=",
"$",
"compilerExtension",
"->",
"getContainerBuilder",
"(",
")",
";",
"$",
"config",
"=",
"$",
"compilerExtension",
"->",
"getConfig",
"(",
")",
";",
"$",
"events",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"config",
"[",
"$",
"indexConfig",
"]",
"as",
"$",
"index",
"=>",
"$",
"event",
")",
"{",
"// get name from event/statement",
"$",
"name",
"=",
"$",
"event",
";",
"if",
"(",
"$",
"event",
"instanceof",
"Statement",
")",
"{",
"$",
"name",
"=",
"$",
"event",
"->",
"getEntity",
"(",
")",
";",
"}",
"// get part name",
"$",
"exp",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"name",
")",
";",
"if",
"(",
"count",
"(",
"$",
"exp",
")",
">",
"1",
")",
"{",
"$",
"name",
"=",
"$",
"exp",
"[",
"count",
"(",
"$",
"exp",
")",
"-",
"1",
"]",
";",
"// get last index",
"}",
"$",
"definitionName",
"=",
"$",
"compilerExtension",
"->",
"prefix",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"builder",
"->",
"hasDefinition",
"(",
"$",
"definitionName",
")",
")",
"{",
"$",
"events",
"[",
"$",
"index",
"]",
"=",
"$",
"builder",
"->",
"addDefinition",
"(",
"$",
"compilerExtension",
"->",
"prefix",
"(",
"$",
"name",
")",
")",
"->",
"setFactory",
"(",
"$",
"event",
")",
"->",
"setAutowired",
"(",
"$",
"config",
"[",
"'autowired'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"events",
"[",
"$",
"index",
"]",
"=",
"$",
"builder",
"->",
"getDefinition",
"(",
"$",
"definitionName",
")",
";",
"}",
"}",
"return",
"$",
"events",
";",
"}"
] | Get definition event container.
@param CompilerExtension $compilerExtension
@param string $indexConfig
@return array | [
"Get",
"definition",
"event",
"container",
"."
] | 0d0548b63cf7db58c17ee12d6933f2dd995a64e6 | https://github.com/geniv/nette-general-form/blob/0d0548b63cf7db58c17ee12d6933f2dd995a64e6/src/GeneralForm.php#L48-L77 | train |
squareproton/Bond | src/Bond/Entity/Types/PgLargeObject.php | PgLargeObject.chainSaving | public function chainSaving( array &$tasks, $key )
{
if( $this->isNew() or $this->isChanged() ) {
$tasks[$key] = $this;
}
} | php | public function chainSaving( array &$tasks, $key )
{
if( $this->isNew() or $this->isChanged() ) {
$tasks[$key] = $this;
}
} | [
"public",
"function",
"chainSaving",
"(",
"array",
"&",
"$",
"tasks",
",",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNew",
"(",
")",
"or",
"$",
"this",
"->",
"isChanged",
"(",
")",
")",
"{",
"$",
"tasks",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
";",
"}",
"}"
] | Add a object to the chain task array if it is changed or new
Required for ChainSavingInterface
@param array $task The existing array of tasks
@param string $key The string under which to add the object | [
"Add",
"a",
"object",
"to",
"the",
"chain",
"task",
"array",
"if",
"it",
"is",
"changed",
"or",
"new",
"Required",
"for",
"ChainSavingInterface"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/PgLargeObject.php#L96-L101 | train |
squareproton/Bond | src/Bond/Entity/Types/PgLargeObject.php | PgLargeObject.md5 | public function md5()
{
if( isset( $this->filePath ) ) {
return md5_file( $this->filePath );
} elseif( $this->oid ) {
$query = new Query(
"SELECT common.md5( %oid:oid|cast% );",
array(
'oid' => $this->oid
)
);
// execute the query and return the result
return $this->oid->pg->query( $query )->fetch( Result::FETCH_SINGLE );
}
throw \LogicException("Shouldn't ever get tripped");
} | php | public function md5()
{
if( isset( $this->filePath ) ) {
return md5_file( $this->filePath );
} elseif( $this->oid ) {
$query = new Query(
"SELECT common.md5( %oid:oid|cast% );",
array(
'oid' => $this->oid
)
);
// execute the query and return the result
return $this->oid->pg->query( $query )->fetch( Result::FETCH_SINGLE );
}
throw \LogicException("Shouldn't ever get tripped");
} | [
"public",
"function",
"md5",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"return",
"md5_file",
"(",
"$",
"this",
"->",
"filePath",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"oid",
")",
"{",
"$",
"query",
"=",
"new",
"Query",
"(",
"\"SELECT common.md5( %oid:oid|cast% );\"",
",",
"array",
"(",
"'oid'",
"=>",
"$",
"this",
"->",
"oid",
")",
")",
";",
"// execute the query and return the result",
"return",
"$",
"this",
"->",
"oid",
"->",
"pg",
"->",
"query",
"(",
"$",
"query",
")",
"->",
"fetch",
"(",
"Result",
"::",
"FETCH_SINGLE",
")",
";",
"}",
"throw",
"\\",
"LogicException",
"(",
"\"Shouldn't ever get tripped\"",
")",
";",
"}"
] | Return the MD5 hash of the data
@return mixed | [
"Return",
"the",
"MD5",
"hash",
"of",
"the",
"data"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/PgLargeObject.php#L184-L207 | train |
squareproton/Bond | src/Bond/Entity/Types/PgLargeObject.php | PgLargeObject.data | public function data()
{
if( isset( $this->filePath ) ) {
return file_get_contents( $this->filePath );
} elseif( $this->oid ) {
$pg = $this->oid->pg;
$pg->query( new Query( 'BEGIN' ) );
$handle = pg_lo_open( $pg->resource->get(), $this->oid->oid, 'r' );
$result = '';
while( ( $data = pg_lo_read( $handle ) ) ){
$result .= $data;
}
pg_lo_close( $handle );
$pg->query( new Query( 'COMMIT' ) );
return $result;
}
throw \LogicException("Shouldn't ever get tripped");
} | php | public function data()
{
if( isset( $this->filePath ) ) {
return file_get_contents( $this->filePath );
} elseif( $this->oid ) {
$pg = $this->oid->pg;
$pg->query( new Query( 'BEGIN' ) );
$handle = pg_lo_open( $pg->resource->get(), $this->oid->oid, 'r' );
$result = '';
while( ( $data = pg_lo_read( $handle ) ) ){
$result .= $data;
}
pg_lo_close( $handle );
$pg->query( new Query( 'COMMIT' ) );
return $result;
}
throw \LogicException("Shouldn't ever get tripped");
} | [
"public",
"function",
"data",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"return",
"file_get_contents",
"(",
"$",
"this",
"->",
"filePath",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"oid",
")",
"{",
"$",
"pg",
"=",
"$",
"this",
"->",
"oid",
"->",
"pg",
";",
"$",
"pg",
"->",
"query",
"(",
"new",
"Query",
"(",
"'BEGIN'",
")",
")",
";",
"$",
"handle",
"=",
"pg_lo_open",
"(",
"$",
"pg",
"->",
"resource",
"->",
"get",
"(",
")",
",",
"$",
"this",
"->",
"oid",
"->",
"oid",
",",
"'r'",
")",
";",
"$",
"result",
"=",
"''",
";",
"while",
"(",
"(",
"$",
"data",
"=",
"pg_lo_read",
"(",
"$",
"handle",
")",
")",
")",
"{",
"$",
"result",
".=",
"$",
"data",
";",
"}",
"pg_lo_close",
"(",
"$",
"handle",
")",
";",
"$",
"pg",
"->",
"query",
"(",
"new",
"Query",
"(",
"'COMMIT'",
")",
")",
";",
"return",
"$",
"result",
";",
"}",
"throw",
"\\",
"LogicException",
"(",
"\"Shouldn't ever get tripped\"",
")",
";",
"}"
] | Get the data stored in the large object resource.
@param void
@return mixed | [
"Get",
"the",
"data",
"stored",
"in",
"the",
"large",
"object",
"resource",
"."
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/PgLargeObject.php#L214-L243 | train |
squareproton/Bond | src/Bond/Entity/Types/PgLargeObject.php | PgLargeObject.export | public function export( $destination, $overwriteIfExists = false )
{
if( !is_string( $destination ) ){
throw new \RuntimeException(sprintf(
'Expected $destination to be a string, got type: %s',
gettype($destination)
));
}
if( file_exists( $destination ) and !$overwriteIfExists ) {
throw new \RuntimeException( sprintf( "File '%s' already exists.", $destination ) );
}
if( !is_writable( dirname( $destination ) ) ){
throw new \RuntimeException( sprintf( "File '%s' is not writable.", $destination ) );
}
if( isset( $this->filePath ) ) {
return copy( $this->filePath, $destination );
}
$pg = $this->oid->pg;;
$pg->query( new Query( 'BEGIN' ) );
$result = pg_lo_export( $pg->resource->get(), $this->oid->oid, $destination );
$pg->query( new Query( 'COMMIT' ) );
return $result;
} | php | public function export( $destination, $overwriteIfExists = false )
{
if( !is_string( $destination ) ){
throw new \RuntimeException(sprintf(
'Expected $destination to be a string, got type: %s',
gettype($destination)
));
}
if( file_exists( $destination ) and !$overwriteIfExists ) {
throw new \RuntimeException( sprintf( "File '%s' already exists.", $destination ) );
}
if( !is_writable( dirname( $destination ) ) ){
throw new \RuntimeException( sprintf( "File '%s' is not writable.", $destination ) );
}
if( isset( $this->filePath ) ) {
return copy( $this->filePath, $destination );
}
$pg = $this->oid->pg;;
$pg->query( new Query( 'BEGIN' ) );
$result = pg_lo_export( $pg->resource->get(), $this->oid->oid, $destination );
$pg->query( new Query( 'COMMIT' ) );
return $result;
} | [
"public",
"function",
"export",
"(",
"$",
"destination",
",",
"$",
"overwriteIfExists",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"destination",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Expected $destination to be a string, got type: %s'",
",",
"gettype",
"(",
"$",
"destination",
")",
")",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"destination",
")",
"and",
"!",
"$",
"overwriteIfExists",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"\"File '%s' already exists.\"",
",",
"$",
"destination",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_writable",
"(",
"dirname",
"(",
"$",
"destination",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"\"File '%s' is not writable.\"",
",",
"$",
"destination",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"return",
"copy",
"(",
"$",
"this",
"->",
"filePath",
",",
"$",
"destination",
")",
";",
"}",
"$",
"pg",
"=",
"$",
"this",
"->",
"oid",
"->",
"pg",
";",
";",
"$",
"pg",
"->",
"query",
"(",
"new",
"Query",
"(",
"'BEGIN'",
")",
")",
";",
"$",
"result",
"=",
"pg_lo_export",
"(",
"$",
"pg",
"->",
"resource",
"->",
"get",
"(",
")",
",",
"$",
"this",
"->",
"oid",
"->",
"oid",
",",
"$",
"destination",
")",
";",
"$",
"pg",
"->",
"query",
"(",
"new",
"Query",
"(",
"'COMMIT'",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Export the data stored in the large object resource to the specified file.
@param mixed $destination
@return boolean. | [
"Export",
"the",
"data",
"stored",
"in",
"the",
"large",
"object",
"resource",
"to",
"the",
"specified",
"file",
"."
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/PgLargeObject.php#L250-L282 | train |
squareproton/Bond | src/Bond/Entity/Types/PgLargeObject.php | PgLargeObject.stream | public function stream()
{
// filesystem
if( isset( $this->filePath ) ) {
return readfile( $this->filePath );
} elseif ( $this->oid ) {
$pg = $this->oid->pg;
$pg->query( new Query( 'BEGIN' ) );
$handle = pg_lo_open( $pg->resource->get(), $this->oid->oid, 'r' );
pg_lo_read_all( $handle );
pg_lo_close( $handle );
$pg->query( new Query( 'COMMIT' ) );
return null;
}
throw \LogicException("Shouldn't ever get tripped");
} | php | public function stream()
{
// filesystem
if( isset( $this->filePath ) ) {
return readfile( $this->filePath );
} elseif ( $this->oid ) {
$pg = $this->oid->pg;
$pg->query( new Query( 'BEGIN' ) );
$handle = pg_lo_open( $pg->resource->get(), $this->oid->oid, 'r' );
pg_lo_read_all( $handle );
pg_lo_close( $handle );
$pg->query( new Query( 'COMMIT' ) );
return null;
}
throw \LogicException("Shouldn't ever get tripped");
} | [
"public",
"function",
"stream",
"(",
")",
"{",
"// filesystem",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"filePath",
")",
")",
"{",
"return",
"readfile",
"(",
"$",
"this",
"->",
"filePath",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"oid",
")",
"{",
"$",
"pg",
"=",
"$",
"this",
"->",
"oid",
"->",
"pg",
";",
"$",
"pg",
"->",
"query",
"(",
"new",
"Query",
"(",
"'BEGIN'",
")",
")",
";",
"$",
"handle",
"=",
"pg_lo_open",
"(",
"$",
"pg",
"->",
"resource",
"->",
"get",
"(",
")",
",",
"$",
"this",
"->",
"oid",
"->",
"oid",
",",
"'r'",
")",
";",
"pg_lo_read_all",
"(",
"$",
"handle",
")",
";",
"pg_lo_close",
"(",
"$",
"handle",
")",
";",
"$",
"pg",
"->",
"query",
"(",
"new",
"Query",
"(",
"'COMMIT'",
")",
")",
";",
"return",
"null",
";",
"}",
"throw",
"\\",
"LogicException",
"(",
"\"Shouldn't ever get tripped\"",
")",
";",
"}"
] | Output the data stored in the large object resource to stdout.
@param void
@return void | [
"Output",
"the",
"data",
"stored",
"in",
"the",
"large",
"object",
"resource",
"to",
"stdout",
"."
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Entity/Types/PgLargeObject.php#L289-L316 | train |
phpffcms/ffcms-core | src/Managers/CronManager.php | CronManager.run | public function run()
{
// check if cron instances is defined
if (!isset($this->configs['instances']) || !Any::isArray($this->configs['instances'])) {
return null;
}
// get timestamp
$time = time();
$log = [];
// each every one instance
foreach ($this->configs['instances'] as $callback => $delay) {
if (((int)$this->configs['log'][$callback] + $delay) <= $time) {
// prepare cron initializing
list($class, $method) = explode('::', $callback);
if (class_exists($class) && method_exists($class, $method)) {
// make static callback
forward_static_call([$class, $method]);
$log[] = $callback;
}
// update log information
$this->configs['log'][$callback] = $time + $delay;
}
}
// write updated configs
App::$Properties->writeConfig('Cron', $this->configs);
return $log;
} | php | public function run()
{
// check if cron instances is defined
if (!isset($this->configs['instances']) || !Any::isArray($this->configs['instances'])) {
return null;
}
// get timestamp
$time = time();
$log = [];
// each every one instance
foreach ($this->configs['instances'] as $callback => $delay) {
if (((int)$this->configs['log'][$callback] + $delay) <= $time) {
// prepare cron initializing
list($class, $method) = explode('::', $callback);
if (class_exists($class) && method_exists($class, $method)) {
// make static callback
forward_static_call([$class, $method]);
$log[] = $callback;
}
// update log information
$this->configs['log'][$callback] = $time + $delay;
}
}
// write updated configs
App::$Properties->writeConfig('Cron', $this->configs);
return $log;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"// check if cron instances is defined",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"configs",
"[",
"'instances'",
"]",
")",
"||",
"!",
"Any",
"::",
"isArray",
"(",
"$",
"this",
"->",
"configs",
"[",
"'instances'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"// get timestamp",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"log",
"=",
"[",
"]",
";",
"// each every one instance",
"foreach",
"(",
"$",
"this",
"->",
"configs",
"[",
"'instances'",
"]",
"as",
"$",
"callback",
"=>",
"$",
"delay",
")",
"{",
"if",
"(",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"configs",
"[",
"'log'",
"]",
"[",
"$",
"callback",
"]",
"+",
"$",
"delay",
")",
"<=",
"$",
"time",
")",
"{",
"// prepare cron initializing",
"list",
"(",
"$",
"class",
",",
"$",
"method",
")",
"=",
"explode",
"(",
"'::'",
",",
"$",
"callback",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
"&&",
"method_exists",
"(",
"$",
"class",
",",
"$",
"method",
")",
")",
"{",
"// make static callback",
"forward_static_call",
"(",
"[",
"$",
"class",
",",
"$",
"method",
"]",
")",
";",
"$",
"log",
"[",
"]",
"=",
"$",
"callback",
";",
"}",
"// update log information",
"$",
"this",
"->",
"configs",
"[",
"'log'",
"]",
"[",
"$",
"callback",
"]",
"=",
"$",
"time",
"+",
"$",
"delay",
";",
"}",
"}",
"// write updated configs",
"App",
"::",
"$",
"Properties",
"->",
"writeConfig",
"(",
"'Cron'",
",",
"$",
"this",
"->",
"configs",
")",
";",
"return",
"$",
"log",
";",
"}"
] | Run cron task. Attention - this method is too 'fat' to run from any app's
@return array|null | [
"Run",
"cron",
"task",
".",
"Attention",
"-",
"this",
"method",
"is",
"too",
"fat",
"to",
"run",
"from",
"any",
"app",
"s"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Managers/CronManager.php#L34-L63 | train |
phpffcms/ffcms-core | src/Managers/CronManager.php | CronManager.remove | public function remove($class, $method)
{
$callback = $class . '::' . $method;
if (isset($this->configs['instances'][$callback])) {
unset($this->configs['instances'][$callback], $this->configs['log'][$callback]);
App::$Properties->writeConfig('Cron', $this->configs);
}
} | php | public function remove($class, $method)
{
$callback = $class . '::' . $method;
if (isset($this->configs['instances'][$callback])) {
unset($this->configs['instances'][$callback], $this->configs['log'][$callback]);
App::$Properties->writeConfig('Cron', $this->configs);
}
} | [
"public",
"function",
"remove",
"(",
"$",
"class",
",",
"$",
"method",
")",
"{",
"$",
"callback",
"=",
"$",
"class",
".",
"'::'",
".",
"$",
"method",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"configs",
"[",
"'instances'",
"]",
"[",
"$",
"callback",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"configs",
"[",
"'instances'",
"]",
"[",
"$",
"callback",
"]",
",",
"$",
"this",
"->",
"configs",
"[",
"'log'",
"]",
"[",
"$",
"callback",
"]",
")",
";",
"App",
"::",
"$",
"Properties",
"->",
"writeConfig",
"(",
"'Cron'",
",",
"$",
"this",
"->",
"configs",
")",
";",
"}",
"}"
] | Remove registered cron task from configs
@param string $class
@param string $method | [
"Remove",
"registered",
"cron",
"task",
"from",
"configs"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Managers/CronManager.php#L95-L102 | train |
eltrino/PHPUnit_MockAnnotations | src/Eltrino/PHPUnit/MockAnnotations/PlainMockObjectFactory.php | PlainMockObjectFactory.create | public function create($classToMock)
{
$mockBuilder = new \PHPUnit_Framework_MockObject_MockBuilder(
$this->testCase, $classToMock
);
$mockBuilder->disableOriginalConstructor();
return $mockBuilder->getMock();
} | php | public function create($classToMock)
{
$mockBuilder = new \PHPUnit_Framework_MockObject_MockBuilder(
$this->testCase, $classToMock
);
$mockBuilder->disableOriginalConstructor();
return $mockBuilder->getMock();
} | [
"public",
"function",
"create",
"(",
"$",
"classToMock",
")",
"{",
"$",
"mockBuilder",
"=",
"new",
"\\",
"PHPUnit_Framework_MockObject_MockBuilder",
"(",
"$",
"this",
"->",
"testCase",
",",
"$",
"classToMock",
")",
";",
"$",
"mockBuilder",
"->",
"disableOriginalConstructor",
"(",
")",
";",
"return",
"$",
"mockBuilder",
"->",
"getMock",
"(",
")",
";",
"}"
] | Creates simple PHPUnit Mock Object with disabled original constructor
@param string $classToMock
@return \PHPUnit_Framework_MockObject_MockObject | [
"Creates",
"simple",
"PHPUnit",
"Mock",
"Object",
"with",
"disabled",
"original",
"constructor"
] | 1a06ed59ea0702359848fc01e958f4f92abb503a | https://github.com/eltrino/PHPUnit_MockAnnotations/blob/1a06ed59ea0702359848fc01e958f4f92abb503a/src/Eltrino/PHPUnit/MockAnnotations/PlainMockObjectFactory.php#L21-L28 | train |
olobu/olobu | core/router.php | O_Router._parse_routes | private function _parse_routes()
{
$uri=implode('/', $this->uri->segments());
if (isset($this->router[$uri])) {
return $this->_set_request(explode('/', $this->router[$uri]));
}
foreach ($this->router as $key => $val) {
$key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
if (preg_match('#^'.$key.'$#', $uri)) {
if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) {
$val = preg_replace('#^'.$key.'$#', $val, $uri);
}
return $this->_set_request(explode('/', $val));
}
}
$this->_set_request($this->uri->segments());
} | php | private function _parse_routes()
{
$uri=implode('/', $this->uri->segments());
if (isset($this->router[$uri])) {
return $this->_set_request(explode('/', $this->router[$uri]));
}
foreach ($this->router as $key => $val) {
$key = str_replace(':any', '.+', str_replace(':num', '[0-9]+', $key));
if (preg_match('#^'.$key.'$#', $uri)) {
if (strpos($val, '$') !== FALSE AND strpos($key, '(') !== FALSE) {
$val = preg_replace('#^'.$key.'$#', $val, $uri);
}
return $this->_set_request(explode('/', $val));
}
}
$this->_set_request($this->uri->segments());
} | [
"private",
"function",
"_parse_routes",
"(",
")",
"{",
"$",
"uri",
"=",
"implode",
"(",
"'/'",
",",
"$",
"this",
"->",
"uri",
"->",
"segments",
"(",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"router",
"[",
"$",
"uri",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_set_request",
"(",
"explode",
"(",
"'/'",
",",
"$",
"this",
"->",
"router",
"[",
"$",
"uri",
"]",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"router",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"key",
"=",
"str_replace",
"(",
"':any'",
",",
"'.+'",
",",
"str_replace",
"(",
"':num'",
",",
"'[0-9]+'",
",",
"$",
"key",
")",
")",
";",
"if",
"(",
"preg_match",
"(",
"'#^'",
".",
"$",
"key",
".",
"'$#'",
",",
"$",
"uri",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"val",
",",
"'$'",
")",
"!==",
"FALSE",
"AND",
"strpos",
"(",
"$",
"key",
",",
"'('",
")",
"!==",
"FALSE",
")",
"{",
"$",
"val",
"=",
"preg_replace",
"(",
"'#^'",
".",
"$",
"key",
".",
"'$#'",
",",
"$",
"val",
",",
"$",
"uri",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_set_request",
"(",
"explode",
"(",
"'/'",
",",
"$",
"val",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_set_request",
"(",
"$",
"this",
"->",
"uri",
"->",
"segments",
"(",
")",
")",
";",
"}"
] | disini mo ba atur akan apa mo kamana | [
"disini",
"mo",
"ba",
"atur",
"akan",
"apa",
"mo",
"kamana"
] | 05bea2bff63d3e38b458fb42e8f07f1d850ae211 | https://github.com/olobu/olobu/blob/05bea2bff63d3e38b458fb42e8f07f1d850ae211/core/router.php#L58-L79 | train |
ARCANESOFT/SEO | src/Providers/PackagesServiceProvider.php | PackagesServiceProvider.registerLaravelSeoPackage | private function registerLaravelSeoPackage()
{
$this->registerProvider(LaravelSeoServiceProvider::class);
$this->app->booting(function () {
Seo::setConfig('database', config('arcanesoft.seo.database'));
Seo::setConfig('metas', config('arcanesoft.seo.metas'));
Seo::setConfig('redirects', config('arcanesoft.seo.redirects'));
Seo::setConfig('redirector.default', 'eloquent');
Relation::morphMap(config('arcanesoft.seo.morph-map'));
});
} | php | private function registerLaravelSeoPackage()
{
$this->registerProvider(LaravelSeoServiceProvider::class);
$this->app->booting(function () {
Seo::setConfig('database', config('arcanesoft.seo.database'));
Seo::setConfig('metas', config('arcanesoft.seo.metas'));
Seo::setConfig('redirects', config('arcanesoft.seo.redirects'));
Seo::setConfig('redirector.default', 'eloquent');
Relation::morphMap(config('arcanesoft.seo.morph-map'));
});
} | [
"private",
"function",
"registerLaravelSeoPackage",
"(",
")",
"{",
"$",
"this",
"->",
"registerProvider",
"(",
"LaravelSeoServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"booting",
"(",
"function",
"(",
")",
"{",
"Seo",
"::",
"setConfig",
"(",
"'database'",
",",
"config",
"(",
"'arcanesoft.seo.database'",
")",
")",
";",
"Seo",
"::",
"setConfig",
"(",
"'metas'",
",",
"config",
"(",
"'arcanesoft.seo.metas'",
")",
")",
";",
"Seo",
"::",
"setConfig",
"(",
"'redirects'",
",",
"config",
"(",
"'arcanesoft.seo.redirects'",
")",
")",
";",
"Seo",
"::",
"setConfig",
"(",
"'redirector.default'",
",",
"'eloquent'",
")",
";",
"Relation",
"::",
"morphMap",
"(",
"config",
"(",
"'arcanesoft.seo.morph-map'",
")",
")",
";",
"}",
")",
";",
"}"
] | Register Laravel Seo package. | [
"Register",
"Laravel",
"Seo",
"package",
"."
] | ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2 | https://github.com/ARCANESOFT/SEO/blob/ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2/src/Providers/PackagesServiceProvider.php#L41-L53 | train |
lasallecms/lasallecms-l5-mailgun-pkg | src/Processing/Validation.php | Validation.verifyWebhookSignature | public function verifyWebhookSignature() {
$timestamp = $this->request->input('timestamp');
$token = $this->request->input('token');
$signature = $this->request->input('signature');
// The Mailgun config param is an array, so grab the full array
$configMailgun = config('services.mailgun');
$hmac = hash_hmac('sha256', $timestamp. $token, $configMailgun['secret']);
if(function_exists('hash_equals')) {
// hash_equals is constant time, but will not be introduced until PHP 5.6
return hash_equals($hmac, $signature);
}
return ($hmac == $signature);
} | php | public function verifyWebhookSignature() {
$timestamp = $this->request->input('timestamp');
$token = $this->request->input('token');
$signature = $this->request->input('signature');
// The Mailgun config param is an array, so grab the full array
$configMailgun = config('services.mailgun');
$hmac = hash_hmac('sha256', $timestamp. $token, $configMailgun['secret']);
if(function_exists('hash_equals')) {
// hash_equals is constant time, but will not be introduced until PHP 5.6
return hash_equals($hmac, $signature);
}
return ($hmac == $signature);
} | [
"public",
"function",
"verifyWebhookSignature",
"(",
")",
"{",
"$",
"timestamp",
"=",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"'timestamp'",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"'token'",
")",
";",
"$",
"signature",
"=",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"'signature'",
")",
";",
"// The Mailgun config param is an array, so grab the full array",
"$",
"configMailgun",
"=",
"config",
"(",
"'services.mailgun'",
")",
";",
"$",
"hmac",
"=",
"hash_hmac",
"(",
"'sha256'",
",",
"$",
"timestamp",
".",
"$",
"token",
",",
"$",
"configMailgun",
"[",
"'secret'",
"]",
")",
";",
"if",
"(",
"function_exists",
"(",
"'hash_equals'",
")",
")",
"{",
"// hash_equals is constant time, but will not be introduced until PHP 5.6",
"return",
"hash_equals",
"(",
"$",
"hmac",
",",
"$",
"signature",
")",
";",
"}",
"return",
"(",
"$",
"hmac",
"==",
"$",
"signature",
")",
";",
"}"
] | Ensure the authenticity of inbound Mailgun request
https://documentation.mailgun.com/user_manual.html#webhooks
https://github.com/mailgun/mailgun-php/blob/master/src/Mailgun/Mailgun.php
http://php.net/manual/en/function.hash-hmac.php
@param timestamp $timestamp Mailgun's timestamp in the POST request
@param string $token Mailguns's token in the POST request
@paraam string $signature Mailgun's signature in the POST request
@return bool | [
"Ensure",
"the",
"authenticity",
"of",
"inbound",
"Mailgun",
"request"
] | f6c1fb92211b2537db87a1f03c126dc46691ee5e | https://github.com/lasallecms/lasallecms-l5-mailgun-pkg/blob/f6c1fb92211b2537db87a1f03c126dc46691ee5e/src/Processing/Validation.php#L80-L99 | train |
lasallecms/lasallecms-l5-mailgun-pkg | src/Processing/Validation.php | Validation.isInboundEmailToEmailAddressMapToUser | public function isInboundEmailToEmailAddressMapToUser() {
// We map an inbound Mailgun route to a record in the "users" table, by email address
$mappedRoutes = config('lasallecmsmailgun.inbound_map_mailgun_routes_with_user_email_address');
foreach ($mappedRoutes as $route => $user) {
// if "from" email address is the same as the route specified in the config...
if ($this->request->input('recipient') == $route) {
return true;
}
}
return false;
} | php | public function isInboundEmailToEmailAddressMapToUser() {
// We map an inbound Mailgun route to a record in the "users" table, by email address
$mappedRoutes = config('lasallecmsmailgun.inbound_map_mailgun_routes_with_user_email_address');
foreach ($mappedRoutes as $route => $user) {
// if "from" email address is the same as the route specified in the config...
if ($this->request->input('recipient') == $route) {
return true;
}
}
return false;
} | [
"public",
"function",
"isInboundEmailToEmailAddressMapToUser",
"(",
")",
"{",
"// We map an inbound Mailgun route to a record in the \"users\" table, by email address",
"$",
"mappedRoutes",
"=",
"config",
"(",
"'lasallecmsmailgun.inbound_map_mailgun_routes_with_user_email_address'",
")",
";",
"foreach",
"(",
"$",
"mappedRoutes",
"as",
"$",
"route",
"=>",
"$",
"user",
")",
"{",
"// if \"from\" email address is the same as the route specified in the config...",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"'recipient'",
")",
"==",
"$",
"route",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Does the recipient's email address map to an email address in the "users" database table?
@return bool | [
"Does",
"the",
"recipient",
"s",
"email",
"address",
"map",
"to",
"an",
"email",
"address",
"in",
"the",
"users",
"database",
"table?"
] | f6c1fb92211b2537db87a1f03c126dc46691ee5e | https://github.com/lasallecms/lasallecms-l5-mailgun-pkg/blob/f6c1fb92211b2537db87a1f03c126dc46691ee5e/src/Processing/Validation.php#L106-L120 | train |
lasallecms/lasallecms-l5-mailgun-pkg | src/Processing/Validation.php | Validation.isMappedUserExistInUsersTable | public function isMappedUserExistInUsersTable() {
// get the mapped recipient (valid because $this->isInboundEmailToEmailAddressMapToUser() is already done)
$mappedRoutes = config('lasallecmsmailgun.inbound_map_mailgun_routes_with_user_email_address');
foreach ($mappedRoutes as $route => $user) {
// if "from" email address is the same as the route specified in the config...
if ($this->request->input('recipient') == $route) {
$userEmailAddress = $user;
}
}
if ($this->userRepository->findUserIdByEmail($userEmailAddress)) {
return true;
}
return false;
} | php | public function isMappedUserExistInUsersTable() {
// get the mapped recipient (valid because $this->isInboundEmailToEmailAddressMapToUser() is already done)
$mappedRoutes = config('lasallecmsmailgun.inbound_map_mailgun_routes_with_user_email_address');
foreach ($mappedRoutes as $route => $user) {
// if "from" email address is the same as the route specified in the config...
if ($this->request->input('recipient') == $route) {
$userEmailAddress = $user;
}
}
if ($this->userRepository->findUserIdByEmail($userEmailAddress)) {
return true;
}
return false;
} | [
"public",
"function",
"isMappedUserExistInUsersTable",
"(",
")",
"{",
"// get the mapped recipient (valid because $this->isInboundEmailToEmailAddressMapToUser() is already done)",
"$",
"mappedRoutes",
"=",
"config",
"(",
"'lasallecmsmailgun.inbound_map_mailgun_routes_with_user_email_address'",
")",
";",
"foreach",
"(",
"$",
"mappedRoutes",
"as",
"$",
"route",
"=>",
"$",
"user",
")",
"{",
"// if \"from\" email address is the same as the route specified in the config...",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"'recipient'",
")",
"==",
"$",
"route",
")",
"{",
"$",
"userEmailAddress",
"=",
"$",
"user",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"userRepository",
"->",
"findUserIdByEmail",
"(",
"$",
"userEmailAddress",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Does the mapped user actually exist in the "users" db table?
@return bool | [
"Does",
"the",
"mapped",
"user",
"actually",
"exist",
"in",
"the",
"users",
"db",
"table?"
] | f6c1fb92211b2537db87a1f03c126dc46691ee5e | https://github.com/lasallecms/lasallecms-l5-mailgun-pkg/blob/f6c1fb92211b2537db87a1f03c126dc46691ee5e/src/Processing/Validation.php#L127-L145 | train |
Xsaven/laravel-intelect-admin | src/Addons/GoogleTranslate/TranslateClient.php | TranslateClient.staticTranslate | private static function staticTranslate($source, $target, $string)
{
self::checkStaticInstance();
try {
$result = self::$staticInstance
->setSource($source)
->setTarget($target)
->translate($string);
} catch (Exception $e) {
throw $e;
}
return $result;
} | php | private static function staticTranslate($source, $target, $string)
{
self::checkStaticInstance();
try {
$result = self::$staticInstance
->setSource($source)
->setTarget($target)
->translate($string);
} catch (Exception $e) {
throw $e;
}
return $result;
} | [
"private",
"static",
"function",
"staticTranslate",
"(",
"$",
"source",
",",
"$",
"target",
",",
"$",
"string",
")",
"{",
"self",
"::",
"checkStaticInstance",
"(",
")",
";",
"try",
"{",
"$",
"result",
"=",
"self",
"::",
"$",
"staticInstance",
"->",
"setSource",
"(",
"$",
"source",
")",
"->",
"setTarget",
"(",
"$",
"target",
")",
"->",
"translate",
"(",
"$",
"string",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Translate text statically.
This can be called from static method translate() using __callStatic() magic method.
Use TranslateClient::translate($source, $target, $string) instead.
@param string $source Source language
@param string $target Target language
@param string $string Text to translate
@throws InvalidArgumentException If the provided argument is not of type 'string'
@throws ErrorException If the HTTP request fails
@throws UnexpectedValueException If received data cannot be decoded
@return string|bool Translated text | [
"Translate",
"text",
"statically",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/GoogleTranslate/TranslateClient.php#L437-L450 | train |
InnovaLangues/LexiconBundle | Entity/Inflection.php | Inflection.setLemma | public function setLemma(\Innova\LexiconBundle\Entity\Lemma $lemma = null)
{
$this->lemma = $lemma;
return $this;
} | php | public function setLemma(\Innova\LexiconBundle\Entity\Lemma $lemma = null)
{
$this->lemma = $lemma;
return $this;
} | [
"public",
"function",
"setLemma",
"(",
"\\",
"Innova",
"\\",
"LexiconBundle",
"\\",
"Entity",
"\\",
"Lemma",
"$",
"lemma",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"lemma",
"=",
"$",
"lemma",
";",
"return",
"$",
"this",
";",
"}"
] | Set lemma.
@param \Innova\LexiconBundle\Entity\Lemma $lemma
@return Inflection | [
"Set",
"lemma",
"."
] | 38684b8a6c9f4636c7eb4d97f793844c2f703cb7 | https://github.com/InnovaLangues/LexiconBundle/blob/38684b8a6c9f4636c7eb4d97f793844c2f703cb7/Entity/Inflection.php#L180-L185 | train |
InnovaLangues/LexiconBundle | Entity/Inflection.php | Inflection.setNumber | public function setNumber(\Innova\LexiconBundle\Entity\Number $number = null)
{
$this->number = $number;
return $this;
} | php | public function setNumber(\Innova\LexiconBundle\Entity\Number $number = null)
{
$this->number = $number;
return $this;
} | [
"public",
"function",
"setNumber",
"(",
"\\",
"Innova",
"\\",
"LexiconBundle",
"\\",
"Entity",
"\\",
"Number",
"$",
"number",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"number",
"=",
"$",
"number",
";",
"return",
"$",
"this",
";",
"}"
] | Set number.
@param \Innova\LexiconBundle\Entity\Number $number
@return Inflection | [
"Set",
"number",
"."
] | 38684b8a6c9f4636c7eb4d97f793844c2f703cb7 | https://github.com/InnovaLangues/LexiconBundle/blob/38684b8a6c9f4636c7eb4d97f793844c2f703cb7/Entity/Inflection.php#L204-L209 | train |
InnovaLangues/LexiconBundle | Entity/Inflection.php | Inflection.setGender | public function setGender(\Innova\LexiconBundle\Entity\Gender $gender = null)
{
$this->gender = $gender;
return $this;
} | php | public function setGender(\Innova\LexiconBundle\Entity\Gender $gender = null)
{
$this->gender = $gender;
return $this;
} | [
"public",
"function",
"setGender",
"(",
"\\",
"Innova",
"\\",
"LexiconBundle",
"\\",
"Entity",
"\\",
"Gender",
"$",
"gender",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"gender",
"=",
"$",
"gender",
";",
"return",
"$",
"this",
";",
"}"
] | Set gender.
@param \Innova\LexiconBundle\Entity\Gender $gender
@return Inflection | [
"Set",
"gender",
"."
] | 38684b8a6c9f4636c7eb4d97f793844c2f703cb7 | https://github.com/InnovaLangues/LexiconBundle/blob/38684b8a6c9f4636c7eb4d97f793844c2f703cb7/Entity/Inflection.php#L228-L233 | train |
InnovaLangues/LexiconBundle | Entity/Inflection.php | Inflection.setTense | public function setTense(\Innova\LexiconBundle\Entity\Tense $tense = null)
{
$this->tense = $tense;
return $this;
} | php | public function setTense(\Innova\LexiconBundle\Entity\Tense $tense = null)
{
$this->tense = $tense;
return $this;
} | [
"public",
"function",
"setTense",
"(",
"\\",
"Innova",
"\\",
"LexiconBundle",
"\\",
"Entity",
"\\",
"Tense",
"$",
"tense",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"tense",
"=",
"$",
"tense",
";",
"return",
"$",
"this",
";",
"}"
] | Set tense.
@param \Innova\LexiconBundle\Entity\Tense $tense
@return Inflection | [
"Set",
"tense",
"."
] | 38684b8a6c9f4636c7eb4d97f793844c2f703cb7 | https://github.com/InnovaLangues/LexiconBundle/blob/38684b8a6c9f4636c7eb4d97f793844c2f703cb7/Entity/Inflection.php#L252-L257 | train |
InnovaLangues/LexiconBundle | Entity/Inflection.php | Inflection.setPerson | public function setPerson(\Innova\LexiconBundle\Entity\Person $person = null)
{
$this->person = $person;
return $this;
} | php | public function setPerson(\Innova\LexiconBundle\Entity\Person $person = null)
{
$this->person = $person;
return $this;
} | [
"public",
"function",
"setPerson",
"(",
"\\",
"Innova",
"\\",
"LexiconBundle",
"\\",
"Entity",
"\\",
"Person",
"$",
"person",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"person",
"=",
"$",
"person",
";",
"return",
"$",
"this",
";",
"}"
] | Set person.
@param \Innova\LexiconBundle\Entity\Person $person
@return Inflection | [
"Set",
"person",
"."
] | 38684b8a6c9f4636c7eb4d97f793844c2f703cb7 | https://github.com/InnovaLangues/LexiconBundle/blob/38684b8a6c9f4636c7eb4d97f793844c2f703cb7/Entity/Inflection.php#L276-L281 | train |
InnovaLangues/LexiconBundle | Entity/Inflection.php | Inflection.setMood | public function setMood(\Innova\LexiconBundle\Entity\Mood $mood = null)
{
$this->mood = $mood;
return $this;
} | php | public function setMood(\Innova\LexiconBundle\Entity\Mood $mood = null)
{
$this->mood = $mood;
return $this;
} | [
"public",
"function",
"setMood",
"(",
"\\",
"Innova",
"\\",
"LexiconBundle",
"\\",
"Entity",
"\\",
"Mood",
"$",
"mood",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"mood",
"=",
"$",
"mood",
";",
"return",
"$",
"this",
";",
"}"
] | Set mood.
@param \Innova\LexiconBundle\Entity\Mood $mood
@return Inflection | [
"Set",
"mood",
"."
] | 38684b8a6c9f4636c7eb4d97f793844c2f703cb7 | https://github.com/InnovaLangues/LexiconBundle/blob/38684b8a6c9f4636c7eb4d97f793844c2f703cb7/Entity/Inflection.php#L300-L305 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/JSONUtils.php | JSONUtils.decode | public static function decode($string, $returnArrays = false)
{
$result = json_decode($string, $returnArrays);
if (function_exists('json_last_error')) {
switch (json_last_error()) {
case JSON_ERROR_NONE:
return $result;
case JSON_ERROR_DEPTH:
throw new JSONException('json_decode - Maximum stack depth exceeded');
case JSON_ERROR_CTRL_CHAR:
throw new JSONException('json_decode - Unexpected control character found');
case JSON_ERROR_SYNTAX:
throw new JSONException('json_decode - Syntax error, malformed JSON');
default:
throw new JSONException('Invalid JSON');
}
} elseif ($result === null) {
throw new JSONException('Invalid JSON');
}
return $result;
} | php | public static function decode($string, $returnArrays = false)
{
$result = json_decode($string, $returnArrays);
if (function_exists('json_last_error')) {
switch (json_last_error()) {
case JSON_ERROR_NONE:
return $result;
case JSON_ERROR_DEPTH:
throw new JSONException('json_decode - Maximum stack depth exceeded');
case JSON_ERROR_CTRL_CHAR:
throw new JSONException('json_decode - Unexpected control character found');
case JSON_ERROR_SYNTAX:
throw new JSONException('json_decode - Syntax error, malformed JSON');
default:
throw new JSONException('Invalid JSON');
}
} elseif ($result === null) {
throw new JSONException('Invalid JSON');
}
return $result;
} | [
"public",
"static",
"function",
"decode",
"(",
"$",
"string",
",",
"$",
"returnArrays",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"string",
",",
"$",
"returnArrays",
")",
";",
"if",
"(",
"function_exists",
"(",
"'json_last_error'",
")",
")",
"{",
"switch",
"(",
"json_last_error",
"(",
")",
")",
"{",
"case",
"JSON_ERROR_NONE",
":",
"return",
"$",
"result",
";",
"case",
"JSON_ERROR_DEPTH",
":",
"throw",
"new",
"JSONException",
"(",
"'json_decode - Maximum stack depth exceeded'",
")",
";",
"case",
"JSON_ERROR_CTRL_CHAR",
":",
"throw",
"new",
"JSONException",
"(",
"'json_decode - Unexpected control character found'",
")",
";",
"case",
"JSON_ERROR_SYNTAX",
":",
"throw",
"new",
"JSONException",
"(",
"'json_decode - Syntax error, malformed JSON'",
")",
";",
"default",
":",
"throw",
"new",
"JSONException",
"(",
"'Invalid JSON'",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"result",
"===",
"null",
")",
"{",
"throw",
"new",
"JSONException",
"(",
"'Invalid JSON'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Performs a JSON decode of the string
@param string $string The json string being decoded.
@param boolean $returnArrays When TRUE, returned objects will be converted into associative arrays.
@throws Exception When a json error occurs
@return mixed | [
"Performs",
"a",
"JSON",
"decode",
"of",
"the",
"string"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/JSONUtils.php#L54-L80 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/JSONUtils.php | JSONUtils.encode | public static function encode($obj, $pretty = false, $html = false)
{
$s = json_encode($obj);
if ($pretty) {
return self::format($s, $html);
}
return $s;
} | php | public static function encode($obj, $pretty = false, $html = false)
{
$s = json_encode($obj);
if ($pretty) {
return self::format($s, $html);
}
return $s;
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"obj",
",",
"$",
"pretty",
"=",
"false",
",",
"$",
"html",
"=",
"false",
")",
"{",
"$",
"s",
"=",
"json_encode",
"(",
"$",
"obj",
")",
";",
"if",
"(",
"$",
"pretty",
")",
"{",
"return",
"self",
"::",
"format",
"(",
"$",
"s",
",",
"$",
"html",
")",
";",
"}",
"return",
"$",
"s",
";",
"}"
] | Encodes the object in json
@param mixed $obj The object to encode
@param boolean $pretty When TRUE, the output is "pretty" with proper indentation
@param boolean $html If true, return the JSON in a format suitable for display in a web browser
Default: false
@return string | [
"Encodes",
"the",
"object",
"in",
"json"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/JSONUtils.php#L92-L101 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/JSONUtils.php | JSONUtils.format | public static function format($json, $html = false)
{
$format = str_replace(
[
' ',
'\/',
], [
' ',
'/',
], json_encode(
json_decode(
str_replace(
[
"\n",
' ',
', }',
', ]',
',}',
',]',
],
[
'',
'',
'}',
'}',
'}',
']',
],
$json
)
),
JSON_PRETTY_PRINT
)
);
if ($html) {
return str_replace("\n", '<br/>', $format);
}
return $format;
} | php | public static function format($json, $html = false)
{
$format = str_replace(
[
' ',
'\/',
], [
' ',
'/',
], json_encode(
json_decode(
str_replace(
[
"\n",
' ',
', }',
', ]',
',}',
',]',
],
[
'',
'',
'}',
'}',
'}',
']',
],
$json
)
),
JSON_PRETTY_PRINT
)
);
if ($html) {
return str_replace("\n", '<br/>', $format);
}
return $format;
} | [
"public",
"static",
"function",
"format",
"(",
"$",
"json",
",",
"$",
"html",
"=",
"false",
")",
"{",
"$",
"format",
"=",
"str_replace",
"(",
"[",
"' '",
",",
"'\\/'",
",",
"]",
",",
"[",
"' '",
",",
"'/'",
",",
"]",
",",
"json_encode",
"(",
"json_decode",
"(",
"str_replace",
"(",
"[",
"\"\\n\"",
",",
"' '",
",",
"', }'",
",",
"', ]'",
",",
"',}'",
",",
"',]'",
",",
"]",
",",
"[",
"''",
",",
"''",
",",
"'}'",
",",
"'}'",
",",
"'}'",
",",
"']'",
",",
"]",
",",
"$",
"json",
")",
")",
",",
"JSON_PRETTY_PRINT",
")",
")",
";",
"if",
"(",
"$",
"html",
")",
"{",
"return",
"str_replace",
"(",
"\"\\n\"",
",",
"'<br/>'",
",",
"$",
"format",
")",
";",
"}",
"return",
"$",
"format",
";",
"}"
] | Indents a flat JSON string to make it more human-readable
Use php function JSON_PRETTY_PRINT. Require php >= 5.4
@param string $json The original JSON string to process
@param boolean $html If true, return the JSON in a format suitable for display in a web browser
Default: false
@return string Indented version of the original JSON string | [
"Indents",
"a",
"flat",
"JSON",
"string",
"to",
"make",
"it",
"more",
"human",
"-",
"readable",
"Use",
"php",
"function",
"JSON_PRETTY_PRINT",
".",
"Require",
"php",
">",
"=",
"5",
".",
"4"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/JSONUtils.php#L118-L158 | train |
Polosa/shade-framework-core | app/Router.php | Router.isRequestedUrlClean | public function isRequestedUrlClean(Request\Web $request)
{
$server = $request->getServer();
if (!isset($server['REQUEST_URI'])) {
throw new Exception('REQUEST_URI is not set');
}
return strpos($server['REQUEST_URI'], $this->entryPoint) !== 0;
} | php | public function isRequestedUrlClean(Request\Web $request)
{
$server = $request->getServer();
if (!isset($server['REQUEST_URI'])) {
throw new Exception('REQUEST_URI is not set');
}
return strpos($server['REQUEST_URI'], $this->entryPoint) !== 0;
} | [
"public",
"function",
"isRequestedUrlClean",
"(",
"Request",
"\\",
"Web",
"$",
"request",
")",
"{",
"$",
"server",
"=",
"$",
"request",
"->",
"getServer",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"server",
"[",
"'REQUEST_URI'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'REQUEST_URI is not set'",
")",
";",
"}",
"return",
"strpos",
"(",
"$",
"server",
"[",
"'REQUEST_URI'",
"]",
",",
"$",
"this",
"->",
"entryPoint",
")",
"!==",
"0",
";",
"}"
] | Check that requested URL is clean
@param \Shade\Request\Web $request Request
@throws \Shade\Exception
@return bool | [
"Check",
"that",
"requested",
"URL",
"is",
"clean"
] | d735d3e8e0616fb9cf4ffc25b8425762ed07940f | https://github.com/Polosa/shade-framework-core/blob/d735d3e8e0616fb9cf4ffc25b8425762ed07940f/app/Router.php#L146-L154 | train |
Polosa/shade-framework-core | app/Router.php | Router.validateRouteMapping | protected function validateRouteMapping(Route\Mapping $mapping)
{
if (!class_exists($mapping->controller())) {
throw new Exception("Controller '{$mapping->controller()}' not found");
}
if (!method_exists($mapping->controller(), $mapping->action())) {
throw new Exception("Action '{$mapping->action()}' does not exist in controller '{$mapping->controller()}'");
}
} | php | protected function validateRouteMapping(Route\Mapping $mapping)
{
if (!class_exists($mapping->controller())) {
throw new Exception("Controller '{$mapping->controller()}' not found");
}
if (!method_exists($mapping->controller(), $mapping->action())) {
throw new Exception("Action '{$mapping->action()}' does not exist in controller '{$mapping->controller()}'");
}
} | [
"protected",
"function",
"validateRouteMapping",
"(",
"Route",
"\\",
"Mapping",
"$",
"mapping",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"mapping",
"->",
"controller",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Controller '{$mapping->controller()}' not found\"",
")",
";",
"}",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"mapping",
"->",
"controller",
"(",
")",
",",
"$",
"mapping",
"->",
"action",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Action '{$mapping->action()}' does not exist in controller '{$mapping->controller()}'\"",
")",
";",
"}",
"}"
] | Validate Route Mapping
@param \Shade\Route\Mapping $mapping Route Mapping
@throws \Shade\Exception | [
"Validate",
"Route",
"Mapping"
] | d735d3e8e0616fb9cf4ffc25b8425762ed07940f | https://github.com/Polosa/shade-framework-core/blob/d735d3e8e0616fb9cf4ffc25b8425762ed07940f/app/Router.php#L189-L198 | train |
bseddon/XPath20 | Value/TimeValue.php | TimeValue.TimezoneToInterval | public function TimezoneToInterval()
{
// Get the timezone
$timezone = $this->Value->getTimezone()->getName();
// No deviation returns an empty sequence
if ( $timezone == "Z" || $timezone == "+00:00" || $timezone == date_default_timezone_get() )
{
return DayTimeDurationValue::Parse( "PT0S" );
// /MinimalConformance/Functions/DurationDateTimeFunc/ComponentExtractionDDT
// K-TimezoneFromDateFunc-7
// return Undefined::getValue();
}
// Create an interval string
if ( ! preg_match( "/(?<sign>[+-])(?<hours>\d{2,2}):(?<minutes>\d{2,2})/", $timezone, $matches ) )
{
return Undefined::getValue();
}
$invert = $matches['sign'] == '-' ? '-' : '';
return DayTimeDurationValue::Parse( "{$invert}PT{$matches['hours']}H{$matches['minutes']}M" );
} | php | public function TimezoneToInterval()
{
// Get the timezone
$timezone = $this->Value->getTimezone()->getName();
// No deviation returns an empty sequence
if ( $timezone == "Z" || $timezone == "+00:00" || $timezone == date_default_timezone_get() )
{
return DayTimeDurationValue::Parse( "PT0S" );
// /MinimalConformance/Functions/DurationDateTimeFunc/ComponentExtractionDDT
// K-TimezoneFromDateFunc-7
// return Undefined::getValue();
}
// Create an interval string
if ( ! preg_match( "/(?<sign>[+-])(?<hours>\d{2,2}):(?<minutes>\d{2,2})/", $timezone, $matches ) )
{
return Undefined::getValue();
}
$invert = $matches['sign'] == '-' ? '-' : '';
return DayTimeDurationValue::Parse( "{$invert}PT{$matches['hours']}H{$matches['minutes']}M" );
} | [
"public",
"function",
"TimezoneToInterval",
"(",
")",
"{",
"// Get the timezone\r",
"$",
"timezone",
"=",
"$",
"this",
"->",
"Value",
"->",
"getTimezone",
"(",
")",
"->",
"getName",
"(",
")",
";",
"// No deviation returns an empty sequence\r",
"if",
"(",
"$",
"timezone",
"==",
"\"Z\"",
"||",
"$",
"timezone",
"==",
"\"+00:00\"",
"||",
"$",
"timezone",
"==",
"date_default_timezone_get",
"(",
")",
")",
"{",
"return",
"DayTimeDurationValue",
"::",
"Parse",
"(",
"\"PT0S\"",
")",
";",
"// /MinimalConformance/Functions/DurationDateTimeFunc/ComponentExtractionDDT\r",
"// K-TimezoneFromDateFunc-7\r",
"// return Undefined::getValue();\r",
"}",
"// Create an interval string\r",
"if",
"(",
"!",
"preg_match",
"(",
"\"/(?<sign>[+-])(?<hours>\\d{2,2}):(?<minutes>\\d{2,2})/\"",
",",
"$",
"timezone",
",",
"$",
"matches",
")",
")",
"{",
"return",
"Undefined",
"::",
"getValue",
"(",
")",
";",
"}",
"$",
"invert",
"=",
"$",
"matches",
"[",
"'sign'",
"]",
"==",
"'-'",
"?",
"'-'",
":",
"''",
";",
"return",
"DayTimeDurationValue",
"::",
"Parse",
"(",
"\"{$invert}PT{$matches['hours']}H{$matches['minutes']}M\"",
")",
";",
"}"
] | Create a DayTimeDurationValue representation of the timezone offset
@return DayTimeDurationValue | [
"Create",
"a",
"DayTimeDurationValue",
"representation",
"of",
"the",
"timezone",
"offset"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/TimeValue.php#L159-L183 | train |
black-lamp/blcms-cart | frontend/components/user/controllers/SecurityController.php | SecurityController.actionLogin | public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
\Yii::$app->getResponse()->redirect(Url::to([\Yii::$app->getHomeUrl()]));
}
/** @var LoginForm $model */
$model = \Yii::createObject(LoginForm::className());
$event = $this->getFormEvent($model);
$this->performAjaxValidation($model);
$this->trigger(self::EVENT_BEFORE_LOGIN, $event);
if ($model->load(\Yii::$app->getRequest()->post()) && $model->login()) {
$this->trigger(self::EVENT_AFTER_LOGIN, $event);
//Checking return url
if (!empty($model->returnUrl)) {
$host = \Yii::$app->request->hostInfo;
$returnUrlHost = substr($model->returnUrl, 0, strlen($host));
if ($returnUrlHost == $host) {
$returnUrl = $model->returnUrl;
}
else {
$returnUrl = \Yii::$app->user->returnUrl;
}
}
else {
$returnUrl = Url::to([\Yii::$app->user->returnUrl]);
}
\Yii::$app->user->setReturnUrl($returnUrl);
return \Yii::$app->getResponse()->redirect($returnUrl);
}
return $this->render('login', [
'model' => $model,
'module' => $this->module,
]);
} | php | public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
\Yii::$app->getResponse()->redirect(Url::to([\Yii::$app->getHomeUrl()]));
}
/** @var LoginForm $model */
$model = \Yii::createObject(LoginForm::className());
$event = $this->getFormEvent($model);
$this->performAjaxValidation($model);
$this->trigger(self::EVENT_BEFORE_LOGIN, $event);
if ($model->load(\Yii::$app->getRequest()->post()) && $model->login()) {
$this->trigger(self::EVENT_AFTER_LOGIN, $event);
//Checking return url
if (!empty($model->returnUrl)) {
$host = \Yii::$app->request->hostInfo;
$returnUrlHost = substr($model->returnUrl, 0, strlen($host));
if ($returnUrlHost == $host) {
$returnUrl = $model->returnUrl;
}
else {
$returnUrl = \Yii::$app->user->returnUrl;
}
}
else {
$returnUrl = Url::to([\Yii::$app->user->returnUrl]);
}
\Yii::$app->user->setReturnUrl($returnUrl);
return \Yii::$app->getResponse()->redirect($returnUrl);
}
return $this->render('login', [
'model' => $model,
'module' => $this->module,
]);
} | [
"public",
"function",
"actionLogin",
"(",
")",
"{",
"if",
"(",
"!",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
"->",
"redirect",
"(",
"Url",
"::",
"to",
"(",
"[",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getHomeUrl",
"(",
")",
"]",
")",
")",
";",
"}",
"/** @var LoginForm $model */",
"$",
"model",
"=",
"\\",
"Yii",
"::",
"createObject",
"(",
"LoginForm",
"::",
"className",
"(",
")",
")",
";",
"$",
"event",
"=",
"$",
"this",
"->",
"getFormEvent",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"performAjaxValidation",
"(",
"$",
"model",
")",
";",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_BEFORE_LOGIN",
",",
"$",
"event",
")",
";",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"login",
"(",
")",
")",
"{",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_AFTER_LOGIN",
",",
"$",
"event",
")",
";",
"//Checking return url",
"if",
"(",
"!",
"empty",
"(",
"$",
"model",
"->",
"returnUrl",
")",
")",
"{",
"$",
"host",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"hostInfo",
";",
"$",
"returnUrlHost",
"=",
"substr",
"(",
"$",
"model",
"->",
"returnUrl",
",",
"0",
",",
"strlen",
"(",
"$",
"host",
")",
")",
";",
"if",
"(",
"$",
"returnUrlHost",
"==",
"$",
"host",
")",
"{",
"$",
"returnUrl",
"=",
"$",
"model",
"->",
"returnUrl",
";",
"}",
"else",
"{",
"$",
"returnUrl",
"=",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"returnUrl",
";",
"}",
"}",
"else",
"{",
"$",
"returnUrl",
"=",
"Url",
"::",
"to",
"(",
"[",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"returnUrl",
"]",
")",
";",
"}",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"setReturnUrl",
"(",
"$",
"returnUrl",
")",
";",
"return",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
"->",
"redirect",
"(",
"$",
"returnUrl",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'login'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"'module'",
"=>",
"$",
"this",
"->",
"module",
",",
"]",
")",
";",
"}"
] | Displays the login page.
@return string|Response | [
"Displays",
"the",
"login",
"page",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/frontend/components/user/controllers/SecurityController.php#L19-L59 | train |
black-lamp/blcms-cart | frontend/components/user/controllers/SecurityController.php | SecurityController.actionLogout | public function actionLogout()
{
$event = $this->getUserEvent(\Yii::$app->user->identity);
$this->trigger(self::EVENT_BEFORE_LOGOUT, $event);
\Yii::$app->getUser()->logout();
$this->trigger(self::EVENT_AFTER_LOGOUT, $event);
\Yii::$app->getResponse()->redirect(Url::to([\Yii::$app->getHomeUrl()]));
} | php | public function actionLogout()
{
$event = $this->getUserEvent(\Yii::$app->user->identity);
$this->trigger(self::EVENT_BEFORE_LOGOUT, $event);
\Yii::$app->getUser()->logout();
$this->trigger(self::EVENT_AFTER_LOGOUT, $event);
\Yii::$app->getResponse()->redirect(Url::to([\Yii::$app->getHomeUrl()]));
} | [
"public",
"function",
"actionLogout",
"(",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"getUserEvent",
"(",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"identity",
")",
";",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_BEFORE_LOGOUT",
",",
"$",
"event",
")",
";",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getUser",
"(",
")",
"->",
"logout",
"(",
")",
";",
"$",
"this",
"->",
"trigger",
"(",
"self",
"::",
"EVENT_AFTER_LOGOUT",
",",
"$",
"event",
")",
";",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getResponse",
"(",
")",
"->",
"redirect",
"(",
"Url",
"::",
"to",
"(",
"[",
"\\",
"Yii",
"::",
"$",
"app",
"->",
"getHomeUrl",
"(",
")",
"]",
")",
")",
";",
"}"
] | Logs the user out and then redirects to the homepage.
@return Response | [
"Logs",
"the",
"user",
"out",
"and",
"then",
"redirects",
"to",
"the",
"homepage",
"."
] | 314796eecae3ca4ed5fecfdc0231a738af50eba7 | https://github.com/black-lamp/blcms-cart/blob/314796eecae3ca4ed5fecfdc0231a738af50eba7/frontend/components/user/controllers/SecurityController.php#L66-L77 | train |
bheisig/cli | src/Command/Init.php | Init.askToSkip | protected function askToSkip() {
$question = 'This part is optional. Do you like to configure it? [y|N]:';
$answer = strtolower(IO::in($question));
switch ($answer) {
case 'yes':
case 'y':
case '1':
case 'true':
return false;
case 'no':
case 'n':
case '0':
case 'false':
case '':
return true;
default:
$this->log->warning('Excuse me, what do you mean?');
return $this->askToSkip();
}
} | php | protected function askToSkip() {
$question = 'This part is optional. Do you like to configure it? [y|N]:';
$answer = strtolower(IO::in($question));
switch ($answer) {
case 'yes':
case 'y':
case '1':
case 'true':
return false;
case 'no':
case 'n':
case '0':
case 'false':
case '':
return true;
default:
$this->log->warning('Excuse me, what do you mean?');
return $this->askToSkip();
}
} | [
"protected",
"function",
"askToSkip",
"(",
")",
"{",
"$",
"question",
"=",
"'This part is optional. Do you like to configure it? [y|N]:'",
";",
"$",
"answer",
"=",
"strtolower",
"(",
"IO",
"::",
"in",
"(",
"$",
"question",
")",
")",
";",
"switch",
"(",
"$",
"answer",
")",
"{",
"case",
"'yes'",
":",
"case",
"'y'",
":",
"case",
"'1'",
":",
"case",
"'true'",
":",
"return",
"false",
";",
"case",
"'no'",
":",
"case",
"'n'",
":",
"case",
"'0'",
":",
"case",
"'false'",
":",
"case",
"''",
":",
"return",
"true",
";",
"default",
":",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'Excuse me, what do you mean?'",
")",
";",
"return",
"$",
"this",
"->",
"askToSkip",
"(",
")",
";",
"}",
"}"
] | Ask to skip optional part
@return bool true means yes, skip it; false means no, configure it
@throws Exception on error | [
"Ask",
"to",
"skip",
"optional",
"part"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/Command/Init.php#L249-L270 | train |
bheisig/cli | src/Command/Init.php | Init.askForString | protected function askForString($key, $required = false, $default = null, array $values = [], $minLength = 0) {
$question = sprintf(
'What is the value for configuration setting "%s"',
$key
);
if (count($values) > 0) {
$question .= sprintf(
' (%s)',
implode(', ', $values)
);
}
$question .= '?';
if (isset($default)) {
$question .= sprintf(' [%s]:', $default);
}
$answer = IO::in($question);
if (strlen($answer) === 0 && $required && !isset($default)) {
$this->log->warning('This setting is required. You need to set a value.');
return $this->askForString($key, $required, $default, $values, $minLength);
} elseif (strlen($answer) === 0 && isset($default)) {
return $default;
} elseif (count($values) && !in_array($answer, $values)) {
$this->log->warning(
'Wrong answer. Here are your options: %s',
implode(', ', $values)
);
return $this->askForString($key, $required, $default, $values, $minLength);
} elseif (strlen($answer) > 0 && strlen($answer) < $minLength) {
$this->log->warning(
'Value must have at least %s character(s)',
$minLength
);
return $this->askForString($key, $required, $default, $values, $minLength);
} elseif (strlen($answer) > 0) {
return $answer;
}
return null;
} | php | protected function askForString($key, $required = false, $default = null, array $values = [], $minLength = 0) {
$question = sprintf(
'What is the value for configuration setting "%s"',
$key
);
if (count($values) > 0) {
$question .= sprintf(
' (%s)',
implode(', ', $values)
);
}
$question .= '?';
if (isset($default)) {
$question .= sprintf(' [%s]:', $default);
}
$answer = IO::in($question);
if (strlen($answer) === 0 && $required && !isset($default)) {
$this->log->warning('This setting is required. You need to set a value.');
return $this->askForString($key, $required, $default, $values, $minLength);
} elseif (strlen($answer) === 0 && isset($default)) {
return $default;
} elseif (count($values) && !in_array($answer, $values)) {
$this->log->warning(
'Wrong answer. Here are your options: %s',
implode(', ', $values)
);
return $this->askForString($key, $required, $default, $values, $minLength);
} elseif (strlen($answer) > 0 && strlen($answer) < $minLength) {
$this->log->warning(
'Value must have at least %s character(s)',
$minLength
);
return $this->askForString($key, $required, $default, $values, $minLength);
} elseif (strlen($answer) > 0) {
return $answer;
}
return null;
} | [
"protected",
"function",
"askForString",
"(",
"$",
"key",
",",
"$",
"required",
"=",
"false",
",",
"$",
"default",
"=",
"null",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"$",
"minLength",
"=",
"0",
")",
"{",
"$",
"question",
"=",
"sprintf",
"(",
"'What is the value for configuration setting \"%s\"'",
",",
"$",
"key",
")",
";",
"if",
"(",
"count",
"(",
"$",
"values",
")",
">",
"0",
")",
"{",
"$",
"question",
".=",
"sprintf",
"(",
"' (%s)'",
",",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
")",
";",
"}",
"$",
"question",
".=",
"'?'",
";",
"if",
"(",
"isset",
"(",
"$",
"default",
")",
")",
"{",
"$",
"question",
".=",
"sprintf",
"(",
"' [%s]:'",
",",
"$",
"default",
")",
";",
"}",
"$",
"answer",
"=",
"IO",
"::",
"in",
"(",
"$",
"question",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"answer",
")",
"===",
"0",
"&&",
"$",
"required",
"&&",
"!",
"isset",
"(",
"$",
"default",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'This setting is required. You need to set a value.'",
")",
";",
"return",
"$",
"this",
"->",
"askForString",
"(",
"$",
"key",
",",
"$",
"required",
",",
"$",
"default",
",",
"$",
"values",
",",
"$",
"minLength",
")",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"answer",
")",
"===",
"0",
"&&",
"isset",
"(",
"$",
"default",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"values",
")",
"&&",
"!",
"in_array",
"(",
"$",
"answer",
",",
"$",
"values",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'Wrong answer. Here are your options: %s'",
",",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
")",
";",
"return",
"$",
"this",
"->",
"askForString",
"(",
"$",
"key",
",",
"$",
"required",
",",
"$",
"default",
",",
"$",
"values",
",",
"$",
"minLength",
")",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"answer",
")",
">",
"0",
"&&",
"strlen",
"(",
"$",
"answer",
")",
"<",
"$",
"minLength",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'Value must have at least %s character(s)'",
",",
"$",
"minLength",
")",
";",
"return",
"$",
"this",
"->",
"askForString",
"(",
"$",
"key",
",",
"$",
"required",
",",
"$",
"default",
",",
"$",
"values",
",",
"$",
"minLength",
")",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"answer",
")",
">",
"0",
")",
"{",
"return",
"$",
"answer",
";",
"}",
"return",
"null",
";",
"}"
] | Ask user for a value which should be a string
@param string $key Setting
@param bool $required Is this setting required? Defaults to false (no, it isn't)
@param string $default Optional default value which will be used if user doesn't provide a value
@param array $values Optional possible values; no other values are accepted
@param int $minLength Optional minimum length of value
@return string|null Value or nothing
@throws Exception on error | [
"Ask",
"user",
"for",
"a",
"value",
"which",
"should",
"be",
"a",
"string"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/Command/Init.php#L285-L328 | train |
bheisig/cli | src/Command/Init.php | Init.askForBoolean | protected function askForBoolean($key, $required = false, $default = null) {
$question = sprintf(
'Enable configuration setting "%s"?',
$key
);
if (isset($default)) {
switch ($default) {
case true:
$question .= ' [Y|n]:';
break;
case false:
$question .= ' [y|N]:';
break;
}
}
$answer = strtolower(IO::in($question));
switch ($answer) {
case 'yes':
case 'y':
case '1':
case 'true':
return true;
case 'no':
case 'n':
case '0':
case 'false':
return false;
case '':
if (isset($default)) {
return $default;
} elseif ($required) {
$this->log->warning('Excuse me, what do you mean?');
return $this->askForBoolean($key, $required, $default);
}
break;
default:
if ($required) {
$this->log->warning('Excuse me, what do you mean?');
return $this->askForBoolean($key, $required, $default);
}
break;
}
return null;
} | php | protected function askForBoolean($key, $required = false, $default = null) {
$question = sprintf(
'Enable configuration setting "%s"?',
$key
);
if (isset($default)) {
switch ($default) {
case true:
$question .= ' [Y|n]:';
break;
case false:
$question .= ' [y|N]:';
break;
}
}
$answer = strtolower(IO::in($question));
switch ($answer) {
case 'yes':
case 'y':
case '1':
case 'true':
return true;
case 'no':
case 'n':
case '0':
case 'false':
return false;
case '':
if (isset($default)) {
return $default;
} elseif ($required) {
$this->log->warning('Excuse me, what do you mean?');
return $this->askForBoolean($key, $required, $default);
}
break;
default:
if ($required) {
$this->log->warning('Excuse me, what do you mean?');
return $this->askForBoolean($key, $required, $default);
}
break;
}
return null;
} | [
"protected",
"function",
"askForBoolean",
"(",
"$",
"key",
",",
"$",
"required",
"=",
"false",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"question",
"=",
"sprintf",
"(",
"'Enable configuration setting \"%s\"?'",
",",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"default",
")",
")",
"{",
"switch",
"(",
"$",
"default",
")",
"{",
"case",
"true",
":",
"$",
"question",
".=",
"' [Y|n]:'",
";",
"break",
";",
"case",
"false",
":",
"$",
"question",
".=",
"' [y|N]:'",
";",
"break",
";",
"}",
"}",
"$",
"answer",
"=",
"strtolower",
"(",
"IO",
"::",
"in",
"(",
"$",
"question",
")",
")",
";",
"switch",
"(",
"$",
"answer",
")",
"{",
"case",
"'yes'",
":",
"case",
"'y'",
":",
"case",
"'1'",
":",
"case",
"'true'",
":",
"return",
"true",
";",
"case",
"'no'",
":",
"case",
"'n'",
":",
"case",
"'0'",
":",
"case",
"'false'",
":",
"return",
"false",
";",
"case",
"''",
":",
"if",
"(",
"isset",
"(",
"$",
"default",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"elseif",
"(",
"$",
"required",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'Excuse me, what do you mean?'",
")",
";",
"return",
"$",
"this",
"->",
"askForBoolean",
"(",
"$",
"key",
",",
"$",
"required",
",",
"$",
"default",
")",
";",
"}",
"break",
";",
"default",
":",
"if",
"(",
"$",
"required",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'Excuse me, what do you mean?'",
")",
";",
"return",
"$",
"this",
"->",
"askForBoolean",
"(",
"$",
"key",
",",
"$",
"required",
",",
"$",
"default",
")",
";",
"}",
"break",
";",
"}",
"return",
"null",
";",
"}"
] | Ask user for a value which should be a boolean
@param string $key Setting
@param bool $required Is this setting required? Defaults to false (no, it isn't)
@param bool $default Optional default value which will be used if user doesn't provide a value
@return bool|null Value or nothing
@throws Exception on error | [
"Ask",
"user",
"for",
"a",
"value",
"which",
"should",
"be",
"a",
"boolean"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/Command/Init.php#L399-L448 | train |
bheisig/cli | src/Command/Init.php | Init.askForMixed | protected function askForMixed($key, $required = false, $default = null, array $values = []) {
$question = sprintf(
'What is the value for configuration setting "%s"',
$key
);
$options = [];
if (count($values) > 0) {
foreach ($values as $value) {
switch (gettype($value)) {
case 'boolean':
$options[] = ($value) ? 'yes' : 'no';
break;
default:
$options[] = $value;
break;
}
}
$question .= sprintf(
' (%s)',
implode(', ', $options)
);
}
$question .= '?';
if (isset($default)) {
switch (gettype($default)) {
case 'boolean':
$question .= sprintf(' [%s]:', ($default) ? 'yes' : 'no');
break;
default:
$question .= sprintf(' [%s]:', $default);
break;
}
}
$answer = trim(IO::in($question));
switch ($answer) {
case 'yes':
case 'y':
case '1':
case 'true':
return true;
case 'no':
case 'n':
case '0':
case 'false':
return false;
case '':
if (isset($default)) {
return $default;
} elseif ($required) {
$this->log->warning('Excuse me, what do you mean?');
return $this->askForMixed($key, $required, $default, $values);
}
break;
default:
if (count($values) && !in_array($answer, $values)) {
$this->log->warning(
'Wrong answer. Here are your options: %s',
implode(', ', $options)
);
return $this->askForMixed($key, $required, $default, $values);
}
return $answer;
}
return null;
} | php | protected function askForMixed($key, $required = false, $default = null, array $values = []) {
$question = sprintf(
'What is the value for configuration setting "%s"',
$key
);
$options = [];
if (count($values) > 0) {
foreach ($values as $value) {
switch (gettype($value)) {
case 'boolean':
$options[] = ($value) ? 'yes' : 'no';
break;
default:
$options[] = $value;
break;
}
}
$question .= sprintf(
' (%s)',
implode(', ', $options)
);
}
$question .= '?';
if (isset($default)) {
switch (gettype($default)) {
case 'boolean':
$question .= sprintf(' [%s]:', ($default) ? 'yes' : 'no');
break;
default:
$question .= sprintf(' [%s]:', $default);
break;
}
}
$answer = trim(IO::in($question));
switch ($answer) {
case 'yes':
case 'y':
case '1':
case 'true':
return true;
case 'no':
case 'n':
case '0':
case 'false':
return false;
case '':
if (isset($default)) {
return $default;
} elseif ($required) {
$this->log->warning('Excuse me, what do you mean?');
return $this->askForMixed($key, $required, $default, $values);
}
break;
default:
if (count($values) && !in_array($answer, $values)) {
$this->log->warning(
'Wrong answer. Here are your options: %s',
implode(', ', $options)
);
return $this->askForMixed($key, $required, $default, $values);
}
return $answer;
}
return null;
} | [
"protected",
"function",
"askForMixed",
"(",
"$",
"key",
",",
"$",
"required",
"=",
"false",
",",
"$",
"default",
"=",
"null",
",",
"array",
"$",
"values",
"=",
"[",
"]",
")",
"{",
"$",
"question",
"=",
"sprintf",
"(",
"'What is the value for configuration setting \"%s\"'",
",",
"$",
"key",
")",
";",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"values",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"case",
"'boolean'",
":",
"$",
"options",
"[",
"]",
"=",
"(",
"$",
"value",
")",
"?",
"'yes'",
":",
"'no'",
";",
"break",
";",
"default",
":",
"$",
"options",
"[",
"]",
"=",
"$",
"value",
";",
"break",
";",
"}",
"}",
"$",
"question",
".=",
"sprintf",
"(",
"' (%s)'",
",",
"implode",
"(",
"', '",
",",
"$",
"options",
")",
")",
";",
"}",
"$",
"question",
".=",
"'?'",
";",
"if",
"(",
"isset",
"(",
"$",
"default",
")",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"default",
")",
")",
"{",
"case",
"'boolean'",
":",
"$",
"question",
".=",
"sprintf",
"(",
"' [%s]:'",
",",
"(",
"$",
"default",
")",
"?",
"'yes'",
":",
"'no'",
")",
";",
"break",
";",
"default",
":",
"$",
"question",
".=",
"sprintf",
"(",
"' [%s]:'",
",",
"$",
"default",
")",
";",
"break",
";",
"}",
"}",
"$",
"answer",
"=",
"trim",
"(",
"IO",
"::",
"in",
"(",
"$",
"question",
")",
")",
";",
"switch",
"(",
"$",
"answer",
")",
"{",
"case",
"'yes'",
":",
"case",
"'y'",
":",
"case",
"'1'",
":",
"case",
"'true'",
":",
"return",
"true",
";",
"case",
"'no'",
":",
"case",
"'n'",
":",
"case",
"'0'",
":",
"case",
"'false'",
":",
"return",
"false",
";",
"case",
"''",
":",
"if",
"(",
"isset",
"(",
"$",
"default",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"elseif",
"(",
"$",
"required",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'Excuse me, what do you mean?'",
")",
";",
"return",
"$",
"this",
"->",
"askForMixed",
"(",
"$",
"key",
",",
"$",
"required",
",",
"$",
"default",
",",
"$",
"values",
")",
";",
"}",
"break",
";",
"default",
":",
"if",
"(",
"count",
"(",
"$",
"values",
")",
"&&",
"!",
"in_array",
"(",
"$",
"answer",
",",
"$",
"values",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"warning",
"(",
"'Wrong answer. Here are your options: %s'",
",",
"implode",
"(",
"', '",
",",
"$",
"options",
")",
")",
";",
"return",
"$",
"this",
"->",
"askForMixed",
"(",
"$",
"key",
",",
"$",
"required",
",",
"$",
"default",
",",
"$",
"values",
")",
";",
"}",
"return",
"$",
"answer",
";",
"}",
"return",
"null",
";",
"}"
] | Ask user for a value, but the data type doesn't matter
@param string $key Setting
@param bool $required Is this setting required? Defaults to false (no, it isn't)
@param mixed $default Optional default value which will be used if user doesn't provide a value
@param array $values Optional possible values; no other values are accepted
@return bool|string|null Value or nothing
@throws Exception on error | [
"Ask",
"user",
"for",
"a",
"value",
"but",
"the",
"data",
"type",
"doesn",
"t",
"matter"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/Command/Init.php#L590-L665 | train |
Erebot/Module_TriggerRegistry | src/TriggerRegistry.php | TriggerRegistry.containsRecursive | protected function containsRecursive(&$array, &$value)
{
if (!is_array($array)) {
return false;
}
foreach ($array as $sub) {
if (is_string($sub) && !strcasecmp($sub, $value)) {
return true;
}
if (is_array($sub) && $this->containsRecursive($sub, $value)) {
return true;
}
}
return false;
} | php | protected function containsRecursive(&$array, &$value)
{
if (!is_array($array)) {
return false;
}
foreach ($array as $sub) {
if (is_string($sub) && !strcasecmp($sub, $value)) {
return true;
}
if (is_array($sub) && $this->containsRecursive($sub, $value)) {
return true;
}
}
return false;
} | [
"protected",
"function",
"containsRecursive",
"(",
"&",
"$",
"array",
",",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"array",
"as",
"$",
"sub",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"sub",
")",
"&&",
"!",
"strcasecmp",
"(",
"$",
"sub",
",",
"$",
"value",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"sub",
")",
"&&",
"$",
"this",
"->",
"containsRecursive",
"(",
"$",
"sub",
",",
"$",
"value",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks whether some array contains the given
data, in a recursive fashion.
\param array $array
Array to test.
\param mixed $value
Look for this specific value.
\retval bool
\b true if the given value is contained
in the passed array, \b false otherwise. | [
"Checks",
"whether",
"some",
"array",
"contains",
"the",
"given",
"data",
"in",
"a",
"recursive",
"fashion",
"."
] | 5b981d38ab8c5b6bd03e07deb3adad71303592a0 | https://github.com/Erebot/Module_TriggerRegistry/blob/5b981d38ab8c5b6bd03e07deb3adad71303592a0/src/TriggerRegistry.php#L115-L131 | train |
Erebot/Module_TriggerRegistry | src/TriggerRegistry.php | TriggerRegistry.registerTriggers | public function registerTriggers($triggers, $channel)
{
if (!is_array($triggers)) {
$triggers = array($triggers);
}
$fmt = $this->getFormatter(false);
$translator = $fmt->getTranslator();
if (!is_string($channel)) {
throw new \Erebot\InvalidValueException($fmt->_('Invalid channel'));
}
$scopes = array(
$channel => $translator->_(
'A trigger named "<var name="trigger"/>" '.
'has already been registered on channel <var name="chan"/>.'
),
self::MATCH_ANY => $translator->_(
'A trigger named "<var name="trigger"/>" '.
'has already been registered globally.'
),
);
foreach ($triggers as $trigger) {
foreach ($scopes as $scope => $error) {
if (isset($this->triggers[$scope])) {
if ($this->containsRecursive($this->triggers[$scope], $trigger)) {
$this->logger and $this->logger->info(
$fmt->render(
$error,
array(
'trigger' => $trigger,
'chan' => $channel,
)
)
);
return null;
}
}
}
}
$this->triggers[$channel][] = $triggers;
end($this->triggers[$channel]);
return $channel.' '.key($this->triggers[$channel]);
} | php | public function registerTriggers($triggers, $channel)
{
if (!is_array($triggers)) {
$triggers = array($triggers);
}
$fmt = $this->getFormatter(false);
$translator = $fmt->getTranslator();
if (!is_string($channel)) {
throw new \Erebot\InvalidValueException($fmt->_('Invalid channel'));
}
$scopes = array(
$channel => $translator->_(
'A trigger named "<var name="trigger"/>" '.
'has already been registered on channel <var name="chan"/>.'
),
self::MATCH_ANY => $translator->_(
'A trigger named "<var name="trigger"/>" '.
'has already been registered globally.'
),
);
foreach ($triggers as $trigger) {
foreach ($scopes as $scope => $error) {
if (isset($this->triggers[$scope])) {
if ($this->containsRecursive($this->triggers[$scope], $trigger)) {
$this->logger and $this->logger->info(
$fmt->render(
$error,
array(
'trigger' => $trigger,
'chan' => $channel,
)
)
);
return null;
}
}
}
}
$this->triggers[$channel][] = $triggers;
end($this->triggers[$channel]);
return $channel.' '.key($this->triggers[$channel]);
} | [
"public",
"function",
"registerTriggers",
"(",
"$",
"triggers",
",",
"$",
"channel",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"triggers",
")",
")",
"{",
"$",
"triggers",
"=",
"array",
"(",
"$",
"triggers",
")",
";",
"}",
"$",
"fmt",
"=",
"$",
"this",
"->",
"getFormatter",
"(",
"false",
")",
";",
"$",
"translator",
"=",
"$",
"fmt",
"->",
"getTranslator",
"(",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"channel",
")",
")",
"{",
"throw",
"new",
"\\",
"Erebot",
"\\",
"InvalidValueException",
"(",
"$",
"fmt",
"->",
"_",
"(",
"'Invalid channel'",
")",
")",
";",
"}",
"$",
"scopes",
"=",
"array",
"(",
"$",
"channel",
"=>",
"$",
"translator",
"->",
"_",
"(",
"'A trigger named \"<var name=\"trigger\"/>\" '",
".",
"'has already been registered on channel <var name=\"chan\"/>.'",
")",
",",
"self",
"::",
"MATCH_ANY",
"=>",
"$",
"translator",
"->",
"_",
"(",
"'A trigger named \"<var name=\"trigger\"/>\" '",
".",
"'has already been registered globally.'",
")",
",",
")",
";",
"foreach",
"(",
"$",
"triggers",
"as",
"$",
"trigger",
")",
"{",
"foreach",
"(",
"$",
"scopes",
"as",
"$",
"scope",
"=>",
"$",
"error",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"triggers",
"[",
"$",
"scope",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"containsRecursive",
"(",
"$",
"this",
"->",
"triggers",
"[",
"$",
"scope",
"]",
",",
"$",
"trigger",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"and",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"$",
"fmt",
"->",
"render",
"(",
"$",
"error",
",",
"array",
"(",
"'trigger'",
"=>",
"$",
"trigger",
",",
"'chan'",
"=>",
"$",
"channel",
",",
")",
")",
")",
";",
"return",
"null",
";",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"triggers",
"[",
"$",
"channel",
"]",
"[",
"]",
"=",
"$",
"triggers",
";",
"end",
"(",
"$",
"this",
"->",
"triggers",
"[",
"$",
"channel",
"]",
")",
";",
"return",
"$",
"channel",
".",
"' '",
".",
"key",
"(",
"$",
"this",
"->",
"triggers",
"[",
"$",
"channel",
"]",
")",
";",
"}"
] | Registers a series of triggers, either globally
or for a specific channel.
\param mixed $triggers
Either a single string or an array of strings
with the names of the triggers to register.
\param string $channel
Either the name of a specific IRC channel
the triggers should be registered for (eg. #Erebot),
or the constant Erebot::Module::TriggerRegistry::MATCH_ANY
to register them globally (for all channels).
\retval mixed
Either a string which acts as a key to later
unregister the triggers at a later time
(see Erebot::Module::TriggerRegistry::freeTriggers),
or \b null if the triggers could not be registered
(eg. because they conflict with other already
registered triggers).
\warning
Triggers should only contain alphanumeric characters
(characters from the range a-z or 0-9), should not
contain spaces or prefixes (eg. "!"), and are
case-insensitive. | [
"Registers",
"a",
"series",
"of",
"triggers",
"either",
"globally",
"or",
"for",
"a",
"specific",
"channel",
"."
] | 5b981d38ab8c5b6bd03e07deb3adad71303592a0 | https://github.com/Erebot/Module_TriggerRegistry/blob/5b981d38ab8c5b6bd03e07deb3adad71303592a0/src/TriggerRegistry.php#L161-L206 | train |
Erebot/Module_TriggerRegistry | src/TriggerRegistry.php | TriggerRegistry.getChanTriggers | public function getChanTriggers($channel)
{
if (!isset($this->triggers[$channel])) {
$fmt = $this->getFormatter(false);
throw new \Erebot\NotFoundException(
$fmt->_(
'No triggers found for channel "<var name="chan"/>"',
array('chan' => $channel)
)
);
}
return $this->triggers[$channel];
} | php | public function getChanTriggers($channel)
{
if (!isset($this->triggers[$channel])) {
$fmt = $this->getFormatter(false);
throw new \Erebot\NotFoundException(
$fmt->_(
'No triggers found for channel "<var name="chan"/>"',
array('chan' => $channel)
)
);
}
return $this->triggers[$channel];
} | [
"public",
"function",
"getChanTriggers",
"(",
"$",
"channel",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"triggers",
"[",
"$",
"channel",
"]",
")",
")",
"{",
"$",
"fmt",
"=",
"$",
"this",
"->",
"getFormatter",
"(",
"false",
")",
";",
"throw",
"new",
"\\",
"Erebot",
"\\",
"NotFoundException",
"(",
"$",
"fmt",
"->",
"_",
"(",
"'No triggers found for channel \"<var name=\"chan\"/>\"'",
",",
"array",
"(",
"'chan'",
"=>",
"$",
"channel",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"triggers",
"[",
"$",
"channel",
"]",
";",
"}"
] | Returns a list of all triggers
registered for a given channel.
\param string $channel
Either the name of a specific IRC channel
to return only those triggers that were
specifically registered for use in that channel,
or the constant Erebot::Module::TriggerRegistry::MATCH_ANY
to return triggers that were registered globally.
\retval array
A list of all triggers registered
for the given IRC channel. | [
"Returns",
"a",
"list",
"of",
"all",
"triggers",
"registered",
"for",
"a",
"given",
"channel",
"."
] | 5b981d38ab8c5b6bd03e07deb3adad71303592a0 | https://github.com/Erebot/Module_TriggerRegistry/blob/5b981d38ab8c5b6bd03e07deb3adad71303592a0/src/TriggerRegistry.php#L257-L270 | train |
Erebot/Module_TriggerRegistry | src/TriggerRegistry.php | TriggerRegistry.getTriggers | public function getTriggers($token)
{
$fmt = $this->getFormatter(false);
if (!is_string($token) || strpos($token, ' ') === false) {
throw new \Erebot\InvalidValueException($fmt->_('Invalid token'));
}
list($chan, $pos) = explode(' ', $token);
if (!isset($this->triggers[$chan][$pos])) {
throw new \Erebot\NotFoundException($fmt->_('No such triggers'));
}
return $this->triggers[$chan][$pos];
} | php | public function getTriggers($token)
{
$fmt = $this->getFormatter(false);
if (!is_string($token) || strpos($token, ' ') === false) {
throw new \Erebot\InvalidValueException($fmt->_('Invalid token'));
}
list($chan, $pos) = explode(' ', $token);
if (!isset($this->triggers[$chan][$pos])) {
throw new \Erebot\NotFoundException($fmt->_('No such triggers'));
}
return $this->triggers[$chan][$pos];
} | [
"public",
"function",
"getTriggers",
"(",
"$",
"token",
")",
"{",
"$",
"fmt",
"=",
"$",
"this",
"->",
"getFormatter",
"(",
"false",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"token",
")",
"||",
"strpos",
"(",
"$",
"token",
",",
"' '",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Erebot",
"\\",
"InvalidValueException",
"(",
"$",
"fmt",
"->",
"_",
"(",
"'Invalid token'",
")",
")",
";",
"}",
"list",
"(",
"$",
"chan",
",",
"$",
"pos",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"token",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"triggers",
"[",
"$",
"chan",
"]",
"[",
"$",
"pos",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Erebot",
"\\",
"NotFoundException",
"(",
"$",
"fmt",
"->",
"_",
"(",
"'No such triggers'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"triggers",
"[",
"$",
"chan",
"]",
"[",
"$",
"pos",
"]",
";",
"}"
] | Returns a list of all triggers
associated with the given key.
\param string $token
Some key associated with a series
of triggers.
\retval array
A list of all triggers associated
with the given key. | [
"Returns",
"a",
"list",
"of",
"all",
"triggers",
"associated",
"with",
"the",
"given",
"key",
"."
] | 5b981d38ab8c5b6bd03e07deb3adad71303592a0 | https://github.com/Erebot/Module_TriggerRegistry/blob/5b981d38ab8c5b6bd03e07deb3adad71303592a0/src/TriggerRegistry.php#L284-L299 | train |
jdmaymeow/cake-auth | src/Controller/ProfilesController.php | ProfilesController.my | public function my()
{
$profile = $this->Profiles->find()
->where([
'Profiles.user_id' => $this->Auth->user('id')
])->contain('Users')->first();
$this->set('profile', $profile);
$this->set('_serialize', ['profile']);
} | php | public function my()
{
$profile = $this->Profiles->find()
->where([
'Profiles.user_id' => $this->Auth->user('id')
])->contain('Users')->first();
$this->set('profile', $profile);
$this->set('_serialize', ['profile']);
} | [
"public",
"function",
"my",
"(",
")",
"{",
"$",
"profile",
"=",
"$",
"this",
"->",
"Profiles",
"->",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'Profiles.user_id'",
"=>",
"$",
"this",
"->",
"Auth",
"->",
"user",
"(",
"'id'",
")",
"]",
")",
"->",
"contain",
"(",
"'Users'",
")",
"->",
"first",
"(",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'profile'",
",",
"$",
"profile",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'_serialize'",
",",
"[",
"'profile'",
"]",
")",
";",
"}"
] | Shows current user profile | [
"Shows",
"current",
"user",
"profile"
] | e9b498fb28fa8b48c520d08341cfab8c2459afab | https://github.com/jdmaymeow/cake-auth/blob/e9b498fb28fa8b48c520d08341cfab8c2459afab/src/Controller/ProfilesController.php#L50-L59 | train |
bheisig/cli | src/Command/Command.php | Command.tearDown | public function tearDown() {
$seconds = time() - $this->start;
switch ($seconds) {
case 1:
$this->log->debug('This took 1 second.');
break;
default:
$this->log->debug('This took %s seconds.', $seconds);
break;
}
$prettifyUnit = function ($bytes) {
$unit = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
if ($bytes === 0) {
return '0 ' . $unit[0];
}
return @round(
$bytes / pow(
1024,
($i = (int) floor(log($bytes, 1024)))
),
2
) . ' ' . (isset($unit[$i]) ? $unit[$i] : 'B');
};
$this->log->debug(
'Memory peak usage: %s',
$prettifyUnit(memory_get_peak_usage(true))
);
if (time() >= mktime(0, 0, 0, 12, 24) &&
time() <= mktime(23, 59, 59, 12, 26)) {
$this->log->debug('Merry christmas!');
} elseif (time() >= mktime(0, 0, 0, 12, 31) &&
time() <= mktime(23, 59, 59, 1, 1)) {
$this->log->debug('Happy new year!');
} elseif (time() >= mktime(0, 0, 0, (int) date('n', easter_date()), (int) date('j', easter_date()) - 2) &&
time() <= mktime(23, 59, 59, (int) date('n', easter_date()), (int) date('j', easter_date()) + 1)) {
$this->log->debug('Happy easter!');
} else {
$this->log->debug('Have fun :)');
}
return $this;
} | php | public function tearDown() {
$seconds = time() - $this->start;
switch ($seconds) {
case 1:
$this->log->debug('This took 1 second.');
break;
default:
$this->log->debug('This took %s seconds.', $seconds);
break;
}
$prettifyUnit = function ($bytes) {
$unit = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
if ($bytes === 0) {
return '0 ' . $unit[0];
}
return @round(
$bytes / pow(
1024,
($i = (int) floor(log($bytes, 1024)))
),
2
) . ' ' . (isset($unit[$i]) ? $unit[$i] : 'B');
};
$this->log->debug(
'Memory peak usage: %s',
$prettifyUnit(memory_get_peak_usage(true))
);
if (time() >= mktime(0, 0, 0, 12, 24) &&
time() <= mktime(23, 59, 59, 12, 26)) {
$this->log->debug('Merry christmas!');
} elseif (time() >= mktime(0, 0, 0, 12, 31) &&
time() <= mktime(23, 59, 59, 1, 1)) {
$this->log->debug('Happy new year!');
} elseif (time() >= mktime(0, 0, 0, (int) date('n', easter_date()), (int) date('j', easter_date()) - 2) &&
time() <= mktime(23, 59, 59, (int) date('n', easter_date()), (int) date('j', easter_date()) + 1)) {
$this->log->debug('Happy easter!');
} else {
$this->log->debug('Have fun :)');
}
return $this;
} | [
"public",
"function",
"tearDown",
"(",
")",
"{",
"$",
"seconds",
"=",
"time",
"(",
")",
"-",
"$",
"this",
"->",
"start",
";",
"switch",
"(",
"$",
"seconds",
")",
"{",
"case",
"1",
":",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'This took 1 second.'",
")",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'This took %s seconds.'",
",",
"$",
"seconds",
")",
";",
"break",
";",
"}",
"$",
"prettifyUnit",
"=",
"function",
"(",
"$",
"bytes",
")",
"{",
"$",
"unit",
"=",
"[",
"'B'",
",",
"'KiB'",
",",
"'MiB'",
",",
"'GiB'",
",",
"'TiB'",
",",
"'PiB'",
"]",
";",
"if",
"(",
"$",
"bytes",
"===",
"0",
")",
"{",
"return",
"'0 '",
".",
"$",
"unit",
"[",
"0",
"]",
";",
"}",
"return",
"@",
"round",
"(",
"$",
"bytes",
"/",
"pow",
"(",
"1024",
",",
"(",
"$",
"i",
"=",
"(",
"int",
")",
"floor",
"(",
"log",
"(",
"$",
"bytes",
",",
"1024",
")",
")",
")",
")",
",",
"2",
")",
".",
"' '",
".",
"(",
"isset",
"(",
"$",
"unit",
"[",
"$",
"i",
"]",
")",
"?",
"$",
"unit",
"[",
"$",
"i",
"]",
":",
"'B'",
")",
";",
"}",
";",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'Memory peak usage: %s'",
",",
"$",
"prettifyUnit",
"(",
"memory_get_peak_usage",
"(",
"true",
")",
")",
")",
";",
"if",
"(",
"time",
"(",
")",
">=",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"12",
",",
"24",
")",
"&&",
"time",
"(",
")",
"<=",
"mktime",
"(",
"23",
",",
"59",
",",
"59",
",",
"12",
",",
"26",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'Merry christmas!'",
")",
";",
"}",
"elseif",
"(",
"time",
"(",
")",
">=",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"12",
",",
"31",
")",
"&&",
"time",
"(",
")",
"<=",
"mktime",
"(",
"23",
",",
"59",
",",
"59",
",",
"1",
",",
"1",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'Happy new year!'",
")",
";",
"}",
"elseif",
"(",
"time",
"(",
")",
">=",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"(",
"int",
")",
"date",
"(",
"'n'",
",",
"easter_date",
"(",
")",
")",
",",
"(",
"int",
")",
"date",
"(",
"'j'",
",",
"easter_date",
"(",
")",
")",
"-",
"2",
")",
"&&",
"time",
"(",
")",
"<=",
"mktime",
"(",
"23",
",",
"59",
",",
"59",
",",
"(",
"int",
")",
"date",
"(",
"'n'",
",",
"easter_date",
"(",
")",
")",
",",
"(",
"int",
")",
"date",
"(",
"'j'",
",",
"easter_date",
"(",
")",
")",
"+",
"1",
")",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'Happy easter!'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'Have fun :)'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Process some routines after executing command
@return self Returns itself
@throws Exception on error | [
"Process",
"some",
"routines",
"after",
"executing",
"command"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/Command/Command.php#L88-L135 | train |
bheisig/cli | src/Command/Command.php | Command.getQuery | protected function getQuery() {
$query = '';
foreach ($this->config['args'] as $index => $arg) {
if (array_key_exists('command', $this->config) &&
$arg === $this->config['command'] &&
array_key_exists(($index + 1), $this->config['args'])) {
$query = $this->config['args'][$index + 1];
break;
}
}
return $query;
} | php | protected function getQuery() {
$query = '';
foreach ($this->config['args'] as $index => $arg) {
if (array_key_exists('command', $this->config) &&
$arg === $this->config['command'] &&
array_key_exists(($index + 1), $this->config['args'])) {
$query = $this->config['args'][$index + 1];
break;
}
}
return $query;
} | [
"protected",
"function",
"getQuery",
"(",
")",
"{",
"$",
"query",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"config",
"[",
"'args'",
"]",
"as",
"$",
"index",
"=>",
"$",
"arg",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'command'",
",",
"$",
"this",
"->",
"config",
")",
"&&",
"$",
"arg",
"===",
"$",
"this",
"->",
"config",
"[",
"'command'",
"]",
"&&",
"array_key_exists",
"(",
"(",
"$",
"index",
"+",
"1",
")",
",",
"$",
"this",
"->",
"config",
"[",
"'args'",
"]",
")",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"config",
"[",
"'args'",
"]",
"[",
"$",
"index",
"+",
"1",
"]",
";",
"break",
";",
"}",
"}",
"return",
"$",
"query",
";",
"}"
] | Looks for a query from given arguments
@return string
@deprecated Use $this->config['arguments'][0] instead! | [
"Looks",
"for",
"a",
"query",
"from",
"given",
"arguments"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/Command/Command.php#L144-L157 | train |
bheisig/cli | src/Command/Command.php | Command.getName | public function getName() {
foreach ($this->config['commands'] as $command => $details) {
if (strpos($details['class'], get_class($this)) !== false) {
return $command;
}
}
return '';
} | php | public function getName() {
foreach ($this->config['commands'] as $command => $details) {
if (strpos($details['class'], get_class($this)) !== false) {
return $command;
}
}
return '';
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"config",
"[",
"'commands'",
"]",
"as",
"$",
"command",
"=>",
"$",
"details",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"details",
"[",
"'class'",
"]",
",",
"get_class",
"(",
"$",
"this",
")",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"command",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Get command name
@return string | [
"Get",
"command",
"name"
] | ee77266e173335950357899cdfe86b43c00a6776 | https://github.com/bheisig/cli/blob/ee77266e173335950357899cdfe86b43c00a6776/src/Command/Command.php#L202-L210 | train |
net-tools/core | src/ExceptionHandlers/Res/StackTrace.php | StackTrace._get | protected function _get(\Throwable $e)
{
$path_to_root = $_SERVER['DOCUMENT_ROOT'];
$rows = array();
// first row : current script with error line
$rows[] = [
// file
str_replace($path_to_root . '/', '', $e->getFile()),
// line
$e->getLine(),
// function
"throw new " . get_class($e),
// function parameters
""
];
// for each call stack element
foreach ( $e->getTrace() as $trace )
{
$rows[] = [
// file
str_replace($path_to_root . '/', '', $trace['file']),
// line
$trace['line'],
// function
$trace['class'] ? ($trace['class'] . '::' . $trace['function']) : $trace['function'],
// args
print_r($trace['args'], true)
];
}
return $rows;
} | php | protected function _get(\Throwable $e)
{
$path_to_root = $_SERVER['DOCUMENT_ROOT'];
$rows = array();
// first row : current script with error line
$rows[] = [
// file
str_replace($path_to_root . '/', '', $e->getFile()),
// line
$e->getLine(),
// function
"throw new " . get_class($e),
// function parameters
""
];
// for each call stack element
foreach ( $e->getTrace() as $trace )
{
$rows[] = [
// file
str_replace($path_to_root . '/', '', $trace['file']),
// line
$trace['line'],
// function
$trace['class'] ? ($trace['class'] . '::' . $trace['function']) : $trace['function'],
// args
print_r($trace['args'], true)
];
}
return $rows;
} | [
"protected",
"function",
"_get",
"(",
"\\",
"Throwable",
"$",
"e",
")",
"{",
"$",
"path_to_root",
"=",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
";",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"// first row : current script with error line",
"$",
"rows",
"[",
"]",
"=",
"[",
"// file\t\t",
"str_replace",
"(",
"$",
"path_to_root",
".",
"'/'",
",",
"''",
",",
"$",
"e",
"->",
"getFile",
"(",
")",
")",
",",
"// line",
"$",
"e",
"->",
"getLine",
"(",
")",
",",
"// function",
"\"throw new \"",
".",
"get_class",
"(",
"$",
"e",
")",
",",
"// function parameters",
"\"\"",
"]",
";",
"// for each call stack element",
"foreach",
"(",
"$",
"e",
"->",
"getTrace",
"(",
")",
"as",
"$",
"trace",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"[",
"// file",
"str_replace",
"(",
"$",
"path_to_root",
".",
"'/'",
",",
"''",
",",
"$",
"trace",
"[",
"'file'",
"]",
")",
",",
"// line",
"$",
"trace",
"[",
"'line'",
"]",
",",
"// function",
"$",
"trace",
"[",
"'class'",
"]",
"?",
"(",
"$",
"trace",
"[",
"'class'",
"]",
".",
"'::'",
".",
"$",
"trace",
"[",
"'function'",
"]",
")",
":",
"$",
"trace",
"[",
"'function'",
"]",
",",
"// args",
"print_r",
"(",
"$",
"trace",
"[",
"'args'",
"]",
",",
"true",
")",
"]",
";",
"}",
"return",
"$",
"rows",
";",
"}"
] | Get a 2-dimensions array with exception stack trace
Each row has 4 0-indexed columns : 0=file, 1=line number, 2=function name, 3=function arguments
@param \Throwable $e Exception object
@return array | [
"Get",
"a",
"2",
"-",
"dimensions",
"array",
"with",
"exception",
"stack",
"trace"
] | 51446641cee22c0cf53d2b409c76cc8bd1a187e7 | https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/ExceptionHandlers/Res/StackTrace.php#L41-L85 | train |
SagittariusX/Beluga.Translation | src/Beluga/Translation/Translator.php | Translator.translateByNumber | public function translateByNumber( int $number, string $defaultTranslation, ...$args ) : string
{
$transStr = $this->_source->getTranslation( $number, $defaultTranslation );
if ( \count( $args ) < 1 )
{
return $transStr;
}
return \sprintf( $transStr, $args );
} | php | public function translateByNumber( int $number, string $defaultTranslation, ...$args ) : string
{
$transStr = $this->_source->getTranslation( $number, $defaultTranslation );
if ( \count( $args ) < 1 )
{
return $transStr;
}
return \sprintf( $transStr, $args );
} | [
"public",
"function",
"translateByNumber",
"(",
"int",
"$",
"number",
",",
"string",
"$",
"defaultTranslation",
",",
"...",
"$",
"args",
")",
":",
"string",
"{",
"$",
"transStr",
"=",
"$",
"this",
"->",
"_source",
"->",
"getTranslation",
"(",
"$",
"number",
",",
"$",
"defaultTranslation",
")",
";",
"if",
"(",
"\\",
"count",
"(",
"$",
"args",
")",
"<",
"1",
")",
"{",
"return",
"$",
"transStr",
";",
"}",
"return",
"\\",
"sprintf",
"(",
"$",
"transStr",
",",
"$",
"args",
")",
";",
"}"
] | Gets the translation by an numeric identifier.
@param int $number The numeric identifier
@param string $defaultTranslation This text is returned as translation if the source not holds the
translation with the requested identifier.
@param array ...$args If the translation contains sprintf compatible replacements
you can declare the replacing values here.
@return string | [
"Gets",
"the",
"translation",
"by",
"an",
"numeric",
"identifier",
"."
] | 8f66c4fef6fa4494413972ca56bd8e13f5a7e444 | https://github.com/SagittariusX/Beluga.Translation/blob/8f66c4fef6fa4494413972ca56bd8e13f5a7e444/src/Beluga/Translation/Translator.php#L83-L95 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.