repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
ufocoder/yii2-SyncSocial | src/SyncService.php | SyncService.isArrayHasKeys | protected function isArrayHasKeys($array = [], $keys = []) {
foreach ($keys as $key) {
if (!ArrayHelper::getValue($array, $key, false)) {
return false;
}
}
return true;
} | php | protected function isArrayHasKeys($array = [], $keys = []) {
foreach ($keys as $key) {
if (!ArrayHelper::getValue($array, $key, false)) {
return false;
}
}
return true;
} | [
"protected",
"function",
"isArrayHasKeys",
"(",
"$",
"array",
"=",
"[",
"]",
",",
"$",
"keys",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"array",
",",
"$",
"key",
",",
"false",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Check if array has keys (include path keys like a.b.c)
@param array $array
@param array $keys
@return bool | [
"Check",
"if",
"array",
"has",
"keys",
"(",
"include",
"path",
"keys",
"like",
"a",
".",
"b",
".",
"c",
")"
]
| train | https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/SyncService.php#L191-L199 |
ufocoder/yii2-SyncSocial | src/SyncService.php | SyncService.parsePublishPost | protected function parsePublishPost($response, $indexAttribute = null, $postAttributes = []) {
if (ArrayHelper::getValue($response, $indexAttribute)) {
$time_created = ArrayHelper::getValue($response, $postAttributes['time_created']);
return [
'service_id_author' => ArrayHelper::getValue($response, $postAttributes['service_id_author']),
'service_id_post' => ArrayHelper::getValue($response, $postAttributes['service_id_post']),
'time_created' => is_integer($time_created) ? $time_created : strtotime($time_created),
];
} else {
return [];
}
} | php | protected function parsePublishPost($response, $indexAttribute = null, $postAttributes = []) {
if (ArrayHelper::getValue($response, $indexAttribute)) {
$time_created = ArrayHelper::getValue($response, $postAttributes['time_created']);
return [
'service_id_author' => ArrayHelper::getValue($response, $postAttributes['service_id_author']),
'service_id_post' => ArrayHelper::getValue($response, $postAttributes['service_id_post']),
'time_created' => is_integer($time_created) ? $time_created : strtotime($time_created),
];
} else {
return [];
}
} | [
"protected",
"function",
"parsePublishPost",
"(",
"$",
"response",
",",
"$",
"indexAttribute",
"=",
"null",
",",
"$",
"postAttributes",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"response",
",",
"$",
"indexAttribute",
")",
")",
"{",
"$",
"time_created",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"response",
",",
"$",
"postAttributes",
"[",
"'time_created'",
"]",
")",
";",
"return",
"[",
"'service_id_author'",
"=>",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"response",
",",
"$",
"postAttributes",
"[",
"'service_id_author'",
"]",
")",
",",
"'service_id_post'",
"=>",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"response",
",",
"$",
"postAttributes",
"[",
"'service_id_post'",
"]",
")",
",",
"'time_created'",
"=>",
"is_integer",
"(",
"$",
"time_created",
")",
"?",
"$",
"time_created",
":",
"strtotime",
"(",
"$",
"time_created",
")",
",",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}"
]
| @param $response
@param string $indexAttribute
@param array $postAttributes
@return array | [
"@param",
"$response",
"@param",
"string",
"$indexAttribute",
"@param",
"array",
"$postAttributes"
]
| train | https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/SyncService.php#L208-L221 |
ufocoder/yii2-SyncSocial | src/SyncService.php | SyncService.parseGetPosts | protected function parseGetPosts($response, $indexAttribute = null, $existsAttributes = [], $postAttributes = []) {
$posts = $indexAttribute === null ? $response : ArrayHelper::getValue($response, $indexAttribute);
if (empty($posts)) {
return null;
}
$list = [];
foreach ($posts as $post) {
if ($this->isArrayHasKeys($post, $existsAttributes)) {
$time_created = ArrayHelper::getValue($post, $postAttributes['time_created']);
array_push($list, [
'service_id_author' => ArrayHelper::getValue($post, $postAttributes['service_id_author']),
'service_id_post' => ArrayHelper::getValue($post, $postAttributes['service_id_post']),
'time_created' => is_integer($time_created) ? $time_created : strtotime($time_created),
'content' => ArrayHelper::getValue($post, $postAttributes['content']),
]);
}
}
return $list;
} | php | protected function parseGetPosts($response, $indexAttribute = null, $existsAttributes = [], $postAttributes = []) {
$posts = $indexAttribute === null ? $response : ArrayHelper::getValue($response, $indexAttribute);
if (empty($posts)) {
return null;
}
$list = [];
foreach ($posts as $post) {
if ($this->isArrayHasKeys($post, $existsAttributes)) {
$time_created = ArrayHelper::getValue($post, $postAttributes['time_created']);
array_push($list, [
'service_id_author' => ArrayHelper::getValue($post, $postAttributes['service_id_author']),
'service_id_post' => ArrayHelper::getValue($post, $postAttributes['service_id_post']),
'time_created' => is_integer($time_created) ? $time_created : strtotime($time_created),
'content' => ArrayHelper::getValue($post, $postAttributes['content']),
]);
}
}
return $list;
} | [
"protected",
"function",
"parseGetPosts",
"(",
"$",
"response",
",",
"$",
"indexAttribute",
"=",
"null",
",",
"$",
"existsAttributes",
"=",
"[",
"]",
",",
"$",
"postAttributes",
"=",
"[",
"]",
")",
"{",
"$",
"posts",
"=",
"$",
"indexAttribute",
"===",
"null",
"?",
"$",
"response",
":",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"response",
",",
"$",
"indexAttribute",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"posts",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"posts",
"as",
"$",
"post",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isArrayHasKeys",
"(",
"$",
"post",
",",
"$",
"existsAttributes",
")",
")",
"{",
"$",
"time_created",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"post",
",",
"$",
"postAttributes",
"[",
"'time_created'",
"]",
")",
";",
"array_push",
"(",
"$",
"list",
",",
"[",
"'service_id_author'",
"=>",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"post",
",",
"$",
"postAttributes",
"[",
"'service_id_author'",
"]",
")",
",",
"'service_id_post'",
"=>",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"post",
",",
"$",
"postAttributes",
"[",
"'service_id_post'",
"]",
")",
",",
"'time_created'",
"=>",
"is_integer",
"(",
"$",
"time_created",
")",
"?",
"$",
"time_created",
":",
"strtotime",
"(",
"$",
"time_created",
")",
",",
"'content'",
"=>",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"post",
",",
"$",
"postAttributes",
"[",
"'content'",
"]",
")",
",",
"]",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
]
| @param $response
@param string $indexAttribute
@param array $existsAttributes
@param array $postAttributes
@return array|null | [
"@param",
"$response",
"@param",
"string",
"$indexAttribute",
"@param",
"array",
"$existsAttributes",
"@param",
"array",
"$postAttributes"
]
| train | https://github.com/ufocoder/yii2-SyncSocial/blob/2dbaaec2dad782c52fdd5b648a31ba7fe2a75e1b/src/SyncService.php#L231-L255 |
slashworks/control-bundle | src/Slashworks/AppBundle/Controller/CustomerController.php | CustomerController.createAction | public function createAction(Request $request)
{
$oCustomer = new Customer();
// create customerform for validation
$oForm = $this->createCreateForm($oCustomer);
$oForm->handleRequest($request);
if ($oForm->isValid()) {
// handle logoupload if present
$sLogoPath = $this->_handleLogoUpload($request, $oCustomer);
$oCustomer->setLogo($sLogoPath);
// save logo to customer
$oCustomer->save();
// redirect to customerlist if successful
return $this->redirect($this->generateUrl('backend_system_customer'));
}
// if error occured, redirect back to form
return $this->render('SlashworksAppBundle:Customer:new.html.twig', array(
'entity' => $oCustomer,
'form' => $oForm->createView(),
));
} | php | public function createAction(Request $request)
{
$oCustomer = new Customer();
// create customerform for validation
$oForm = $this->createCreateForm($oCustomer);
$oForm->handleRequest($request);
if ($oForm->isValid()) {
// handle logoupload if present
$sLogoPath = $this->_handleLogoUpload($request, $oCustomer);
$oCustomer->setLogo($sLogoPath);
// save logo to customer
$oCustomer->save();
// redirect to customerlist if successful
return $this->redirect($this->generateUrl('backend_system_customer'));
}
// if error occured, redirect back to form
return $this->render('SlashworksAppBundle:Customer:new.html.twig', array(
'entity' => $oCustomer,
'form' => $oForm->createView(),
));
} | [
"public",
"function",
"createAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"oCustomer",
"=",
"new",
"Customer",
"(",
")",
";",
"// create customerform for validation",
"$",
"oForm",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"oCustomer",
")",
";",
"$",
"oForm",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"oForm",
"->",
"isValid",
"(",
")",
")",
"{",
"// handle logoupload if present",
"$",
"sLogoPath",
"=",
"$",
"this",
"->",
"_handleLogoUpload",
"(",
"$",
"request",
",",
"$",
"oCustomer",
")",
";",
"$",
"oCustomer",
"->",
"setLogo",
"(",
"$",
"sLogoPath",
")",
";",
"// save logo to customer",
"$",
"oCustomer",
"->",
"save",
"(",
")",
";",
"// redirect to customerlist if successful",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'backend_system_customer'",
")",
")",
";",
"}",
"// if error occured, redirect back to form",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksAppBundle:Customer:new.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"oCustomer",
",",
"'form'",
"=>",
"$",
"oForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
]
| Create new customer
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
@throws \Exception
@throws \PropelException | [
"Create",
"new",
"customer"
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/CustomerController.php#L75-L99 |
slashworks/control-bundle | src/Slashworks/AppBundle/Controller/CustomerController.php | CustomerController.modalInfoAction | public function modalInfoAction($id)
{
/** @var Customer $oCustomer */
$oCustomer = CustomerQuery::create()->findOneById($id);
return $this->render('SlashworksAppBundle:Customer:modal_info.html.twig', array(
'customer' => $oCustomer
));
} | php | public function modalInfoAction($id)
{
/** @var Customer $oCustomer */
$oCustomer = CustomerQuery::create()->findOneById($id);
return $this->render('SlashworksAppBundle:Customer:modal_info.html.twig', array(
'customer' => $oCustomer
));
} | [
"public",
"function",
"modalInfoAction",
"(",
"$",
"id",
")",
"{",
"/** @var Customer $oCustomer */",
"$",
"oCustomer",
"=",
"CustomerQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksAppBundle:Customer:modal_info.html.twig'",
",",
"array",
"(",
"'customer'",
"=>",
"$",
"oCustomer",
")",
")",
";",
"}"
]
| Modal info window for customerinformations
@param int $id
@return \Symfony\Component\HttpFoundation\Response | [
"Modal",
"info",
"window",
"for",
"customerinformations"
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/CustomerController.php#L109-L119 |
slashworks/control-bundle | src/Slashworks/AppBundle/Controller/CustomerController.php | CustomerController.newAction | public function newAction()
{
$oCustomer = new Customer();
$form = $this->createCreateForm($oCustomer);
return $this->render('SlashworksAppBundle:Customer:new.html.twig', array(
'entity' => $oCustomer,
'form' => $form->createView(),
));
} | php | public function newAction()
{
$oCustomer = new Customer();
$form = $this->createCreateForm($oCustomer);
return $this->render('SlashworksAppBundle:Customer:new.html.twig', array(
'entity' => $oCustomer,
'form' => $form->createView(),
));
} | [
"public",
"function",
"newAction",
"(",
")",
"{",
"$",
"oCustomer",
"=",
"new",
"Customer",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"oCustomer",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksAppBundle:Customer:new.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"oCustomer",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
]
| Displays a form to create a new Customer entity.
@return \Symfony\Component\HttpFoundation\Response | [
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"Customer",
"entity",
"."
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/CustomerController.php#L127-L137 |
slashworks/control-bundle | src/Slashworks/AppBundle/Controller/CustomerController.php | CustomerController.editAction | public function editAction($id)
{
/** @var Customer $oCustomer */
$oCustomer = CustomerQuery::create()->findOneById($id);
if (count($oCustomer) === 0) {
throw $this->createNotFoundException('Unable to find Customer entity.');
}
$oEditForm = $this->createEditForm($oCustomer);
$oDeleteForm = $this->createDeleteForm($id);
return $this->render('SlashworksAppBundle:Customer:edit.html.twig', array(
'entity' => $oCustomer,
'edit_form' => $oEditForm->createView(),
'delete_form' => $oDeleteForm->createView(),
));
} | php | public function editAction($id)
{
/** @var Customer $oCustomer */
$oCustomer = CustomerQuery::create()->findOneById($id);
if (count($oCustomer) === 0) {
throw $this->createNotFoundException('Unable to find Customer entity.');
}
$oEditForm = $this->createEditForm($oCustomer);
$oDeleteForm = $this->createDeleteForm($id);
return $this->render('SlashworksAppBundle:Customer:edit.html.twig', array(
'entity' => $oCustomer,
'edit_form' => $oEditForm->createView(),
'delete_form' => $oDeleteForm->createView(),
));
} | [
"public",
"function",
"editAction",
"(",
"$",
"id",
")",
"{",
"/** @var Customer $oCustomer */",
"$",
"oCustomer",
"=",
"CustomerQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"count",
"(",
"$",
"oCustomer",
")",
"===",
"0",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find Customer entity.'",
")",
";",
"}",
"$",
"oEditForm",
"=",
"$",
"this",
"->",
"createEditForm",
"(",
"$",
"oCustomer",
")",
";",
"$",
"oDeleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksAppBundle:Customer:edit.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"oCustomer",
",",
"'edit_form'",
"=>",
"$",
"oEditForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"oDeleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
]
| Displays a form to edit an existing Customer entity.
@param int $id
@return \Symfony\Component\HttpFoundation\Response | [
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"Customer",
"entity",
"."
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/CustomerController.php#L147-L165 |
slashworks/control-bundle | src/Slashworks/AppBundle/Controller/CustomerController.php | CustomerController.updateAction | public function updateAction(Request $request, $id)
{
/** @var Customer $oCustomer */
$oCustomer = CustomerQuery::create()->findOneById($id);
if (count($oCustomer) === 0) {
throw $this->createNotFoundException('Unable to find Customer entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($oCustomer);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$sLogoPath = $this->_handleLogoUpload($request, $oCustomer);
$oCustomer->setLogo($sLogoPath);
$oCustomer->save();
return $this->redirect($this->generateUrl('backend_system_customer'));
}
return $this->render('SlashworksAppBundle:Customer:edit.html.twig', array(
'entity' => $oCustomer,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | php | public function updateAction(Request $request, $id)
{
/** @var Customer $oCustomer */
$oCustomer = CustomerQuery::create()->findOneById($id);
if (count($oCustomer) === 0) {
throw $this->createNotFoundException('Unable to find Customer entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($oCustomer);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$sLogoPath = $this->_handleLogoUpload($request, $oCustomer);
$oCustomer->setLogo($sLogoPath);
$oCustomer->save();
return $this->redirect($this->generateUrl('backend_system_customer'));
}
return $this->render('SlashworksAppBundle:Customer:edit.html.twig', array(
'entity' => $oCustomer,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | [
"public",
"function",
"updateAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"/** @var Customer $oCustomer */",
"$",
"oCustomer",
"=",
"CustomerQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"count",
"(",
"$",
"oCustomer",
")",
"===",
"0",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find Customer entity.'",
")",
";",
"}",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"id",
")",
";",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createEditForm",
"(",
"$",
"oCustomer",
")",
";",
"$",
"editForm",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"editForm",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"sLogoPath",
"=",
"$",
"this",
"->",
"_handleLogoUpload",
"(",
"$",
"request",
",",
"$",
"oCustomer",
")",
";",
"$",
"oCustomer",
"->",
"setLogo",
"(",
"$",
"sLogoPath",
")",
";",
"$",
"oCustomer",
"->",
"save",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'backend_system_customer'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'SlashworksAppBundle:Customer:edit.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"oCustomer",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
]
| Update existing customer
@param \Symfony\Component\HttpFoundation\Request $request
@param int $id
@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response | [
"Update",
"existing",
"customer"
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/CustomerController.php#L176-L207 |
slashworks/control-bundle | src/Slashworks/AppBundle/Controller/CustomerController.php | CustomerController.deleteAction | public function deleteAction(Request $request, $id)
{
/** @var Customer $oCustomer */
$oCustomer = CustomerQuery::create()->findOneById($id);
if ($oCustomer === null) {
throw $this->createNotFoundException('Unable to find Customer entity.');
}
$oCustomer->delete();
return $this->redirect($this->generateUrl('backend_system_customer'));
} | php | public function deleteAction(Request $request, $id)
{
/** @var Customer $oCustomer */
$oCustomer = CustomerQuery::create()->findOneById($id);
if ($oCustomer === null) {
throw $this->createNotFoundException('Unable to find Customer entity.');
}
$oCustomer->delete();
return $this->redirect($this->generateUrl('backend_system_customer'));
} | [
"public",
"function",
"deleteAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"/** @var Customer $oCustomer */",
"$",
"oCustomer",
"=",
"CustomerQuery",
"::",
"create",
"(",
")",
"->",
"findOneById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"oCustomer",
"===",
"null",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find Customer entity.'",
")",
";",
"}",
"$",
"oCustomer",
"->",
"delete",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'backend_system_customer'",
")",
")",
";",
"}"
]
| Delete customer
@param \Symfony\Component\HttpFoundation\Request $request
@param $id
@return \Symfony\Component\HttpFoundation\RedirectResponse | [
"Delete",
"customer"
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/CustomerController.php#L218-L231 |
slashworks/control-bundle | src/Slashworks/AppBundle/Controller/CustomerController.php | CustomerController._handleLogoUpload | private function _handleLogoUpload(Request &$request, Customer &$oCustomer)
{
$sLogoPath = "";
/** @var FileBag $t */
$oFiles = $request->files;
$aFiles = $oFiles->get("slashworks_appbundle_customer");
$sUploadPath = __DIR__ . "/../../../../web/files/customers";
if (isset($aFiles['logo'])) {
if (!empty($aFiles['logo'])) {
/** @var UploadedFile $oUploadedFile */
$oUploadedFile = $aFiles['logo'];
$sUniqId = sha1(uniqid(mt_rand(), true));
$sFileName = $sUniqId . '.' . $oUploadedFile->guessExtension();
$oUploadedFile->move($sUploadPath, $sFileName);
$sLogoPath = $sFileName;
}
}
return $sLogoPath;
} | php | private function _handleLogoUpload(Request &$request, Customer &$oCustomer)
{
$sLogoPath = "";
/** @var FileBag $t */
$oFiles = $request->files;
$aFiles = $oFiles->get("slashworks_appbundle_customer");
$sUploadPath = __DIR__ . "/../../../../web/files/customers";
if (isset($aFiles['logo'])) {
if (!empty($aFiles['logo'])) {
/** @var UploadedFile $oUploadedFile */
$oUploadedFile = $aFiles['logo'];
$sUniqId = sha1(uniqid(mt_rand(), true));
$sFileName = $sUniqId . '.' . $oUploadedFile->guessExtension();
$oUploadedFile->move($sUploadPath, $sFileName);
$sLogoPath = $sFileName;
}
}
return $sLogoPath;
} | [
"private",
"function",
"_handleLogoUpload",
"(",
"Request",
"&",
"$",
"request",
",",
"Customer",
"&",
"$",
"oCustomer",
")",
"{",
"$",
"sLogoPath",
"=",
"\"\"",
";",
"/** @var FileBag $t */",
"$",
"oFiles",
"=",
"$",
"request",
"->",
"files",
";",
"$",
"aFiles",
"=",
"$",
"oFiles",
"->",
"get",
"(",
"\"slashworks_appbundle_customer\"",
")",
";",
"$",
"sUploadPath",
"=",
"__DIR__",
".",
"\"/../../../../web/files/customers\"",
";",
"if",
"(",
"isset",
"(",
"$",
"aFiles",
"[",
"'logo'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aFiles",
"[",
"'logo'",
"]",
")",
")",
"{",
"/** @var UploadedFile $oUploadedFile */",
"$",
"oUploadedFile",
"=",
"$",
"aFiles",
"[",
"'logo'",
"]",
";",
"$",
"sUniqId",
"=",
"sha1",
"(",
"uniqid",
"(",
"mt_rand",
"(",
")",
",",
"true",
")",
")",
";",
"$",
"sFileName",
"=",
"$",
"sUniqId",
".",
"'.'",
".",
"$",
"oUploadedFile",
"->",
"guessExtension",
"(",
")",
";",
"$",
"oUploadedFile",
"->",
"move",
"(",
"$",
"sUploadPath",
",",
"$",
"sFileName",
")",
";",
"$",
"sLogoPath",
"=",
"$",
"sFileName",
";",
"}",
"}",
"return",
"$",
"sLogoPath",
";",
"}"
]
| Handle Logo uplaod
@param \Symfony\Component\HttpFoundation\Request $request
@param \Slashworks\AppBundle\Model\Customer $oCustomer
@return string | [
"Handle",
"Logo",
"uplaod"
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/CustomerController.php#L242-L267 |
slashworks/control-bundle | src/Slashworks/AppBundle/Controller/CustomerController.php | CustomerController.createCreateForm | private function createCreateForm(Customer $oCustomer)
{
$form = $this->createForm(new CustomerType(array("language" => $this->get('request')->getLocale())), $oCustomer, array(
'action' => $this->generateUrl('backend_system_customer_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
} | php | private function createCreateForm(Customer $oCustomer)
{
$form = $this->createForm(new CustomerType(array("language" => $this->get('request')->getLocale())), $oCustomer, array(
'action' => $this->generateUrl('backend_system_customer_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
return $form;
} | [
"private",
"function",
"createCreateForm",
"(",
"Customer",
"$",
"oCustomer",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"CustomerType",
"(",
"array",
"(",
"\"language\"",
"=>",
"$",
"this",
"->",
"get",
"(",
"'request'",
")",
"->",
"getLocale",
"(",
")",
")",
")",
",",
"$",
"oCustomer",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'backend_system_customer_create'",
")",
",",
"'method'",
"=>",
"'POST'",
",",
")",
")",
";",
"$",
"form",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"array",
"(",
"'label'",
"=>",
"'Create'",
")",
")",
";",
"return",
"$",
"form",
";",
"}"
]
| Creates a form to create a Customer entity.
@param Customer $oCustomer The entity
@return \Symfony\Component\Form\Form The form | [
"Creates",
"a",
"form",
"to",
"create",
"a",
"Customer",
"entity",
"."
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/CustomerController.php#L277-L288 |
slashworks/control-bundle | src/Slashworks/AppBundle/Controller/CustomerController.php | CustomerController.createEditForm | private function createEditForm(Customer $oCustomer)
{
$oForm = $this->createForm(new CustomerType(array("language" => $this->get('request')->getLocale())), $oCustomer, array(
'action' => $this->generateUrl('backend_system_customer_update', array('id' => $oCustomer->getId())),
'method' => 'PUT',
));
$oForm->add('submit', 'submit', array('label' => 'Update'));
return $oForm;
} | php | private function createEditForm(Customer $oCustomer)
{
$oForm = $this->createForm(new CustomerType(array("language" => $this->get('request')->getLocale())), $oCustomer, array(
'action' => $this->generateUrl('backend_system_customer_update', array('id' => $oCustomer->getId())),
'method' => 'PUT',
));
$oForm->add('submit', 'submit', array('label' => 'Update'));
return $oForm;
} | [
"private",
"function",
"createEditForm",
"(",
"Customer",
"$",
"oCustomer",
")",
"{",
"$",
"oForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"CustomerType",
"(",
"array",
"(",
"\"language\"",
"=>",
"$",
"this",
"->",
"get",
"(",
"'request'",
")",
"->",
"getLocale",
"(",
")",
")",
")",
",",
"$",
"oCustomer",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'backend_system_customer_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"oCustomer",
"->",
"getId",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"$",
"oForm",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"array",
"(",
"'label'",
"=>",
"'Update'",
")",
")",
";",
"return",
"$",
"oForm",
";",
"}"
]
| Create form for editing customer
@param \Slashworks\AppBundle\Model\Customer $oCustomer
@return \Symfony\Component\Form\Form | [
"Create",
"form",
"for",
"editing",
"customer"
]
| train | https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/CustomerController.php#L298-L309 |
mremi/Flowdock | src/Mremi/Flowdock/Api/Push/Push.php | Push.sendChatMessage | public function sendChatMessage(ChatMessageInterface $message, array $options = array())
{
return $this->sendMessage($message, self::BASE_CHAT_URL, $options);
} | php | public function sendChatMessage(ChatMessageInterface $message, array $options = array())
{
return $this->sendMessage($message, self::BASE_CHAT_URL, $options);
} | [
"public",
"function",
"sendChatMessage",
"(",
"ChatMessageInterface",
"$",
"message",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sendMessage",
"(",
"$",
"message",
",",
"self",
"::",
"BASE_CHAT_URL",
",",
"$",
"options",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/mremi/Flowdock/blob/287bfdcef17529055f803f2316e3ad31826e79eb/src/Mremi/Flowdock/Api/Push/Push.php#L44-L47 |
mremi/Flowdock | src/Mremi/Flowdock/Api/Push/Push.php | Push.sendTeamInboxMessage | public function sendTeamInboxMessage(TeamInboxMessageInterface $message, array $options = array())
{
return $this->sendMessage($message, self::BASE_TEAM_INBOX_URL, $options);
} | php | public function sendTeamInboxMessage(TeamInboxMessageInterface $message, array $options = array())
{
return $this->sendMessage($message, self::BASE_TEAM_INBOX_URL, $options);
} | [
"public",
"function",
"sendTeamInboxMessage",
"(",
"TeamInboxMessageInterface",
"$",
"message",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sendMessage",
"(",
"$",
"message",
",",
"self",
"::",
"BASE_TEAM_INBOX_URL",
",",
"$",
"options",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/mremi/Flowdock/blob/287bfdcef17529055f803f2316e3ad31826e79eb/src/Mremi/Flowdock/Api/Push/Push.php#L52-L55 |
mremi/Flowdock | src/Mremi/Flowdock/Api/Push/Push.php | Push.sendMessage | protected function sendMessage(BaseMessageInterface $message, $baseUrl, array $options = array())
{
$client = $this->createClient(sprintf('%s/%s', $baseUrl, $this->flowApiToken));
$response = $client->post(null, array_merge(
$options, [
'headers' => ['Content-Type' => 'application/json'],
'json' => $message->getData()
]
));
$message->setResponse($response);
return !$message->hasResponseErrors();
} | php | protected function sendMessage(BaseMessageInterface $message, $baseUrl, array $options = array())
{
$client = $this->createClient(sprintf('%s/%s', $baseUrl, $this->flowApiToken));
$response = $client->post(null, array_merge(
$options, [
'headers' => ['Content-Type' => 'application/json'],
'json' => $message->getData()
]
));
$message->setResponse($response);
return !$message->hasResponseErrors();
} | [
"protected",
"function",
"sendMessage",
"(",
"BaseMessageInterface",
"$",
"message",
",",
"$",
"baseUrl",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"client",
"=",
"$",
"this",
"->",
"createClient",
"(",
"sprintf",
"(",
"'%s/%s'",
",",
"$",
"baseUrl",
",",
"$",
"this",
"->",
"flowApiToken",
")",
")",
";",
"$",
"response",
"=",
"$",
"client",
"->",
"post",
"(",
"null",
",",
"array_merge",
"(",
"$",
"options",
",",
"[",
"'headers'",
"=>",
"[",
"'Content-Type'",
"=>",
"'application/json'",
"]",
",",
"'json'",
"=>",
"$",
"message",
"->",
"getData",
"(",
")",
"]",
")",
")",
";",
"$",
"message",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"return",
"!",
"$",
"message",
"->",
"hasResponseErrors",
"(",
")",
";",
"}"
]
| Sends a message to a flow
@param BaseMessageInterface $message A message instance to send
@param string $baseUrl A base URL
@param array $options An array of options used by request
@return boolean | [
"Sends",
"a",
"message",
"to",
"a",
"flow"
]
| train | https://github.com/mremi/Flowdock/blob/287bfdcef17529055f803f2316e3ad31826e79eb/src/Mremi/Flowdock/Api/Push/Push.php#L66-L80 |
alanpich/slender | src/Core/ConfigFinder/ConfigFinder.php | ConfigFinder.findFiles | public function findFiles()
{
$search = (new Finder())->files();
// Add in paths
foreach ($this->paths as $path) {
if (is_readable($path)) {
$search->in($path);
}
}
// Add in names
foreach ($this->files as $pattern) {
$search->name($pattern);
}
$array = array();
foreach ($search as $f) {
$array[] = $f->getRealPath();
}
return $array;
} | php | public function findFiles()
{
$search = (new Finder())->files();
// Add in paths
foreach ($this->paths as $path) {
if (is_readable($path)) {
$search->in($path);
}
}
// Add in names
foreach ($this->files as $pattern) {
$search->name($pattern);
}
$array = array();
foreach ($search as $f) {
$array[] = $f->getRealPath();
}
return $array;
} | [
"public",
"function",
"findFiles",
"(",
")",
"{",
"$",
"search",
"=",
"(",
"new",
"Finder",
"(",
")",
")",
"->",
"files",
"(",
")",
";",
"// Add in paths",
"foreach",
"(",
"$",
"this",
"->",
"paths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"is_readable",
"(",
"$",
"path",
")",
")",
"{",
"$",
"search",
"->",
"in",
"(",
"$",
"path",
")",
";",
"}",
"}",
"// Add in names",
"foreach",
"(",
"$",
"this",
"->",
"files",
"as",
"$",
"pattern",
")",
"{",
"$",
"search",
"->",
"name",
"(",
"$",
"pattern",
")",
";",
"}",
"$",
"array",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"search",
"as",
"$",
"f",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"$",
"f",
"->",
"getRealPath",
"(",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
]
| Return an array of file paths to config files
@return array of string paths | [
"Return",
"an",
"array",
"of",
"file",
"paths",
"to",
"config",
"files"
]
| train | https://github.com/alanpich/slender/blob/247f5c08af20cda95b116eb5d9f6f623d61e8a8a/src/Core/ConfigFinder/ConfigFinder.php#L54-L75 |
seeruo/framework | src/Command/PushCommand.php | PushCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$output->writeln([
'<bg=yellow;>Push Script Starting...</>',
'=====================',
]);
$push = new PushService($this->config);
$type = $input->getArgument('type');
$push->run($type);
$output->writeln([
'=====================',
'<bg=yellow;>Push Script End!</>'
]);
} catch (Exception $e) {
$output->writeln('<bg=red;>'.$e->getMessage().'</> <options=bold></>');
$output->writeln('');
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$output->writeln([
'<bg=yellow;>Push Script Starting...</>',
'=====================',
]);
$push = new PushService($this->config);
$type = $input->getArgument('type');
$push->run($type);
$output->writeln([
'=====================',
'<bg=yellow;>Push Script End!</>'
]);
} catch (Exception $e) {
$output->writeln('<bg=red;>'.$e->getMessage().'</> <options=bold></>');
$output->writeln('');
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"try",
"{",
"$",
"output",
"->",
"writeln",
"(",
"[",
"'<bg=yellow;>Push Script Starting...</>'",
",",
"'====================='",
",",
"]",
")",
";",
"$",
"push",
"=",
"new",
"PushService",
"(",
"$",
"this",
"->",
"config",
")",
";",
"$",
"type",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'type'",
")",
";",
"$",
"push",
"->",
"run",
"(",
"$",
"type",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"[",
"'====================='",
",",
"'<bg=yellow;>Push Script End!</>'",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'<bg=red;>'",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"'</> <options=bold></>'",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"''",
")",
";",
"}",
"}"
]
| [执行命令]
@DateTime 2018-12-13
@param InputInterface $input 输入对象
@param OutputInterface $output 输出对象 | [
"[",
"执行命令",
"]"
]
| train | https://github.com/seeruo/framework/blob/689c6e95bc95fe2ae037e056d8228820dd08d7e9/src/Command/PushCommand.php#L36-L54 |
vi-kon/laravel-auth | src/ViKon/Auth/Model/User.php | User.hasRole | public function hasRole($role)
{
if (!$this->roles->where('token', $role)->isEmpty()) {
return true;
}
foreach ($this->groups as $group) {
if (!$group->roles->where('token', $role)->isEmpty()) {
return true;
}
}
return false;
} | php | public function hasRole($role)
{
if (!$this->roles->where('token', $role)->isEmpty()) {
return true;
}
foreach ($this->groups as $group) {
if (!$group->roles->where('token', $role)->isEmpty()) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasRole",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"roles",
"->",
"where",
"(",
"'token'",
",",
"$",
"role",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"groups",
"as",
"$",
"group",
")",
"{",
"if",
"(",
"!",
"$",
"group",
"->",
"roles",
"->",
"where",
"(",
"'token'",
",",
"$",
"role",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Check if user has given role
@param string $role
@return bool | [
"Check",
"if",
"user",
"has",
"given",
"role"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Model/User.php#L167-L180 |
vi-kon/laravel-auth | src/ViKon/Auth/Model/User.php | User.hasPermission | public function hasPermission($permission)
{
if (!$this->permissions->where('token', $permission)->isEmpty()) {
return true;
}
foreach ($this->groups as $group) {
foreach ($group->roles as $role) {
if (!$role->permissions->where('token', $permission)->isEmpty()) {
return true;
}
}
}
foreach ($this->roles as $role) {
if (!$role->permissions->where('token', $permission)->isEmpty()) {
return true;
}
}
return false;
} | php | public function hasPermission($permission)
{
if (!$this->permissions->where('token', $permission)->isEmpty()) {
return true;
}
foreach ($this->groups as $group) {
foreach ($group->roles as $role) {
if (!$role->permissions->where('token', $permission)->isEmpty()) {
return true;
}
}
}
foreach ($this->roles as $role) {
if (!$role->permissions->where('token', $permission)->isEmpty()) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasPermission",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"permissions",
"->",
"where",
"(",
"'token'",
",",
"$",
"permission",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"groups",
"as",
"$",
"group",
")",
"{",
"foreach",
"(",
"$",
"group",
"->",
"roles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"!",
"$",
"role",
"->",
"permissions",
"->",
"where",
"(",
"'token'",
",",
"$",
"permission",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"roles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"!",
"$",
"role",
"->",
"permissions",
"->",
"where",
"(",
"'token'",
",",
"$",
"permission",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Check if user has given permission
@param string $permission
@return bool | [
"Check",
"if",
"user",
"has",
"given",
"permission"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Model/User.php#L189-L210 |
nguyenanhung/nusoap | src/soap_transport_http.php | soap_transport_http.setCredentials | function setCredentials($username, $password, $authtype = 'basic', $digestRequest = [], $certRequest = [])
{
$this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
$this->appendDebug($this->varDump($digestRequest));
$this->debug("certRequest=");
$this->appendDebug($this->varDump($certRequest));
// cf. RFC 2617
if ($authtype == 'basic') {
$this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password));
} elseif ($authtype == 'digest') {
if (isset($digestRequest['nonce'])) {
$digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
// calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
// A1 = unq(username-value) ":" unq(realm-value) ":" passwd
$A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
// H(A1) = MD5(A1)
$HA1 = md5($A1);
// A2 = Method ":" digest-uri-value
$A2 = $this->request_method . ':' . $this->digest_uri;
// H(A2)
$HA2 = md5($A2);
// KD(secret, data) = H(concat(secret, ":", data))
// if qop == auth:
// request-digest = <"> < KD ( H(A1), unq(nonce-value)
// ":" nc-value
// ":" unq(cnonce-value)
// ":" unq(qop-value)
// ":" H(A2)
// ) <">
// if qop is missing,
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
$unhashedDigest = '';
$nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
$cnonce = $nonce;
if ($digestRequest['qop'] != '') {
$unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
} else {
$unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
}
$hashedDigest = md5($unhashedDigest);
$opaque = '';
if (isset($digestRequest['opaque'])) {
$opaque = ', opaque="' . $digestRequest['opaque'] . '"';
}
$this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf("%08x", $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"');
}
} elseif ($authtype == 'certificate') {
$this->certRequest = $certRequest;
$this->debug('Authorization header not set for certificate');
} elseif ($authtype == 'ntlm') {
// do nothing
$this->debug('Authorization header not set for ntlm');
}
$this->username = $username;
$this->password = $password;
$this->authtype = $authtype;
$this->digestRequest = $digestRequest;
} | php | function setCredentials($username, $password, $authtype = 'basic', $digestRequest = [], $certRequest = [])
{
$this->debug("setCredentials username=$username authtype=$authtype digestRequest=");
$this->appendDebug($this->varDump($digestRequest));
$this->debug("certRequest=");
$this->appendDebug($this->varDump($certRequest));
// cf. RFC 2617
if ($authtype == 'basic') {
$this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password));
} elseif ($authtype == 'digest') {
if (isset($digestRequest['nonce'])) {
$digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1;
// calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)
// A1 = unq(username-value) ":" unq(realm-value) ":" passwd
$A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password;
// H(A1) = MD5(A1)
$HA1 = md5($A1);
// A2 = Method ":" digest-uri-value
$A2 = $this->request_method . ':' . $this->digest_uri;
// H(A2)
$HA2 = md5($A2);
// KD(secret, data) = H(concat(secret, ":", data))
// if qop == auth:
// request-digest = <"> < KD ( H(A1), unq(nonce-value)
// ":" nc-value
// ":" unq(cnonce-value)
// ":" unq(qop-value)
// ":" H(A2)
// ) <">
// if qop is missing,
// request-digest = <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) > <">
$unhashedDigest = '';
$nonce = isset($digestRequest['nonce']) ? $digestRequest['nonce'] : '';
$cnonce = $nonce;
if ($digestRequest['qop'] != '') {
$unhashedDigest = $HA1 . ':' . $nonce . ':' . sprintf("%08d", $digestRequest['nc']) . ':' . $cnonce . ':' . $digestRequest['qop'] . ':' . $HA2;
} else {
$unhashedDigest = $HA1 . ':' . $nonce . ':' . $HA2;
}
$hashedDigest = md5($unhashedDigest);
$opaque = '';
if (isset($digestRequest['opaque'])) {
$opaque = ', opaque="' . $digestRequest['opaque'] . '"';
}
$this->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . $digestRequest['realm'] . '", nonce="' . $nonce . '", uri="' . $this->digest_uri . $opaque . '", cnonce="' . $cnonce . '", nc=' . sprintf("%08x", $digestRequest['nc']) . ', qop="' . $digestRequest['qop'] . '", response="' . $hashedDigest . '"');
}
} elseif ($authtype == 'certificate') {
$this->certRequest = $certRequest;
$this->debug('Authorization header not set for certificate');
} elseif ($authtype == 'ntlm') {
// do nothing
$this->debug('Authorization header not set for ntlm');
}
$this->username = $username;
$this->password = $password;
$this->authtype = $authtype;
$this->digestRequest = $digestRequest;
} | [
"function",
"setCredentials",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"authtype",
"=",
"'basic'",
",",
"$",
"digestRequest",
"=",
"[",
"]",
",",
"$",
"certRequest",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"debug",
"(",
"\"setCredentials username=$username authtype=$authtype digestRequest=\"",
")",
";",
"$",
"this",
"->",
"appendDebug",
"(",
"$",
"this",
"->",
"varDump",
"(",
"$",
"digestRequest",
")",
")",
";",
"$",
"this",
"->",
"debug",
"(",
"\"certRequest=\"",
")",
";",
"$",
"this",
"->",
"appendDebug",
"(",
"$",
"this",
"->",
"varDump",
"(",
"$",
"certRequest",
")",
")",
";",
"// cf. RFC 2617\r",
"if",
"(",
"$",
"authtype",
"==",
"'basic'",
")",
"{",
"$",
"this",
"->",
"setHeader",
"(",
"'Authorization'",
",",
"'Basic '",
".",
"base64_encode",
"(",
"str_replace",
"(",
"':'",
",",
"''",
",",
"$",
"username",
")",
".",
"':'",
".",
"$",
"password",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"authtype",
"==",
"'digest'",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"digestRequest",
"[",
"'nonce'",
"]",
")",
")",
"{",
"$",
"digestRequest",
"[",
"'nc'",
"]",
"=",
"isset",
"(",
"$",
"digestRequest",
"[",
"'nc'",
"]",
")",
"?",
"$",
"digestRequest",
"[",
"'nc'",
"]",
"++",
":",
"1",
";",
"// calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html)\r",
"// A1 = unq(username-value) \":\" unq(realm-value) \":\" passwd\r",
"$",
"A1",
"=",
"$",
"username",
".",
"':'",
".",
"(",
"isset",
"(",
"$",
"digestRequest",
"[",
"'realm'",
"]",
")",
"?",
"$",
"digestRequest",
"[",
"'realm'",
"]",
":",
"''",
")",
".",
"':'",
".",
"$",
"password",
";",
"// H(A1) = MD5(A1)\r",
"$",
"HA1",
"=",
"md5",
"(",
"$",
"A1",
")",
";",
"// A2 = Method \":\" digest-uri-value\r",
"$",
"A2",
"=",
"$",
"this",
"->",
"request_method",
".",
"':'",
".",
"$",
"this",
"->",
"digest_uri",
";",
"// H(A2)\r",
"$",
"HA2",
"=",
"md5",
"(",
"$",
"A2",
")",
";",
"// KD(secret, data) = H(concat(secret, \":\", data))\r",
"// if qop == auth:\r",
"// request-digest = <\"> < KD ( H(A1), unq(nonce-value)\r",
"// \":\" nc-value\r",
"// \":\" unq(cnonce-value)\r",
"// \":\" unq(qop-value)\r",
"// \":\" H(A2)\r",
"// ) <\">\r",
"// if qop is missing,\r",
"// request-digest = <\"> < KD ( H(A1), unq(nonce-value) \":\" H(A2) ) > <\">\r",
"$",
"unhashedDigest",
"=",
"''",
";",
"$",
"nonce",
"=",
"isset",
"(",
"$",
"digestRequest",
"[",
"'nonce'",
"]",
")",
"?",
"$",
"digestRequest",
"[",
"'nonce'",
"]",
":",
"''",
";",
"$",
"cnonce",
"=",
"$",
"nonce",
";",
"if",
"(",
"$",
"digestRequest",
"[",
"'qop'",
"]",
"!=",
"''",
")",
"{",
"$",
"unhashedDigest",
"=",
"$",
"HA1",
".",
"':'",
".",
"$",
"nonce",
".",
"':'",
".",
"sprintf",
"(",
"\"%08d\"",
",",
"$",
"digestRequest",
"[",
"'nc'",
"]",
")",
".",
"':'",
".",
"$",
"cnonce",
".",
"':'",
".",
"$",
"digestRequest",
"[",
"'qop'",
"]",
".",
"':'",
".",
"$",
"HA2",
";",
"}",
"else",
"{",
"$",
"unhashedDigest",
"=",
"$",
"HA1",
".",
"':'",
".",
"$",
"nonce",
".",
"':'",
".",
"$",
"HA2",
";",
"}",
"$",
"hashedDigest",
"=",
"md5",
"(",
"$",
"unhashedDigest",
")",
";",
"$",
"opaque",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"digestRequest",
"[",
"'opaque'",
"]",
")",
")",
"{",
"$",
"opaque",
"=",
"', opaque=\"'",
".",
"$",
"digestRequest",
"[",
"'opaque'",
"]",
".",
"'\"'",
";",
"}",
"$",
"this",
"->",
"setHeader",
"(",
"'Authorization'",
",",
"'Digest username=\"'",
".",
"$",
"username",
".",
"'\", realm=\"'",
".",
"$",
"digestRequest",
"[",
"'realm'",
"]",
".",
"'\", nonce=\"'",
".",
"$",
"nonce",
".",
"'\", uri=\"'",
".",
"$",
"this",
"->",
"digest_uri",
".",
"$",
"opaque",
".",
"'\", cnonce=\"'",
".",
"$",
"cnonce",
".",
"'\", nc='",
".",
"sprintf",
"(",
"\"%08x\"",
",",
"$",
"digestRequest",
"[",
"'nc'",
"]",
")",
".",
"', qop=\"'",
".",
"$",
"digestRequest",
"[",
"'qop'",
"]",
".",
"'\", response=\"'",
".",
"$",
"hashedDigest",
".",
"'\"'",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"authtype",
"==",
"'certificate'",
")",
"{",
"$",
"this",
"->",
"certRequest",
"=",
"$",
"certRequest",
";",
"$",
"this",
"->",
"debug",
"(",
"'Authorization header not set for certificate'",
")",
";",
"}",
"elseif",
"(",
"$",
"authtype",
"==",
"'ntlm'",
")",
"{",
"// do nothing\r",
"$",
"this",
"->",
"debug",
"(",
"'Authorization header not set for ntlm'",
")",
";",
"}",
"$",
"this",
"->",
"username",
"=",
"$",
"username",
";",
"$",
"this",
"->",
"password",
"=",
"$",
"password",
";",
"$",
"this",
"->",
"authtype",
"=",
"$",
"authtype",
";",
"$",
"this",
"->",
"digestRequest",
"=",
"$",
"digestRequest",
";",
"}"
]
| if authenticating, set user credentials here
@param string $username
@param string $password
@param string $authtype (basic|digest|certificate|ntlm)
@param array $digestRequest (keys must be nonce, nc, realm, qop)
@param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional),
verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs)
@access public | [
"if",
"authenticating",
"set",
"user",
"credentials",
"here"
]
| train | https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src/soap_transport_http.php#L494-L561 |
nguyenanhung/nusoap | src/soap_transport_http.php | soap_transport_http.usePersistentConnection | function usePersistentConnection()
{
if (isset($this->outgoing_headers['Accept-Encoding'])) {
return FALSE;
}
$this->protocol_version = '1.1';
$this->persistentConnection = TRUE;
$this->setHeader('Connection', 'Keep-Alive');
return TRUE;
} | php | function usePersistentConnection()
{
if (isset($this->outgoing_headers['Accept-Encoding'])) {
return FALSE;
}
$this->protocol_version = '1.1';
$this->persistentConnection = TRUE;
$this->setHeader('Connection', 'Keep-Alive');
return TRUE;
} | [
"function",
"usePersistentConnection",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"outgoing_headers",
"[",
"'Accept-Encoding'",
"]",
")",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"this",
"->",
"protocol_version",
"=",
"'1.1'",
";",
"$",
"this",
"->",
"persistentConnection",
"=",
"TRUE",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Connection'",
",",
"'Keep-Alive'",
")",
";",
"return",
"TRUE",
";",
"}"
]
| specifies that an HTTP persistent connection should be used
@return boolean whether the request was honored by this method.
@access public | [
"specifies",
"that",
"an",
"HTTP",
"persistent",
"connection",
"should",
"be",
"used"
]
| train | https://github.com/nguyenanhung/nusoap/blob/a9b4d98f4f3fe748f8e5d9f8091dfc53585d2556/src/soap_transport_http.php#L1244-L1254 |
jenwachter/html-form | src/Elements/Parents/Field.php | Field.extractArgs | public function extractArgs($args)
{
foreach ($args as $k => $v) {
if (property_exists($this, $k)) {
$this->$k = $v;
} else {
throw new \InvalidArgumentException("{$k} is not a valid option.");
}
}
} | php | public function extractArgs($args)
{
foreach ($args as $k => $v) {
if (property_exists($this, $k)) {
$this->$k = $v;
} else {
throw new \InvalidArgumentException("{$k} is not a valid option.");
}
}
} | [
"public",
"function",
"extractArgs",
"(",
"$",
"args",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"$",
"k",
")",
")",
"{",
"$",
"this",
"->",
"$",
"k",
"=",
"$",
"v",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"{$k} is not a valid option.\"",
")",
";",
"}",
"}",
"}"
]
| Loops through a given array and it the key
exists as a property on this object, it is
assigned.
@param array $args Associative array
@return self | [
"Loops",
"through",
"a",
"given",
"array",
"and",
"it",
"the",
"key",
"exists",
"as",
"a",
"property",
"on",
"this",
"object",
"it",
"is",
"assigned",
"."
]
| train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Elements/Parents/Field.php#L125-L134 |
jenwachter/html-form | src/Elements/Parents/Field.php | Field.getRawValue | public function getRawValue()
{
$name = $this->name;
return !empty($_POST[$name]) ? $_POST[$name] : null;
} | php | public function getRawValue()
{
$name = $this->name;
return !empty($_POST[$name]) ? $_POST[$name] : null;
} | [
"public",
"function",
"getRawValue",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"name",
";",
"return",
"!",
"empty",
"(",
"$",
"_POST",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"_POST",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
]
| Get the raw $_POST value of a field
@return string | [
"Get",
"the",
"raw",
"$_POST",
"value",
"of",
"a",
"field"
]
| train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Elements/Parents/Field.php#L152-L156 |
jenwachter/html-form | src/Elements/Parents/Field.php | Field.getDisplayValue | public function getDisplayValue($formid = null)
{
if ($formid && isset($_SESSION[$formid][$this->name])) {
$value = $_SESSION[$formid][$this->name];
} else if (isset($_POST[$this->name])) {
$value = $_POST[$this->name];
} else {
$value = $this->defaultValue;
}
return $this->cleanValue($value);
} | php | public function getDisplayValue($formid = null)
{
if ($formid && isset($_SESSION[$formid][$this->name])) {
$value = $_SESSION[$formid][$this->name];
} else if (isset($_POST[$this->name])) {
$value = $_POST[$this->name];
} else {
$value = $this->defaultValue;
}
return $this->cleanValue($value);
} | [
"public",
"function",
"getDisplayValue",
"(",
"$",
"formid",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"formid",
"&&",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"formid",
"]",
"[",
"$",
"this",
"->",
"name",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"_SESSION",
"[",
"$",
"formid",
"]",
"[",
"$",
"this",
"->",
"name",
"]",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"this",
"->",
"name",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"_POST",
"[",
"$",
"this",
"->",
"name",
"]",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"defaultValue",
";",
"}",
"return",
"$",
"this",
"->",
"cleanValue",
"(",
"$",
"value",
")",
";",
"}"
]
| Get the value to display in the form field.
Either the value in the session, post data,
the default value, or nothing.
@param string Form ID
@return [type] [description] | [
"Get",
"the",
"value",
"to",
"display",
"in",
"the",
"form",
"field",
".",
"Either",
"the",
"value",
"in",
"the",
"session",
"post",
"data",
"the",
"default",
"value",
"or",
"nothing",
"."
]
| train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Elements/Parents/Field.php#L165-L176 |
jenwachter/html-form | src/Elements/Parents/Field.php | Field.cleanValue | protected function cleanValue($value)
{
if (is_array($value)) {
return array_map(function ($v) {
return $this->cleanValue($v);
}, $value);
} else {
return stripslashes($value);
}
} | php | protected function cleanValue($value)
{
if (is_array($value)) {
return array_map(function ($v) {
return $this->cleanValue($v);
}, $value);
} else {
return stripslashes($value);
}
} | [
"protected",
"function",
"cleanValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"v",
")",
"{",
"return",
"$",
"this",
"->",
"cleanValue",
"(",
"$",
"v",
")",
";",
"}",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"return",
"stripslashes",
"(",
"$",
"value",
")",
";",
"}",
"}"
]
| Clean a value up for repopulation in a form field
@param mixed $value String or array
@return mixed | [
"Clean",
"a",
"value",
"up",
"for",
"repopulation",
"in",
"a",
"form",
"field"
]
| train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Elements/Parents/Field.php#L183-L192 |
jenwachter/html-form | src/Elements/Parents/Field.php | Field.validate | public function validate()
{
$this->errors = array();
$value = $this->getRawValue();
if ($this->required) {
$passed = $this->validateRequired($value);
// don't do anymore validation until it passes the required validation
if (!$passed) return $this->errors;
// validate by field type
$this->validateType($value);
// validate by pattern, if defined
$this->validatePattern($value);
// validate by maxlength, if defined
$this->validateMaxLength($value);
// hook for users?
}
return $this->errors;
} | php | public function validate()
{
$this->errors = array();
$value = $this->getRawValue();
if ($this->required) {
$passed = $this->validateRequired($value);
// don't do anymore validation until it passes the required validation
if (!$passed) return $this->errors;
// validate by field type
$this->validateType($value);
// validate by pattern, if defined
$this->validatePattern($value);
// validate by maxlength, if defined
$this->validateMaxLength($value);
// hook for users?
}
return $this->errors;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"$",
"this",
"->",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getRawValue",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"required",
")",
"{",
"$",
"passed",
"=",
"$",
"this",
"->",
"validateRequired",
"(",
"$",
"value",
")",
";",
"// don't do anymore validation until it passes the required validation",
"if",
"(",
"!",
"$",
"passed",
")",
"return",
"$",
"this",
"->",
"errors",
";",
"// validate by field type",
"$",
"this",
"->",
"validateType",
"(",
"$",
"value",
")",
";",
"// validate by pattern, if defined",
"$",
"this",
"->",
"validatePattern",
"(",
"$",
"value",
")",
";",
"// validate by maxlength, if defined",
"$",
"this",
"->",
"validateMaxLength",
"(",
"$",
"value",
")",
";",
"// hook for users?",
"}",
"return",
"$",
"this",
"->",
"errors",
";",
"}"
]
| Validate a field
@return boolean TRUE is valid; FALSE if invalid | [
"Validate",
"a",
"field"
]
| train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Elements/Parents/Field.php#L198-L224 |
jenwachter/html-form | src/Elements/Parents/Field.php | Field.validateMaxLength | public function validateMaxLength($value)
{
if (!isset($this->attr["maxlength"])) return true;
$maxlength = trim($this->attr["maxlength"]);
$length = strlen($value);
if ($length > $maxlength) {
$this->errors[] = "\"{$this->label}\" contains {$length} characters, but it is limited to {$maxlength} characters. Please shorten the length.";
return false;
}
return true;
} | php | public function validateMaxLength($value)
{
if (!isset($this->attr["maxlength"])) return true;
$maxlength = trim($this->attr["maxlength"]);
$length = strlen($value);
if ($length > $maxlength) {
$this->errors[] = "\"{$this->label}\" contains {$length} characters, but it is limited to {$maxlength} characters. Please shorten the length.";
return false;
}
return true;
} | [
"public",
"function",
"validateMaxLength",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attr",
"[",
"\"maxlength\"",
"]",
")",
")",
"return",
"true",
";",
"$",
"maxlength",
"=",
"trim",
"(",
"$",
"this",
"->",
"attr",
"[",
"\"maxlength\"",
"]",
")",
";",
"$",
"length",
"=",
"strlen",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"length",
">",
"$",
"maxlength",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"\"\\\"{$this->label}\\\" contains {$length} characters, but it is limited to {$maxlength} characters. Please shorten the length.\"",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Validates the maximum length of a form element.
@param string $value Current value of form field
@return boolean | [
"Validates",
"the",
"maximum",
"length",
"of",
"a",
"form",
"element",
"."
]
| train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Elements/Parents/Field.php#L248-L261 |
jenwachter/html-form | src/Elements/Parents/Field.php | Field.validatePattern | public function validatePattern($value)
{
if (!isset($this->attr["pattern"])) return true;
$pattern = trim($this->attr["pattern"], "/");
if (!preg_match("/{$pattern}/", $value)) {
$this->errors[] = "\"{$this->label}\" must match the specified pattern.";
return false;
}
return true;
} | php | public function validatePattern($value)
{
if (!isset($this->attr["pattern"])) return true;
$pattern = trim($this->attr["pattern"], "/");
if (!preg_match("/{$pattern}/", $value)) {
$this->errors[] = "\"{$this->label}\" must match the specified pattern.";
return false;
}
return true;
} | [
"public",
"function",
"validatePattern",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attr",
"[",
"\"pattern\"",
"]",
")",
")",
"return",
"true",
";",
"$",
"pattern",
"=",
"trim",
"(",
"$",
"this",
"->",
"attr",
"[",
"\"pattern\"",
"]",
",",
"\"/\"",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"/{$pattern}/\"",
",",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"\"\\\"{$this->label}\\\" must match the specified pattern.\"",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Validates a form element with a pattern attribute.
@param string $label Form element label
@param string $value Current value of form field
@param string $element Form element object
@return boolean TRUE if passed validation; FALSE if failed validation | [
"Validates",
"a",
"form",
"element",
"with",
"a",
"pattern",
"attribute",
"."
]
| train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Elements/Parents/Field.php#L282-L294 |
Double-Opt-in/php-client-api | src/Client/Commands/ActionsCommand.php | ActionsCommand.uri | public function uri(CryptographyEngine $cryptographyEngine)
{
$uri = parent::uri($cryptographyEngine);
$params = array(
'hash' => $cryptographyEngine->hash($this->email),
);
if (null !== $this->action)
$params['action'] = $this->action;
if (null !== $this->scope)
$params['scope'] = $this->scope;
$query = http_build_query($params);
return $uri . (empty($query) ? '' : '?' . $query);
} | php | public function uri(CryptographyEngine $cryptographyEngine)
{
$uri = parent::uri($cryptographyEngine);
$params = array(
'hash' => $cryptographyEngine->hash($this->email),
);
if (null !== $this->action)
$params['action'] = $this->action;
if (null !== $this->scope)
$params['scope'] = $this->scope;
$query = http_build_query($params);
return $uri . (empty($query) ? '' : '?' . $query);
} | [
"public",
"function",
"uri",
"(",
"CryptographyEngine",
"$",
"cryptographyEngine",
")",
"{",
"$",
"uri",
"=",
"parent",
"::",
"uri",
"(",
"$",
"cryptographyEngine",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'hash'",
"=>",
"$",
"cryptographyEngine",
"->",
"hash",
"(",
"$",
"this",
"->",
"email",
")",
",",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"action",
")",
"$",
"params",
"[",
"'action'",
"]",
"=",
"$",
"this",
"->",
"action",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"scope",
")",
"$",
"params",
"[",
"'scope'",
"]",
"=",
"$",
"this",
"->",
"scope",
";",
"$",
"query",
"=",
"http_build_query",
"(",
"$",
"params",
")",
";",
"return",
"$",
"uri",
".",
"(",
"empty",
"(",
"$",
"query",
")",
"?",
"''",
":",
"'?'",
".",
"$",
"query",
")",
";",
"}"
]
| returns query parameter
hash: email will be hashed before requesting the server
action: optional action will be transmitted in plain text
scope: optional scope will be transmitted in plain text
@param CryptographyEngine $cryptographyEngine
@return string | [
"returns",
"query",
"parameter"
]
| train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Commands/ActionsCommand.php#L74-L91 |
Double-Opt-in/php-client-api | src/Client/Commands/ActionsCommand.php | ActionsCommand.response | public function response(Response $response, CryptographyEngine $cryptographyEngine)
{
$decryptedResponse = new DecryptedCommandResponse($response);
$decryptedResponse->assignCryptographyEngine($cryptographyEngine, $this->email);
return $decryptedResponse;
} | php | public function response(Response $response, CryptographyEngine $cryptographyEngine)
{
$decryptedResponse = new DecryptedCommandResponse($response);
$decryptedResponse->assignCryptographyEngine($cryptographyEngine, $this->email);
return $decryptedResponse;
} | [
"public",
"function",
"response",
"(",
"Response",
"$",
"response",
",",
"CryptographyEngine",
"$",
"cryptographyEngine",
")",
"{",
"$",
"decryptedResponse",
"=",
"new",
"DecryptedCommandResponse",
"(",
"$",
"response",
")",
";",
"$",
"decryptedResponse",
"->",
"assignCryptographyEngine",
"(",
"$",
"cryptographyEngine",
",",
"$",
"this",
"->",
"email",
")",
";",
"return",
"$",
"decryptedResponse",
";",
"}"
]
| creates a response from http response
@param Response $response
@param CryptographyEngine $cryptographyEngine
@return DecryptedCommandResponse | [
"creates",
"a",
"response",
"from",
"http",
"response"
]
| train | https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Commands/ActionsCommand.php#L113-L120 |
userfriendly/SocialUserBundle | Controller/ProfileController.php | ProfileController.usernameAvailableAction | public function usernameAvailableAction( Request $request )
{
$response = array(
'cssClass' => 'success',
'text' => 'username is available',
);
$user = $this->get( 'userfriendly_social_user.oauth_user_provider' )
->findOneByUsernameSlug( $request->get( 'username_slug' ));
$currentUser = $this->get( 'security.context' )->getToken()->getUser();
if ( $currentUser->getId() != $user->getId() && !$this->get( 'security.context' )->isGranted( 'ROLE_ADMIN' ))
{
throw new NotFoundHttpException();
}
$requestedUsername = $request->get( 'username' );
$canonicalUsername = $this->get( 'fos_user.util.username_canonicalizer' )->canonicalize( $requestedUsername );
if ( $requestedUsername != $user->getUsername() )
{
$users = $repo->findByUsernameCanonical( $canonicalUsername );
if ( count( $users ) > 0 )
{
$response['cssClass'] = 'error';
$response['text'] = 'username not available';
}
}
return new Response( json_encode( $response ));
} | php | public function usernameAvailableAction( Request $request )
{
$response = array(
'cssClass' => 'success',
'text' => 'username is available',
);
$user = $this->get( 'userfriendly_social_user.oauth_user_provider' )
->findOneByUsernameSlug( $request->get( 'username_slug' ));
$currentUser = $this->get( 'security.context' )->getToken()->getUser();
if ( $currentUser->getId() != $user->getId() && !$this->get( 'security.context' )->isGranted( 'ROLE_ADMIN' ))
{
throw new NotFoundHttpException();
}
$requestedUsername = $request->get( 'username' );
$canonicalUsername = $this->get( 'fos_user.util.username_canonicalizer' )->canonicalize( $requestedUsername );
if ( $requestedUsername != $user->getUsername() )
{
$users = $repo->findByUsernameCanonical( $canonicalUsername );
if ( count( $users ) > 0 )
{
$response['cssClass'] = 'error';
$response['text'] = 'username not available';
}
}
return new Response( json_encode( $response ));
} | [
"public",
"function",
"usernameAvailableAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"response",
"=",
"array",
"(",
"'cssClass'",
"=>",
"'success'",
",",
"'text'",
"=>",
"'username is available'",
",",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"get",
"(",
"'userfriendly_social_user.oauth_user_provider'",
")",
"->",
"findOneByUsernameSlug",
"(",
"$",
"request",
"->",
"get",
"(",
"'username_slug'",
")",
")",
";",
"$",
"currentUser",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"$",
"currentUser",
"->",
"getId",
"(",
")",
"!=",
"$",
"user",
"->",
"getId",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"isGranted",
"(",
"'ROLE_ADMIN'",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"$",
"requestedUsername",
"=",
"$",
"request",
"->",
"get",
"(",
"'username'",
")",
";",
"$",
"canonicalUsername",
"=",
"$",
"this",
"->",
"get",
"(",
"'fos_user.util.username_canonicalizer'",
")",
"->",
"canonicalize",
"(",
"$",
"requestedUsername",
")",
";",
"if",
"(",
"$",
"requestedUsername",
"!=",
"$",
"user",
"->",
"getUsername",
"(",
")",
")",
"{",
"$",
"users",
"=",
"$",
"repo",
"->",
"findByUsernameCanonical",
"(",
"$",
"canonicalUsername",
")",
";",
"if",
"(",
"count",
"(",
"$",
"users",
")",
">",
"0",
")",
"{",
"$",
"response",
"[",
"'cssClass'",
"]",
"=",
"'error'",
";",
"$",
"response",
"[",
"'text'",
"]",
"=",
"'username not available'",
";",
"}",
"}",
"return",
"new",
"Response",
"(",
"json_encode",
"(",
"$",
"response",
")",
")",
";",
"}"
]
| AJAX action for checking username availability
@param \Symfony\Component\HttpFoundation\Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"AJAX",
"action",
"for",
"checking",
"username",
"availability"
]
| train | https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/Controller/ProfileController.php#L131-L156 |
userfriendly/SocialUserBundle | Controller/ProfileController.php | ProfileController.showAndEdit | private function showAndEdit( Request $request, $action )
{
$user = $this->get( 'userfriendly_social_user.oauth_user_provider' )
->findOneByUsernameSlug( $request->get( 'username_slug' ));
if ( $user )
{
$currentUser = $this->get( 'security.context' )->getToken()->getUser();
if (
self::SHOW == $action
|| $currentUser->getId() == $user->getId()
|| $this->get( 'security.context' )->isGranted( 'ROLE_ADMIN' )
)
{
return $this->render( 'UserfriendlySocialUserBundle:Profile:' . $action . '.html.twig', array(
'user' => $user,
));
}
throw new AccessDeniedException();
}
throw new NotFoundHttpException();
} | php | private function showAndEdit( Request $request, $action )
{
$user = $this->get( 'userfriendly_social_user.oauth_user_provider' )
->findOneByUsernameSlug( $request->get( 'username_slug' ));
if ( $user )
{
$currentUser = $this->get( 'security.context' )->getToken()->getUser();
if (
self::SHOW == $action
|| $currentUser->getId() == $user->getId()
|| $this->get( 'security.context' )->isGranted( 'ROLE_ADMIN' )
)
{
return $this->render( 'UserfriendlySocialUserBundle:Profile:' . $action . '.html.twig', array(
'user' => $user,
));
}
throw new AccessDeniedException();
}
throw new NotFoundHttpException();
} | [
"private",
"function",
"showAndEdit",
"(",
"Request",
"$",
"request",
",",
"$",
"action",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"get",
"(",
"'userfriendly_social_user.oauth_user_provider'",
")",
"->",
"findOneByUsernameSlug",
"(",
"$",
"request",
"->",
"get",
"(",
"'username_slug'",
")",
")",
";",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"currentUser",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"self",
"::",
"SHOW",
"==",
"$",
"action",
"||",
"$",
"currentUser",
"->",
"getId",
"(",
")",
"==",
"$",
"user",
"->",
"getId",
"(",
")",
"||",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"isGranted",
"(",
"'ROLE_ADMIN'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"render",
"(",
"'UserfriendlySocialUserBundle:Profile:'",
".",
"$",
"action",
".",
"'.html.twig'",
",",
"array",
"(",
"'user'",
"=>",
"$",
"user",
",",
")",
")",
";",
"}",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}"
]
| Private methods for use in this Controller's public methods | [
"Private",
"methods",
"for",
"use",
"in",
"this",
"Controller",
"s",
"public",
"methods"
]
| train | https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/Controller/ProfileController.php#L162-L182 |
yuncms/framework | src/user/migrations/m180223_102826Create_user_profile_table.php | m180223_102826Create_user_profile_table.safeUp | public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
/**
* 创建用户资料表
*/
$this->createTable($this->tableName, [
'user_id' => $this->integer()->unsigned()->notNull()->comment('User ID'),
'gender' => $this->smallInteger(1)->notNull()->defaultValue(0)->comment('Gender'),
'mobile' => $this->string()->comment('Mobile'),
'email' => $this->string()->comment('Email'),
'country' => $this->string()->comment('Country'),
'province' => $this->string()->comment('Province'),
'city' => $this->string()->comment('City'),
'location' => $this->string()->comment('Location'),
'address' => $this->string()->comment('Address'),
'website' => $this->string()->comment('Website'),
'timezone' => $this->string(100)->comment('Timezone'),//默认格林威治时间
'birthday' => $this->string(15)->comment('Birthday'),
'current' => $this->smallInteger(1)->comment('Current'),
'qq' => $this->string(11)->comment('QQ'),
'weibo' => $this->string(50)->comment('Weibo'),
'wechat' => $this->string(50)->comment('Wechat'),
'facebook' => $this->string(50)->comment('Facebook'),
'twitter' => $this->string(50)->comment('Twitter'),
'company' => $this->string()->comment('Company'),
'company_job' => $this->string()->comment('Company Job'),
'school' => $this->string()->comment('School'),
'introduction' => $this->string()->comment('Introduction'),
'bio' => $this->text()->comment('Bio'),
], $tableOptions);
$this->addPrimaryKey('{{%user_profile_pk}}', $this->tableName, 'user_id');
$this->addForeignKey('{{%user_profile_fk_1}}', $this->tableName, 'user_id', '{{%user}}', 'id', 'CASCADE', 'RESTRICT');
} | php | public function safeUp()
{
$tableOptions = null;
if ($this->db->driverName === 'mysql') {
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB';
}
/**
* 创建用户资料表
*/
$this->createTable($this->tableName, [
'user_id' => $this->integer()->unsigned()->notNull()->comment('User ID'),
'gender' => $this->smallInteger(1)->notNull()->defaultValue(0)->comment('Gender'),
'mobile' => $this->string()->comment('Mobile'),
'email' => $this->string()->comment('Email'),
'country' => $this->string()->comment('Country'),
'province' => $this->string()->comment('Province'),
'city' => $this->string()->comment('City'),
'location' => $this->string()->comment('Location'),
'address' => $this->string()->comment('Address'),
'website' => $this->string()->comment('Website'),
'timezone' => $this->string(100)->comment('Timezone'),//默认格林威治时间
'birthday' => $this->string(15)->comment('Birthday'),
'current' => $this->smallInteger(1)->comment('Current'),
'qq' => $this->string(11)->comment('QQ'),
'weibo' => $this->string(50)->comment('Weibo'),
'wechat' => $this->string(50)->comment('Wechat'),
'facebook' => $this->string(50)->comment('Facebook'),
'twitter' => $this->string(50)->comment('Twitter'),
'company' => $this->string()->comment('Company'),
'company_job' => $this->string()->comment('Company Job'),
'school' => $this->string()->comment('School'),
'introduction' => $this->string()->comment('Introduction'),
'bio' => $this->text()->comment('Bio'),
], $tableOptions);
$this->addPrimaryKey('{{%user_profile_pk}}', $this->tableName, 'user_id');
$this->addForeignKey('{{%user_profile_fk_1}}', $this->tableName, 'user_id', '{{%user}}', 'id', 'CASCADE', 'RESTRICT');
} | [
"public",
"function",
"safeUp",
"(",
")",
"{",
"$",
"tableOptions",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"driverName",
"===",
"'mysql'",
")",
"{",
"// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci",
"$",
"tableOptions",
"=",
"'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=InnoDB'",
";",
"}",
"/**\n * 创建用户资料表\n */",
"$",
"this",
"->",
"createTable",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'user_id'",
"=>",
"$",
"this",
"->",
"integer",
"(",
")",
"->",
"unsigned",
"(",
")",
"->",
"notNull",
"(",
")",
"->",
"comment",
"(",
"'User ID'",
")",
",",
"'gender'",
"=>",
"$",
"this",
"->",
"smallInteger",
"(",
"1",
")",
"->",
"notNull",
"(",
")",
"->",
"defaultValue",
"(",
"0",
")",
"->",
"comment",
"(",
"'Gender'",
")",
",",
"'mobile'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Mobile'",
")",
",",
"'email'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Email'",
")",
",",
"'country'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Country'",
")",
",",
"'province'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Province'",
")",
",",
"'city'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'City'",
")",
",",
"'location'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Location'",
")",
",",
"'address'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Address'",
")",
",",
"'website'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Website'",
")",
",",
"'timezone'",
"=>",
"$",
"this",
"->",
"string",
"(",
"100",
")",
"->",
"comment",
"(",
"'Timezone'",
")",
",",
"//默认格林威治时间",
"'birthday'",
"=>",
"$",
"this",
"->",
"string",
"(",
"15",
")",
"->",
"comment",
"(",
"'Birthday'",
")",
",",
"'current'",
"=>",
"$",
"this",
"->",
"smallInteger",
"(",
"1",
")",
"->",
"comment",
"(",
"'Current'",
")",
",",
"'qq'",
"=>",
"$",
"this",
"->",
"string",
"(",
"11",
")",
"->",
"comment",
"(",
"'QQ'",
")",
",",
"'weibo'",
"=>",
"$",
"this",
"->",
"string",
"(",
"50",
")",
"->",
"comment",
"(",
"'Weibo'",
")",
",",
"'wechat'",
"=>",
"$",
"this",
"->",
"string",
"(",
"50",
")",
"->",
"comment",
"(",
"'Wechat'",
")",
",",
"'facebook'",
"=>",
"$",
"this",
"->",
"string",
"(",
"50",
")",
"->",
"comment",
"(",
"'Facebook'",
")",
",",
"'twitter'",
"=>",
"$",
"this",
"->",
"string",
"(",
"50",
")",
"->",
"comment",
"(",
"'Twitter'",
")",
",",
"'company'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Company'",
")",
",",
"'company_job'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Company Job'",
")",
",",
"'school'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'School'",
")",
",",
"'introduction'",
"=>",
"$",
"this",
"->",
"string",
"(",
")",
"->",
"comment",
"(",
"'Introduction'",
")",
",",
"'bio'",
"=>",
"$",
"this",
"->",
"text",
"(",
")",
"->",
"comment",
"(",
"'Bio'",
")",
",",
"]",
",",
"$",
"tableOptions",
")",
";",
"$",
"this",
"->",
"addPrimaryKey",
"(",
"'{{%user_profile_pk}}'",
",",
"$",
"this",
"->",
"tableName",
",",
"'user_id'",
")",
";",
"$",
"this",
"->",
"addForeignKey",
"(",
"'{{%user_profile_fk_1}}'",
",",
"$",
"this",
"->",
"tableName",
",",
"'user_id'",
",",
"'{{%user}}'",
",",
"'id'",
",",
"'CASCADE'",
",",
"'RESTRICT'",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/migrations/m180223_102826Create_user_profile_table.php#L12-L50 |
FuriosoJack/LaraException | src/Controllers/BasicController.php | BasicController.laraException | public function laraException(Request $request)
{
$storage = Storage::disk('local');
$fileName = base64_decode(urldecode($request->get('errors')));
if(!$storage->exists($fileName)){
$info = null;
}else{
$info = $storage->get($fileName);
}
$view = self::VIEW_DEFAULT;
// $info = $request->cookie('lara_exception_code');
$errors =[];
if(is_null($info)){
$errors = [
'details' => '',
'message' => 'LaraException',
'debugCode' => '0',
'errors' => [],
'routeBack' => ''
];
}else{
//$urlEncode = \Crypt::decrypt($info);
//\Cookie::forget('lara_exception_code');
///$urlEncode = urldecode($info);
$storage->delete($fileName);
$data = json_decode(base64_decode($info),true);
$errors = $data['errors'];
$view = $data['view'];
}
return view($view,$errors);
} | php | public function laraException(Request $request)
{
$storage = Storage::disk('local');
$fileName = base64_decode(urldecode($request->get('errors')));
if(!$storage->exists($fileName)){
$info = null;
}else{
$info = $storage->get($fileName);
}
$view = self::VIEW_DEFAULT;
// $info = $request->cookie('lara_exception_code');
$errors =[];
if(is_null($info)){
$errors = [
'details' => '',
'message' => 'LaraException',
'debugCode' => '0',
'errors' => [],
'routeBack' => ''
];
}else{
//$urlEncode = \Crypt::decrypt($info);
//\Cookie::forget('lara_exception_code');
///$urlEncode = urldecode($info);
$storage->delete($fileName);
$data = json_decode(base64_decode($info),true);
$errors = $data['errors'];
$view = $data['view'];
}
return view($view,$errors);
} | [
"public",
"function",
"laraException",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"storage",
"=",
"Storage",
"::",
"disk",
"(",
"'local'",
")",
";",
"$",
"fileName",
"=",
"base64_decode",
"(",
"urldecode",
"(",
"$",
"request",
"->",
"get",
"(",
"'errors'",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"storage",
"->",
"exists",
"(",
"$",
"fileName",
")",
")",
"{",
"$",
"info",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"info",
"=",
"$",
"storage",
"->",
"get",
"(",
"$",
"fileName",
")",
";",
"}",
"$",
"view",
"=",
"self",
"::",
"VIEW_DEFAULT",
";",
"// $info = $request->cookie('lara_exception_code');",
"$",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"info",
")",
")",
"{",
"$",
"errors",
"=",
"[",
"'details'",
"=>",
"''",
",",
"'message'",
"=>",
"'LaraException'",
",",
"'debugCode'",
"=>",
"'0'",
",",
"'errors'",
"=>",
"[",
"]",
",",
"'routeBack'",
"=>",
"''",
"]",
";",
"}",
"else",
"{",
"//$urlEncode = \\Crypt::decrypt($info);",
"//\\Cookie::forget('lara_exception_code');",
"///$urlEncode = urldecode($info);",
"$",
"storage",
"->",
"delete",
"(",
"$",
"fileName",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"base64_decode",
"(",
"$",
"info",
")",
",",
"true",
")",
";",
"$",
"errors",
"=",
"$",
"data",
"[",
"'errors'",
"]",
";",
"$",
"view",
"=",
"$",
"data",
"[",
"'view'",
"]",
";",
"}",
"return",
"view",
"(",
"$",
"view",
",",
"$",
"errors",
")",
";",
"}"
]
| Controlador encargado de validar que debe retornar si la vista o el response JSON
@return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View | [
"Controlador",
"encargado",
"de",
"validar",
"que",
"debe",
"retornar",
"si",
"la",
"vista",
"o",
"el",
"response",
"JSON"
]
| train | https://github.com/FuriosoJack/LaraException/blob/b30ec2ed3331d99fca4d0ae47c8710a522bd0c19/src/Controllers/BasicController.php#L31-L67 |
CakeCMS/Core | src/ORM/Behavior/CachedBehavior.php | CachedBehavior.initialize | public function initialize(array $config)
{
$config = Hash::merge($this->_defaultConfig, $config);
$this->setConfig($config);
} | php | public function initialize(array $config)
{
$config = Hash::merge($this->_defaultConfig, $config);
$this->setConfig($config);
} | [
"public",
"function",
"initialize",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"config",
"=",
"Hash",
"::",
"merge",
"(",
"$",
"this",
"->",
"_defaultConfig",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"setConfig",
"(",
"$",
"config",
")",
";",
"}"
]
| Initialize hook.
@param array $config The config for this behavior.
@return void | [
"Initialize",
"hook",
"."
]
| train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/ORM/Behavior/CachedBehavior.php#L49-L53 |
CakeCMS/Core | src/ORM/Behavior/CachedBehavior.php | CachedBehavior._clearCacheGroup | protected function _clearCacheGroup()
{
$cacheGroups = (array) $this->getConfig('groups');
foreach ($cacheGroups as $group) {
Cache::clearGroup($group, $this->getConfig('config'));
}
} | php | protected function _clearCacheGroup()
{
$cacheGroups = (array) $this->getConfig('groups');
foreach ($cacheGroups as $group) {
Cache::clearGroup($group, $this->getConfig('config'));
}
} | [
"protected",
"function",
"_clearCacheGroup",
"(",
")",
"{",
"$",
"cacheGroups",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getConfig",
"(",
"'groups'",
")",
";",
"foreach",
"(",
"$",
"cacheGroups",
"as",
"$",
"group",
")",
"{",
"Cache",
"::",
"clearGroup",
"(",
"$",
"group",
",",
"$",
"this",
"->",
"getConfig",
"(",
"'config'",
")",
")",
";",
"}",
"}"
]
| Clear cache group.
@return void | [
"Clear",
"cache",
"group",
"."
]
| train | https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/ORM/Behavior/CachedBehavior.php#L86-L92 |
Kylob/Bootstrap | src/Common.php | Common.row | public function row($size, $columns)
{
$html = '';
$prefix = array();
for ($i = 1; $i <= 12; ++$i) {
$prefix[] = 'offset-'.$i;
$prefix[] = 'push-'.$i;
$prefix[] = 'pull-'.$i;
$prefix[] = $i;
}
$sizes = func_get_args();
$columns = array_pop($sizes);
foreach ($columns as $cols) {
if (is_string($cols)) {
$html .= $cols;
} else {
$content = array_pop($cols);
foreach ($cols as $key => $classes) {
$cols[$key] = $this->prefixClasses("col-{$sizes[$key]}", $prefix, $classes, 'exclude_base');
}
$html .= '<div class="'.implode(' ', $cols).'">'.$content.'</div>';
}
}
return '<div class="row">'.$html.'</div>';
} | php | public function row($size, $columns)
{
$html = '';
$prefix = array();
for ($i = 1; $i <= 12; ++$i) {
$prefix[] = 'offset-'.$i;
$prefix[] = 'push-'.$i;
$prefix[] = 'pull-'.$i;
$prefix[] = $i;
}
$sizes = func_get_args();
$columns = array_pop($sizes);
foreach ($columns as $cols) {
if (is_string($cols)) {
$html .= $cols;
} else {
$content = array_pop($cols);
foreach ($cols as $key => $classes) {
$cols[$key] = $this->prefixClasses("col-{$sizes[$key]}", $prefix, $classes, 'exclude_base');
}
$html .= '<div class="'.implode(' ', $cols).'">'.$content.'</div>';
}
}
return '<div class="row">'.$html.'</div>';
} | [
"public",
"function",
"row",
"(",
"$",
"size",
",",
"$",
"columns",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"prefix",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"12",
";",
"++",
"$",
"i",
")",
"{",
"$",
"prefix",
"[",
"]",
"=",
"'offset-'",
".",
"$",
"i",
";",
"$",
"prefix",
"[",
"]",
"=",
"'push-'",
".",
"$",
"i",
";",
"$",
"prefix",
"[",
"]",
"=",
"'pull-'",
".",
"$",
"i",
";",
"$",
"prefix",
"[",
"]",
"=",
"$",
"i",
";",
"}",
"$",
"sizes",
"=",
"func_get_args",
"(",
")",
";",
"$",
"columns",
"=",
"array_pop",
"(",
"$",
"sizes",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"cols",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"cols",
")",
")",
"{",
"$",
"html",
".=",
"$",
"cols",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"array_pop",
"(",
"$",
"cols",
")",
";",
"foreach",
"(",
"$",
"cols",
"as",
"$",
"key",
"=>",
"$",
"classes",
")",
"{",
"$",
"cols",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"prefixClasses",
"(",
"\"col-{$sizes[$key]}\"",
",",
"$",
"prefix",
",",
"$",
"classes",
",",
"'exclude_base'",
")",
";",
"}",
"$",
"html",
".=",
"'<div class=\"'",
".",
"implode",
"(",
"' '",
",",
"$",
"cols",
")",
".",
"'\">'",
".",
"$",
"content",
".",
"'</div>'",
";",
"}",
"}",
"return",
"'<div class=\"row\">'",
".",
"$",
"html",
".",
"'</div>'",
";",
"}"
]
| This method works in conjunction with ``$bp->col()`` below. It makes things a little less verbose, but much easier to edit, modify, and see at a glance what in the world is going on.
@param string $size This value can be either '**xs**' < 768px, '**sm**' >= 768px, '**md**' >= 992 , or '**lg**' >= 1200. This is the point at which your grid will break, if no smaller size is indicated. With this method you can indicate multiple sizes by simply inserting another argument. All of your ``$size``'s must correspond with the values given in the ``$bp->col()``'s or ``$columns`` below.
@param array $columns An array of ``$bp->col()``'s. This argument does not need to be the second one in line. It is merely the last one given.
@return string
@example
```php
echo $bp->row('sm', array(
$bp->col(3, 'left'),
$bp->col(6, 'center'),
$bp->col(3, 'right'),
));
``` | [
"This",
"method",
"works",
"in",
"conjunction",
"with",
"$bp",
"-",
">",
"col",
"()",
"below",
".",
"It",
"makes",
"things",
"a",
"little",
"less",
"verbose",
"but",
"much",
"easier",
"to",
"edit",
"modify",
"and",
"see",
"at",
"a",
"glance",
"what",
"in",
"the",
"world",
"is",
"going",
"on",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L82-L107 |
Kylob/Bootstrap | src/Common.php | Common.lister | public function lister($tag, array $list)
{
$html = '';
$class = '';
if ($space = strpos($tag, ' ')) {
$class = trim(substr($tag, $space));
$tag = substr($tag, 0, $space);
}
foreach ($list as $key => $value) {
if ($tag == 'dl') {
$html .= '<dt>'.$key.'</dt>';
$html .= '<dd>'.(is_array($value) ? implode('</dd><dd>', $value) : $value).'</dd>';
} else {
$html .= '<li>'.(is_array($value) ? $key.$this->lister($tag, $value) : $value).'</li>';
}
}
return $this->page->tag($tag, array('class' => $class), $html);
} | php | public function lister($tag, array $list)
{
$html = '';
$class = '';
if ($space = strpos($tag, ' ')) {
$class = trim(substr($tag, $space));
$tag = substr($tag, 0, $space);
}
foreach ($list as $key => $value) {
if ($tag == 'dl') {
$html .= '<dt>'.$key.'</dt>';
$html .= '<dd>'.(is_array($value) ? implode('</dd><dd>', $value) : $value).'</dd>';
} else {
$html .= '<li>'.(is_array($value) ? $key.$this->lister($tag, $value) : $value).'</li>';
}
}
return $this->page->tag($tag, array('class' => $class), $html);
} | [
"public",
"function",
"lister",
"(",
"$",
"tag",
",",
"array",
"$",
"list",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"class",
"=",
"''",
";",
"if",
"(",
"$",
"space",
"=",
"strpos",
"(",
"$",
"tag",
",",
"' '",
")",
")",
"{",
"$",
"class",
"=",
"trim",
"(",
"substr",
"(",
"$",
"tag",
",",
"$",
"space",
")",
")",
";",
"$",
"tag",
"=",
"substr",
"(",
"$",
"tag",
",",
"0",
",",
"$",
"space",
")",
";",
"}",
"foreach",
"(",
"$",
"list",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"tag",
"==",
"'dl'",
")",
"{",
"$",
"html",
".=",
"'<dt>'",
".",
"$",
"key",
".",
"'</dt>'",
";",
"$",
"html",
".=",
"'<dd>'",
".",
"(",
"is_array",
"(",
"$",
"value",
")",
"?",
"implode",
"(",
"'</dd><dd>'",
",",
"$",
"value",
")",
":",
"$",
"value",
")",
".",
"'</dd>'",
";",
"}",
"else",
"{",
"$",
"html",
".=",
"'<li>'",
".",
"(",
"is_array",
"(",
"$",
"value",
")",
"?",
"$",
"key",
".",
"$",
"this",
"->",
"lister",
"(",
"$",
"tag",
",",
"$",
"value",
")",
":",
"$",
"value",
")",
".",
"'</li>'",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"$",
"tag",
",",
"array",
"(",
"'class'",
"=>",
"$",
"class",
")",
",",
"$",
"html",
")",
";",
"}"
]
| This assists you in making Ordered, Unordered, and Definition lists. It is especially useful when you are nesting lists within lists. Your code almost looks exactly like you would expect to see it on the big screen. It would have been nice if we could have named this method 'list', but someone has taken that already.
@param string $tag Either an '**ol**' (Ordered list), '**ul**' (Unordered list), or a '**dl**' (Definition list). You can add any other classes you like (or not), but the special ones that Bootstrap has blessed us with are:
- '**list-inline**' - For an unordered list to be displayed horizontally.
- '**list-unstyled**' - For an unordered list to be unbulleted.
- '**dl-horizontal**' - For a definition to be displayed beside it's title rather than below.
@param array $list For Ordered and Unordered lists this is an ``array($li, $li, ...)``, and to nest another list just make the ``$li`` another array.
For Definition Lists this is an ``array($title => $definition, ...)``. If you have multiple ``$definition``'s, then just make ``$title`` an array of them.
@return string
@example
```php
echo $bp->lister('ol', array(
'Coffee',
'Tea' => array(
'Black tea',
'Green tea',
),
'Milk',
));
echo $bp->lister('ul list-inline', array(
'Coffee',
'Tea',
'Milk',
));
echo $bp->lister('dl dl-horizontal', array(
'Coffee' => array(
'Black hot drink',
'Caffeinated beverage',
),
'Milk' => 'White cold drink',
));
``` | [
"This",
"assists",
"you",
"in",
"making",
"Ordered",
"Unordered",
"and",
"Definition",
"lists",
".",
"It",
"is",
"especially",
"useful",
"when",
"you",
"are",
"nesting",
"lists",
"within",
"lists",
".",
"Your",
"code",
"almost",
"looks",
"exactly",
"like",
"you",
"would",
"expect",
"to",
"see",
"it",
"on",
"the",
"big",
"screen",
".",
"It",
"would",
"have",
"been",
"nice",
"if",
"we",
"could",
"have",
"named",
"this",
"method",
"list",
"but",
"someone",
"has",
"taken",
"that",
"already",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L172-L190 |
Kylob/Bootstrap | src/Common.php | Common.search | public function search($url, array $form = array())
{
$html = '';
$form = array_merge(array(
'name' => 'search',
'role' => 'search',
'class' => 'form-horizontal',
'placeholder' => 'Search',
'button' => $this->icon('search'),
'size' => '',
), $form);
$form['method'] = 'get';
$form['action'] = $url;
$input = array('class' => 'form-control', 'placeholder' => $form['placeholder']);
$button = $form['button'];
$size = $form['size'];
unset($form['placeholder'], $form['button'], $form['size']);
$form = new BPForm($form);
$form->validator->set($form->header['name'], 'required');
if (!empty($button)) {
if (strpos($button, '<button') === false) {
$button = '<button type="submit" class="btn btn-default" title="Search">'.$button.'</button>';
}
$html .= '<div class="'.$this->prefixClasses('input-group', array('sm', 'md', 'lg'), $size).'">';
$html .= $form->text($form->header['name'], $input);
$html .= '<div class="input-group-btn">'.$button.'</div>';
$html .= '</div>';
} else {
if (!empty($size) && in_array($size, array('sm', 'md', 'lg'))) {
$input['class'] .= " input-{$size}";
}
$html .= $form->text($form->header['name'], $input);
}
return $form->header().$html.$form->close();
} | php | public function search($url, array $form = array())
{
$html = '';
$form = array_merge(array(
'name' => 'search',
'role' => 'search',
'class' => 'form-horizontal',
'placeholder' => 'Search',
'button' => $this->icon('search'),
'size' => '',
), $form);
$form['method'] = 'get';
$form['action'] = $url;
$input = array('class' => 'form-control', 'placeholder' => $form['placeholder']);
$button = $form['button'];
$size = $form['size'];
unset($form['placeholder'], $form['button'], $form['size']);
$form = new BPForm($form);
$form->validator->set($form->header['name'], 'required');
if (!empty($button)) {
if (strpos($button, '<button') === false) {
$button = '<button type="submit" class="btn btn-default" title="Search">'.$button.'</button>';
}
$html .= '<div class="'.$this->prefixClasses('input-group', array('sm', 'md', 'lg'), $size).'">';
$html .= $form->text($form->header['name'], $input);
$html .= '<div class="input-group-btn">'.$button.'</div>';
$html .= '</div>';
} else {
if (!empty($size) && in_array($size, array('sm', 'md', 'lg'))) {
$input['class'] .= " input-{$size}";
}
$html .= $form->text($form->header['name'], $input);
}
return $form->header().$html.$form->close();
} | [
"public",
"function",
"search",
"(",
"$",
"url",
",",
"array",
"$",
"form",
"=",
"array",
"(",
")",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"form",
"=",
"array_merge",
"(",
"array",
"(",
"'name'",
"=>",
"'search'",
",",
"'role'",
"=>",
"'search'",
",",
"'class'",
"=>",
"'form-horizontal'",
",",
"'placeholder'",
"=>",
"'Search'",
",",
"'button'",
"=>",
"$",
"this",
"->",
"icon",
"(",
"'search'",
")",
",",
"'size'",
"=>",
"''",
",",
")",
",",
"$",
"form",
")",
";",
"$",
"form",
"[",
"'method'",
"]",
"=",
"'get'",
";",
"$",
"form",
"[",
"'action'",
"]",
"=",
"$",
"url",
";",
"$",
"input",
"=",
"array",
"(",
"'class'",
"=>",
"'form-control'",
",",
"'placeholder'",
"=>",
"$",
"form",
"[",
"'placeholder'",
"]",
")",
";",
"$",
"button",
"=",
"$",
"form",
"[",
"'button'",
"]",
";",
"$",
"size",
"=",
"$",
"form",
"[",
"'size'",
"]",
";",
"unset",
"(",
"$",
"form",
"[",
"'placeholder'",
"]",
",",
"$",
"form",
"[",
"'button'",
"]",
",",
"$",
"form",
"[",
"'size'",
"]",
")",
";",
"$",
"form",
"=",
"new",
"BPForm",
"(",
"$",
"form",
")",
";",
"$",
"form",
"->",
"validator",
"->",
"set",
"(",
"$",
"form",
"->",
"header",
"[",
"'name'",
"]",
",",
"'required'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"button",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"button",
",",
"'<button'",
")",
"===",
"false",
")",
"{",
"$",
"button",
"=",
"'<button type=\"submit\" class=\"btn btn-default\" title=\"Search\">'",
".",
"$",
"button",
".",
"'</button>'",
";",
"}",
"$",
"html",
".=",
"'<div class=\"'",
".",
"$",
"this",
"->",
"prefixClasses",
"(",
"'input-group'",
",",
"array",
"(",
"'sm'",
",",
"'md'",
",",
"'lg'",
")",
",",
"$",
"size",
")",
".",
"'\">'",
";",
"$",
"html",
".=",
"$",
"form",
"->",
"text",
"(",
"$",
"form",
"->",
"header",
"[",
"'name'",
"]",
",",
"$",
"input",
")",
";",
"$",
"html",
".=",
"'<div class=\"input-group-btn\">'",
".",
"$",
"button",
".",
"'</div>'",
";",
"$",
"html",
".=",
"'</div>'",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"size",
")",
"&&",
"in_array",
"(",
"$",
"size",
",",
"array",
"(",
"'sm'",
",",
"'md'",
",",
"'lg'",
")",
")",
")",
"{",
"$",
"input",
"[",
"'class'",
"]",
".=",
"\" input-{$size}\"",
";",
"}",
"$",
"html",
".=",
"$",
"form",
"->",
"text",
"(",
"$",
"form",
"->",
"header",
"[",
"'name'",
"]",
",",
"$",
"input",
")",
";",
"}",
"return",
"$",
"form",
"->",
"header",
"(",
")",
".",
"$",
"html",
".",
"$",
"form",
"->",
"close",
"(",
")",
";",
"}"
]
| This will assist you in creating a search bar for your site.
@param string $url This is the url that you would like the search term to be sent to
@param array $form To customize the form, you can submit an array with any of the following keys:
- '**name**' - The name of the input field. The default is '**search**'.
- '**placeholder**' - Subtle text to indicate what sort of field it is. The default is '**Search**'.
- '**button**' - The button itself with tags and all, or just a name. The default is ``$bp->icon('search')``.
- If you don't want a button at all then just give this an empty value.
- '**class**' - Any special class(es) to give the ``<form>`` tag. The default is '**form-horizontal**'.
- '**size**' - Either '**sm**', '**md**' (the default), or '**lg**'.
@return string
@example
```php
echo $bp->search('http://example.com');
``` | [
"This",
"will",
"assist",
"you",
"in",
"creating",
"a",
"search",
"bar",
"for",
"your",
"site",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L213-L248 |
Kylob/Bootstrap | src/Common.php | Common.icon | public function icon($symbol, $prefix = 'glyphicon', $tag = 'i')
{
$base = $prefix;
$classes = explode(' ', $symbol);
$prefix = array($classes[0]); // ie. only prefix the first class
$params = '';
if ($space = strpos($tag, ' ')) {
$params = ' '.trim(substr($tag, $space));
$tag = substr($tag, 0, $space);
}
if ($base == 'glyphicon') {
$tag = 'span';
}
return $this->addClass("<{$tag}{$params}></{$tag}>", array(
$tag => $this->prefixClasses($base, $prefix, $classes),
));
} | php | public function icon($symbol, $prefix = 'glyphicon', $tag = 'i')
{
$base = $prefix;
$classes = explode(' ', $symbol);
$prefix = array($classes[0]); // ie. only prefix the first class
$params = '';
if ($space = strpos($tag, ' ')) {
$params = ' '.trim(substr($tag, $space));
$tag = substr($tag, 0, $space);
}
if ($base == 'glyphicon') {
$tag = 'span';
}
return $this->addClass("<{$tag}{$params}></{$tag}>", array(
$tag => $this->prefixClasses($base, $prefix, $classes),
));
} | [
"public",
"function",
"icon",
"(",
"$",
"symbol",
",",
"$",
"prefix",
"=",
"'glyphicon'",
",",
"$",
"tag",
"=",
"'i'",
")",
"{",
"$",
"base",
"=",
"$",
"prefix",
";",
"$",
"classes",
"=",
"explode",
"(",
"' '",
",",
"$",
"symbol",
")",
";",
"$",
"prefix",
"=",
"array",
"(",
"$",
"classes",
"[",
"0",
"]",
")",
";",
"// ie. only prefix the first class",
"$",
"params",
"=",
"''",
";",
"if",
"(",
"$",
"space",
"=",
"strpos",
"(",
"$",
"tag",
",",
"' '",
")",
")",
"{",
"$",
"params",
"=",
"' '",
".",
"trim",
"(",
"substr",
"(",
"$",
"tag",
",",
"$",
"space",
")",
")",
";",
"$",
"tag",
"=",
"substr",
"(",
"$",
"tag",
",",
"0",
",",
"$",
"space",
")",
";",
"}",
"if",
"(",
"$",
"base",
"==",
"'glyphicon'",
")",
"{",
"$",
"tag",
"=",
"'span'",
";",
"}",
"return",
"$",
"this",
"->",
"addClass",
"(",
"\"<{$tag}{$params}></{$tag}>\"",
",",
"array",
"(",
"$",
"tag",
"=>",
"$",
"this",
"->",
"prefixClasses",
"(",
"$",
"base",
",",
"$",
"prefix",
",",
"$",
"classes",
")",
",",
")",
")",
";",
"}"
]
| Create an icon without the verbosity.
@param string $symbol The icon you would like to display without the base and icon class prefix.
@param string $prefix The base and icon class prefix. The default is a Bootstrap icon, but this can be used with any icon font by simply entering their prefix value here.
@param string $tag The tag to use for displaying your font. Everyone uses the ``<i>`` tag, so that is the default. If ``$prefix == 'glyphicon'`` (the default for Bootstrap) then we will use a span element. Why? I don't know, but since v.2 that seems to be what they prefer to use now. If you want to style an icon further then you can do so here. eg. ``'i style="font-size:16px;"'``.
@return string
@example
```php
echo $bp->icon('asterisk');
``` | [
"Create",
"an",
"icon",
"without",
"the",
"verbosity",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L309-L326 |
Kylob/Bootstrap | src/Common.php | Common.button | public function button($class, $name, array $options = array())
{
$attributes = array('type' => 'button');
foreach ($options as $key => $value) {
if (!in_array($key, array('dropdown', 'dropup', 'active', 'disabled', 'pull'))) {
$attributes[$key] = $value;
}
}
$attributes['class'] = $this->prefixClasses('btn', array('block', 'xs', 'sm', 'lg', 'default', 'primary', 'success', 'info', 'warning', 'danger', 'link'), $class);
if (isset($options['dropdown']) || isset($options['dropup'])) {
$html = '';
unset($attributes['href']);
$class = (isset($options['dropup'])) ? 'btn-group dropup' : 'btn-group';
$links = (isset($options['dropup'])) ? $options['dropup'] : $options['dropdown'];
$html .= '<div class="'.$class.'">';
list($dropdown, $id) = $this->dropdown($links, $options);
if (is_array($name) && isset($name['split'])) {
$html .= $this->page->tag('button', $attributes, $name['split']);
$attributes['id'] = $id;
$attributes['class'] .= ' dropdown-toggle';
$attributes['data-toggle'] = 'dropdown';
$attributes['aria-haspopup'] = 'true';
$attributes['aria-expanded'] = 'false';
$html .= $this->page->tag('button', $attributes, '<span class="caret"></span>', '<span class="sr-only">Toggle Dropdown</span>');
} else {
$attributes['id'] = $id;
$attributes['class'] .= ' dropdown-toggle';
$attributes['data-toggle'] = 'dropdown';
$attributes['aria-haspopup'] = 'true';
$attributes['aria-expanded'] = 'false';
$html .= $this->page->tag('button', $attributes, $name, '<span class="caret"></span>');
}
$html .= $dropdown;
$html .= '</div>';
return $html;
} elseif (isset($options['href'])) {
unset($attributes['type']);
return $this->page->tag('a', $attributes, $name);
} else {
return $this->page->tag('button', $attributes, $name);
}
} | php | public function button($class, $name, array $options = array())
{
$attributes = array('type' => 'button');
foreach ($options as $key => $value) {
if (!in_array($key, array('dropdown', 'dropup', 'active', 'disabled', 'pull'))) {
$attributes[$key] = $value;
}
}
$attributes['class'] = $this->prefixClasses('btn', array('block', 'xs', 'sm', 'lg', 'default', 'primary', 'success', 'info', 'warning', 'danger', 'link'), $class);
if (isset($options['dropdown']) || isset($options['dropup'])) {
$html = '';
unset($attributes['href']);
$class = (isset($options['dropup'])) ? 'btn-group dropup' : 'btn-group';
$links = (isset($options['dropup'])) ? $options['dropup'] : $options['dropdown'];
$html .= '<div class="'.$class.'">';
list($dropdown, $id) = $this->dropdown($links, $options);
if (is_array($name) && isset($name['split'])) {
$html .= $this->page->tag('button', $attributes, $name['split']);
$attributes['id'] = $id;
$attributes['class'] .= ' dropdown-toggle';
$attributes['data-toggle'] = 'dropdown';
$attributes['aria-haspopup'] = 'true';
$attributes['aria-expanded'] = 'false';
$html .= $this->page->tag('button', $attributes, '<span class="caret"></span>', '<span class="sr-only">Toggle Dropdown</span>');
} else {
$attributes['id'] = $id;
$attributes['class'] .= ' dropdown-toggle';
$attributes['data-toggle'] = 'dropdown';
$attributes['aria-haspopup'] = 'true';
$attributes['aria-expanded'] = 'false';
$html .= $this->page->tag('button', $attributes, $name, '<span class="caret"></span>');
}
$html .= $dropdown;
$html .= '</div>';
return $html;
} elseif (isset($options['href'])) {
unset($attributes['type']);
return $this->page->tag('a', $attributes, $name);
} else {
return $this->page->tag('button', $attributes, $name);
}
} | [
"public",
"function",
"button",
"(",
"$",
"class",
",",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'type'",
"=>",
"'button'",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"array",
"(",
"'dropdown'",
",",
"'dropup'",
",",
"'active'",
",",
"'disabled'",
",",
"'pull'",
")",
")",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"attributes",
"[",
"'class'",
"]",
"=",
"$",
"this",
"->",
"prefixClasses",
"(",
"'btn'",
",",
"array",
"(",
"'block'",
",",
"'xs'",
",",
"'sm'",
",",
"'lg'",
",",
"'default'",
",",
"'primary'",
",",
"'success'",
",",
"'info'",
",",
"'warning'",
",",
"'danger'",
",",
"'link'",
")",
",",
"$",
"class",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'dropdown'",
"]",
")",
"||",
"isset",
"(",
"$",
"options",
"[",
"'dropup'",
"]",
")",
")",
"{",
"$",
"html",
"=",
"''",
";",
"unset",
"(",
"$",
"attributes",
"[",
"'href'",
"]",
")",
";",
"$",
"class",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'dropup'",
"]",
")",
")",
"?",
"'btn-group dropup'",
":",
"'btn-group'",
";",
"$",
"links",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'dropup'",
"]",
")",
")",
"?",
"$",
"options",
"[",
"'dropup'",
"]",
":",
"$",
"options",
"[",
"'dropdown'",
"]",
";",
"$",
"html",
".=",
"'<div class=\"'",
".",
"$",
"class",
".",
"'\">'",
";",
"list",
"(",
"$",
"dropdown",
",",
"$",
"id",
")",
"=",
"$",
"this",
"->",
"dropdown",
"(",
"$",
"links",
",",
"$",
"options",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
"&&",
"isset",
"(",
"$",
"name",
"[",
"'split'",
"]",
")",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'button'",
",",
"$",
"attributes",
",",
"$",
"name",
"[",
"'split'",
"]",
")",
";",
"$",
"attributes",
"[",
"'id'",
"]",
"=",
"$",
"id",
";",
"$",
"attributes",
"[",
"'class'",
"]",
".=",
"' dropdown-toggle'",
";",
"$",
"attributes",
"[",
"'data-toggle'",
"]",
"=",
"'dropdown'",
";",
"$",
"attributes",
"[",
"'aria-haspopup'",
"]",
"=",
"'true'",
";",
"$",
"attributes",
"[",
"'aria-expanded'",
"]",
"=",
"'false'",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'button'",
",",
"$",
"attributes",
",",
"'<span class=\"caret\"></span>'",
",",
"'<span class=\"sr-only\">Toggle Dropdown</span>'",
")",
";",
"}",
"else",
"{",
"$",
"attributes",
"[",
"'id'",
"]",
"=",
"$",
"id",
";",
"$",
"attributes",
"[",
"'class'",
"]",
".=",
"' dropdown-toggle'",
";",
"$",
"attributes",
"[",
"'data-toggle'",
"]",
"=",
"'dropdown'",
";",
"$",
"attributes",
"[",
"'aria-haspopup'",
"]",
"=",
"'true'",
";",
"$",
"attributes",
"[",
"'aria-expanded'",
"]",
"=",
"'false'",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'button'",
",",
"$",
"attributes",
",",
"$",
"name",
",",
"'<span class=\"caret\"></span>'",
")",
";",
"}",
"$",
"html",
".=",
"$",
"dropdown",
";",
"$",
"html",
".=",
"'</div>'",
";",
"return",
"$",
"html",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"options",
"[",
"'href'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"attributes",
"[",
"'type'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'a'",
",",
"$",
"attributes",
",",
"$",
"name",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'button'",
",",
"$",
"attributes",
",",
"$",
"name",
")",
";",
"}",
"}"
]
| A button by itself is easy enough, but when you start including dropdowns and groups your markup can get ugly quick. Follow the examples. We'll start simple and go from there.
@param string $class The classes: '**xs**', '**sm**', '**lg**', '**block**', '**default**', '**primary**', '**success**', '**info**', '**warning**', '**danger**', and '**link**' will all be prefixed with '**btn-...**', and we include the '**btn**' class too. Notice how we left out the '**btn-group**' option? Don't worry about that one. Feel free to add any more that you like such as '**disabled**'.
@param string $name The text of your button. You may also include badges, labels, icons, etc, but leave the caret up to us. If you are including a dropdown menu and you would like to split the button from the menu, then you can make this an ``array('split' => $name)``.
@param array $options These are all of the attributes that you would like to include in the ``<button>`` tag, except if you include an '**href**' key then it will be an ``<a>`` tag. Other potential options include: '**id**', '**style**', '**title**', '**type**', '**data-...**', etc, but the ones we take notice of and do special things with are:
- '**dropdown**' => This is an ``array($name => $link, ...)`` of names and their associated links.
- If the **$name** is numeric (ie. not specified) then the **$link** will be a header (if it is not empty), or a divider if it is.
- '**dropup**' => The same as dropdown, only the caret and menu goes up instead of down.
- '**active**' => This is to specify a **$link** that will receive the "**active**" class. You can set this value to either the **$name** or the **$link** of your dropdown menu, or an **integer** (starting from 1). If you just want it to select the current page then you can specify '**url**' which will match the current url and path, or '**urlquery**' which will match the current url, path, and query string.
- '**disabled**' => This is to specify a link that will receive the "disabled" class. You can set this value to either the **$name** or the **$link** of your dropdown menu.
- '**pull**' => Either '**left**' (default) or '**right**'. Where you would like the dropdown to be positioned, relative to the parent.
@return string
@example
```php
echo $bp->button('primary', 'Primary');
echo $bp->button('lg success', 'Link', array('href'=>'#'));
echo $bp->button('default', 'Dropdown', array(
'dropdown' => array(
'Header',
'Action' => '#',
'Another action' => '#',
'Active link' => '#',
'',
'Separated link' => '#',
'Disabled link' => '#',
),
'active' => 'Active link',
'disabled' => 'Disabled link',
));
``` | [
"A",
"button",
"by",
"itself",
"is",
"easy",
"enough",
"but",
"when",
"you",
"start",
"including",
"dropdowns",
"and",
"groups",
"your",
"markup",
"can",
"get",
"ugly",
"quick",
".",
"Follow",
"the",
"examples",
".",
"We",
"ll",
"start",
"simple",
"and",
"go",
"from",
"there",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L366-L409 |
Kylob/Bootstrap | src/Common.php | Common.group | public function group($class, array $buttons, $form = '')
{
$attributes = array('class' => $this->prefixClasses('btn-group', array('xs', 'sm', 'lg', 'justified', 'vertical'), $class));
if ($form == 'checkbox' || $form == 'radio') {
$attributes['data-toggle'] = 'buttons-'.$form;
}
if (strpos($class, 'justified') !== false) {
$buttons = '<div class="btn-group" role="group">'.implode('</div><div class="btn-group" role="group">', $buttons).'</div>';
} else {
$buttons = implode('', $buttons);
}
$attributes['role'] = 'group';
return $this->page->tag('div', $attributes, $buttons);
} | php | public function group($class, array $buttons, $form = '')
{
$attributes = array('class' => $this->prefixClasses('btn-group', array('xs', 'sm', 'lg', 'justified', 'vertical'), $class));
if ($form == 'checkbox' || $form == 'radio') {
$attributes['data-toggle'] = 'buttons-'.$form;
}
if (strpos($class, 'justified') !== false) {
$buttons = '<div class="btn-group" role="group">'.implode('</div><div class="btn-group" role="group">', $buttons).'</div>';
} else {
$buttons = implode('', $buttons);
}
$attributes['role'] = 'group';
return $this->page->tag('div', $attributes, $buttons);
} | [
"public",
"function",
"group",
"(",
"$",
"class",
",",
"array",
"$",
"buttons",
",",
"$",
"form",
"=",
"''",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'class'",
"=>",
"$",
"this",
"->",
"prefixClasses",
"(",
"'btn-group'",
",",
"array",
"(",
"'xs'",
",",
"'sm'",
",",
"'lg'",
",",
"'justified'",
",",
"'vertical'",
")",
",",
"$",
"class",
")",
")",
";",
"if",
"(",
"$",
"form",
"==",
"'checkbox'",
"||",
"$",
"form",
"==",
"'radio'",
")",
"{",
"$",
"attributes",
"[",
"'data-toggle'",
"]",
"=",
"'buttons-'",
".",
"$",
"form",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"class",
",",
"'justified'",
")",
"!==",
"false",
")",
"{",
"$",
"buttons",
"=",
"'<div class=\"btn-group\" role=\"group\">'",
".",
"implode",
"(",
"'</div><div class=\"btn-group\" role=\"group\">'",
",",
"$",
"buttons",
")",
".",
"'</div>'",
";",
"}",
"else",
"{",
"$",
"buttons",
"=",
"implode",
"(",
"''",
",",
"$",
"buttons",
")",
";",
"}",
"$",
"attributes",
"[",
"'role'",
"]",
"=",
"'group'",
";",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'div'",
",",
"$",
"attributes",
",",
"$",
"buttons",
")",
";",
"}"
]
| Group your buttons together.
@param string $class The classes: '**xs**', '**sm**', '**lg**', '**justified**', and '**vertical**' will all be prefixed with '**btn-group-...**', and we include the '**btn-group**' class too. When you size a group up, then don't size the individual buttons.
@param array $buttons An ``array($bp->button(), ...)`` of buttons.
@param string $form This can be either '**checkbox**' or '**radio**' and your button group will act accordingly.
@return string
@example
```php
echo $bp->group('', array(
$bp->button('default', 'Left'),
$bp->button('default', 'Middle'),
$bp->button('default', array('split'=>'Right'), array(
'dropdown' => array(
'Works' => '#',
'Here' => '#',
'Too' => '#',
),
'pull' => 'right',
)),
));
``` | [
"Group",
"your",
"buttons",
"together",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L437-L451 |
Kylob/Bootstrap | src/Common.php | Common.links | public function links($tag, array $links, array $options = array())
{
$html = '';
$class = null;
if ($space = strpos($tag, ' ')) {
$class = ' '.trim(substr($tag, $space));
$tag = substr($tag, 0, $space);
}
if ($tag != 'li') {
$tag = 'a';
}
$count = 1;
if (isset($options['active'])) {
if ($options['active'] == 'url') {
$options['active'] = $this->page->url('delete', '', '?');
} elseif ($options['active'] == 'urlquery') {
$options['active'] = $this->page->url();
}
}
foreach ($links as $name => $href) {
if (is_array($href)) {
list($dropdown, $id) = $this->dropdown($href, $options, $count);
$active = (strpos($dropdown, 'class="active"') !== false) ? ' active' : null;
$link = $this->page->tag('a', array(
'id' => $id,
'data-target' => '#',
'href' => '#',
'role' => 'button',
'data-toggle' => 'dropdown',
'aria-haspopup' => 'true',
'aria-expanded' => $active ? 'true' : 'false',
), $name, '<span class="caret"></span>');
if ($tag == 'li') {
$html .= $this->page->tag('li', array('class' => 'dropdown'.$active.$class), $link, $dropdown);
} else {
if ($active || $class) {
$link = $this->addClass($link, array('a' => $active.$class));
}
$html .= $this->page->tag('span', array('class' => 'dropdown'.$active), $link, $dropdown);
}
} else {
if (is_numeric($name)) {
$link = $href;
} else {
$attributes = array('href' => $href);
if (isset($options['toggle'])) {
if ($href[0] == '#') {
$attributes['aria-controls'] = substr($href, 1);
}
$attributes['role'] = $options['toggle'];
$attributes['data-toggle'] = $options['toggle'];
}
$link = $this->page->tag('a', $attributes, $name);
}
$li = $this->listItem($link, $options, $name, $href, $count);
if ($tag == 'li') {
if ($class) {
$li = $this->addClass($li, array('li' => $class));
}
$html .= $li;
} else {
if ($class) {
$link = $this->addClass($link, array('a' => $class));
}
if (strpos($li, 'class="active"') !== false) {
$link = $this->addClass($link, array('a' => 'active'));
} elseif (strpos($li, 'class="disabled"') !== false) {
$link = $this->addClass($link, array('a' => 'disabled'));
}
$html .= $link;
}
++$count;
}
}
return $html;
} | php | public function links($tag, array $links, array $options = array())
{
$html = '';
$class = null;
if ($space = strpos($tag, ' ')) {
$class = ' '.trim(substr($tag, $space));
$tag = substr($tag, 0, $space);
}
if ($tag != 'li') {
$tag = 'a';
}
$count = 1;
if (isset($options['active'])) {
if ($options['active'] == 'url') {
$options['active'] = $this->page->url('delete', '', '?');
} elseif ($options['active'] == 'urlquery') {
$options['active'] = $this->page->url();
}
}
foreach ($links as $name => $href) {
if (is_array($href)) {
list($dropdown, $id) = $this->dropdown($href, $options, $count);
$active = (strpos($dropdown, 'class="active"') !== false) ? ' active' : null;
$link = $this->page->tag('a', array(
'id' => $id,
'data-target' => '#',
'href' => '#',
'role' => 'button',
'data-toggle' => 'dropdown',
'aria-haspopup' => 'true',
'aria-expanded' => $active ? 'true' : 'false',
), $name, '<span class="caret"></span>');
if ($tag == 'li') {
$html .= $this->page->tag('li', array('class' => 'dropdown'.$active.$class), $link, $dropdown);
} else {
if ($active || $class) {
$link = $this->addClass($link, array('a' => $active.$class));
}
$html .= $this->page->tag('span', array('class' => 'dropdown'.$active), $link, $dropdown);
}
} else {
if (is_numeric($name)) {
$link = $href;
} else {
$attributes = array('href' => $href);
if (isset($options['toggle'])) {
if ($href[0] == '#') {
$attributes['aria-controls'] = substr($href, 1);
}
$attributes['role'] = $options['toggle'];
$attributes['data-toggle'] = $options['toggle'];
}
$link = $this->page->tag('a', $attributes, $name);
}
$li = $this->listItem($link, $options, $name, $href, $count);
if ($tag == 'li') {
if ($class) {
$li = $this->addClass($li, array('li' => $class));
}
$html .= $li;
} else {
if ($class) {
$link = $this->addClass($link, array('a' => $class));
}
if (strpos($li, 'class="active"') !== false) {
$link = $this->addClass($link, array('a' => 'active'));
} elseif (strpos($li, 'class="disabled"') !== false) {
$link = $this->addClass($link, array('a' => 'disabled'));
}
$html .= $link;
}
++$count;
}
}
return $html;
} | [
"public",
"function",
"links",
"(",
"$",
"tag",
",",
"array",
"$",
"links",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"class",
"=",
"null",
";",
"if",
"(",
"$",
"space",
"=",
"strpos",
"(",
"$",
"tag",
",",
"' '",
")",
")",
"{",
"$",
"class",
"=",
"' '",
".",
"trim",
"(",
"substr",
"(",
"$",
"tag",
",",
"$",
"space",
")",
")",
";",
"$",
"tag",
"=",
"substr",
"(",
"$",
"tag",
",",
"0",
",",
"$",
"space",
")",
";",
"}",
"if",
"(",
"$",
"tag",
"!=",
"'li'",
")",
"{",
"$",
"tag",
"=",
"'a'",
";",
"}",
"$",
"count",
"=",
"1",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'active'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"options",
"[",
"'active'",
"]",
"==",
"'url'",
")",
"{",
"$",
"options",
"[",
"'active'",
"]",
"=",
"$",
"this",
"->",
"page",
"->",
"url",
"(",
"'delete'",
",",
"''",
",",
"'?'",
")",
";",
"}",
"elseif",
"(",
"$",
"options",
"[",
"'active'",
"]",
"==",
"'urlquery'",
")",
"{",
"$",
"options",
"[",
"'active'",
"]",
"=",
"$",
"this",
"->",
"page",
"->",
"url",
"(",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"links",
"as",
"$",
"name",
"=>",
"$",
"href",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"href",
")",
")",
"{",
"list",
"(",
"$",
"dropdown",
",",
"$",
"id",
")",
"=",
"$",
"this",
"->",
"dropdown",
"(",
"$",
"href",
",",
"$",
"options",
",",
"$",
"count",
")",
";",
"$",
"active",
"=",
"(",
"strpos",
"(",
"$",
"dropdown",
",",
"'class=\"active\"'",
")",
"!==",
"false",
")",
"?",
"' active'",
":",
"null",
";",
"$",
"link",
"=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'a'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'data-target'",
"=>",
"'#'",
",",
"'href'",
"=>",
"'#'",
",",
"'role'",
"=>",
"'button'",
",",
"'data-toggle'",
"=>",
"'dropdown'",
",",
"'aria-haspopup'",
"=>",
"'true'",
",",
"'aria-expanded'",
"=>",
"$",
"active",
"?",
"'true'",
":",
"'false'",
",",
")",
",",
"$",
"name",
",",
"'<span class=\"caret\"></span>'",
")",
";",
"if",
"(",
"$",
"tag",
"==",
"'li'",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'li'",
",",
"array",
"(",
"'class'",
"=>",
"'dropdown'",
".",
"$",
"active",
".",
"$",
"class",
")",
",",
"$",
"link",
",",
"$",
"dropdown",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"active",
"||",
"$",
"class",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"link",
",",
"array",
"(",
"'a'",
"=>",
"$",
"active",
".",
"$",
"class",
")",
")",
";",
"}",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'span'",
",",
"array",
"(",
"'class'",
"=>",
"'dropdown'",
".",
"$",
"active",
")",
",",
"$",
"link",
",",
"$",
"dropdown",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"name",
")",
")",
"{",
"$",
"link",
"=",
"$",
"href",
";",
"}",
"else",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'href'",
"=>",
"$",
"href",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'toggle'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"href",
"[",
"0",
"]",
"==",
"'#'",
")",
"{",
"$",
"attributes",
"[",
"'aria-controls'",
"]",
"=",
"substr",
"(",
"$",
"href",
",",
"1",
")",
";",
"}",
"$",
"attributes",
"[",
"'role'",
"]",
"=",
"$",
"options",
"[",
"'toggle'",
"]",
";",
"$",
"attributes",
"[",
"'data-toggle'",
"]",
"=",
"$",
"options",
"[",
"'toggle'",
"]",
";",
"}",
"$",
"link",
"=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'a'",
",",
"$",
"attributes",
",",
"$",
"name",
")",
";",
"}",
"$",
"li",
"=",
"$",
"this",
"->",
"listItem",
"(",
"$",
"link",
",",
"$",
"options",
",",
"$",
"name",
",",
"$",
"href",
",",
"$",
"count",
")",
";",
"if",
"(",
"$",
"tag",
"==",
"'li'",
")",
"{",
"if",
"(",
"$",
"class",
")",
"{",
"$",
"li",
"=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"li",
",",
"array",
"(",
"'li'",
"=>",
"$",
"class",
")",
")",
";",
"}",
"$",
"html",
".=",
"$",
"li",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"class",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"link",
",",
"array",
"(",
"'a'",
"=>",
"$",
"class",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"li",
",",
"'class=\"active\"'",
")",
"!==",
"false",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"link",
",",
"array",
"(",
"'a'",
"=>",
"'active'",
")",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"li",
",",
"'class=\"disabled\"'",
")",
"!==",
"false",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"link",
",",
"array",
"(",
"'a'",
"=>",
"'disabled'",
")",
")",
";",
"}",
"$",
"html",
".=",
"$",
"link",
";",
"}",
"++",
"$",
"count",
";",
"}",
"}",
"return",
"$",
"html",
";",
"}"
]
| This used to be a private method that we only used internally for tabs and pills and buttons and so forth, but it is just so useful. Now you can make your own dropdowns with regular ``<a>`` links as well.
@param string $tag If this isn't 'li', then it will be an '**a**'. If you specify 'li' tags then you will need to surround this method's output with your own ``<ul>`` or ``<ol>`` tags. Otherwise you can just use the returned ``<a>`` $links (with dropdowns if any) as is. The ``<a>``'s with dropdowns will be surrounded by a ``<span class="dropdown">``. If one of those dropdown links are active then the ``<span>`` and ``<a>`` tags will receive an additional 'active' class as well. To add any other class(es) to the ``<a>`` or ``<li>`` tags just add them after the $tag here eg. '**a special-class**'.
@param array $links An ``array($name => $href, ...)`` of links. If **$href** is an array unto itself, then it will be turned into a dropdown menu with the same header and divider rules applied as with ``$bp->buttons()``.
@param array $options The available options are:
- '**active**' => **$name**, **$href**, '**url**', '**urlquery**', or an **integer** (starting from 1).
- '**disabled**' => **$name**, **$href** or an **integer** (starting from 1).
- '**align**' => '**left**' (default) or '**right**' - the direction you would like to pull them towards.
@return string
@example
```php
echo $bp->links('a special-class', array(
'Home' => BASE_URL,
'Dropdown' => array(
'Header',
'Action' => '#',
'Another Action' => '#',
),
), array(
'active' => 'url',
));
``` | [
"This",
"used",
"to",
"be",
"a",
"private",
"method",
"that",
"we",
"only",
"used",
"internally",
"for",
"tabs",
"and",
"pills",
"and",
"buttons",
"and",
"so",
"forth",
"but",
"it",
"is",
"just",
"so",
"useful",
".",
"Now",
"you",
"can",
"make",
"your",
"own",
"dropdowns",
"with",
"regular",
"<a",
">",
"links",
"as",
"well",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L481-L557 |
Kylob/Bootstrap | src/Common.php | Common.tabs | public function tabs(array $links, array $options = array())
{
$class = 'nav nav-tabs';
if (isset($options['align'])) {
switch ($options['align']) {
case 'justified':
$class .= ' nav-justified';
break;
case 'left':
case 'right':
$class .= ' pull-'.$options['align'];
break;
}
}
return $this->page->tag('ul', array('class' => $class), $this->links('li', $links, $options));
} | php | public function tabs(array $links, array $options = array())
{
$class = 'nav nav-tabs';
if (isset($options['align'])) {
switch ($options['align']) {
case 'justified':
$class .= ' nav-justified';
break;
case 'left':
case 'right':
$class .= ' pull-'.$options['align'];
break;
}
}
return $this->page->tag('ul', array('class' => $class), $this->links('li', $links, $options));
} | [
"public",
"function",
"tabs",
"(",
"array",
"$",
"links",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"class",
"=",
"'nav nav-tabs'",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'align'",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"options",
"[",
"'align'",
"]",
")",
"{",
"case",
"'justified'",
":",
"$",
"class",
".=",
"' nav-justified'",
";",
"break",
";",
"case",
"'left'",
":",
"case",
"'right'",
":",
"$",
"class",
".=",
"' pull-'",
".",
"$",
"options",
"[",
"'align'",
"]",
";",
"break",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'ul'",
",",
"array",
"(",
"'class'",
"=>",
"$",
"class",
")",
",",
"$",
"this",
"->",
"links",
"(",
"'li'",
",",
"$",
"links",
",",
"$",
"options",
")",
")",
";",
"}"
]
| Creates a Bootstrap tabs nav menu.
@param array $links An ``array($name => $href, ...)`` of links. If **$href** is an array unto itself, then it will be turned into a dropdown menu with the same header and divider rules applied as with ``$bp->buttons()``.
@param array $options The available options are:
- '**active**' => **$name**, **$href**, '**url**', '**urlquery**', or an **integer** (starting from 1).
- '**disabled**' => **$name**, **$href**, or an **integer** (starting from 1).
- '**align**' =>
- '**justified**' - So the tabs will horizontally extend the full width.
- '**left**' (default) or '**right**' - The direction you would like to pull them towards.
@return string
@example
```php
echo $bp->tabs(array(
'Nav' => '#',
'Tabs' => '#',
'Justified' => '#',
), array(
'align' => 'justified',
'active' => 1,
));
``` | [
"Creates",
"a",
"Bootstrap",
"tabs",
"nav",
"menu",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L586-L602 |
Kylob/Bootstrap | src/Common.php | Common.pills | public function pills(array $links, array $options = array())
{
$class = 'nav nav-pills';
if (isset($options['align'])) {
switch ($options['align']) {
case 'justified':
$class .= ' nav-justified';
break;
case 'vertical':
case 'stacked':
$class .= ' nav-stacked';
break;
case 'left':
case 'right':
$class .= ' pull-'.$options['align'];
break;
}
}
return $this->page->tag('ul', array('class' => $class), $this->links('li', $links, $options));
} | php | public function pills(array $links, array $options = array())
{
$class = 'nav nav-pills';
if (isset($options['align'])) {
switch ($options['align']) {
case 'justified':
$class .= ' nav-justified';
break;
case 'vertical':
case 'stacked':
$class .= ' nav-stacked';
break;
case 'left':
case 'right':
$class .= ' pull-'.$options['align'];
break;
}
}
return $this->page->tag('ul', array('class' => $class), $this->links('li', $links, $options));
} | [
"public",
"function",
"pills",
"(",
"array",
"$",
"links",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"class",
"=",
"'nav nav-pills'",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'align'",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"options",
"[",
"'align'",
"]",
")",
"{",
"case",
"'justified'",
":",
"$",
"class",
".=",
"' nav-justified'",
";",
"break",
";",
"case",
"'vertical'",
":",
"case",
"'stacked'",
":",
"$",
"class",
".=",
"' nav-stacked'",
";",
"break",
";",
"case",
"'left'",
":",
"case",
"'right'",
":",
"$",
"class",
".=",
"' pull-'",
".",
"$",
"options",
"[",
"'align'",
"]",
";",
"break",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'ul'",
",",
"array",
"(",
"'class'",
"=>",
"$",
"class",
")",
",",
"$",
"this",
"->",
"links",
"(",
"'li'",
",",
"$",
"links",
",",
"$",
"options",
")",
")",
";",
"}"
]
| Creates a Bootstrap pills nav menu.
@param array $links An ``array($name => $href, ...)`` of links. If **$href** is an array unto itself, then it will be turned into a dropdown menu with the same header and divider rules applied as with ``$bp->buttons()``.
@param array $options The available options are:
- '**active**' => **$name**, **$href**, '**url**', '**urlquery**', or an **integer** (starting from 1).
- '**disabled**' => **$name**, **$href** or an **integer** (starting from 1).
- '**align**' =>
- '**justified**' - The pills will horizontally extend the full width.
- '**vertical**' or '**stacked**' - Each pill will be stacked on top of the other.
- '**left**' (default) or '**right**' - The direction you would like to pull them towards.
@return string
@example
```php
echo $bp->pills(array(
'Home ' . $bp->badge(42) => '#',
'Profile' . $bp->badge(0) => '#',
'Messages' . $bp->badge(3) => array(
'New! ' . $bp->badge(1) => '#',
'Read ' => '#',
'Trashed ' => '#',
'',
'Spam ' . $bp->badge(2) => '#',
),
), array(
'active' => 'Home',
));
``` | [
"Creates",
"a",
"Bootstrap",
"pills",
"nav",
"menu",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L637-L657 |
Kylob/Bootstrap | src/Common.php | Common.breadcrumbs | public function breadcrumbs(array $links)
{
if (empty($links)) {
return '';
}
foreach ($links as $name => $href) {
if (is_array($href)) {
list($dropdown, $id) = $this->dropdown($href);
$link = $this->page->tag('a', array('href' => '#', 'data-toggle' => 'dropdown', 'id' => $id), $name, '<b class="caret"></b>');
$links[$name] = '<li class="dropdown">'.$link.$dropdown.'</li>';
} else {
$links[$name] = '<li><a href="'.$href.'">'.$name.'</a></li>';
}
if ($name === 0) {
$name = $href; // this should only happen to the last breadcrumb
}
}
array_pop($links);
return '<ul class="breadcrumb">'.implode(' ', $links).' <li class="active">'.$name.'</li></ul>';
} | php | public function breadcrumbs(array $links)
{
if (empty($links)) {
return '';
}
foreach ($links as $name => $href) {
if (is_array($href)) {
list($dropdown, $id) = $this->dropdown($href);
$link = $this->page->tag('a', array('href' => '#', 'data-toggle' => 'dropdown', 'id' => $id), $name, '<b class="caret"></b>');
$links[$name] = '<li class="dropdown">'.$link.$dropdown.'</li>';
} else {
$links[$name] = '<li><a href="'.$href.'">'.$name.'</a></li>';
}
if ($name === 0) {
$name = $href; // this should only happen to the last breadcrumb
}
}
array_pop($links);
return '<ul class="breadcrumb">'.implode(' ', $links).' <li class="active">'.$name.'</li></ul>';
} | [
"public",
"function",
"breadcrumbs",
"(",
"array",
"$",
"links",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"links",
")",
")",
"{",
"return",
"''",
";",
"}",
"foreach",
"(",
"$",
"links",
"as",
"$",
"name",
"=>",
"$",
"href",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"href",
")",
")",
"{",
"list",
"(",
"$",
"dropdown",
",",
"$",
"id",
")",
"=",
"$",
"this",
"->",
"dropdown",
"(",
"$",
"href",
")",
";",
"$",
"link",
"=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'a'",
",",
"array",
"(",
"'href'",
"=>",
"'#'",
",",
"'data-toggle'",
"=>",
"'dropdown'",
",",
"'id'",
"=>",
"$",
"id",
")",
",",
"$",
"name",
",",
"'<b class=\"caret\"></b>'",
")",
";",
"$",
"links",
"[",
"$",
"name",
"]",
"=",
"'<li class=\"dropdown\">'",
".",
"$",
"link",
".",
"$",
"dropdown",
".",
"'</li>'",
";",
"}",
"else",
"{",
"$",
"links",
"[",
"$",
"name",
"]",
"=",
"'<li><a href=\"'",
".",
"$",
"href",
".",
"'\">'",
".",
"$",
"name",
".",
"'</a></li>'",
";",
"}",
"if",
"(",
"$",
"name",
"===",
"0",
")",
"{",
"$",
"name",
"=",
"$",
"href",
";",
"// this should only happen to the last breadcrumb",
"}",
"}",
"array_pop",
"(",
"$",
"links",
")",
";",
"return",
"'<ul class=\"breadcrumb\">'",
".",
"implode",
"(",
"' '",
",",
"$",
"links",
")",
".",
"' <li class=\"active\">'",
".",
"$",
"name",
".",
"'</li></ul>'",
";",
"}"
]
| Creates a Bootstrap styled breadcrumb trail. The last link is automatically activated.
@param array $links An ``array($name => $href)`` of links to display. The **$href** may also be another ``array($name => $href)`` of dropdown links.
@return string
@example
```php
$bp->breadcrumbs(array(
'Home' => '#',
'Library' => '#',
'Data' => '#',
));
``` | [
"Creates",
"a",
"Bootstrap",
"styled",
"breadcrumb",
"trail",
".",
"The",
"last",
"link",
"is",
"automatically",
"activated",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L676-L696 |
Kylob/Bootstrap | src/Common.php | Common.badge | public function badge($count, $align = '')
{
return $this->page->tag('span', array(
'class' => !empty($align) ? 'badge pull-'.$align : 'badge',
), (is_numeric($count) && $count == 0) ? '' : $count);
} | php | public function badge($count, $align = '')
{
return $this->page->tag('span', array(
'class' => !empty($align) ? 'badge pull-'.$align : 'badge',
), (is_numeric($count) && $count == 0) ? '' : $count);
} | [
"public",
"function",
"badge",
"(",
"$",
"count",
",",
"$",
"align",
"=",
"''",
")",
"{",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'span'",
",",
"array",
"(",
"'class'",
"=>",
"!",
"empty",
"(",
"$",
"align",
")",
"?",
"'badge pull-'",
".",
"$",
"align",
":",
"'badge'",
",",
")",
",",
"(",
"is_numeric",
"(",
"$",
"count",
")",
"&&",
"$",
"count",
"==",
"0",
")",
"?",
"''",
":",
"$",
"count",
")",
";",
"}"
]
| Creates a Bootstrap badge, and is a bit more useful than ``$bp->label()``. If **$count** equals 0, or if it's not numeric (null?), then it still includes the tag, but leaves the value empty.
@param int $count The number you would like to display.
@param string $align This will pull your badge '**right**' or '**left**' or not (default). In a list group, badges are automatically positioned to the right.
@return string
@example
```php
echo $bp->badge(13, 'right');
``` | [
"Creates",
"a",
"Bootstrap",
"badge",
"and",
"is",
"a",
"bit",
"more",
"useful",
"than",
"$bp",
"-",
">",
"label",
"()",
".",
"If",
"**",
"$count",
"**",
"equals",
"0",
"or",
"if",
"it",
"s",
"not",
"numeric",
"(",
"null?",
")",
"then",
"it",
"still",
"includes",
"the",
"tag",
"but",
"leaves",
"the",
"value",
"empty",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L733-L738 |
Kylob/Bootstrap | src/Common.php | Common.alert | public function alert($type, $alert, $dismissable = true)
{
$html = '';
$class = 'alert alert-'.$type;
if ($dismissable) {
$class .= ' alert-dismissable';
}
$html .= '<div class="'.$class.'" role="alert">';
if ($dismissable) {
$html .= '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>';
}
$html .= $this->addClass($alert, array('h([1-6]){1}' => 'alert-heading', 'a' => 'alert-link'));
$html .= '</div>';
return $html;
} | php | public function alert($type, $alert, $dismissable = true)
{
$html = '';
$class = 'alert alert-'.$type;
if ($dismissable) {
$class .= ' alert-dismissable';
}
$html .= '<div class="'.$class.'" role="alert">';
if ($dismissable) {
$html .= '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>';
}
$html .= $this->addClass($alert, array('h([1-6]){1}' => 'alert-heading', 'a' => 'alert-link'));
$html .= '</div>';
return $html;
} | [
"public",
"function",
"alert",
"(",
"$",
"type",
",",
"$",
"alert",
",",
"$",
"dismissable",
"=",
"true",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"class",
"=",
"'alert alert-'",
".",
"$",
"type",
";",
"if",
"(",
"$",
"dismissable",
")",
"{",
"$",
"class",
".=",
"' alert-dismissable'",
";",
"}",
"$",
"html",
".=",
"'<div class=\"'",
".",
"$",
"class",
".",
"'\" role=\"alert\">'",
";",
"if",
"(",
"$",
"dismissable",
")",
"{",
"$",
"html",
".=",
"'<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">×</span></button>'",
";",
"}",
"$",
"html",
".=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"alert",
",",
"array",
"(",
"'h([1-6]){1}'",
"=>",
"'alert-heading'",
",",
"'a'",
"=>",
"'alert-link'",
")",
")",
";",
"$",
"html",
".=",
"'</div>'",
";",
"return",
"$",
"html",
";",
"}"
]
| Creates Bootstrap alert messages.
@param string $type Either '**success**', '**info**', '**warning**', or '**danger**'.
@param string $alert The status message. All ``<h1-6>`` headers and ``<a>`` links will be classed appropriately.
@param bool $dismissable If you set this to false, then the alert will not be dismissable.
@return string
@example
```php
echo $bp->alert('info', '<h3>Heads up!</h3> This alert needs your attention, but it\'s not <a href="#">super important</a>.');
echo $bp->alert('danger', '<h3>Oh snap!</h3> Change a few things up and <a href="#">try submitting again</a>.', false);
``` | [
"Creates",
"Bootstrap",
"alert",
"messages",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L757-L772 |
Kylob/Bootstrap | src/Common.php | Common.progress | public function progress($percent, $class = '', $display = false)
{
$html = '';
$classes = (array) $class;
foreach ((array) $percent as $key => $progress) {
$class = (isset($classes[$key])) ? $classes[$key] : '';
$class = $this->prefixClasses('progress-bar', array('success', 'info', 'warning', 'danger', 'striped'), $class);
$html .= $this->page->tag('div', array(
'class' => $class,
'style' => 'width:'.$progress.'%;',
'role' => 'progressbar',
'aria-valuenow' => $progress,
'aria-valuemin' => 0,
'aria-valuemax' => 100,
), $display !== false ? $progress.'%' : '<span class="sr-only">'.$progress.'% Complete</span>');
}
return '<div class="progress">'.$html.'</div>';
} | php | public function progress($percent, $class = '', $display = false)
{
$html = '';
$classes = (array) $class;
foreach ((array) $percent as $key => $progress) {
$class = (isset($classes[$key])) ? $classes[$key] : '';
$class = $this->prefixClasses('progress-bar', array('success', 'info', 'warning', 'danger', 'striped'), $class);
$html .= $this->page->tag('div', array(
'class' => $class,
'style' => 'width:'.$progress.'%;',
'role' => 'progressbar',
'aria-valuenow' => $progress,
'aria-valuemin' => 0,
'aria-valuemax' => 100,
), $display !== false ? $progress.'%' : '<span class="sr-only">'.$progress.'% Complete</span>');
}
return '<div class="progress">'.$html.'</div>';
} | [
"public",
"function",
"progress",
"(",
"$",
"percent",
",",
"$",
"class",
"=",
"''",
",",
"$",
"display",
"=",
"false",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"classes",
"=",
"(",
"array",
")",
"$",
"class",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"percent",
"as",
"$",
"key",
"=>",
"$",
"progress",
")",
"{",
"$",
"class",
"=",
"(",
"isset",
"(",
"$",
"classes",
"[",
"$",
"key",
"]",
")",
")",
"?",
"$",
"classes",
"[",
"$",
"key",
"]",
":",
"''",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"prefixClasses",
"(",
"'progress-bar'",
",",
"array",
"(",
"'success'",
",",
"'info'",
",",
"'warning'",
",",
"'danger'",
",",
"'striped'",
")",
",",
"$",
"class",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"$",
"class",
",",
"'style'",
"=>",
"'width:'",
".",
"$",
"progress",
".",
"'%;'",
",",
"'role'",
"=>",
"'progressbar'",
",",
"'aria-valuenow'",
"=>",
"$",
"progress",
",",
"'aria-valuemin'",
"=>",
"0",
",",
"'aria-valuemax'",
"=>",
"100",
",",
")",
",",
"$",
"display",
"!==",
"false",
"?",
"$",
"progress",
".",
"'%'",
":",
"'<span class=\"sr-only\">'",
".",
"$",
"progress",
".",
"'% Complete</span>'",
")",
";",
"}",
"return",
"'<div class=\"progress\">'",
".",
"$",
"html",
".",
"'</div>'",
";",
"}"
]
| Creates every flavor of progress bar that Bootstrap has to offer.
@param int $percent The amount of progress from 0 to 100. In order to stack multiple values then turn this into an array.
@param string $class You can include one of the four contextual classes: '**success**', '**info**', '**warning**' or '**danger**'. Also '**striped**' and '**active**' if you like the looks of those. These will all be properly prefixed with '**progress-...**'. If you are stacking multiple bars, then turn this into an array and make sure your classes correspond with your percentages.
@param mixed $display If anything but false, then the percentage will be displayed in the progress bar.
@return string
@example
```php
echo $bp->progress(60, 'info', 'display');
echo $bp->progress(array(25, 25, 25, 25), array('', 'warning', 'success', 'danger striped'));
``` | [
"Creates",
"every",
"flavor",
"of",
"progress",
"bar",
"that",
"Bootstrap",
"has",
"to",
"offer",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L791-L809 |
Kylob/Bootstrap | src/Common.php | Common.media | public function media(array $list, $parent = 0)
{
if (is_numeric($parent) && isset($list[0]) && is_array($list[0])) {
$media = array();
foreach ($list[$parent] as $child => $display) {
if (isset($list[$child])) {
$display[] = $this->media($list, $child)[0];
}
$media[] = $display;
}
return ($parent === 0) ? call_user_func_array(array($this, 'media'), $media) : $media;
} else {
$html = '';
$siblings = func_get_args();
$parent = array_shift($siblings);
$children = array();
foreach ($parent as $key => $value) {
if (is_array($value)) {
$children[] = $value;
unset($parent[$key]);
}
}
$div = $parent;
unset($parent['id'], $parent['class']);
list($left, $body, $right) = array_pad($parent, 3, '');
$media = '';
if (!empty($left)) {
$media .= '<div class="media-left">'.$this->addClass($left, array('img' => 'media-object')).'</div>';
}
$media .= '<div class="media-body">';
if (!empty($body)) {
$media .= $this->addClass($body, array('h([1-6]){1}' => 'media-heading'));
}
if (!empty($children)) {
$media .= call_user_func_array(array($this, 'media'), $children);
}
$media .= '</div>';
if (!empty($right)) {
$media .= '<div class="media-right">'.$this->addClass($right, array('img' => 'media-object')).'</div>';
}
$html .= $this->page->tag('div', array(
'id' => isset($div['id']) ? $div['id'] : '',
'class' => isset($div['class']) ? 'media '.$div['class'] : 'media',
), $media);
if (!empty($siblings)) {
$html .= call_user_func_array(array($this, 'media'), $siblings);
}
return $html;
}
} | php | public function media(array $list, $parent = 0)
{
if (is_numeric($parent) && isset($list[0]) && is_array($list[0])) {
$media = array();
foreach ($list[$parent] as $child => $display) {
if (isset($list[$child])) {
$display[] = $this->media($list, $child)[0];
}
$media[] = $display;
}
return ($parent === 0) ? call_user_func_array(array($this, 'media'), $media) : $media;
} else {
$html = '';
$siblings = func_get_args();
$parent = array_shift($siblings);
$children = array();
foreach ($parent as $key => $value) {
if (is_array($value)) {
$children[] = $value;
unset($parent[$key]);
}
}
$div = $parent;
unset($parent['id'], $parent['class']);
list($left, $body, $right) = array_pad($parent, 3, '');
$media = '';
if (!empty($left)) {
$media .= '<div class="media-left">'.$this->addClass($left, array('img' => 'media-object')).'</div>';
}
$media .= '<div class="media-body">';
if (!empty($body)) {
$media .= $this->addClass($body, array('h([1-6]){1}' => 'media-heading'));
}
if (!empty($children)) {
$media .= call_user_func_array(array($this, 'media'), $children);
}
$media .= '</div>';
if (!empty($right)) {
$media .= '<div class="media-right">'.$this->addClass($right, array('img' => 'media-object')).'</div>';
}
$html .= $this->page->tag('div', array(
'id' => isset($div['id']) ? $div['id'] : '',
'class' => isset($div['class']) ? 'media '.$div['class'] : 'media',
), $media);
if (!empty($siblings)) {
$html .= call_user_func_array(array($this, 'media'), $siblings);
}
return $html;
}
} | [
"public",
"function",
"media",
"(",
"array",
"$",
"list",
",",
"$",
"parent",
"=",
"0",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"parent",
")",
"&&",
"isset",
"(",
"$",
"list",
"[",
"0",
"]",
")",
"&&",
"is_array",
"(",
"$",
"list",
"[",
"0",
"]",
")",
")",
"{",
"$",
"media",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"list",
"[",
"$",
"parent",
"]",
"as",
"$",
"child",
"=>",
"$",
"display",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"list",
"[",
"$",
"child",
"]",
")",
")",
"{",
"$",
"display",
"[",
"]",
"=",
"$",
"this",
"->",
"media",
"(",
"$",
"list",
",",
"$",
"child",
")",
"[",
"0",
"]",
";",
"}",
"$",
"media",
"[",
"]",
"=",
"$",
"display",
";",
"}",
"return",
"(",
"$",
"parent",
"===",
"0",
")",
"?",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"'media'",
")",
",",
"$",
"media",
")",
":",
"$",
"media",
";",
"}",
"else",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"siblings",
"=",
"func_get_args",
"(",
")",
";",
"$",
"parent",
"=",
"array_shift",
"(",
"$",
"siblings",
")",
";",
"$",
"children",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parent",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"children",
"[",
"]",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"parent",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"div",
"=",
"$",
"parent",
";",
"unset",
"(",
"$",
"parent",
"[",
"'id'",
"]",
",",
"$",
"parent",
"[",
"'class'",
"]",
")",
";",
"list",
"(",
"$",
"left",
",",
"$",
"body",
",",
"$",
"right",
")",
"=",
"array_pad",
"(",
"$",
"parent",
",",
"3",
",",
"''",
")",
";",
"$",
"media",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"left",
")",
")",
"{",
"$",
"media",
".=",
"'<div class=\"media-left\">'",
".",
"$",
"this",
"->",
"addClass",
"(",
"$",
"left",
",",
"array",
"(",
"'img'",
"=>",
"'media-object'",
")",
")",
".",
"'</div>'",
";",
"}",
"$",
"media",
".=",
"'<div class=\"media-body\">'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"body",
")",
")",
"{",
"$",
"media",
".=",
"$",
"this",
"->",
"addClass",
"(",
"$",
"body",
",",
"array",
"(",
"'h([1-6]){1}'",
"=>",
"'media-heading'",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"children",
")",
")",
"{",
"$",
"media",
".=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"'media'",
")",
",",
"$",
"children",
")",
";",
"}",
"$",
"media",
".=",
"'</div>'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"right",
")",
")",
"{",
"$",
"media",
".=",
"'<div class=\"media-right\">'",
".",
"$",
"this",
"->",
"addClass",
"(",
"$",
"right",
",",
"array",
"(",
"'img'",
"=>",
"'media-object'",
")",
")",
".",
"'</div>'",
";",
"}",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'div'",
",",
"array",
"(",
"'id'",
"=>",
"isset",
"(",
"$",
"div",
"[",
"'id'",
"]",
")",
"?",
"$",
"div",
"[",
"'id'",
"]",
":",
"''",
",",
"'class'",
"=>",
"isset",
"(",
"$",
"div",
"[",
"'class'",
"]",
")",
"?",
"'media '",
".",
"$",
"div",
"[",
"'class'",
"]",
":",
"'media'",
",",
")",
",",
"$",
"media",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"siblings",
")",
")",
"{",
"$",
"html",
".=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"'media'",
")",
",",
"$",
"siblings",
")",
";",
"}",
"return",
"$",
"html",
";",
"}",
"}"
]
| This is the easiest way I could devise of making Bootstrap media objects as manageable as possible. ``<h1-6>`` headers and ``<img>``es will automatically be classed appropriately.
@param array $list A media array row that looks like this: ``array($left, $body, $right)``.
- If you don't have an image or whatever for the left side, then set an empty value.
- If you have nothing to right align then you can either leave it off, or set an empty value.
- If you have a special class and / or id to assign, then you can include them in the array like so:
- ``array('id' => $id, 'class' => 'custom', $left, $body, $right);``
- You can pack unlimited $list's (arguments) into this method, each $list being a sibling of the other:
- ``$bp->media(array($left, $body, $right), array($left, $body, $right), array($left, $body, $right));``
- To nest media lists in a parent / child relationship, just add another media array row to the parent:
- ``array($left, $body, $right, array($left, $body, $right, array($left, $body, $right)));`` - This would be a parent, child, grandchild arrangement.
- ``array($left, $body, $right, array($left, $body, $right), array($left, $body, $right));`` - A parent, child, child condition.
- ``array($left, $body, $right, array($left, $body, $right, array($left, $body, $right), array($left, $body, $right)), array($left, $body, $right)), array($left, $body, $right));`` - Now I'm just messing with you, but I think you've got the picture (a parent, child, grandchild, grandchild, child, sibling).
- This could go on ad infinitum, but soon your content will become pretty scrunched up if you take it too far.
@return string
@example
```php
echo $bp->media(array(
'Image',
'<h1>Parent</h1> <p>Paragraph</p>',
'<img src="parent.jpg" alt="Family Photo">',
array(
'Image',
'<h2>1st Child</h2>',
array(
'Image',
'<h3>1st Grandchild</h3>',
),
),
array(
'Image',
'<h2>2nd Child</h2>',
),
), array(
'class' => 'special',
'Image',
'<h1>Sibling</h1> <a href="#">Link</a>',
'<img src="sibling.jpg" alt="Family Photo">',
));
``` | [
"This",
"is",
"the",
"easiest",
"way",
"I",
"could",
"devise",
"of",
"making",
"Bootstrap",
"media",
"objects",
"as",
"manageable",
"as",
"possible",
".",
"<h1",
"-",
"6",
">",
"headers",
"and",
"<img",
">",
"es",
"will",
"automatically",
"be",
"classed",
"appropriately",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L857-L909 |
Kylob/Bootstrap | src/Common.php | Common.listGroup | public function listGroup(array $links, $active = false)
{
$html = '';
$tag = 'a';
$count = 1;
foreach ($links as $name => $href) {
if (empty($html) && empty($name)) {
$tag = 'li';
}
$attributes = array('class' => 'list-group-item');
if ($tag == 'li') {
$name = $href;
} else {
$attributes['href'] = $href;
if (in_array($active, array($count, $name, $href))) {
$attributes['class'] .= ' active';
}
}
$html .= $this->page->tag($tag, $attributes, $this->addClass($name, array(
'h([1-6]){1}' => 'list-group-item-heading',
'p' => 'list-group-item-text',
)));
++$count;
}
return $this->page->tag($tag == 'a' ? 'div' : 'ul', array('class' => 'list-group'), $html);
} | php | public function listGroup(array $links, $active = false)
{
$html = '';
$tag = 'a';
$count = 1;
foreach ($links as $name => $href) {
if (empty($html) && empty($name)) {
$tag = 'li';
}
$attributes = array('class' => 'list-group-item');
if ($tag == 'li') {
$name = $href;
} else {
$attributes['href'] = $href;
if (in_array($active, array($count, $name, $href))) {
$attributes['class'] .= ' active';
}
}
$html .= $this->page->tag($tag, $attributes, $this->addClass($name, array(
'h([1-6]){1}' => 'list-group-item-heading',
'p' => 'list-group-item-text',
)));
++$count;
}
return $this->page->tag($tag == 'a' ? 'div' : 'ul', array('class' => 'list-group'), $html);
} | [
"public",
"function",
"listGroup",
"(",
"array",
"$",
"links",
",",
"$",
"active",
"=",
"false",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"tag",
"=",
"'a'",
";",
"$",
"count",
"=",
"1",
";",
"foreach",
"(",
"$",
"links",
"as",
"$",
"name",
"=>",
"$",
"href",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"html",
")",
"&&",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"$",
"tag",
"=",
"'li'",
";",
"}",
"$",
"attributes",
"=",
"array",
"(",
"'class'",
"=>",
"'list-group-item'",
")",
";",
"if",
"(",
"$",
"tag",
"==",
"'li'",
")",
"{",
"$",
"name",
"=",
"$",
"href",
";",
"}",
"else",
"{",
"$",
"attributes",
"[",
"'href'",
"]",
"=",
"$",
"href",
";",
"if",
"(",
"in_array",
"(",
"$",
"active",
",",
"array",
"(",
"$",
"count",
",",
"$",
"name",
",",
"$",
"href",
")",
")",
")",
"{",
"$",
"attributes",
"[",
"'class'",
"]",
".=",
"' active'",
";",
"}",
"}",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"$",
"tag",
",",
"$",
"attributes",
",",
"$",
"this",
"->",
"addClass",
"(",
"$",
"name",
",",
"array",
"(",
"'h([1-6]){1}'",
"=>",
"'list-group-item-heading'",
",",
"'p'",
"=>",
"'list-group-item-text'",
",",
")",
")",
")",
";",
"++",
"$",
"count",
";",
"}",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"$",
"tag",
"==",
"'a'",
"?",
"'div'",
":",
"'ul'",
",",
"array",
"(",
"'class'",
"=>",
"'list-group'",
")",
",",
"$",
"html",
")",
";",
"}"
]
| Creates a Bootstrap list group. ``<h1-6>`` Headers and ``<p>`` paragraphs will automatically be classed appropriately.
@param array $links If you would like to create an unordered list, then this is just an array of values. Otherwise this will be an ``array($name => $href, ...)`` of links. **$name** badges will automatically be positioned on the right.
@param mixed $active This value can be either the **$name**, **$href** (link), or an **integer** (starting from 1) that you would like to be selected as "**active**".
@return string
@example
```php
$bp->listGroup(array(
'Basic',
'List',
$bp->badge(1) . ' Group',
));
$bp->listGroup(array(
'Linked' => '#',
'List' => '#',
'Group ' . $bp->badge(2) => '#',
), 'Linked');
$bp->listGroup(array(
'<h4>Custom</h4> <p>List</p>' => '#',
$bp->badge(3) . ' <h4>Group</h4> <p>Linked</p>' => '#',
), 1);
``` | [
"Creates",
"a",
"Bootstrap",
"list",
"group",
".",
"<h1",
"-",
"6",
">",
"Headers",
"and",
"<p",
">",
"paragraphs",
"will",
"automatically",
"be",
"classed",
"appropriately",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L940-L966 |
Kylob/Bootstrap | src/Common.php | Common.panel | public function panel($class, array $sections)
{
$html = '';
foreach ($sections as $panel => $content) {
if (!is_numeric($panel)) {
$panel = substr($panel, 0, 4);
}
switch ((string) $panel) {
case 'head':
$html .= '<div class="panel-heading">'.$this->addClass($content, array('h([1-6]){1}' => 'panel-title')).'</div>';
break;
case 'body':
$html .= '<div class="panel-body">'.$content.'</div>';
break;
case 'foot':
$html .= '<div class="panel-footer">'.$content.'</div>';
break;
default:
$html .= $content;
break; // a table, or list group, or ...
}
}
return $this->page->tag('div', array(
'class' => $this->prefixClasses('panel', array('default', 'primary', 'success', 'info', 'warning', 'danger'), $class),
), $html);
} | php | public function panel($class, array $sections)
{
$html = '';
foreach ($sections as $panel => $content) {
if (!is_numeric($panel)) {
$panel = substr($panel, 0, 4);
}
switch ((string) $panel) {
case 'head':
$html .= '<div class="panel-heading">'.$this->addClass($content, array('h([1-6]){1}' => 'panel-title')).'</div>';
break;
case 'body':
$html .= '<div class="panel-body">'.$content.'</div>';
break;
case 'foot':
$html .= '<div class="panel-footer">'.$content.'</div>';
break;
default:
$html .= $content;
break; // a table, or list group, or ...
}
}
return $this->page->tag('div', array(
'class' => $this->prefixClasses('panel', array('default', 'primary', 'success', 'info', 'warning', 'danger'), $class),
), $html);
} | [
"public",
"function",
"panel",
"(",
"$",
"class",
",",
"array",
"$",
"sections",
")",
"{",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"panel",
"=>",
"$",
"content",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"panel",
")",
")",
"{",
"$",
"panel",
"=",
"substr",
"(",
"$",
"panel",
",",
"0",
",",
"4",
")",
";",
"}",
"switch",
"(",
"(",
"string",
")",
"$",
"panel",
")",
"{",
"case",
"'head'",
":",
"$",
"html",
".=",
"'<div class=\"panel-heading\">'",
".",
"$",
"this",
"->",
"addClass",
"(",
"$",
"content",
",",
"array",
"(",
"'h([1-6]){1}'",
"=>",
"'panel-title'",
")",
")",
".",
"'</div>'",
";",
"break",
";",
"case",
"'body'",
":",
"$",
"html",
".=",
"'<div class=\"panel-body\">'",
".",
"$",
"content",
".",
"'</div>'",
";",
"break",
";",
"case",
"'foot'",
":",
"$",
"html",
".=",
"'<div class=\"panel-footer\">'",
".",
"$",
"content",
".",
"'</div>'",
";",
"break",
";",
"default",
":",
"$",
"html",
".=",
"$",
"content",
";",
"break",
";",
"// a table, or list group, or ...",
"}",
"}",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"$",
"this",
"->",
"prefixClasses",
"(",
"'panel'",
",",
"array",
"(",
"'default'",
",",
"'primary'",
",",
"'success'",
",",
"'info'",
",",
"'warning'",
",",
"'danger'",
")",
",",
"$",
"class",
")",
",",
")",
",",
"$",
"html",
")",
";",
"}"
]
| Creates a Bootstrap panel component.
@param string $class Either '**default**', '**primary**', '**success**', '**info**', '**warning**', or '**danger**'. The '**panel**' class and prefix are automatically included. You can add more classes to it if you like.
@param array $sections An ``array($panel => $content, ...)`` of sections. If **$panel** equals:
- '**head**', '**header**', or '**heading**' => The panel heading **$content**. All ``<h1-6>`` headers will be classed appropriately.
- '**body**' => The panel body **$content**.
- '**foot**', '**footer**', or '**footing**' => The panel footer **$content**.
- Anything else will just be inserted as is. It could be a table, or list group, or ...
@return string
@example
```php
echo $bp->panel('primary', array(
'header' => '<h3>Title</h3>',
'body' => 'Content',
'footer' => '<a href="#">Link</a>',
));
echo $bp->panel('default', array(
'header': 'List group',
$bp->listGroup(array(
'One',
'Two',
'Three',
)),
));
``` | [
"Creates",
"a",
"Bootstrap",
"panel",
"component",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L1000-L1026 |
Kylob/Bootstrap | src/Common.php | Common.toggle | public function toggle($type, array $links, array $options = array())
{
$count = 1;
$toggle = array();
$content = '';
$class = (in_array('fade', $options)) ? 'tab-pane fade' : 'tab-pane';
$active = (isset($options['active'])) ? $options['active'] : '';
$disabled = (isset($options['disabled'])) ? $options['disabled'] : '';
foreach ($links as $name => $html) {
if (is_array($html)) {
foreach ($html as $drop => $down) { // cannot be an array, but can be disabled, active, or empty
if (is_numeric($drop)) { // then it is either a header or a divider
$toggle[$name][$drop] = $down;
} else {
$id = $this->page->id('tabs');
}
$toggle[$name][$drop] = '#'.$id;
if ($active == $drop || $active == $count) {
$options['active'] = '#'.$id;
$content .= '<div role="tabpanel" class="'.$class.' in active" id="'.$id.'">'.$down.'</div>';
} else {
if ($disabled == $drop || $disabled == $count) {
$options['disabled'] = '#'.$id;
}
$content .= '<div role="tabpanel" class="'.$class.'" id="'.$id.'">'.$down.'</div>';
}
++$count;
}
} else { // $name (a tab) cannot be empty
if ($frag = strpos($name, '#')) { // if it is the first character then it doesn't count
$id = substr($name, $frag + 1);
$name = substr($name, 0, $frag);
} else {
$id = $this->page->id('tabs');
}
$toggle[$name] = '#'.$id;
if ($active == $name || $active == $count) {
$options['active'] = '#'.$id;
$content .= '<div role="tabpanel" class="'.$class.' in active" id="'.$id.'">'.$html.'</div>';
} else {
if ($disabled == $name || $disabled == $count) {
$options['disabled'] = '#'.$id;
}
$content .= '<div role="tabpanel" class="'.$class.'" id="'.$id.'">'.$html.'</div>';
}
++$count;
}
}
if (substr($type, 0, 4) == 'pill') {
$options['toggle'] = 'pill';
$class = 'nav nav-pills';
} else { // tabs
$options['toggle'] = 'tab';
$class = 'nav nav-tabs';
}
if (isset($options['align']) && $options['align'] == 'justified') {
$class .= ' nav-justified';
}
return '<ul class="'.$class.'" role="tablist">'.$this->links('li', $toggle, $options).'</ul><div class="tab-content">'.$content.'</div>';
} | php | public function toggle($type, array $links, array $options = array())
{
$count = 1;
$toggle = array();
$content = '';
$class = (in_array('fade', $options)) ? 'tab-pane fade' : 'tab-pane';
$active = (isset($options['active'])) ? $options['active'] : '';
$disabled = (isset($options['disabled'])) ? $options['disabled'] : '';
foreach ($links as $name => $html) {
if (is_array($html)) {
foreach ($html as $drop => $down) { // cannot be an array, but can be disabled, active, or empty
if (is_numeric($drop)) { // then it is either a header or a divider
$toggle[$name][$drop] = $down;
} else {
$id = $this->page->id('tabs');
}
$toggle[$name][$drop] = '#'.$id;
if ($active == $drop || $active == $count) {
$options['active'] = '#'.$id;
$content .= '<div role="tabpanel" class="'.$class.' in active" id="'.$id.'">'.$down.'</div>';
} else {
if ($disabled == $drop || $disabled == $count) {
$options['disabled'] = '#'.$id;
}
$content .= '<div role="tabpanel" class="'.$class.'" id="'.$id.'">'.$down.'</div>';
}
++$count;
}
} else { // $name (a tab) cannot be empty
if ($frag = strpos($name, '#')) { // if it is the first character then it doesn't count
$id = substr($name, $frag + 1);
$name = substr($name, 0, $frag);
} else {
$id = $this->page->id('tabs');
}
$toggle[$name] = '#'.$id;
if ($active == $name || $active == $count) {
$options['active'] = '#'.$id;
$content .= '<div role="tabpanel" class="'.$class.' in active" id="'.$id.'">'.$html.'</div>';
} else {
if ($disabled == $name || $disabled == $count) {
$options['disabled'] = '#'.$id;
}
$content .= '<div role="tabpanel" class="'.$class.'" id="'.$id.'">'.$html.'</div>';
}
++$count;
}
}
if (substr($type, 0, 4) == 'pill') {
$options['toggle'] = 'pill';
$class = 'nav nav-pills';
} else { // tabs
$options['toggle'] = 'tab';
$class = 'nav nav-tabs';
}
if (isset($options['align']) && $options['align'] == 'justified') {
$class .= ' nav-justified';
}
return '<ul class="'.$class.'" role="tablist">'.$this->links('li', $toggle, $options).'</ul><div class="tab-content">'.$content.'</div>';
} | [
"public",
"function",
"toggle",
"(",
"$",
"type",
",",
"array",
"$",
"links",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"count",
"=",
"1",
";",
"$",
"toggle",
"=",
"array",
"(",
")",
";",
"$",
"content",
"=",
"''",
";",
"$",
"class",
"=",
"(",
"in_array",
"(",
"'fade'",
",",
"$",
"options",
")",
")",
"?",
"'tab-pane fade'",
":",
"'tab-pane'",
";",
"$",
"active",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'active'",
"]",
")",
")",
"?",
"$",
"options",
"[",
"'active'",
"]",
":",
"''",
";",
"$",
"disabled",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'disabled'",
"]",
")",
")",
"?",
"$",
"options",
"[",
"'disabled'",
"]",
":",
"''",
";",
"foreach",
"(",
"$",
"links",
"as",
"$",
"name",
"=>",
"$",
"html",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"html",
")",
")",
"{",
"foreach",
"(",
"$",
"html",
"as",
"$",
"drop",
"=>",
"$",
"down",
")",
"{",
"// cannot be an array, but can be disabled, active, or empty",
"if",
"(",
"is_numeric",
"(",
"$",
"drop",
")",
")",
"{",
"// then it is either a header or a divider",
"$",
"toggle",
"[",
"$",
"name",
"]",
"[",
"$",
"drop",
"]",
"=",
"$",
"down",
";",
"}",
"else",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"page",
"->",
"id",
"(",
"'tabs'",
")",
";",
"}",
"$",
"toggle",
"[",
"$",
"name",
"]",
"[",
"$",
"drop",
"]",
"=",
"'#'",
".",
"$",
"id",
";",
"if",
"(",
"$",
"active",
"==",
"$",
"drop",
"||",
"$",
"active",
"==",
"$",
"count",
")",
"{",
"$",
"options",
"[",
"'active'",
"]",
"=",
"'#'",
".",
"$",
"id",
";",
"$",
"content",
".=",
"'<div role=\"tabpanel\" class=\"'",
".",
"$",
"class",
".",
"' in active\" id=\"'",
".",
"$",
"id",
".",
"'\">'",
".",
"$",
"down",
".",
"'</div>'",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"disabled",
"==",
"$",
"drop",
"||",
"$",
"disabled",
"==",
"$",
"count",
")",
"{",
"$",
"options",
"[",
"'disabled'",
"]",
"=",
"'#'",
".",
"$",
"id",
";",
"}",
"$",
"content",
".=",
"'<div role=\"tabpanel\" class=\"'",
".",
"$",
"class",
".",
"'\" id=\"'",
".",
"$",
"id",
".",
"'\">'",
".",
"$",
"down",
".",
"'</div>'",
";",
"}",
"++",
"$",
"count",
";",
"}",
"}",
"else",
"{",
"// $name (a tab) cannot be empty",
"if",
"(",
"$",
"frag",
"=",
"strpos",
"(",
"$",
"name",
",",
"'#'",
")",
")",
"{",
"// if it is the first character then it doesn't count",
"$",
"id",
"=",
"substr",
"(",
"$",
"name",
",",
"$",
"frag",
"+",
"1",
")",
";",
"$",
"name",
"=",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"$",
"frag",
")",
";",
"}",
"else",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"page",
"->",
"id",
"(",
"'tabs'",
")",
";",
"}",
"$",
"toggle",
"[",
"$",
"name",
"]",
"=",
"'#'",
".",
"$",
"id",
";",
"if",
"(",
"$",
"active",
"==",
"$",
"name",
"||",
"$",
"active",
"==",
"$",
"count",
")",
"{",
"$",
"options",
"[",
"'active'",
"]",
"=",
"'#'",
".",
"$",
"id",
";",
"$",
"content",
".=",
"'<div role=\"tabpanel\" class=\"'",
".",
"$",
"class",
".",
"' in active\" id=\"'",
".",
"$",
"id",
".",
"'\">'",
".",
"$",
"html",
".",
"'</div>'",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"disabled",
"==",
"$",
"name",
"||",
"$",
"disabled",
"==",
"$",
"count",
")",
"{",
"$",
"options",
"[",
"'disabled'",
"]",
"=",
"'#'",
".",
"$",
"id",
";",
"}",
"$",
"content",
".=",
"'<div role=\"tabpanel\" class=\"'",
".",
"$",
"class",
".",
"'\" id=\"'",
".",
"$",
"id",
".",
"'\">'",
".",
"$",
"html",
".",
"'</div>'",
";",
"}",
"++",
"$",
"count",
";",
"}",
"}",
"if",
"(",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"4",
")",
"==",
"'pill'",
")",
"{",
"$",
"options",
"[",
"'toggle'",
"]",
"=",
"'pill'",
";",
"$",
"class",
"=",
"'nav nav-pills'",
";",
"}",
"else",
"{",
"// tabs",
"$",
"options",
"[",
"'toggle'",
"]",
"=",
"'tab'",
";",
"$",
"class",
"=",
"'nav nav-tabs'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'align'",
"]",
")",
"&&",
"$",
"options",
"[",
"'align'",
"]",
"==",
"'justified'",
")",
"{",
"$",
"class",
".=",
"' nav-justified'",
";",
"}",
"return",
"'<ul class=\"'",
".",
"$",
"class",
".",
"'\" role=\"tablist\">'",
".",
"$",
"this",
"->",
"links",
"(",
"'li'",
",",
"$",
"toggle",
",",
"$",
"options",
")",
".",
"'</ul><div class=\"tab-content\">'",
".",
"$",
"content",
".",
"'</div>'",
";",
"}"
]
| Creates toggleable tabs and pills for transitioning through panes of local content.
@param string $type Specify either '**tabs**' or '**pills**'.
@param array $links An ``array($name => $html, ...)`` of content to toggle through. If **$html** is an array unto itself, then it will be turned into a dropdown menu with the same header and divider rules applied as with ``$bp->buttons()``.
@param array $options The available options are:
- '**fade**' - No key, just the value. This will give your panes a fade in effect while toggling.
- '**active**' => **$name**, **$html** (if you dare), or an **integer** (starting from 1).
- '**disabled**' => **$name**, **$html** (if you dare), or an **integer** (starting from 1).
- '**align**' => '**justified**', '**left**', or '**right**'.
@return string
@example
```php
echo $bp->toggle('tabs', array(
'Home' => 'One',
'Profile' => 'Two',
'Dropdown' => array(
'This' => 'Three',
'That' => 'Four',
),
), array(
'active' => 'This',
'fade',
));
``` | [
"Creates",
"toggleable",
"tabs",
"and",
"pills",
"for",
"transitioning",
"through",
"panes",
"of",
"local",
"content",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L1058-L1118 |
Kylob/Bootstrap | src/Common.php | Common.accordion | public function accordion($class, array $sections, $open = 1)
{
$html = '';
$count = 0;
$id = $this->page->id('accordion');
foreach ($sections as $head => $body) {
++$count;
$heading = $this->page->id('heading');
$collapse = $this->page->id('collapse');
$in = ($open == $count) ? ' in' : '';
$attributes = array(
'role' => 'button',
'data-toggle' => 'collapse',
'data-parent' => '#'.$id,
'href' => '#'.$collapse,
'aria-expanded' => !empty($in) ? 'true' : 'false',
'aria-controls' => $collapse,
);
$begin = strpos($head, '>') + 1;
$end = strrpos($head, '</');
$head = substr($head, 0, $begin).$this->page->tag('a', $attributes, substr($head, $begin, $end - $begin)).substr($head, $end);
$head = substr($this->panel($class, array('head' => $head)), 0, -6); // </div>
$html .= substr_replace($head, ' role="tab" id="'.$heading.'"', strpos($head, 'class="panel-heading"') + 21, 0);
$html .= $this->page->tag('div', array(
'id' => $collapse,
'class' => 'panel-collapse collapse'.$in,
'role' => 'tabpanel',
'aria-labelledby' => $heading,
), strpos($body, 'class="list-group"') ? $body : '<div class="panel-body">'.$body.'</div>');
$html .= '</div>'; // the one we removed from the $head up top
}
return $this->page->tag('div', array(
'class' => 'panel-group',
'id' => $id,
'role' => 'tablist',
'aria-multiselectable' => 'true',
), $html);
} | php | public function accordion($class, array $sections, $open = 1)
{
$html = '';
$count = 0;
$id = $this->page->id('accordion');
foreach ($sections as $head => $body) {
++$count;
$heading = $this->page->id('heading');
$collapse = $this->page->id('collapse');
$in = ($open == $count) ? ' in' : '';
$attributes = array(
'role' => 'button',
'data-toggle' => 'collapse',
'data-parent' => '#'.$id,
'href' => '#'.$collapse,
'aria-expanded' => !empty($in) ? 'true' : 'false',
'aria-controls' => $collapse,
);
$begin = strpos($head, '>') + 1;
$end = strrpos($head, '</');
$head = substr($head, 0, $begin).$this->page->tag('a', $attributes, substr($head, $begin, $end - $begin)).substr($head, $end);
$head = substr($this->panel($class, array('head' => $head)), 0, -6); // </div>
$html .= substr_replace($head, ' role="tab" id="'.$heading.'"', strpos($head, 'class="panel-heading"') + 21, 0);
$html .= $this->page->tag('div', array(
'id' => $collapse,
'class' => 'panel-collapse collapse'.$in,
'role' => 'tabpanel',
'aria-labelledby' => $heading,
), strpos($body, 'class="list-group"') ? $body : '<div class="panel-body">'.$body.'</div>');
$html .= '</div>'; // the one we removed from the $head up top
}
return $this->page->tag('div', array(
'class' => 'panel-group',
'id' => $id,
'role' => 'tablist',
'aria-multiselectable' => 'true',
), $html);
} | [
"public",
"function",
"accordion",
"(",
"$",
"class",
",",
"array",
"$",
"sections",
",",
"$",
"open",
"=",
"1",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"count",
"=",
"0",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"page",
"->",
"id",
"(",
"'accordion'",
")",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"head",
"=>",
"$",
"body",
")",
"{",
"++",
"$",
"count",
";",
"$",
"heading",
"=",
"$",
"this",
"->",
"page",
"->",
"id",
"(",
"'heading'",
")",
";",
"$",
"collapse",
"=",
"$",
"this",
"->",
"page",
"->",
"id",
"(",
"'collapse'",
")",
";",
"$",
"in",
"=",
"(",
"$",
"open",
"==",
"$",
"count",
")",
"?",
"' in'",
":",
"''",
";",
"$",
"attributes",
"=",
"array",
"(",
"'role'",
"=>",
"'button'",
",",
"'data-toggle'",
"=>",
"'collapse'",
",",
"'data-parent'",
"=>",
"'#'",
".",
"$",
"id",
",",
"'href'",
"=>",
"'#'",
".",
"$",
"collapse",
",",
"'aria-expanded'",
"=>",
"!",
"empty",
"(",
"$",
"in",
")",
"?",
"'true'",
":",
"'false'",
",",
"'aria-controls'",
"=>",
"$",
"collapse",
",",
")",
";",
"$",
"begin",
"=",
"strpos",
"(",
"$",
"head",
",",
"'>'",
")",
"+",
"1",
";",
"$",
"end",
"=",
"strrpos",
"(",
"$",
"head",
",",
"'</'",
")",
";",
"$",
"head",
"=",
"substr",
"(",
"$",
"head",
",",
"0",
",",
"$",
"begin",
")",
".",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'a'",
",",
"$",
"attributes",
",",
"substr",
"(",
"$",
"head",
",",
"$",
"begin",
",",
"$",
"end",
"-",
"$",
"begin",
")",
")",
".",
"substr",
"(",
"$",
"head",
",",
"$",
"end",
")",
";",
"$",
"head",
"=",
"substr",
"(",
"$",
"this",
"->",
"panel",
"(",
"$",
"class",
",",
"array",
"(",
"'head'",
"=>",
"$",
"head",
")",
")",
",",
"0",
",",
"-",
"6",
")",
";",
"// </div>",
"$",
"html",
".=",
"substr_replace",
"(",
"$",
"head",
",",
"' role=\"tab\" id=\"'",
".",
"$",
"heading",
".",
"'\"'",
",",
"strpos",
"(",
"$",
"head",
",",
"'class=\"panel-heading\"'",
")",
"+",
"21",
",",
"0",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'div'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"collapse",
",",
"'class'",
"=>",
"'panel-collapse collapse'",
".",
"$",
"in",
",",
"'role'",
"=>",
"'tabpanel'",
",",
"'aria-labelledby'",
"=>",
"$",
"heading",
",",
")",
",",
"strpos",
"(",
"$",
"body",
",",
"'class=\"list-group\"'",
")",
"?",
"$",
"body",
":",
"'<div class=\"panel-body\">'",
".",
"$",
"body",
".",
"'</div>'",
")",
";",
"$",
"html",
".=",
"'</div>'",
";",
"// the one we removed from the $head up top",
"}",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"'panel-group'",
",",
"'id'",
"=>",
"$",
"id",
",",
"'role'",
"=>",
"'tablist'",
",",
"'aria-multiselectable'",
"=>",
"'true'",
",",
")",
",",
"$",
"html",
")",
";",
"}"
]
| Bootstrap accordions are basically collapsible panels. That is essentially what you are creating here.
@param string $class Either '**default**', '**primary**', '**success**', '**info**', '**warning**', or '**danger**'. These only apply to the head section, and are passed directly by us into ``$bp->panel()``.
@param array $sections An ``array($heading => $body, ...)`` of sections that will become your accordion. The ``<h1-6>`` headers in the **$heading** will be automatically classed appropriately. Accordions are definitely nestable, but we don't create them via nested arrays through this method. Just add a pre-made accordion to the **$body** you would like it to reside in ie. the **$body** should never be an array.
@param int $open This is the panel number you would like be open from the get-go (starting at 1). If you don't want any panel to be opened initially, then set this to 0.
@return string
@example
```php
echo $bp->accordion('info', array(
'<h4>Group Item #1</h4>' => 'One',
'<h4>Group Item #2</h4>' => 'Two',
'<h4>Group Item #3</h4>' => 'Three',
), 2);
``` | [
"Bootstrap",
"accordions",
"are",
"basically",
"collapsible",
"panels",
".",
"That",
"is",
"essentially",
"what",
"you",
"are",
"creating",
"here",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L1139-L1177 |
Kylob/Bootstrap | src/Common.php | Common.carousel | public function carousel(array $images, array $options = array())
{
$html = '';
$id = $this->page->id('carousel');
$options = array_merge(array(
'interval' => 5000, // ie. 5 seconds in between frame changes
'indicators' => true, // set to false if you don't want them
'controls' => true, // set to false if you don't want them
), $options);
if ($options['indicators']) {
$indicators = array_keys(array_values($images));
$html .= '<ol class="carousel-indicators">';
$html .= '<li data-target="#'.$id.'" data-slide-to="'.array_shift($indicators).'" class="active"></li>';
foreach ($indicators as $num) {
$html .= '<li data-target="#'.$id.'" data-slide-to="'.$num.'"></li>';
}
$html .= '</ol>';
}
$html .= '<div class="carousel-inner" role="listbox">';
foreach ($images as $key => $value) {
$class = (isset($class)) ? 'item' : 'item active'; // ie. the first one is active
$img = (!is_numeric($key)) ? $key : $value;
$caption = (!is_numeric($key)) ? '<div class="carousel-caption">'.$value.'</div>' : '';
$html .= '<div class="'.$class.'">'.$img.$caption.'</div>';
}
$html .= '</div>';
if ($options['controls']) {
if (is_array($options['controls'])) {
list($left, $right) = $options['controls'];
if (strpos($left, '<') === false) {
$left = $this->icon($left, 'glyphicon', 'span aria-hidden="true"');
}
if (strpos($right, '<') === false) {
$right = $this->icon($right, 'glyphicon', 'span aria-hidden="true"');
}
} else {
$left = $this->icon('chevron-left', 'glyphicon', 'span aria-hidden="true"');
$right = $this->icon('chevron-right', 'glyphicon', 'span aria-hidden="true"');
}
$html .= $this->page->tag('a', array(
'class' => 'left carousel-control',
'href' => '#'.$id,
'role' => 'button',
'data-slide' => 'prev',
), $left, '<span class="sr-only">Previous</span>');
$html .= $this->page->tag('a', array(
'class' => 'right carousel-control',
'href' => '#'.$id,
'role' => 'button',
'data-slide' => 'next',
), $right, '<span class="sr-only">Next</span>');
}
return $this->page->tag('div', array(
'id' => $id,
'class' => 'carousel slide',
'data-ride' => 'carousel',
'data-interval' => $options['interval'],
), $html);
} | php | public function carousel(array $images, array $options = array())
{
$html = '';
$id = $this->page->id('carousel');
$options = array_merge(array(
'interval' => 5000, // ie. 5 seconds in between frame changes
'indicators' => true, // set to false if you don't want them
'controls' => true, // set to false if you don't want them
), $options);
if ($options['indicators']) {
$indicators = array_keys(array_values($images));
$html .= '<ol class="carousel-indicators">';
$html .= '<li data-target="#'.$id.'" data-slide-to="'.array_shift($indicators).'" class="active"></li>';
foreach ($indicators as $num) {
$html .= '<li data-target="#'.$id.'" data-slide-to="'.$num.'"></li>';
}
$html .= '</ol>';
}
$html .= '<div class="carousel-inner" role="listbox">';
foreach ($images as $key => $value) {
$class = (isset($class)) ? 'item' : 'item active'; // ie. the first one is active
$img = (!is_numeric($key)) ? $key : $value;
$caption = (!is_numeric($key)) ? '<div class="carousel-caption">'.$value.'</div>' : '';
$html .= '<div class="'.$class.'">'.$img.$caption.'</div>';
}
$html .= '</div>';
if ($options['controls']) {
if (is_array($options['controls'])) {
list($left, $right) = $options['controls'];
if (strpos($left, '<') === false) {
$left = $this->icon($left, 'glyphicon', 'span aria-hidden="true"');
}
if (strpos($right, '<') === false) {
$right = $this->icon($right, 'glyphicon', 'span aria-hidden="true"');
}
} else {
$left = $this->icon('chevron-left', 'glyphicon', 'span aria-hidden="true"');
$right = $this->icon('chevron-right', 'glyphicon', 'span aria-hidden="true"');
}
$html .= $this->page->tag('a', array(
'class' => 'left carousel-control',
'href' => '#'.$id,
'role' => 'button',
'data-slide' => 'prev',
), $left, '<span class="sr-only">Previous</span>');
$html .= $this->page->tag('a', array(
'class' => 'right carousel-control',
'href' => '#'.$id,
'role' => 'button',
'data-slide' => 'next',
), $right, '<span class="sr-only">Next</span>');
}
return $this->page->tag('div', array(
'id' => $id,
'class' => 'carousel slide',
'data-ride' => 'carousel',
'data-interval' => $options['interval'],
), $html);
} | [
"public",
"function",
"carousel",
"(",
"array",
"$",
"images",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"html",
"=",
"''",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"page",
"->",
"id",
"(",
"'carousel'",
")",
";",
"$",
"options",
"=",
"array_merge",
"(",
"array",
"(",
"'interval'",
"=>",
"5000",
",",
"// ie. 5 seconds in between frame changes",
"'indicators'",
"=>",
"true",
",",
"// set to false if you don't want them",
"'controls'",
"=>",
"true",
",",
"// set to false if you don't want them",
")",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'indicators'",
"]",
")",
"{",
"$",
"indicators",
"=",
"array_keys",
"(",
"array_values",
"(",
"$",
"images",
")",
")",
";",
"$",
"html",
".=",
"'<ol class=\"carousel-indicators\">'",
";",
"$",
"html",
".=",
"'<li data-target=\"#'",
".",
"$",
"id",
".",
"'\" data-slide-to=\"'",
".",
"array_shift",
"(",
"$",
"indicators",
")",
".",
"'\" class=\"active\"></li>'",
";",
"foreach",
"(",
"$",
"indicators",
"as",
"$",
"num",
")",
"{",
"$",
"html",
".=",
"'<li data-target=\"#'",
".",
"$",
"id",
".",
"'\" data-slide-to=\"'",
".",
"$",
"num",
".",
"'\"></li>'",
";",
"}",
"$",
"html",
".=",
"'</ol>'",
";",
"}",
"$",
"html",
".=",
"'<div class=\"carousel-inner\" role=\"listbox\">'",
";",
"foreach",
"(",
"$",
"images",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"class",
"=",
"(",
"isset",
"(",
"$",
"class",
")",
")",
"?",
"'item'",
":",
"'item active'",
";",
"// ie. the first one is active",
"$",
"img",
"=",
"(",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"?",
"$",
"key",
":",
"$",
"value",
";",
"$",
"caption",
"=",
"(",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"?",
"'<div class=\"carousel-caption\">'",
".",
"$",
"value",
".",
"'</div>'",
":",
"''",
";",
"$",
"html",
".=",
"'<div class=\"'",
".",
"$",
"class",
".",
"'\">'",
".",
"$",
"img",
".",
"$",
"caption",
".",
"'</div>'",
";",
"}",
"$",
"html",
".=",
"'</div>'",
";",
"if",
"(",
"$",
"options",
"[",
"'controls'",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"options",
"[",
"'controls'",
"]",
")",
")",
"{",
"list",
"(",
"$",
"left",
",",
"$",
"right",
")",
"=",
"$",
"options",
"[",
"'controls'",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"left",
",",
"'<'",
")",
"===",
"false",
")",
"{",
"$",
"left",
"=",
"$",
"this",
"->",
"icon",
"(",
"$",
"left",
",",
"'glyphicon'",
",",
"'span aria-hidden=\"true\"'",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"right",
",",
"'<'",
")",
"===",
"false",
")",
"{",
"$",
"right",
"=",
"$",
"this",
"->",
"icon",
"(",
"$",
"right",
",",
"'glyphicon'",
",",
"'span aria-hidden=\"true\"'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"left",
"=",
"$",
"this",
"->",
"icon",
"(",
"'chevron-left'",
",",
"'glyphicon'",
",",
"'span aria-hidden=\"true\"'",
")",
";",
"$",
"right",
"=",
"$",
"this",
"->",
"icon",
"(",
"'chevron-right'",
",",
"'glyphicon'",
",",
"'span aria-hidden=\"true\"'",
")",
";",
"}",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'a'",
",",
"array",
"(",
"'class'",
"=>",
"'left carousel-control'",
",",
"'href'",
"=>",
"'#'",
".",
"$",
"id",
",",
"'role'",
"=>",
"'button'",
",",
"'data-slide'",
"=>",
"'prev'",
",",
")",
",",
"$",
"left",
",",
"'<span class=\"sr-only\">Previous</span>'",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'a'",
",",
"array",
"(",
"'class'",
"=>",
"'right carousel-control'",
",",
"'href'",
"=>",
"'#'",
".",
"$",
"id",
",",
"'role'",
"=>",
"'button'",
",",
"'data-slide'",
"=>",
"'next'",
",",
")",
",",
"$",
"right",
",",
"'<span class=\"sr-only\">Next</span>'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"page",
"->",
"tag",
"(",
"'div'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'class'",
"=>",
"'carousel slide'",
",",
"'data-ride'",
"=>",
"'carousel'",
",",
"'data-interval'",
"=>",
"$",
"options",
"[",
"'interval'",
"]",
",",
")",
",",
"$",
"html",
")",
";",
"}"
]
| Creates a Bootstrap carousel for cycling through elements. Those elements don't necessarily need to be images, but pretty much they always are.
@param array $images An ``array($image, ...)`` of images to cycle through, starting with the first (logically). To get fancy and add captions, then make this an ``array($image => $caption, ...)`` of images with captions to cycle through. If you have some images with captions and others without, then you can merge these two concepts no problem. Remember, the **$image** is not just a location, it is the entire ``<img>`` tag src and all.
@param array $options The available options are:
- '**interval**' => The time delay in thousandths of a second between cycles (or frame changes). The default is **5000** ie. 5 seconds.
- '**indicators**' => The little circle things at the bottom that show where you are at. If you don't want them, then set this to **false**. The default is **true** ie. include them.
- '**controls**' => The clickable arrows on the side for scrolling back and forth. If you don't want them, then set this to **false**. The default is **true** ie. include them. Also by default we use ``array($bp->icon('chevron-left'), $bp->icon('chevron-right'))`` for the left and right arrows. If you would like something else, then you can make this an array of your preferences.
@return string
@example
```php
echo '<div style="width:500px; height:300px; margin:20px auto;">';
echo $bp->carousel(array(
'<img src="http://lorempixel.com/500/300/food/1/" width="500" height="300">',
'<img src="http://lorempixel.com/500/300/food/2/" width="500" height="300">' => '<p>Caption</p>',
'<img src="http://lorempixel.com/500/300/food/3/" width="500" height="300">' => '<h3>Header</h3>',
), array(
'interval' => 3000,
));
echo '</div>';
``` | [
"Creates",
"a",
"Bootstrap",
"carousel",
"for",
"cycling",
"through",
"elements",
".",
"Those",
"elements",
"don",
"t",
"necessarily",
"need",
"to",
"be",
"images",
"but",
"pretty",
"much",
"they",
"always",
"are",
"."
]
| train | https://github.com/Kylob/Bootstrap/blob/0d7677a90656fbc461eabb5512ab16f9d5f728c6/src/Common.php#L1205-L1264 |
userfriendly/SocialUserBundle | DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root( 'userfriendly_social_user' );
$supportedDrivers = array( 'orm' );
//$supportedDrivers = array( 'orm', 'mongodb' );
$rootNode
->children()
->scalarNode( 'db_driver' )
->validate()
->ifNotInArray( $supportedDrivers )
->thenInvalid( 'The driver %s is not supported. Please choose one of ' . json_encode( $supportedDrivers ))
->end()
->cannotBeOverwritten()
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode( 'firewall_name' )->isRequired()->cannotBeEmpty()->end()
->scalarNode( 'user_class' )->isRequired()->cannotBeEmpty()->end()
->scalarNode( 'user_identity_class' )->defaultNull()->end()
->scalarNode( 'group_class' )->defaultNull()->end()
->scalarNode( 'model_manager_name' )->defaultNull()->end()
->scalarNode( 'mailsubject_emailchange' )->end()
->scalarNode( 'mailsubject_accountdetails' )->end()
->end();
$this->defineResourceOwnerConfig( $rootNode );
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root( 'userfriendly_social_user' );
$supportedDrivers = array( 'orm' );
//$supportedDrivers = array( 'orm', 'mongodb' );
$rootNode
->children()
->scalarNode( 'db_driver' )
->validate()
->ifNotInArray( $supportedDrivers )
->thenInvalid( 'The driver %s is not supported. Please choose one of ' . json_encode( $supportedDrivers ))
->end()
->cannotBeOverwritten()
->isRequired()
->cannotBeEmpty()
->end()
->scalarNode( 'firewall_name' )->isRequired()->cannotBeEmpty()->end()
->scalarNode( 'user_class' )->isRequired()->cannotBeEmpty()->end()
->scalarNode( 'user_identity_class' )->defaultNull()->end()
->scalarNode( 'group_class' )->defaultNull()->end()
->scalarNode( 'model_manager_name' )->defaultNull()->end()
->scalarNode( 'mailsubject_emailchange' )->end()
->scalarNode( 'mailsubject_accountdetails' )->end()
->end();
$this->defineResourceOwnerConfig( $rootNode );
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"rootNode",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"'userfriendly_social_user'",
")",
";",
"$",
"supportedDrivers",
"=",
"array",
"(",
"'orm'",
")",
";",
"//$supportedDrivers = array( 'orm', 'mongodb' );",
"$",
"rootNode",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'db_driver'",
")",
"->",
"validate",
"(",
")",
"->",
"ifNotInArray",
"(",
"$",
"supportedDrivers",
")",
"->",
"thenInvalid",
"(",
"'The driver %s is not supported. Please choose one of '",
".",
"json_encode",
"(",
"$",
"supportedDrivers",
")",
")",
"->",
"end",
"(",
")",
"->",
"cannotBeOverwritten",
"(",
")",
"->",
"isRequired",
"(",
")",
"->",
"cannotBeEmpty",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'firewall_name'",
")",
"->",
"isRequired",
"(",
")",
"->",
"cannotBeEmpty",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'user_class'",
")",
"->",
"isRequired",
"(",
")",
"->",
"cannotBeEmpty",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'user_identity_class'",
")",
"->",
"defaultNull",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'group_class'",
")",
"->",
"defaultNull",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'model_manager_name'",
")",
"->",
"defaultNull",
"(",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'mailsubject_emailchange'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'mailsubject_accountdetails'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"$",
"this",
"->",
"defineResourceOwnerConfig",
"(",
"$",
"rootNode",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
]
| Generates the configuration tree.
@return TreeBuilder | [
"Generates",
"the",
"configuration",
"tree",
"."
]
| train | https://github.com/userfriendly/SocialUserBundle/blob/1dfcf76af2bc639901c471e6f28b04d73fb65452/DependencyInjection/Configuration.php#L39-L70 |
webforge-labs/psc-cms | lib/Psc/Data/Crypt/AES.php | AES.encrypt | public function encrypt($clearText) {
return base64_encode(
mcrypt_encrypt(MCRYPT_RIJNDAEL_256,
$this->password,
$clearText,
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
MCRYPT_RAND
)
)
);
} | php | public function encrypt($clearText) {
return base64_encode(
mcrypt_encrypt(MCRYPT_RIJNDAEL_256,
$this->password,
$clearText,
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
MCRYPT_RAND
)
)
);
} | [
"public",
"function",
"encrypt",
"(",
"$",
"clearText",
")",
"{",
"return",
"base64_encode",
"(",
"mcrypt_encrypt",
"(",
"MCRYPT_RIJNDAEL_256",
",",
"$",
"this",
"->",
"password",
",",
"$",
"clearText",
",",
"MCRYPT_MODE_ECB",
",",
"mcrypt_create_iv",
"(",
"mcrypt_get_iv_size",
"(",
"MCRYPT_RIJNDAEL_256",
",",
"MCRYPT_MODE_ECB",
")",
",",
"MCRYPT_RAND",
")",
")",
")",
";",
"}"
]
| Gibt das encryptete in base64 zurück | [
"Gibt",
"das",
"encryptete",
"in",
"base64",
"zurück"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/Crypt/AES.php#L16-L28 |
webforge-labs/psc-cms | lib/Psc/Data/Crypt/AES.php | AES.decrypt | public function decrypt($encrypted) {
return trim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_256,
$this->password,
base64_decode($encrypted),
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
MCRYPT_RAND
)
)
);
} | php | public function decrypt($encrypted) {
return trim(
mcrypt_decrypt(
MCRYPT_RIJNDAEL_256,
$this->password,
base64_decode($encrypted),
MCRYPT_MODE_ECB,
mcrypt_create_iv(
mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),
MCRYPT_RAND
)
)
);
} | [
"public",
"function",
"decrypt",
"(",
"$",
"encrypted",
")",
"{",
"return",
"trim",
"(",
"mcrypt_decrypt",
"(",
"MCRYPT_RIJNDAEL_256",
",",
"$",
"this",
"->",
"password",
",",
"base64_decode",
"(",
"$",
"encrypted",
")",
",",
"MCRYPT_MODE_ECB",
",",
"mcrypt_create_iv",
"(",
"mcrypt_get_iv_size",
"(",
"MCRYPT_RIJNDAEL_256",
",",
"MCRYPT_MODE_ECB",
")",
",",
"MCRYPT_RAND",
")",
")",
")",
";",
"}"
]
| Gibt das decryptete in Klartext zurück
@param string $encrypted in base64 | [
"Gibt",
"das",
"decryptete",
"in",
"Klartext",
"zurück"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/Crypt/AES.php#L35-L48 |
steeffeen/FancyManiaLinks | FML/Script/Features/KeyAction.php | KeyAction.setKeyName | public function setKeyName($keyName)
{
$this->keyName = (string)$keyName;
$this->keyCode = null;
$this->charPressed = null;
return $this;
} | php | public function setKeyName($keyName)
{
$this->keyName = (string)$keyName;
$this->keyCode = null;
$this->charPressed = null;
return $this;
} | [
"public",
"function",
"setKeyName",
"(",
"$",
"keyName",
")",
"{",
"$",
"this",
"->",
"keyName",
"=",
"(",
"string",
")",
"$",
"keyName",
";",
"$",
"this",
"->",
"keyCode",
"=",
"null",
";",
"$",
"this",
"->",
"charPressed",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the key name for triggering the action
@api
@param string $keyName Key Name
@return static | [
"Set",
"the",
"key",
"name",
"for",
"triggering",
"the",
"action"
]
| train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/KeyAction.php#L99-L105 |
steeffeen/FancyManiaLinks | FML/Script/Features/KeyAction.php | KeyAction.setCharPressed | public function setCharPressed($charPressed)
{
$this->keyName = null;
$this->keyCode = null;
$this->charPressed = (string)$charPressed;
return $this;
} | php | public function setCharPressed($charPressed)
{
$this->keyName = null;
$this->keyCode = null;
$this->charPressed = (string)$charPressed;
return $this;
} | [
"public",
"function",
"setCharPressed",
"(",
"$",
"charPressed",
")",
"{",
"$",
"this",
"->",
"keyName",
"=",
"null",
";",
"$",
"this",
"->",
"keyCode",
"=",
"null",
";",
"$",
"this",
"->",
"charPressed",
"=",
"(",
"string",
")",
"$",
"charPressed",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the character to press for triggering the action
@api
@param string $charPressed Pressed character
@return static | [
"Set",
"the",
"character",
"to",
"press",
"for",
"triggering",
"the",
"action"
]
| train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/KeyAction.php#L151-L157 |
steeffeen/FancyManiaLinks | FML/Script/Features/KeyAction.php | KeyAction.getScriptText | protected function getScriptText()
{
$actionName = Builder::escapeText($this->actionName);
$key = null;
$value = null;
if ($this->keyName !== null) {
$key = "KeyName";
$value = $this->keyName;
} else if ($this->keyCode !== null) {
$key = "KeyCode";
$value = $this->keyCode;
} else if ($this->charPressed !== null) {
$key = "CharPressed";
$value = $this->charPressed;
}
$value = Builder::escapeText($value);
return "
if (Event.{$key} == {$value}) {
TriggerPageAction({$actionName});
}";
} | php | protected function getScriptText()
{
$actionName = Builder::escapeText($this->actionName);
$key = null;
$value = null;
if ($this->keyName !== null) {
$key = "KeyName";
$value = $this->keyName;
} else if ($this->keyCode !== null) {
$key = "KeyCode";
$value = $this->keyCode;
} else if ($this->charPressed !== null) {
$key = "CharPressed";
$value = $this->charPressed;
}
$value = Builder::escapeText($value);
return "
if (Event.{$key} == {$value}) {
TriggerPageAction({$actionName});
}";
} | [
"protected",
"function",
"getScriptText",
"(",
")",
"{",
"$",
"actionName",
"=",
"Builder",
"::",
"escapeText",
"(",
"$",
"this",
"->",
"actionName",
")",
";",
"$",
"key",
"=",
"null",
";",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"keyName",
"!==",
"null",
")",
"{",
"$",
"key",
"=",
"\"KeyName\"",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"keyName",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"keyCode",
"!==",
"null",
")",
"{",
"$",
"key",
"=",
"\"KeyCode\"",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"keyCode",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"charPressed",
"!==",
"null",
")",
"{",
"$",
"key",
"=",
"\"CharPressed\"",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"charPressed",
";",
"}",
"$",
"value",
"=",
"Builder",
"::",
"escapeText",
"(",
"$",
"value",
")",
";",
"return",
"\"\nif (Event.{$key} == {$value}) {\n\tTriggerPageAction({$actionName});\n}\"",
";",
"}"
]
| Get the script text
@return string | [
"Get",
"the",
"script",
"text"
]
| train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/KeyAction.php#L173-L193 |
parsnick/steak | src/Boot/ConfigureViewEngines.php | ConfigureViewEngines.boot | public function boot(Container $app)
{
$app->afterResolving(function (Factory $factory, $app) {
$factory->addExtension('php', 'php', function () {
return new PhpEngine();
});
$factory->addExtension('blade.php', 'blade', function () use ($app) {
return new CompilerEngine($app->make(BladeCompiler::class));
});
$factory->addExtension('md', 'markdown', function () use ($app) {
return new CompilerEngine($app->make(Markdown::class));
});
});
$app->when(BladeCompiler::class)
->needs('$cachePath')
->give(vfsStream::setup('root/.blade')->url());
} | php | public function boot(Container $app)
{
$app->afterResolving(function (Factory $factory, $app) {
$factory->addExtension('php', 'php', function () {
return new PhpEngine();
});
$factory->addExtension('blade.php', 'blade', function () use ($app) {
return new CompilerEngine($app->make(BladeCompiler::class));
});
$factory->addExtension('md', 'markdown', function () use ($app) {
return new CompilerEngine($app->make(Markdown::class));
});
});
$app->when(BladeCompiler::class)
->needs('$cachePath')
->give(vfsStream::setup('root/.blade')->url());
} | [
"public",
"function",
"boot",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"app",
"->",
"afterResolving",
"(",
"function",
"(",
"Factory",
"$",
"factory",
",",
"$",
"app",
")",
"{",
"$",
"factory",
"->",
"addExtension",
"(",
"'php'",
",",
"'php'",
",",
"function",
"(",
")",
"{",
"return",
"new",
"PhpEngine",
"(",
")",
";",
"}",
")",
";",
"$",
"factory",
"->",
"addExtension",
"(",
"'blade.php'",
",",
"'blade'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"CompilerEngine",
"(",
"$",
"app",
"->",
"make",
"(",
"BladeCompiler",
"::",
"class",
")",
")",
";",
"}",
")",
";",
"$",
"factory",
"->",
"addExtension",
"(",
"'md'",
",",
"'markdown'",
",",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"CompilerEngine",
"(",
"$",
"app",
"->",
"make",
"(",
"Markdown",
"::",
"class",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"$",
"app",
"->",
"when",
"(",
"BladeCompiler",
"::",
"class",
")",
"->",
"needs",
"(",
"'$cachePath'",
")",
"->",
"give",
"(",
"vfsStream",
"::",
"setup",
"(",
"'root/.blade'",
")",
"->",
"url",
"(",
")",
")",
";",
"}"
]
| Set up the various view engines.
@param Container $app | [
"Set",
"up",
"the",
"various",
"view",
"engines",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Boot/ConfigureViewEngines.php#L20-L41 |
vorbind/influx-analytics | src/Analytics.php | Analytics.getData | public function getData($rp, $metric, $tags, $granularity = 'daily', $startDt = null, $endDt = '2100-12-01T00:00:00Z', $timezone = 'UTC') {
$points = [];
try {
$pointsRp = $this->mapper->getRpPoints($rp, $metric, $tags, $granularity, $startDt, $endDt, $timezone);
$pointsTmp = $this->mapper->getPoints($metric, $tags, $granularity, $endDt, $timezone);
if (count($pointsRp) > 0 || count($pointsTmp) > 0) {
$points = $this->combineSumPoints(
$pointsRp, $this->fixTimeForGranularity($pointsTmp, $granularity)
);
}
return $points;
} catch (Exception $e) {
throw new AnalyticsException("Analytics client period get data exception", 0, $e);
}
} | php | public function getData($rp, $metric, $tags, $granularity = 'daily', $startDt = null, $endDt = '2100-12-01T00:00:00Z', $timezone = 'UTC') {
$points = [];
try {
$pointsRp = $this->mapper->getRpPoints($rp, $metric, $tags, $granularity, $startDt, $endDt, $timezone);
$pointsTmp = $this->mapper->getPoints($metric, $tags, $granularity, $endDt, $timezone);
if (count($pointsRp) > 0 || count($pointsTmp) > 0) {
$points = $this->combineSumPoints(
$pointsRp, $this->fixTimeForGranularity($pointsTmp, $granularity)
);
}
return $points;
} catch (Exception $e) {
throw new AnalyticsException("Analytics client period get data exception", 0, $e);
}
} | [
"public",
"function",
"getData",
"(",
"$",
"rp",
",",
"$",
"metric",
",",
"$",
"tags",
",",
"$",
"granularity",
"=",
"'daily'",
",",
"$",
"startDt",
"=",
"null",
",",
"$",
"endDt",
"=",
"'2100-12-01T00:00:00Z'",
",",
"$",
"timezone",
"=",
"'UTC'",
")",
"{",
"$",
"points",
"=",
"[",
"]",
";",
"try",
"{",
"$",
"pointsRp",
"=",
"$",
"this",
"->",
"mapper",
"->",
"getRpPoints",
"(",
"$",
"rp",
",",
"$",
"metric",
",",
"$",
"tags",
",",
"$",
"granularity",
",",
"$",
"startDt",
",",
"$",
"endDt",
",",
"$",
"timezone",
")",
";",
"$",
"pointsTmp",
"=",
"$",
"this",
"->",
"mapper",
"->",
"getPoints",
"(",
"$",
"metric",
",",
"$",
"tags",
",",
"$",
"granularity",
",",
"$",
"endDt",
",",
"$",
"timezone",
")",
";",
"if",
"(",
"count",
"(",
"$",
"pointsRp",
")",
">",
"0",
"||",
"count",
"(",
"$",
"pointsTmp",
")",
">",
"0",
")",
"{",
"$",
"points",
"=",
"$",
"this",
"->",
"combineSumPoints",
"(",
"$",
"pointsRp",
",",
"$",
"this",
"->",
"fixTimeForGranularity",
"(",
"$",
"pointsTmp",
",",
"$",
"granularity",
")",
")",
";",
"}",
"return",
"$",
"points",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"AnalyticsException",
"(",
"\"Analytics client period get data exception\"",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
]
| Get analytics data in right time zone by period and granularity
@param string $rp
@param string $metric
@param array $tags
@param string $granularity
@param string $startDt
@param string $endDt
@param string $timezone
@return int
@throws AnalyticsException | [
"Get",
"analytics",
"data",
"in",
"right",
"time",
"zone",
"by",
"period",
"and",
"granularity"
]
| train | https://github.com/vorbind/influx-analytics/blob/8c0c150351f045ccd3d57063f2b3b50a2c926e3e/src/Analytics.php#L57-L72 |
vorbind/influx-analytics | src/Analytics.php | Analytics.getTotal | public function getTotal($rp, $metric, $tags) {
try {
$todayDt = date("Y-m-d") . "T00:00:00Z";
return $this->mapper->getRpSum('forever', $metric, $tags) +
$this->mapper->getRpSum($rp, $metric, $tags, $todayDt) +
$this->mapper->getSum($metric, $tags);
} catch (Exception $e) {
throw new AnalyticsException("Analytics client get total exception", 0, $e);
}
} | php | public function getTotal($rp, $metric, $tags) {
try {
$todayDt = date("Y-m-d") . "T00:00:00Z";
return $this->mapper->getRpSum('forever', $metric, $tags) +
$this->mapper->getRpSum($rp, $metric, $tags, $todayDt) +
$this->mapper->getSum($metric, $tags);
} catch (Exception $e) {
throw new AnalyticsException("Analytics client get total exception", 0, $e);
}
} | [
"public",
"function",
"getTotal",
"(",
"$",
"rp",
",",
"$",
"metric",
",",
"$",
"tags",
")",
"{",
"try",
"{",
"$",
"todayDt",
"=",
"date",
"(",
"\"Y-m-d\"",
")",
".",
"\"T00:00:00Z\"",
";",
"return",
"$",
"this",
"->",
"mapper",
"->",
"getRpSum",
"(",
"'forever'",
",",
"$",
"metric",
",",
"$",
"tags",
")",
"+",
"$",
"this",
"->",
"mapper",
"->",
"getRpSum",
"(",
"$",
"rp",
",",
"$",
"metric",
",",
"$",
"tags",
",",
"$",
"todayDt",
")",
"+",
"$",
"this",
"->",
"mapper",
"->",
"getSum",
"(",
"$",
"metric",
",",
"$",
"tags",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"AnalyticsException",
"(",
"\"Analytics client get total exception\"",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
]
| Returns analytics total for right metric
@param string $rp
@param string $metric
@param array $tags
@return int
@throws AnalyticsException | [
"Returns",
"analytics",
"total",
"for",
"right",
"metric"
]
| train | https://github.com/vorbind/influx-analytics/blob/8c0c150351f045ccd3d57063f2b3b50a2c926e3e/src/Analytics.php#L83-L93 |
vorbind/influx-analytics | src/Analytics.php | Analytics.save | public function save($metric, $tags = array(), $value = 1, $date = null, $rp = null) {
try {
return $this->mapper->save($metric, $tags, $value, $date, $rp);
} catch (Exception $e) {
throw new AnalyticsException("Analytics client save exception", 0, $e);
}
} | php | public function save($metric, $tags = array(), $value = 1, $date = null, $rp = null) {
try {
return $this->mapper->save($metric, $tags, $value, $date, $rp);
} catch (Exception $e) {
throw new AnalyticsException("Analytics client save exception", 0, $e);
}
} | [
"public",
"function",
"save",
"(",
"$",
"metric",
",",
"$",
"tags",
"=",
"array",
"(",
")",
",",
"$",
"value",
"=",
"1",
",",
"$",
"date",
"=",
"null",
",",
"$",
"rp",
"=",
"null",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"mapper",
"->",
"save",
"(",
"$",
"metric",
",",
"$",
"tags",
",",
"$",
"value",
",",
"$",
"date",
",",
"$",
"rp",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"AnalyticsException",
"(",
"\"Analytics client save exception\"",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
]
| Save analytics
@param string $metric
@param array $tags
@param int $value
@param string $date
@param string $rp
@throws AnalyticsException | [
"Save",
"analytics"
]
| train | https://github.com/vorbind/influx-analytics/blob/8c0c150351f045ccd3d57063f2b3b50a2c926e3e/src/Analytics.php#L105-L111 |
vorbind/influx-analytics | src/Analytics.php | Analytics.fixTimeForGranularity | private function fixTimeForGranularity($points, $granularity) {
if ($granularity != $this->mapper::GRANULARITY_DAILY) {
return $points;
}
foreach ($points as &$value) {
$date = substr($value['time'],0, 10); // get date (2017-08-29)
$offset = substr($value['time'], -6); // get timezone offset (+02:00, -04:00)
$value['time'] = $date . "T00:00:00" . $offset;
}
return $points;
} | php | private function fixTimeForGranularity($points, $granularity) {
if ($granularity != $this->mapper::GRANULARITY_DAILY) {
return $points;
}
foreach ($points as &$value) {
$date = substr($value['time'],0, 10); // get date (2017-08-29)
$offset = substr($value['time'], -6); // get timezone offset (+02:00, -04:00)
$value['time'] = $date . "T00:00:00" . $offset;
}
return $points;
} | [
"private",
"function",
"fixTimeForGranularity",
"(",
"$",
"points",
",",
"$",
"granularity",
")",
"{",
"if",
"(",
"$",
"granularity",
"!=",
"$",
"this",
"->",
"mapper",
"::",
"GRANULARITY_DAILY",
")",
"{",
"return",
"$",
"points",
";",
"}",
"foreach",
"(",
"$",
"points",
"as",
"&",
"$",
"value",
")",
"{",
"$",
"date",
"=",
"substr",
"(",
"$",
"value",
"[",
"'time'",
"]",
",",
"0",
",",
"10",
")",
";",
"// get date (2017-08-29)",
"$",
"offset",
"=",
"substr",
"(",
"$",
"value",
"[",
"'time'",
"]",
",",
"-",
"6",
")",
";",
"// get timezone offset (+02:00, -04:00)",
"$",
"value",
"[",
"'time'",
"]",
"=",
"$",
"date",
".",
"\"T00:00:00\"",
".",
"$",
"offset",
";",
"}",
"return",
"$",
"points",
";",
"}"
]
| Fix time part for non-downsampled data
@param array $points
@param string $granularity
@return array | [
"Fix",
"time",
"part",
"for",
"non",
"-",
"downsampled",
"data"
]
| train | https://github.com/vorbind/influx-analytics/blob/8c0c150351f045ccd3d57063f2b3b50a2c926e3e/src/Analytics.php#L122-L132 |
vorbind/influx-analytics | src/Analytics.php | Analytics.combineSumPoints | private function combineSumPoints($points1, $points2) {
$pointsCount = count($points1);
$currPoint = 0;
foreach ($points2 as $point2) {
$pointFound = false;
//leverage the fact that points are sorted and improve O(n^2)
while ($currPoint < $pointsCount) {
$point1 = $points1[$currPoint];
if ($point1['time'] == $point2['time']) {
$points1[$currPoint]['sum'] += $point2['sum'];
$currPoint++;
$pointFound = true;
break;
}
$currPoint++;
}
//point not found in downsampled array, then just append
if (!$pointFound) {
$points1[] = $point2;
}
}
return $points1;
} | php | private function combineSumPoints($points1, $points2) {
$pointsCount = count($points1);
$currPoint = 0;
foreach ($points2 as $point2) {
$pointFound = false;
//leverage the fact that points are sorted and improve O(n^2)
while ($currPoint < $pointsCount) {
$point1 = $points1[$currPoint];
if ($point1['time'] == $point2['time']) {
$points1[$currPoint]['sum'] += $point2['sum'];
$currPoint++;
$pointFound = true;
break;
}
$currPoint++;
}
//point not found in downsampled array, then just append
if (!$pointFound) {
$points1[] = $point2;
}
}
return $points1;
} | [
"private",
"function",
"combineSumPoints",
"(",
"$",
"points1",
",",
"$",
"points2",
")",
"{",
"$",
"pointsCount",
"=",
"count",
"(",
"$",
"points1",
")",
";",
"$",
"currPoint",
"=",
"0",
";",
"foreach",
"(",
"$",
"points2",
"as",
"$",
"point2",
")",
"{",
"$",
"pointFound",
"=",
"false",
";",
"//leverage the fact that points are sorted and improve O(n^2)",
"while",
"(",
"$",
"currPoint",
"<",
"$",
"pointsCount",
")",
"{",
"$",
"point1",
"=",
"$",
"points1",
"[",
"$",
"currPoint",
"]",
";",
"if",
"(",
"$",
"point1",
"[",
"'time'",
"]",
"==",
"$",
"point2",
"[",
"'time'",
"]",
")",
"{",
"$",
"points1",
"[",
"$",
"currPoint",
"]",
"[",
"'sum'",
"]",
"+=",
"$",
"point2",
"[",
"'sum'",
"]",
";",
"$",
"currPoint",
"++",
";",
"$",
"pointFound",
"=",
"true",
";",
"break",
";",
"}",
"$",
"currPoint",
"++",
";",
"}",
"//point not found in downsampled array, then just append",
"if",
"(",
"!",
"$",
"pointFound",
")",
"{",
"$",
"points1",
"[",
"]",
"=",
"$",
"point2",
";",
"}",
"}",
"return",
"$",
"points1",
";",
"}"
]
| Combine downsampled and non-downsampled points
@param array $points1
@param array $points2
@return array | [
"Combine",
"downsampled",
"and",
"non",
"-",
"downsampled",
"points"
]
| train | https://github.com/vorbind/influx-analytics/blob/8c0c150351f045ccd3d57063f2b3b50a2c926e3e/src/Analytics.php#L141-L164 |
factorio-item-browser/export-data | src/Entity/Recipe/Product.php | Product.writeData | public function writeData(): array
{
$dataBuilder = new DataBuilder();
$dataBuilder->setString('t', $this->type, '')
->setString('n', $this->name, '')
->setFloat('i', $this->amountMin, 1.)
->setFloat('a', $this->amountMax, 1.)
->setFloat('p', $this->probability, 1.)
->setInteger('o', $this->order, 0);
return $dataBuilder->getData();
} | php | public function writeData(): array
{
$dataBuilder = new DataBuilder();
$dataBuilder->setString('t', $this->type, '')
->setString('n', $this->name, '')
->setFloat('i', $this->amountMin, 1.)
->setFloat('a', $this->amountMax, 1.)
->setFloat('p', $this->probability, 1.)
->setInteger('o', $this->order, 0);
return $dataBuilder->getData();
} | [
"public",
"function",
"writeData",
"(",
")",
":",
"array",
"{",
"$",
"dataBuilder",
"=",
"new",
"DataBuilder",
"(",
")",
";",
"$",
"dataBuilder",
"->",
"setString",
"(",
"'t'",
",",
"$",
"this",
"->",
"type",
",",
"''",
")",
"->",
"setString",
"(",
"'n'",
",",
"$",
"this",
"->",
"name",
",",
"''",
")",
"->",
"setFloat",
"(",
"'i'",
",",
"$",
"this",
"->",
"amountMin",
",",
"1.",
")",
"->",
"setFloat",
"(",
"'a'",
",",
"$",
"this",
"->",
"amountMax",
",",
"1.",
")",
"->",
"setFloat",
"(",
"'p'",
",",
"$",
"this",
"->",
"probability",
",",
"1.",
")",
"->",
"setInteger",
"(",
"'o'",
",",
"$",
"this",
"->",
"order",
",",
"0",
")",
";",
"return",
"$",
"dataBuilder",
"->",
"getData",
"(",
")",
";",
"}"
]
| Writes the entity data to an array.
@return array | [
"Writes",
"the",
"entity",
"data",
"to",
"an",
"array",
"."
]
| train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Recipe/Product.php#L180-L190 |
factorio-item-browser/export-data | src/Entity/Recipe/Product.php | Product.readData | public function readData(DataContainer $data)
{
$this->type = $data->getString('t', '');
$this->name = $data->getString('n', '');
$this->amountMin = $data->getFloat('i', 1.);
$this->amountMax = $data->getFloat('a', 1.);
$this->probability = $data->getFloat('p', 1.);
$this->order = $data->getInteger('o', 0);
return $this;
} | php | public function readData(DataContainer $data)
{
$this->type = $data->getString('t', '');
$this->name = $data->getString('n', '');
$this->amountMin = $data->getFloat('i', 1.);
$this->amountMax = $data->getFloat('a', 1.);
$this->probability = $data->getFloat('p', 1.);
$this->order = $data->getInteger('o', 0);
return $this;
} | [
"public",
"function",
"readData",
"(",
"DataContainer",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"$",
"data",
"->",
"getString",
"(",
"'t'",
",",
"''",
")",
";",
"$",
"this",
"->",
"name",
"=",
"$",
"data",
"->",
"getString",
"(",
"'n'",
",",
"''",
")",
";",
"$",
"this",
"->",
"amountMin",
"=",
"$",
"data",
"->",
"getFloat",
"(",
"'i'",
",",
"1.",
")",
";",
"$",
"this",
"->",
"amountMax",
"=",
"$",
"data",
"->",
"getFloat",
"(",
"'a'",
",",
"1.",
")",
";",
"$",
"this",
"->",
"probability",
"=",
"$",
"data",
"->",
"getFloat",
"(",
"'p'",
",",
"1.",
")",
";",
"$",
"this",
"->",
"order",
"=",
"$",
"data",
"->",
"getInteger",
"(",
"'o'",
",",
"0",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Reads the entity data.
@param DataContainer $data
@return $this | [
"Reads",
"the",
"entity",
"data",
"."
]
| train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Recipe/Product.php#L197-L206 |
factorio-item-browser/export-data | src/Entity/Recipe/Product.php | Product.calculateHash | public function calculateHash(): string
{
return EntityUtils::calculateHashOfArray([
$this->type,
$this->name,
$this->amountMin,
$this->amountMax,
$this->probability,
$this->order,
]);
} | php | public function calculateHash(): string
{
return EntityUtils::calculateHashOfArray([
$this->type,
$this->name,
$this->amountMin,
$this->amountMax,
$this->probability,
$this->order,
]);
} | [
"public",
"function",
"calculateHash",
"(",
")",
":",
"string",
"{",
"return",
"EntityUtils",
"::",
"calculateHashOfArray",
"(",
"[",
"$",
"this",
"->",
"type",
",",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"amountMin",
",",
"$",
"this",
"->",
"amountMax",
",",
"$",
"this",
"->",
"probability",
",",
"$",
"this",
"->",
"order",
",",
"]",
")",
";",
"}"
]
| Calculates a hash value representing the entity.
@return string | [
"Calculates",
"a",
"hash",
"value",
"representing",
"the",
"entity",
"."
]
| train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Recipe/Product.php#L212-L222 |
phpmob/changmin | src/PhpMob/MediaBundle/PhpMobMediaBundle.php | PhpMobMediaBundle.build | public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->addCompilerPass(new Compiler\RegisterImageTypesPass());
} | php | public function build(ContainerBuilder $container): void
{
parent::build($container);
$container->addCompilerPass(new Compiler\RegisterImageTypesPass());
} | [
"public",
"function",
"build",
"(",
"ContainerBuilder",
"$",
"container",
")",
":",
"void",
"{",
"parent",
"::",
"build",
"(",
"$",
"container",
")",
";",
"$",
"container",
"->",
"addCompilerPass",
"(",
"new",
"Compiler",
"\\",
"RegisterImageTypesPass",
"(",
")",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/MediaBundle/PhpMobMediaBundle.php#L36-L41 |
vi-kon/laravel-auth | src/database/migrations/2014_08_27_000004_create_user_groups_table.php | CreateUserGroupsTable.up | public function up()
{
$schema = app()->make('db')->connection()->getSchemaBuilder();
$schema->create(config('vi-kon.auth.table.user_groups'), function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('token');
$table->boolean('static')
->default(false);
$table->boolean('hidden')
->default(false);
});
} | php | public function up()
{
$schema = app()->make('db')->connection()->getSchemaBuilder();
$schema->create(config('vi-kon.auth.table.user_groups'), function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('token');
$table->boolean('static')
->default(false);
$table->boolean('hidden')
->default(false);
});
} | [
"public",
"function",
"up",
"(",
")",
"{",
"$",
"schema",
"=",
"app",
"(",
")",
"->",
"make",
"(",
"'db'",
")",
"->",
"connection",
"(",
")",
"->",
"getSchemaBuilder",
"(",
")",
";",
"$",
"schema",
"->",
"create",
"(",
"config",
"(",
"'vi-kon.auth.table.user_groups'",
")",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"engine",
"=",
"'InnoDB'",
";",
"$",
"table",
"->",
"increments",
"(",
"'id'",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'token'",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'static'",
")",
"->",
"default",
"(",
"false",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'hidden'",
")",
"->",
"default",
"(",
"false",
")",
";",
"}",
")",
";",
"}"
]
| Run the migrations.
@return void | [
"Run",
"the",
"migrations",
"."
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/database/migrations/2014_08_27_000004_create_user_groups_table.php#L18-L32 |
xinix-technology/norm | src/Norm/Filter/FilterException.php | FilterException.context | public function context($context = null)
{
if (is_null($context)) {
return $this->context;
}
$this->context = $context;
return $this;
} | php | public function context($context = null)
{
if (is_null($context)) {
return $this->context;
}
$this->context = $context;
return $this;
} | [
"public",
"function",
"context",
"(",
"$",
"context",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"context",
")",
")",
"{",
"return",
"$",
"this",
"->",
"context",
";",
"}",
"$",
"this",
"->",
"context",
"=",
"$",
"context",
";",
"return",
"$",
"this",
";",
"}"
]
| Set field context of exception
@param string $context The field context
@return FilterException return self object to be chained | [
"Set",
"field",
"context",
"of",
"exception"
]
| train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Filter/FilterException.php#L113-L122 |
xinix-technology/norm | src/Norm/Filter/FilterException.php | FilterException.args | public function args()
{
$this->args = func_get_args();
$params = array_merge(array($this->formatMessage), $this->args);
$this->message = call_user_func_array('sprintf', $params);
return $this;
} | php | public function args()
{
$this->args = func_get_args();
$params = array_merge(array($this->formatMessage), $this->args);
$this->message = call_user_func_array('sprintf', $params);
return $this;
} | [
"public",
"function",
"args",
"(",
")",
"{",
"$",
"this",
"->",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"array",
"(",
"$",
"this",
"->",
"formatMessage",
")",
",",
"$",
"this",
"->",
"args",
")",
";",
"$",
"this",
"->",
"message",
"=",
"call_user_func_array",
"(",
"'sprintf'",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Get the arrguments passed and build message by them.
@return Norm\Filter\FilterException | [
"Get",
"the",
"arrguments",
"passed",
"and",
"build",
"message",
"by",
"them",
"."
]
| train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Filter/FilterException.php#L129-L137 |
mgallegos/decima-file | src/migrations/2016_09_21_201625_create_file_table.php | CreateFileTable.up | public function up()
{
Schema::create('FILE_File', function (Blueprint $table) {
$table->increments('id');
$table->string('name' , 100);
$table->char('type' , 1);
$table->string('system_type', 100)->nullable();
$table->string('system_route')->nullable();
$table->text('url')->nullable();
$table->text('url_html')->nullable();
$table->boolean('is_public')->default(false);
$table->string('key')->nullable();
$table->string('icon' , 20)->nullable();
$table->string('icon_html')->nullable();
$table->float('width')->nullable();
$table->float('height')->nullable();
$table->unsignedInteger('parent_file_id')->nullable();
$table->string('system_reference_type' , 40)->nullable();
$table->unsignedInteger('system_reference_id')->nullable();
//Foreign Keys
$table->unsignedInteger('organization_id');
//Timestamps
$table->timestamps(); //Adds created_at and updated_at columns
$table->softDeletes(); //Adds deleted_at column for soft deletes
});
Schema::table('FILE_File', function(Blueprint $table)
{
//Foreign Key
$table->foreign('parent_file_id')->references('id')->on('FILE_File');
});
} | php | public function up()
{
Schema::create('FILE_File', function (Blueprint $table) {
$table->increments('id');
$table->string('name' , 100);
$table->char('type' , 1);
$table->string('system_type', 100)->nullable();
$table->string('system_route')->nullable();
$table->text('url')->nullable();
$table->text('url_html')->nullable();
$table->boolean('is_public')->default(false);
$table->string('key')->nullable();
$table->string('icon' , 20)->nullable();
$table->string('icon_html')->nullable();
$table->float('width')->nullable();
$table->float('height')->nullable();
$table->unsignedInteger('parent_file_id')->nullable();
$table->string('system_reference_type' , 40)->nullable();
$table->unsignedInteger('system_reference_id')->nullable();
//Foreign Keys
$table->unsignedInteger('organization_id');
//Timestamps
$table->timestamps(); //Adds created_at and updated_at columns
$table->softDeletes(); //Adds deleted_at column for soft deletes
});
Schema::table('FILE_File', function(Blueprint $table)
{
//Foreign Key
$table->foreign('parent_file_id')->references('id')->on('FILE_File');
});
} | [
"public",
"function",
"up",
"(",
")",
"{",
"Schema",
"::",
"create",
"(",
"'FILE_File'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"increments",
"(",
"'id'",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'name'",
",",
"100",
")",
";",
"$",
"table",
"->",
"char",
"(",
"'type'",
",",
"1",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'system_type'",
",",
"100",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'system_route'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"text",
"(",
"'url'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"text",
"(",
"'url_html'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'is_public'",
")",
"->",
"default",
"(",
"false",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'key'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'icon'",
",",
"20",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'icon_html'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"float",
"(",
"'width'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"float",
"(",
"'height'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"unsignedInteger",
"(",
"'parent_file_id'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'system_reference_type'",
",",
"40",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"unsignedInteger",
"(",
"'system_reference_id'",
")",
"->",
"nullable",
"(",
")",
";",
"//Foreign Keys",
"$",
"table",
"->",
"unsignedInteger",
"(",
"'organization_id'",
")",
";",
"//Timestamps",
"$",
"table",
"->",
"timestamps",
"(",
")",
";",
"//Adds created_at and updated_at columns",
"$",
"table",
"->",
"softDeletes",
"(",
")",
";",
"//Adds deleted_at column for soft deletes",
"}",
")",
";",
"Schema",
"::",
"table",
"(",
"'FILE_File'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"//Foreign Key",
"$",
"table",
"->",
"foreign",
"(",
"'parent_file_id'",
")",
"->",
"references",
"(",
"'id'",
")",
"->",
"on",
"(",
"'FILE_File'",
")",
";",
"}",
")",
";",
"}"
]
| Run the migrations.
@return void | [
"Run",
"the",
"migrations",
"."
]
| train | https://github.com/mgallegos/decima-file/blob/94c26ab40f5c4dd12e913e73376c24db27588f0b/src/migrations/2016_09_21_201625_create_file_table.php#L13-L46 |
simple-php-mvc/simple-php-mvc | src/MVC/File/Explorer.php | Explorer.copy | public function copy($sourceDir, $destinyDir)
{
$dir = opendir($sourceDir);
$this->mkdir($destinyDir);
while (false !== ( $file = readdir($dir))) {
if (( $file != '.' ) && ( $file != '..' )) {
if (is_dir($sourceDir . '/' . $file)) {
$this->copy($sourceDir . '/' . $file, $destinyDir . '/' . $file);
} else {
copy($sourceDir . '/' . $file, $destinyDir . '/' . $file);
}
}
}
closedir($dir);
} | php | public function copy($sourceDir, $destinyDir)
{
$dir = opendir($sourceDir);
$this->mkdir($destinyDir);
while (false !== ( $file = readdir($dir))) {
if (( $file != '.' ) && ( $file != '..' )) {
if (is_dir($sourceDir . '/' . $file)) {
$this->copy($sourceDir . '/' . $file, $destinyDir . '/' . $file);
} else {
copy($sourceDir . '/' . $file, $destinyDir . '/' . $file);
}
}
}
closedir($dir);
} | [
"public",
"function",
"copy",
"(",
"$",
"sourceDir",
",",
"$",
"destinyDir",
")",
"{",
"$",
"dir",
"=",
"opendir",
"(",
"$",
"sourceDir",
")",
";",
"$",
"this",
"->",
"mkdir",
"(",
"$",
"destinyDir",
")",
";",
"while",
"(",
"false",
"!==",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dir",
")",
")",
")",
"{",
"if",
"(",
"(",
"$",
"file",
"!=",
"'.'",
")",
"&&",
"(",
"$",
"file",
"!=",
"'..'",
")",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"sourceDir",
".",
"'/'",
".",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"copy",
"(",
"$",
"sourceDir",
".",
"'/'",
".",
"$",
"file",
",",
"$",
"destinyDir",
".",
"'/'",
".",
"$",
"file",
")",
";",
"}",
"else",
"{",
"copy",
"(",
"$",
"sourceDir",
".",
"'/'",
".",
"$",
"file",
",",
"$",
"destinyDir",
".",
"'/'",
".",
"$",
"file",
")",
";",
"}",
"}",
"}",
"closedir",
"(",
"$",
"dir",
")",
";",
"}"
]
| Copy directory to destiny directory
@param string $sourceDir
@param string $destinyDir | [
"Copy",
"directory",
"to",
"destiny",
"directory"
]
| train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/File/Explorer.php#L41-L55 |
simple-php-mvc/simple-php-mvc | src/MVC/File/Explorer.php | Explorer.getFiles | public function getFiles()
{
$files = array();
while ($this->valid() && $this->isFile()) {
if (!$this->searchPattern) {
$files[] = $this->current();
} elseif(preg_match($this->searchPattern, $this->getFilename())) {
$files[] = $this->current();
}
$this->next();
}
return $files;
} | php | public function getFiles()
{
$files = array();
while ($this->valid() && $this->isFile()) {
if (!$this->searchPattern) {
$files[] = $this->current();
} elseif(preg_match($this->searchPattern, $this->getFilename())) {
$files[] = $this->current();
}
$this->next();
}
return $files;
} | [
"public",
"function",
"getFiles",
"(",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"this",
"->",
"valid",
"(",
")",
"&&",
"$",
"this",
"->",
"isFile",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"searchPattern",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"this",
"->",
"current",
"(",
")",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"$",
"this",
"->",
"searchPattern",
",",
"$",
"this",
"->",
"getFilename",
"(",
")",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"this",
"->",
"current",
"(",
")",
";",
"}",
"$",
"this",
"->",
"next",
"(",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
]
| Get files
@return Explorer | [
"Get",
"files"
]
| train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/File/Explorer.php#L62-L74 |
simple-php-mvc/simple-php-mvc | src/MVC/File/Explorer.php | Explorer.rmdir | public function rmdir($path)
{
$files = array_diff(scandir($path), array('.', '..'));
foreach ($files as $file) {
(is_dir("$path/$file")) ? $this->rmdir("$path/$file") : unlink("$path/$file");
}
return rmdir($path);
} | php | public function rmdir($path)
{
$files = array_diff(scandir($path), array('.', '..'));
foreach ($files as $file) {
(is_dir("$path/$file")) ? $this->rmdir("$path/$file") : unlink("$path/$file");
}
return rmdir($path);
} | [
"public",
"function",
"rmdir",
"(",
"$",
"path",
")",
"{",
"$",
"files",
"=",
"array_diff",
"(",
"scandir",
"(",
"$",
"path",
")",
",",
"array",
"(",
"'.'",
",",
"'..'",
")",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"(",
"is_dir",
"(",
"\"$path/$file\"",
")",
")",
"?",
"$",
"this",
"->",
"rmdir",
"(",
"\"$path/$file\"",
")",
":",
"unlink",
"(",
"\"$path/$file\"",
")",
";",
"}",
"return",
"rmdir",
"(",
"$",
"path",
")",
";",
"}"
]
| Remove dir
@param string $path
@return boolean | [
"Remove",
"dir"
]
| train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/File/Explorer.php#L94-L101 |
seeruo/framework | src/Service/PushService.php | PushService.pushServer | public function pushServer()
{
if (!isset($this->config['ssh_user'])) {
Log::info( 'SSH账户没有配置,请在Config.php文件参照如下方式配置:' );
Log::info( '$config[\'ssh_user\']=\'root\';' );
die();
}
if (!isset($this->config['ssh_address'])) {
Log::info( 'SSH地址没有配置,请在Config.php文件参照如下方式配置:' );
Log::info( '$config[\'ssh_address\']=\'127.0.0.1\';' );
die();
}
if (!isset($this->config['ssh_path'])) {
Log::info( 'SSH路径没有配置,请在Config.php文件参照如下方式配置:' );
Log::info( '$config[\'ssh_path\']=\'/usr/www/html\';' );
die();
}
// 网站根目录
$web_root = ROOT.DIRECTORY_SEPARATOR.$this->config['public'].DIRECTORY_SEPARATOR;
if (strstr(PHP_OS, 'WIN')) {
$web_root = str_replace("\\","/", $web_root);
$web_root = iconv('UTF-8', 'gbk', $web_root);
}
// 上传指令
$cmd = 'scp -r '. $web_root . '* ';
$cmd .= $this->config['ssh_user'] . '@'.$this->config['ssh_address'] . ':';
$cmd .= $this->config['ssh_path'];
// 最终需要执行的命令
$cmd = "cd ".$web_root." && ".$cmd;
system($cmd, $out);
if ($out === false) {
throw new Exception('指令执行失败,请坚持是否配置错误');
}
} | php | public function pushServer()
{
if (!isset($this->config['ssh_user'])) {
Log::info( 'SSH账户没有配置,请在Config.php文件参照如下方式配置:' );
Log::info( '$config[\'ssh_user\']=\'root\';' );
die();
}
if (!isset($this->config['ssh_address'])) {
Log::info( 'SSH地址没有配置,请在Config.php文件参照如下方式配置:' );
Log::info( '$config[\'ssh_address\']=\'127.0.0.1\';' );
die();
}
if (!isset($this->config['ssh_path'])) {
Log::info( 'SSH路径没有配置,请在Config.php文件参照如下方式配置:' );
Log::info( '$config[\'ssh_path\']=\'/usr/www/html\';' );
die();
}
// 网站根目录
$web_root = ROOT.DIRECTORY_SEPARATOR.$this->config['public'].DIRECTORY_SEPARATOR;
if (strstr(PHP_OS, 'WIN')) {
$web_root = str_replace("\\","/", $web_root);
$web_root = iconv('UTF-8', 'gbk', $web_root);
}
// 上传指令
$cmd = 'scp -r '. $web_root . '* ';
$cmd .= $this->config['ssh_user'] . '@'.$this->config['ssh_address'] . ':';
$cmd .= $this->config['ssh_path'];
// 最终需要执行的命令
$cmd = "cd ".$web_root." && ".$cmd;
system($cmd, $out);
if ($out === false) {
throw new Exception('指令执行失败,请坚持是否配置错误');
}
} | [
"public",
"function",
"pushServer",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'ssh_user'",
"]",
")",
")",
"{",
"Log",
"::",
"info",
"(",
"'SSH账户没有配置,请在Config.php文件参照如下方式配置:' );",
"",
"",
"Log",
"::",
"info",
"(",
"'$config[\\'ssh_user\\']=\\'root\\';'",
")",
";",
"die",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'ssh_address'",
"]",
")",
")",
"{",
"Log",
"::",
"info",
"(",
"'SSH地址没有配置,请在Config.php文件参照如下方式配置:' );",
"",
"",
"Log",
"::",
"info",
"(",
"'$config[\\'ssh_address\\']=\\'127.0.0.1\\';'",
")",
";",
"die",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'ssh_path'",
"]",
")",
")",
"{",
"Log",
"::",
"info",
"(",
"'SSH路径没有配置,请在Config.php文件参照如下方式配置:' );",
"",
"",
"Log",
"::",
"info",
"(",
"'$config[\\'ssh_path\\']=\\'/usr/www/html\\';'",
")",
";",
"die",
"(",
")",
";",
"}",
"// 网站根目录",
"$",
"web_root",
"=",
"ROOT",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"config",
"[",
"'public'",
"]",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"strstr",
"(",
"PHP_OS",
",",
"'WIN'",
")",
")",
"{",
"$",
"web_root",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"/\"",
",",
"$",
"web_root",
")",
";",
"$",
"web_root",
"=",
"iconv",
"(",
"'UTF-8'",
",",
"'gbk'",
",",
"$",
"web_root",
")",
";",
"}",
"// 上传指令",
"$",
"cmd",
"=",
"'scp -r '",
".",
"$",
"web_root",
".",
"'* '",
";",
"$",
"cmd",
".=",
"$",
"this",
"->",
"config",
"[",
"'ssh_user'",
"]",
".",
"'@'",
".",
"$",
"this",
"->",
"config",
"[",
"'ssh_address'",
"]",
".",
"':'",
";",
"$",
"cmd",
".=",
"$",
"this",
"->",
"config",
"[",
"'ssh_path'",
"]",
";",
"// 最终需要执行的命令",
"$",
"cmd",
"=",
"\"cd \"",
".",
"$",
"web_root",
".",
"\" && \"",
".",
"$",
"cmd",
";",
"system",
"(",
"$",
"cmd",
",",
"$",
"out",
")",
";",
"if",
"(",
"$",
"out",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'指令执行失败,请坚持是否配置错误');",
"",
"",
"}",
"}"
]
| [Git推送方式]
@return [type] [description] | [
"[",
"Git推送方式",
"]"
]
| train | https://github.com/seeruo/framework/blob/689c6e95bc95fe2ae037e056d8228820dd08d7e9/src/Service/PushService.php#L53-L87 |
seeruo/framework | src/Service/PushService.php | PushService.pushGit | public function pushGit()
{
if (!isset($this->config['git_address'])) {
Log::info('Git地址没有配置,请在Config.php文件参照如下方式配置:' );
Log::info('$config[\'git_address\']=\'[email protected]:seeruo/seeruo.github.io.git\';','error');
}
$Git = new GitService($this->config);
$Git->add();
$Git->commit();
$Git->push();
} | php | public function pushGit()
{
if (!isset($this->config['git_address'])) {
Log::info('Git地址没有配置,请在Config.php文件参照如下方式配置:' );
Log::info('$config[\'git_address\']=\'[email protected]:seeruo/seeruo.github.io.git\';','error');
}
$Git = new GitService($this->config);
$Git->add();
$Git->commit();
$Git->push();
} | [
"public",
"function",
"pushGit",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'git_address'",
"]",
")",
")",
"{",
"Log",
"::",
"info",
"(",
"'Git地址没有配置,请在Config.php文件参照如下方式配置:' );",
"",
"",
"Log",
"::",
"info",
"(",
"'$config[\\'git_address\\']=\\'[email protected]:seeruo/seeruo.github.io.git\\';'",
",",
"'error'",
")",
";",
"}",
"$",
"Git",
"=",
"new",
"GitService",
"(",
"$",
"this",
"->",
"config",
")",
";",
"$",
"Git",
"->",
"add",
"(",
")",
";",
"$",
"Git",
"->",
"commit",
"(",
")",
";",
"$",
"Git",
"->",
"push",
"(",
")",
";",
"}"
]
| [Git推送方式]
@return [type] [description] | [
"[",
"Git推送方式",
"]"
]
| train | https://github.com/seeruo/framework/blob/689c6e95bc95fe2ae037e056d8228820dd08d7e9/src/Service/PushService.php#L92-L104 |
seeruo/framework | src/Service/PushService.php | PushService.pushGitInit | public function pushGitInit()
{
if (!isset($this->config['git_address'])) {
Log::info('Git地址没有配置,请在Config.php文件参照如下方式配置:' );
Log::info('$config[\'git_address\']=\'[email protected]:seeruo/seeruo.github.io.git\';','error');
}
$Git = new GitService($this->config);
$Git->init();
$Git->remote();
$Git->pull();
// 重新构建一次
$build = new BuildService();
$build->run();
} | php | public function pushGitInit()
{
if (!isset($this->config['git_address'])) {
Log::info('Git地址没有配置,请在Config.php文件参照如下方式配置:' );
Log::info('$config[\'git_address\']=\'[email protected]:seeruo/seeruo.github.io.git\';','error');
}
$Git = new GitService($this->config);
$Git->init();
$Git->remote();
$Git->pull();
// 重新构建一次
$build = new BuildService();
$build->run();
} | [
"public",
"function",
"pushGitInit",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'git_address'",
"]",
")",
")",
"{",
"Log",
"::",
"info",
"(",
"'Git地址没有配置,请在Config.php文件参照如下方式配置:' );",
"",
"",
"Log",
"::",
"info",
"(",
"'$config[\\'git_address\\']=\\'[email protected]:seeruo/seeruo.github.io.git\\';'",
",",
"'error'",
")",
";",
"}",
"$",
"Git",
"=",
"new",
"GitService",
"(",
"$",
"this",
"->",
"config",
")",
";",
"$",
"Git",
"->",
"init",
"(",
")",
";",
"$",
"Git",
"->",
"remote",
"(",
")",
";",
"$",
"Git",
"->",
"pull",
"(",
")",
";",
"// 重新构建一次",
"$",
"build",
"=",
"new",
"BuildService",
"(",
")",
";",
"$",
"build",
"->",
"run",
"(",
")",
";",
"}"
]
| [Git仓库初始化]
@return [type] [description] | [
"[",
"Git仓库初始化",
"]"
]
| train | https://github.com/seeruo/framework/blob/689c6e95bc95fe2ae037e056d8228820dd08d7e9/src/Service/PushService.php#L110-L125 |
Lansoweb/LosBase | src/LosBase/Document/DocumentManagerAwareTrait.php | DocumentManagerAwareTrait.getDocumentManager | public function getDocumentManager()
{
if (null === $this->dm) {
$this->dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
}
return $this->dm;
} | php | public function getDocumentManager()
{
if (null === $this->dm) {
$this->dm = $this->getServiceLocator()->get('doctrine.documentmanager.odm_default');
}
return $this->dm;
} | [
"public",
"function",
"getDocumentManager",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"dm",
")",
"{",
"$",
"this",
"->",
"dm",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'doctrine.documentmanager.odm_default'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"dm",
";",
"}"
]
| Retorna o DocumentManager.
@return \Doctrine\ODM\MongoDb\DocumentManager | [
"Retorna",
"o",
"DocumentManager",
"."
]
| train | https://github.com/Lansoweb/LosBase/blob/90e18a53d29c1bd841c149dca43aa365eecc656d/src/LosBase/Document/DocumentManagerAwareTrait.php#L29-L36 |
linkorb/graphael | src/AbstractPdoObjectType.php | AbstractPdoObjectType.getBy | protected function getBy($key, $value)
{
$stmt = $this->pdo->prepare('SELECT * FROM ' . $this->tableName . ' WHERE ' . $key . ' = :value');
$result = $stmt->execute(['value'=>$value]);
return $this->processRow($stmt->fetch(PDO::FETCH_ASSOC));
} | php | protected function getBy($key, $value)
{
$stmt = $this->pdo->prepare('SELECT * FROM ' . $this->tableName . ' WHERE ' . $key . ' = :value');
$result = $stmt->execute(['value'=>$value]);
return $this->processRow($stmt->fetch(PDO::FETCH_ASSOC));
} | [
"protected",
"function",
"getBy",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"'SELECT * FROM '",
".",
"$",
"this",
"->",
"tableName",
".",
"' WHERE '",
".",
"$",
"key",
".",
"' = :value'",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"return",
"$",
"this",
"->",
"processRow",
"(",
"$",
"stmt",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
")",
";",
"}"
]
| TODO: rename to getOneBy | [
"TODO",
":",
"rename",
"to",
"getOneBy"
]
| train | https://github.com/linkorb/graphael/blob/ce79b58d31f6703f23db36475e971080ff7f2a1f/src/AbstractPdoObjectType.php#L21-L26 |
ClanCats/Core | src/bundles/UI/HTML.php | HTML.maker | public static function maker( $param, $param2 = null )
{
if ( !is_null( $param2 ) )
{
return static::create( $param, $param2 );
}
$param = explode( ' ', $param );
$element = array_shift( $param );
return static::create( $element, implode( ' ', $param ) );
} | php | public static function maker( $param, $param2 = null )
{
if ( !is_null( $param2 ) )
{
return static::create( $param, $param2 );
}
$param = explode( ' ', $param );
$element = array_shift( $param );
return static::create( $element, implode( ' ', $param ) );
} | [
"public",
"static",
"function",
"maker",
"(",
"$",
"param",
",",
"$",
"param2",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"param2",
")",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"$",
"param",
",",
"$",
"param2",
")",
";",
"}",
"$",
"param",
"=",
"explode",
"(",
"' '",
",",
"$",
"param",
")",
";",
"$",
"element",
"=",
"array_shift",
"(",
"$",
"param",
")",
";",
"return",
"static",
"::",
"create",
"(",
"$",
"element",
",",
"implode",
"(",
"' '",
",",
"$",
"param",
")",
")",
";",
"}"
]
| The maker is like a development shortcut to create
html elements on the go
If param2 is set it wil be used as the content otherwise
the the first parameter will be splittet by the first space.
@param string $param
@param string $param2 | [
"The",
"maker",
"is",
"like",
"a",
"development",
"shortcut",
"to",
"create",
"html",
"elements",
"on",
"the",
"go"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/HTML.php#L23-L35 |
ClanCats/Core | src/bundles/UI/HTML.php | HTML.attr | public static function attr( $attr = array() ) {
$buffer = " ";
foreach( $attr as $key => $value ) {
switch( $key ) {
case 'class':
if ( is_array( $value ) ) { $value = implode( ' ', $value ); }
break;
case 'style':
if ( is_array( $value ) ) {
$style = $value; $value = "";
foreach( $style as $k => $v ) {
$value .= $k.':'.$v.';';
}
}
break;
}
$buffer .= $key.'="'.$value.'" ';
}
return substr( $buffer, 0, -1 );
} | php | public static function attr( $attr = array() ) {
$buffer = " ";
foreach( $attr as $key => $value ) {
switch( $key ) {
case 'class':
if ( is_array( $value ) ) { $value = implode( ' ', $value ); }
break;
case 'style':
if ( is_array( $value ) ) {
$style = $value; $value = "";
foreach( $style as $k => $v ) {
$value .= $k.':'.$v.';';
}
}
break;
}
$buffer .= $key.'="'.$value.'" ';
}
return substr( $buffer, 0, -1 );
} | [
"public",
"static",
"function",
"attr",
"(",
"$",
"attr",
"=",
"array",
"(",
")",
")",
"{",
"$",
"buffer",
"=",
"\" \"",
";",
"foreach",
"(",
"$",
"attr",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'class'",
":",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"implode",
"(",
"' '",
",",
"$",
"value",
")",
";",
"}",
"break",
";",
"case",
"'style'",
":",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"style",
"=",
"$",
"value",
";",
"$",
"value",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"style",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"value",
".=",
"$",
"k",
".",
"':'",
".",
"$",
"v",
".",
"';'",
";",
"}",
"}",
"break",
";",
"}",
"$",
"buffer",
".=",
"$",
"key",
".",
"'=\"'",
".",
"$",
"value",
".",
"'\" '",
";",
"}",
"return",
"substr",
"(",
"$",
"buffer",
",",
"0",
",",
"-",
"1",
")",
";",
"}"
]
| generates html attribute string
@param array $attr | [
"generates",
"html",
"attribute",
"string"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/HTML.php#L42-L66 |
ClanCats/Core | src/bundles/UI/HTML.php | HTML.tag | public static function tag( $name, $param1 = null, $param2 = null )
{
return static::create( $name, $param1, $param2 );
} | php | public static function tag( $name, $param1 = null, $param2 = null )
{
return static::create( $name, $param1, $param2 );
} | [
"public",
"static",
"function",
"tag",
"(",
"$",
"name",
",",
"$",
"param1",
"=",
"null",
",",
"$",
"param2",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"$",
"name",
",",
"$",
"param1",
",",
"$",
"param2",
")",
";",
"}"
]
| generates an html tag
@param string $name
@param mixed $param1
@param mixed $param2 | [
"generates",
"an",
"html",
"tag"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/HTML.php#L75-L78 |
ClanCats/Core | src/bundles/UI/HTML.php | HTML.add_class | public function add_class( $class ) {
if ( !isset( $this->attr['class'] ) || !is_array( $this->attr['class'] ) ) {
$this->_sanitize_class();
}
if ( strpos( $class, ' ' ) !== false ) {
$class = explode( ' ', $class );
}
if ( is_string( $class ) ) {
$class = array( $class );
}
foreach ( $class as $c ) {
$this->attr['class'][] = $c;
}
return $this;
} | php | public function add_class( $class ) {
if ( !isset( $this->attr['class'] ) || !is_array( $this->attr['class'] ) ) {
$this->_sanitize_class();
}
if ( strpos( $class, ' ' ) !== false ) {
$class = explode( ' ', $class );
}
if ( is_string( $class ) ) {
$class = array( $class );
}
foreach ( $class as $c ) {
$this->attr['class'][] = $c;
}
return $this;
} | [
"public",
"function",
"add_class",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_sanitize_class",
"(",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"class",
",",
"' '",
")",
"!==",
"false",
")",
"{",
"$",
"class",
"=",
"explode",
"(",
"' '",
",",
"$",
"class",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"array",
"(",
"$",
"class",
")",
";",
"}",
"foreach",
"(",
"$",
"class",
"as",
"$",
"c",
")",
"{",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
"[",
"]",
"=",
"$",
"c",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| add html class
@param string $class | [
"add",
"html",
"class"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/HTML.php#L95-L109 |
ClanCats/Core | src/bundles/UI/HTML.php | HTML.remove_class | public function remove_class( $class ) {
if ( !isset( $this->attr['class'] ) || !is_array( $this->attr['class'] ) ) {
$this->_sanitize_class();
}
$this->attr['class'] = array_diff( $this->attr['class'], array( $class ) );
return $this;
} | php | public function remove_class( $class ) {
if ( !isset( $this->attr['class'] ) || !is_array( $this->attr['class'] ) ) {
$this->_sanitize_class();
}
$this->attr['class'] = array_diff( $this->attr['class'], array( $class ) );
return $this;
} | [
"public",
"function",
"remove_class",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_sanitize_class",
"(",
")",
";",
"}",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
"=",
"array_diff",
"(",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
",",
"array",
"(",
"$",
"class",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| remove html class
@param string $class | [
"remove",
"html",
"class"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/HTML.php#L116-L122 |
ClanCats/Core | src/bundles/UI/HTML.php | HTML._sanitize_class | private function _sanitize_class() {
if ( isset( $this->attr['class'] ) && is_string( $this->attr['class'] ) ) {
$this->attr['class'] = explode( ' ', $this->attr['class'] );
}
if ( !isset( $this->attr['class'] ) || !is_array( $this->attr['class'] ) ) {
$this->attr['class'] = array();
}
} | php | private function _sanitize_class() {
if ( isset( $this->attr['class'] ) && is_string( $this->attr['class'] ) ) {
$this->attr['class'] = explode( ' ', $this->attr['class'] );
}
if ( !isset( $this->attr['class'] ) || !is_array( $this->attr['class'] ) ) {
$this->attr['class'] = array();
}
} | [
"private",
"function",
"_sanitize_class",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
")",
"&&",
"is_string",
"(",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
"=",
"explode",
"(",
"' '",
",",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"attr",
"[",
"'class'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"}"
]
| clean the classes attribute | [
"clean",
"the",
"classes",
"attribute"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/UI/HTML.php#L127-L134 |
inpsyde/inpsyde-filter | src/WordPress/SanitizeTitleWithDashes.php | SanitizeTitleWithDashes.filter | public function filter( $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not string or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
$raw_title = (string) $this->options[ 'raw_title' ];
$context = (string) $this->options[ 'context' ];
return sanitize_title_with_dashes( $value, $raw_title, $context );
} | php | public function filter( $value ) {
if ( ! is_string( $value ) || empty( $value ) ) {
do_action( 'inpsyde.filter.error', 'The given value is not string or empty.', [ 'method' => __METHOD__, 'value' => $value ] );
return $value;
}
$raw_title = (string) $this->options[ 'raw_title' ];
$context = (string) $this->options[ 'context' ];
return sanitize_title_with_dashes( $value, $raw_title, $context );
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
"||",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"do_action",
"(",
"'inpsyde.filter.error'",
",",
"'The given value is not string or empty.'",
",",
"[",
"'method'",
"=>",
"__METHOD__",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"return",
"$",
"value",
";",
"}",
"$",
"raw_title",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"options",
"[",
"'raw_title'",
"]",
";",
"$",
"context",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"options",
"[",
"'context'",
"]",
";",
"return",
"sanitize_title_with_dashes",
"(",
"$",
"value",
",",
"$",
"raw_title",
",",
"$",
"context",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/WordPress/SanitizeTitleWithDashes.php#L25-L36 |
webforge-labs/psc-cms | lib/Psc/TPL/Template.php | Template.validate | public function validate() {
if (!isset($this->fileName)) {
throw new Exception('fileName muss gesetzt sein');
}
$file = (string) $this->getDirectory().implode(DIRECTORY_SEPARATOR,(array) $this->fileName).$this->extension;
$file = new File($file);
if (!$file->getDirectory()->isSubdirectoryOf($this->getDirectory()) && !$file->getDirectory()->equals($this->getDirectory())) {
throw new Exception('Security: '.$file->getDirectory().' ist kein Unterverzeichnis von: '.$this->getDirectory());
}
$this->file = $file;
return TRUE;
} | php | public function validate() {
if (!isset($this->fileName)) {
throw new Exception('fileName muss gesetzt sein');
}
$file = (string) $this->getDirectory().implode(DIRECTORY_SEPARATOR,(array) $this->fileName).$this->extension;
$file = new File($file);
if (!$file->getDirectory()->isSubdirectoryOf($this->getDirectory()) && !$file->getDirectory()->equals($this->getDirectory())) {
throw new Exception('Security: '.$file->getDirectory().' ist kein Unterverzeichnis von: '.$this->getDirectory());
}
$this->file = $file;
return TRUE;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fileName",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'fileName muss gesetzt sein'",
")",
";",
"}",
"$",
"file",
"=",
"(",
"string",
")",
"$",
"this",
"->",
"getDirectory",
"(",
")",
".",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"(",
"array",
")",
"$",
"this",
"->",
"fileName",
")",
".",
"$",
"this",
"->",
"extension",
";",
"$",
"file",
"=",
"new",
"File",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"$",
"file",
"->",
"getDirectory",
"(",
")",
"->",
"isSubdirectoryOf",
"(",
"$",
"this",
"->",
"getDirectory",
"(",
")",
")",
"&&",
"!",
"$",
"file",
"->",
"getDirectory",
"(",
")",
"->",
"equals",
"(",
"$",
"this",
"->",
"getDirectory",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Security: '",
".",
"$",
"file",
"->",
"getDirectory",
"(",
")",
".",
"' ist kein Unterverzeichnis von: '",
".",
"$",
"this",
"->",
"getDirectory",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"file",
"=",
"$",
"file",
";",
"return",
"TRUE",
";",
"}"
]
| Überprüft die Sicherheit des Templates
z.b. darf keine Datei includiert werden die außerhalb des tpl Verzeichnisses liegt ($this->getDirectory())
@return bool | [
"Überprüft",
"die",
"Sicherheit",
"des",
"Templates"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/TPL/Template.php#L102-L117 |
webforge-labs/psc-cms | lib/Psc/TPL/Template.php | Template.get | public function get() {
$__html = NULL;
if ($this->validate()) {
/* dies ersetzt variablen die durch das template verändert werden können: $$__varName */
extract((array)$this->vars);
$tpl = $this;
/* get as String */
try {
ob_start();
require $this->file;
$__html = ob_get_contents();
ob_end_clean();
} catch (\Psc\Exception $e) {
$e->setMessage(sprintf('in TPL(%s): %s',$this->getDisplayName(),$e->getMessage()));
throw $e;
}
/* testen ob noch variablen übrig sind */
//if (DEV) {
// $__matches = array();
// if (preg_match_all('/\{\$([a-zA-Z_0-9]*)\}/',$__html,$__matches,PREG_SET_ORDER) > 0) {
// foreach ($__matches as $__match) {
// //throw new Exception('in Template: '.$__fileName.' ist Variable "'.$__match[1].'" nicht definiert');
// trigger_error('in Template: '.$__fileName.' wird die Variable "'.$__match[1].'" nicht definiert (die von einem anderen Template benötigt wird)',E_USER_WARNING);
// }
// }
//}
if ($this->indent !== NULL) {
$__html = S::indent($__html, $this->indent);
}
}
return $__html;
} | php | public function get() {
$__html = NULL;
if ($this->validate()) {
/* dies ersetzt variablen die durch das template verändert werden können: $$__varName */
extract((array)$this->vars);
$tpl = $this;
/* get as String */
try {
ob_start();
require $this->file;
$__html = ob_get_contents();
ob_end_clean();
} catch (\Psc\Exception $e) {
$e->setMessage(sprintf('in TPL(%s): %s',$this->getDisplayName(),$e->getMessage()));
throw $e;
}
/* testen ob noch variablen übrig sind */
//if (DEV) {
// $__matches = array();
// if (preg_match_all('/\{\$([a-zA-Z_0-9]*)\}/',$__html,$__matches,PREG_SET_ORDER) > 0) {
// foreach ($__matches as $__match) {
// //throw new Exception('in Template: '.$__fileName.' ist Variable "'.$__match[1].'" nicht definiert');
// trigger_error('in Template: '.$__fileName.' wird die Variable "'.$__match[1].'" nicht definiert (die von einem anderen Template benötigt wird)',E_USER_WARNING);
// }
// }
//}
if ($this->indent !== NULL) {
$__html = S::indent($__html, $this->indent);
}
}
return $__html;
} | [
"public",
"function",
"get",
"(",
")",
"{",
"$",
"__html",
"=",
"NULL",
";",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"/* dies ersetzt variablen die durch das template verändert werden können: $$__varName */",
"extract",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"vars",
")",
";",
"$",
"tpl",
"=",
"$",
"this",
";",
"/* get as String */",
"try",
"{",
"ob_start",
"(",
")",
";",
"require",
"$",
"this",
"->",
"file",
";",
"$",
"__html",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Psc",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"e",
"->",
"setMessage",
"(",
"sprintf",
"(",
"'in TPL(%s): %s'",
",",
"$",
"this",
"->",
"getDisplayName",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"throw",
"$",
"e",
";",
"}",
"/* testen ob noch variablen übrig sind */",
"//if (DEV) {",
"// $__matches = array();",
"// if (preg_match_all('/\\{\\$([a-zA-Z_0-9]*)\\}/',$__html,$__matches,PREG_SET_ORDER) > 0) {",
"// foreach ($__matches as $__match) {",
"// //throw new Exception('in Template: '.$__fileName.' ist Variable \"'.$__match[1].'\" nicht definiert');",
"// trigger_error('in Template: '.$__fileName.' wird die Variable \"'.$__match[1].'\" nicht definiert (die von einem anderen Template benötigt wird)',E_USER_WARNING);",
"// }",
"// }",
"//}",
"if",
"(",
"$",
"this",
"->",
"indent",
"!==",
"NULL",
")",
"{",
"$",
"__html",
"=",
"S",
"::",
"indent",
"(",
"$",
"__html",
",",
"$",
"this",
"->",
"indent",
")",
";",
"}",
"}",
"return",
"$",
"__html",
";",
"}"
]
| Gibt das Template als String zurück
@return string | [
"Gibt",
"das",
"Template",
"als",
"String",
"zurück"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/TPL/Template.php#L124-L162 |
php-rise/rise | src/Database.php | Database.getConnectionConfig | public function getConnectionConfig($name = null) {
if (is_null($name)) {
$name = $this->defaultConfigName;
}
if (isset($this->connectionConfigs[$name])) {
return $this->connectionConfigs[$name];
}
return null;
} | php | public function getConnectionConfig($name = null) {
if (is_null($name)) {
$name = $this->defaultConfigName;
}
if (isset($this->connectionConfigs[$name])) {
return $this->connectionConfigs[$name];
}
return null;
} | [
"public",
"function",
"getConnectionConfig",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"defaultConfigName",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"connectionConfigs",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"connectionConfigs",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Get connection config.
@param string $name
@return array|null | [
"Get",
"connection",
"config",
"."
]
| train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Database.php#L48-L58 |
php-rise/rise | src/Database.php | Database.getConnection | public function getConnection($name = null, $forceNew = false) {
if (!$forceNew && isset($this->connections[$name])) {
return $this->connections[$name];
}
$config = $this->getConnectionConfig($name);
if (!$config) {
return null;
}
$pdoArgs = [$config['dsn'], $config['username'], $config['password']];
$options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
if (isset($config['options'])) {
$options = $config['options'] + $options;
}
$pdoArgs[] = $options;
$this->connections[$name] = new PDO(...$pdoArgs);
return $this->connections[$name];
} | php | public function getConnection($name = null, $forceNew = false) {
if (!$forceNew && isset($this->connections[$name])) {
return $this->connections[$name];
}
$config = $this->getConnectionConfig($name);
if (!$config) {
return null;
}
$pdoArgs = [$config['dsn'], $config['username'], $config['password']];
$options = [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
if (isset($config['options'])) {
$options = $config['options'] + $options;
}
$pdoArgs[] = $options;
$this->connections[$name] = new PDO(...$pdoArgs);
return $this->connections[$name];
} | [
"public",
"function",
"getConnection",
"(",
"$",
"name",
"=",
"null",
",",
"$",
"forceNew",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"forceNew",
"&&",
"isset",
"(",
"$",
"this",
"->",
"connections",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"connections",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"config",
"=",
"$",
"this",
"->",
"getConnectionConfig",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"config",
")",
"{",
"return",
"null",
";",
"}",
"$",
"pdoArgs",
"=",
"[",
"$",
"config",
"[",
"'dsn'",
"]",
",",
"$",
"config",
"[",
"'username'",
"]",
",",
"$",
"config",
"[",
"'password'",
"]",
"]",
";",
"$",
"options",
"=",
"[",
"PDO",
"::",
"ATTR_ERRMODE",
"=>",
"PDO",
"::",
"ERRMODE_EXCEPTION",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"options",
"=",
"$",
"config",
"[",
"'options'",
"]",
"+",
"$",
"options",
";",
"}",
"$",
"pdoArgs",
"[",
"]",
"=",
"$",
"options",
";",
"$",
"this",
"->",
"connections",
"[",
"$",
"name",
"]",
"=",
"new",
"PDO",
"(",
"...",
"$",
"pdoArgs",
")",
";",
"return",
"$",
"this",
"->",
"connections",
"[",
"$",
"name",
"]",
";",
"}"
]
| Get a connection by name.
@param string $name Optional. Connection name.
@param bool $forceNew Optional. Create a new connection or reuse the old one if exists.
@return \PDO|null | [
"Get",
"a",
"connection",
"by",
"name",
"."
]
| train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Database.php#L79-L101 |
php-rise/rise | src/Database.php | Database.readConfig | public function readConfig() {
$file = $this->path->getConfigPath() . '/database.php';
if (file_exists($file)) {
$config = require($file);
$this->defaultConfigName = $config['default'];
$this->connectionConfigs = $config['connections'];
}
} | php | public function readConfig() {
$file = $this->path->getConfigPath() . '/database.php';
if (file_exists($file)) {
$config = require($file);
$this->defaultConfigName = $config['default'];
$this->connectionConfigs = $config['connections'];
}
} | [
"public",
"function",
"readConfig",
"(",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"path",
"->",
"getConfigPath",
"(",
")",
".",
"'/database.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"config",
"=",
"require",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"defaultConfigName",
"=",
"$",
"config",
"[",
"'default'",
"]",
";",
"$",
"this",
"->",
"connectionConfigs",
"=",
"$",
"config",
"[",
"'connections'",
"]",
";",
"}",
"}"
]
| Read configuration file. | [
"Read",
"configuration",
"file",
"."
]
| train | https://github.com/php-rise/rise/blob/cd14ef9956f1b6875b7bcd642545dcef6a9152b7/src/Database.php#L118-L125 |
Chill-project/Main | Search/AbstractSearch.php | AbstractSearch.parseDate | public function parseDate($string)
{
try {
return new \DateTime($string);
} catch (ParsingException $ex) {
$exception = new ParsingException('The date is '
. 'not parsable', 0, $ex);
throw $exception;
}
} | php | public function parseDate($string)
{
try {
return new \DateTime($string);
} catch (ParsingException $ex) {
$exception = new ParsingException('The date is '
. 'not parsable', 0, $ex);
throw $exception;
}
} | [
"public",
"function",
"parseDate",
"(",
"$",
"string",
")",
"{",
"try",
"{",
"return",
"new",
"\\",
"DateTime",
"(",
"$",
"string",
")",
";",
"}",
"catch",
"(",
"ParsingException",
"$",
"ex",
")",
"{",
"$",
"exception",
"=",
"new",
"ParsingException",
"(",
"'The date is '",
".",
"'not parsable'",
",",
"0",
",",
"$",
"ex",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"}"
]
| parse string expected to be a date and transform to a DateTime object
@param type $string
@return \DateTime
@throws ParsingException if the date is not parseable | [
"parse",
"string",
"expected",
"to",
"be",
"a",
"date",
"and",
"transform",
"to",
"a",
"DateTime",
"object"
]
| train | https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Search/AbstractSearch.php#L45-L55 |
Chill-project/Main | Search/AbstractSearch.php | AbstractSearch.recomposePattern | protected function recomposePattern(array $terms, array $supportedTerms, $domain = NULL)
{
$recomposed = '';
if ($domain !== NULL)
{
$recomposed .= '@'.$domain.' ';
}
foreach ($supportedTerms as $term) {
if (array_key_exists($term, $terms) && $term !== '_default') {
$recomposed .= ' '.$term.':';
$recomposed .= (mb_stristr(' ', $terms[$term]) === FALSE) ? $terms[$term] : '('.$terms[$term].')';
}
}
if ($terms['_default'] !== '') {
$recomposed .= ' '.$terms['_default'];
}
//strip first character if empty
if (mb_strcut($recomposed, 0, 1) === ' '){
$recomposed = mb_strcut($recomposed, 1);
}
return $recomposed;
} | php | protected function recomposePattern(array $terms, array $supportedTerms, $domain = NULL)
{
$recomposed = '';
if ($domain !== NULL)
{
$recomposed .= '@'.$domain.' ';
}
foreach ($supportedTerms as $term) {
if (array_key_exists($term, $terms) && $term !== '_default') {
$recomposed .= ' '.$term.':';
$recomposed .= (mb_stristr(' ', $terms[$term]) === FALSE) ? $terms[$term] : '('.$terms[$term].')';
}
}
if ($terms['_default'] !== '') {
$recomposed .= ' '.$terms['_default'];
}
//strip first character if empty
if (mb_strcut($recomposed, 0, 1) === ' '){
$recomposed = mb_strcut($recomposed, 1);
}
return $recomposed;
} | [
"protected",
"function",
"recomposePattern",
"(",
"array",
"$",
"terms",
",",
"array",
"$",
"supportedTerms",
",",
"$",
"domain",
"=",
"NULL",
")",
"{",
"$",
"recomposed",
"=",
"''",
";",
"if",
"(",
"$",
"domain",
"!==",
"NULL",
")",
"{",
"$",
"recomposed",
".=",
"'@'",
".",
"$",
"domain",
".",
"' '",
";",
"}",
"foreach",
"(",
"$",
"supportedTerms",
"as",
"$",
"term",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"term",
",",
"$",
"terms",
")",
"&&",
"$",
"term",
"!==",
"'_default'",
")",
"{",
"$",
"recomposed",
".=",
"' '",
".",
"$",
"term",
".",
"':'",
";",
"$",
"recomposed",
".=",
"(",
"mb_stristr",
"(",
"' '",
",",
"$",
"terms",
"[",
"$",
"term",
"]",
")",
"===",
"FALSE",
")",
"?",
"$",
"terms",
"[",
"$",
"term",
"]",
":",
"'('",
".",
"$",
"terms",
"[",
"$",
"term",
"]",
".",
"')'",
";",
"}",
"}",
"if",
"(",
"$",
"terms",
"[",
"'_default'",
"]",
"!==",
"''",
")",
"{",
"$",
"recomposed",
".=",
"' '",
".",
"$",
"terms",
"[",
"'_default'",
"]",
";",
"}",
"//strip first character if empty",
"if",
"(",
"mb_strcut",
"(",
"$",
"recomposed",
",",
"0",
",",
"1",
")",
"===",
"' '",
")",
"{",
"$",
"recomposed",
"=",
"mb_strcut",
"(",
"$",
"recomposed",
",",
"1",
")",
";",
"}",
"return",
"$",
"recomposed",
";",
"}"
]
| recompose a pattern, retaining only supported terms
the outputted string should be used to show users their search
@param array $terms
@param array $supportedTerms
@param string $domain if your domain is NULL, you should set NULL. You should set used domain instead
@return string | [
"recompose",
"a",
"pattern",
"retaining",
"only",
"supported",
"terms"
]
| train | https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Search/AbstractSearch.php#L67-L93 |
webforge-labs/psc-cms | lib/Psc/CMS/Item/ButtonableValueObject.php | ButtonableValueObject.copyFromButtonable | public static function copyFromButtonable(Buttonable $tabButtonable) {
$valueObject = new static();
// ugly, but fast
$valueObject->setButtonLabel($tabButtonable->getButtonLabel());
$valueObject->setFullButtonLabel($tabButtonable->getFullButtonLabel());
$valueObject->setButtonLeftIcon($tabButtonable->getButtonLeftIcon());
$valueObject->setButtonRightIcon($tabButtonable->getButtonRightIcon());
$valueObject->setButtonMode($tabButtonable->getButtonMode());
return $valueObject;
} | php | public static function copyFromButtonable(Buttonable $tabButtonable) {
$valueObject = new static();
// ugly, but fast
$valueObject->setButtonLabel($tabButtonable->getButtonLabel());
$valueObject->setFullButtonLabel($tabButtonable->getFullButtonLabel());
$valueObject->setButtonLeftIcon($tabButtonable->getButtonLeftIcon());
$valueObject->setButtonRightIcon($tabButtonable->getButtonRightIcon());
$valueObject->setButtonMode($tabButtonable->getButtonMode());
return $valueObject;
} | [
"public",
"static",
"function",
"copyFromButtonable",
"(",
"Buttonable",
"$",
"tabButtonable",
")",
"{",
"$",
"valueObject",
"=",
"new",
"static",
"(",
")",
";",
"// ugly, but fast",
"$",
"valueObject",
"->",
"setButtonLabel",
"(",
"$",
"tabButtonable",
"->",
"getButtonLabel",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setFullButtonLabel",
"(",
"$",
"tabButtonable",
"->",
"getFullButtonLabel",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setButtonLeftIcon",
"(",
"$",
"tabButtonable",
"->",
"getButtonLeftIcon",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setButtonRightIcon",
"(",
"$",
"tabButtonable",
"->",
"getButtonRightIcon",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setButtonMode",
"(",
"$",
"tabButtonable",
"->",
"getButtonMode",
"(",
")",
")",
";",
"return",
"$",
"valueObject",
";",
"}"
]
| Creates a copy of an Buttonable
use this to have a modified Version of the interface
@return ButtonableValueObject | [
"Creates",
"a",
"copy",
"of",
"an",
"Buttonable"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/Item/ButtonableValueObject.php#L25-L36 |
terion-name/package-installer | src/Terion/PackageInstaller/PackageInstallCommand.php | PackageInstallCommand.fire | public function fire()
{
$packageName = $this->argument('packageName');
if (strpos($packageName, '/') !== false) {
$this->getPackage($packageName);
} else {
$this->searchPackage($packageName);
}
} | php | public function fire()
{
$packageName = $this->argument('packageName');
if (strpos($packageName, '/') !== false) {
$this->getPackage($packageName);
} else {
$this->searchPackage($packageName);
}
} | [
"public",
"function",
"fire",
"(",
")",
"{",
"$",
"packageName",
"=",
"$",
"this",
"->",
"argument",
"(",
"'packageName'",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"packageName",
",",
"'/'",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"getPackage",
"(",
"$",
"packageName",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"searchPackage",
"(",
"$",
"packageName",
")",
";",
"}",
"}"
]
| Execute the console command.
@return void | [
"Execute",
"the",
"console",
"command",
"."
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/PackageInstallCommand.php#L74-L82 |
terion-name/package-installer | src/Terion/PackageInstaller/PackageInstallCommand.php | PackageInstallCommand.getPackage | protected function getPackage($packageName)
{
try {
$package = $this->packagist->get($packageName);
$this->getOutput()->writeln(sprintf(
'Package to install: <info>%s</info> (%s)',
$package->getName(),
$package->getDescription()
));
$this->requirePackage($package);
} catch (ClientErrorResponseException $e) {
$this->searchPackage($packageName);
}
} | php | protected function getPackage($packageName)
{
try {
$package = $this->packagist->get($packageName);
$this->getOutput()->writeln(sprintf(
'Package to install: <info>%s</info> (%s)',
$package->getName(),
$package->getDescription()
));
$this->requirePackage($package);
} catch (ClientErrorResponseException $e) {
$this->searchPackage($packageName);
}
} | [
"protected",
"function",
"getPackage",
"(",
"$",
"packageName",
")",
"{",
"try",
"{",
"$",
"package",
"=",
"$",
"this",
"->",
"packagist",
"->",
"get",
"(",
"$",
"packageName",
")",
";",
"$",
"this",
"->",
"getOutput",
"(",
")",
"->",
"writeln",
"(",
"sprintf",
"(",
"'Package to install: <info>%s</info> (%s)'",
",",
"$",
"package",
"->",
"getName",
"(",
")",
",",
"$",
"package",
"->",
"getDescription",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"requirePackage",
"(",
"$",
"package",
")",
";",
"}",
"catch",
"(",
"ClientErrorResponseException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"searchPackage",
"(",
"$",
"packageName",
")",
";",
"}",
"}"
]
| Try to get a package by name. If not present — search it.
@param $packageName | [
"Try",
"to",
"get",
"a",
"package",
"by",
"name",
".",
"If",
"not",
"present",
"—",
"search",
"it",
"."
]
| train | https://github.com/terion-name/package-installer/blob/a1f53085b0b5dbbcc308476f61188103051bd201/src/Terion/PackageInstaller/PackageInstallCommand.php#L89-L102 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.