repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
melisplatform/melis-calendar | src/Controller/ToolCalendarController.php | ToolCalendarController.retrieveCalendarEventsAction | public function retrieveCalendarEventsAction(){
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$result = $calendarTable->retrieveCalendarEvents();
return new JsonModel($result->toArray());
} | php | public function retrieveCalendarEventsAction(){
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$result = $calendarTable->retrieveCalendarEvents();
return new JsonModel($result->toArray());
} | [
"public",
"function",
"retrieveCalendarEventsAction",
"(",
")",
"{",
"$",
"calendarTable",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCalendarTable'",
")",
";",
"$",
"result",
"=",
"$",
"calendarTable",
"->",
"retrieveCalendarEvents",
"(",
")",
";",
"return",
"new",
"JsonModel",
"(",
"$",
"result",
"->",
"toArray",
"(",
")",
")",
";",
"}"
] | Retrieve Calendar Event to initialize calender ui
@return \Zend\View\Model\JsonModel | [
"Retrieve",
"Calendar",
"Event",
"to",
"initialize",
"calender",
"ui"
] | 1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223 | https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Controller/ToolCalendarController.php#L36-L40 | train |
melisplatform/melis-calendar | src/Controller/ToolCalendarController.php | ToolCalendarController.saveEventAction | public function saveEventAction(){
$translator = $this->getServiceLocator()->get('translator');
$request = $this->getRequest();
// Default Values
$status = 0;
$textMessage = '';
$errors = array();
$textTitle = '';
$responseData = array();
$melisMelisCoreConfig = $this->serviceLocator->get('MelisCoreConfig');
$appConfigForm = $melisMelisCoreConfig->getFormMergedAndOrdered('meliscalendar/forms/melicalendar_event_form','melicalendar_event_form');
$factory = new \Zend\Form\Factory();
$formElements = $this->serviceLocator->get('FormElementManager');
$factory->setFormElementManager($formElements);
$propertyForm = $factory->createForm($appConfigForm);
$melisTool = $this->getServiceLocator()->get('MelisCoreTool');
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
$postValues = $melisTool->sanitizePost($postValues);
$propertyForm->setData($postValues);
if (empty($postValues['cal_id']))
{
$logTypeCode = 'CALENDAR_EVENT_ADD';
}
else
{
$logTypeCode = 'CALENDAR_EVENT_UPDATE';
}
if($propertyForm->isValid()) {
$calendarService = $this->getServiceLocator()->get('MelisCalendarService');
$responseData = $calendarService->addCalendarEvent($postValues);
if (!empty($responseData)){
$textMessage = 'tr_melistoolcalendar_save_event_success';
$status = 1;
}
}else{
$errors = $propertyForm->getMessages();
$textMessage = 'tr_melistoolcalendar_form_event_error_msg';
}
$appConfigForm = $appConfigForm['elements'];
foreach ($errors as $keyError => $valueError)
{
foreach ($appConfigForm as $keyForm => $valueForm)
{
if ($valueForm['spec']['name'] == $keyError &&
!empty($valueForm['spec']['options']['label']))
$errors[$keyError]['label'] = $valueForm['spec']['options']['label'];
}
}
}
$response = array(
'success' => $status,
'textTitle' => 'tr_melistoolcalendar_save_event_title',
'textMessage' => $textMessage,
'errors' => $errors,
'event' => $responseData
);
$calId = null;
if (!empty($responseData['id']))
{
$calId = $responseData['id'];
}
if ($status){
$this->getEventManager()->trigger('meliscalendar_save_event_end', $this, array_merge($response, array('typeCode' => $logTypeCode, 'itemId' => $calId)));
}
return new JsonModel($response);
} | php | public function saveEventAction(){
$translator = $this->getServiceLocator()->get('translator');
$request = $this->getRequest();
// Default Values
$status = 0;
$textMessage = '';
$errors = array();
$textTitle = '';
$responseData = array();
$melisMelisCoreConfig = $this->serviceLocator->get('MelisCoreConfig');
$appConfigForm = $melisMelisCoreConfig->getFormMergedAndOrdered('meliscalendar/forms/melicalendar_event_form','melicalendar_event_form');
$factory = new \Zend\Form\Factory();
$formElements = $this->serviceLocator->get('FormElementManager');
$factory->setFormElementManager($formElements);
$propertyForm = $factory->createForm($appConfigForm);
$melisTool = $this->getServiceLocator()->get('MelisCoreTool');
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
$postValues = $melisTool->sanitizePost($postValues);
$propertyForm->setData($postValues);
if (empty($postValues['cal_id']))
{
$logTypeCode = 'CALENDAR_EVENT_ADD';
}
else
{
$logTypeCode = 'CALENDAR_EVENT_UPDATE';
}
if($propertyForm->isValid()) {
$calendarService = $this->getServiceLocator()->get('MelisCalendarService');
$responseData = $calendarService->addCalendarEvent($postValues);
if (!empty($responseData)){
$textMessage = 'tr_melistoolcalendar_save_event_success';
$status = 1;
}
}else{
$errors = $propertyForm->getMessages();
$textMessage = 'tr_melistoolcalendar_form_event_error_msg';
}
$appConfigForm = $appConfigForm['elements'];
foreach ($errors as $keyError => $valueError)
{
foreach ($appConfigForm as $keyForm => $valueForm)
{
if ($valueForm['spec']['name'] == $keyError &&
!empty($valueForm['spec']['options']['label']))
$errors[$keyError]['label'] = $valueForm['spec']['options']['label'];
}
}
}
$response = array(
'success' => $status,
'textTitle' => 'tr_melistoolcalendar_save_event_title',
'textMessage' => $textMessage,
'errors' => $errors,
'event' => $responseData
);
$calId = null;
if (!empty($responseData['id']))
{
$calId = $responseData['id'];
}
if ($status){
$this->getEventManager()->trigger('meliscalendar_save_event_end', $this, array_merge($response, array('typeCode' => $logTypeCode, 'itemId' => $calId)));
}
return new JsonModel($response);
} | [
"public",
"function",
"saveEventAction",
"(",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"// Default Values",
"$",
"status",
"=",
"0",
";",
"$",
"textMessage",
"=",
"''",
";",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"textTitle",
"=",
"''",
";",
"$",
"responseData",
"=",
"array",
"(",
")",
";",
"$",
"melisMelisCoreConfig",
"=",
"$",
"this",
"->",
"serviceLocator",
"->",
"get",
"(",
"'MelisCoreConfig'",
")",
";",
"$",
"appConfigForm",
"=",
"$",
"melisMelisCoreConfig",
"->",
"getFormMergedAndOrdered",
"(",
"'meliscalendar/forms/melicalendar_event_form'",
",",
"'melicalendar_event_form'",
")",
";",
"$",
"factory",
"=",
"new",
"\\",
"Zend",
"\\",
"Form",
"\\",
"Factory",
"(",
")",
";",
"$",
"formElements",
"=",
"$",
"this",
"->",
"serviceLocator",
"->",
"get",
"(",
"'FormElementManager'",
")",
";",
"$",
"factory",
"->",
"setFormElementManager",
"(",
"$",
"formElements",
")",
";",
"$",
"propertyForm",
"=",
"$",
"factory",
"->",
"createForm",
"(",
"$",
"appConfigForm",
")",
";",
"$",
"melisTool",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCoreTool'",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"postValues",
"=",
"get_object_vars",
"(",
"$",
"request",
"->",
"getPost",
"(",
")",
")",
";",
"$",
"postValues",
"=",
"$",
"melisTool",
"->",
"sanitizePost",
"(",
"$",
"postValues",
")",
";",
"$",
"propertyForm",
"->",
"setData",
"(",
"$",
"postValues",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"postValues",
"[",
"'cal_id'",
"]",
")",
")",
"{",
"$",
"logTypeCode",
"=",
"'CALENDAR_EVENT_ADD'",
";",
"}",
"else",
"{",
"$",
"logTypeCode",
"=",
"'CALENDAR_EVENT_UPDATE'",
";",
"}",
"if",
"(",
"$",
"propertyForm",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"calendarService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCalendarService'",
")",
";",
"$",
"responseData",
"=",
"$",
"calendarService",
"->",
"addCalendarEvent",
"(",
"$",
"postValues",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"responseData",
")",
")",
"{",
"$",
"textMessage",
"=",
"'tr_melistoolcalendar_save_event_success'",
";",
"$",
"status",
"=",
"1",
";",
"}",
"}",
"else",
"{",
"$",
"errors",
"=",
"$",
"propertyForm",
"->",
"getMessages",
"(",
")",
";",
"$",
"textMessage",
"=",
"'tr_melistoolcalendar_form_event_error_msg'",
";",
"}",
"$",
"appConfigForm",
"=",
"$",
"appConfigForm",
"[",
"'elements'",
"]",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"keyError",
"=>",
"$",
"valueError",
")",
"{",
"foreach",
"(",
"$",
"appConfigForm",
"as",
"$",
"keyForm",
"=>",
"$",
"valueForm",
")",
"{",
"if",
"(",
"$",
"valueForm",
"[",
"'spec'",
"]",
"[",
"'name'",
"]",
"==",
"$",
"keyError",
"&&",
"!",
"empty",
"(",
"$",
"valueForm",
"[",
"'spec'",
"]",
"[",
"'options'",
"]",
"[",
"'label'",
"]",
")",
")",
"$",
"errors",
"[",
"$",
"keyError",
"]",
"[",
"'label'",
"]",
"=",
"$",
"valueForm",
"[",
"'spec'",
"]",
"[",
"'options'",
"]",
"[",
"'label'",
"]",
";",
"}",
"}",
"}",
"$",
"response",
"=",
"array",
"(",
"'success'",
"=>",
"$",
"status",
",",
"'textTitle'",
"=>",
"'tr_melistoolcalendar_save_event_title'",
",",
"'textMessage'",
"=>",
"$",
"textMessage",
",",
"'errors'",
"=>",
"$",
"errors",
",",
"'event'",
"=>",
"$",
"responseData",
")",
";",
"$",
"calId",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"responseData",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"calId",
"=",
"$",
"responseData",
"[",
"'id'",
"]",
";",
"}",
"if",
"(",
"$",
"status",
")",
"{",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"'meliscalendar_save_event_end'",
",",
"$",
"this",
",",
"array_merge",
"(",
"$",
"response",
",",
"array",
"(",
"'typeCode'",
"=>",
"$",
"logTypeCode",
",",
"'itemId'",
"=>",
"$",
"calId",
")",
")",
")",
";",
"}",
"return",
"new",
"JsonModel",
"(",
"$",
"response",
")",
";",
"}"
] | This action will save an event to the calendar
@return \Zend\View\Model\JsonModel | [
"This",
"action",
"will",
"save",
"an",
"event",
"to",
"the",
"calendar"
] | 1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223 | https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Controller/ToolCalendarController.php#L47-L129 | train |
melisplatform/melis-calendar | src/Controller/ToolCalendarController.php | ToolCalendarController.searchCalendarEventAction | public function searchCalendarEventAction(){
$translator = $this->getServiceLocator()->get('translator');
$textMessage = '';
$request = $this->getRequest();
// Default Values
$id = null;
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
if (!empty($postValues)){
$calendarService = $this->getServiceLocator()->get('MelisCalendarService');
$id = $responseData = $calendarService->deleteCalendarEvent($postValues);
}
}
$response = array(
'success' => '0',
'textTitle' => 'tr_melistoolcalendar_delete_event_title',
'textMessage' => $textMessage,
'errors' => $errors,
);
return new JsonModel($response);
} | php | public function searchCalendarEventAction(){
$translator = $this->getServiceLocator()->get('translator');
$textMessage = '';
$request = $this->getRequest();
// Default Values
$id = null;
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
if (!empty($postValues)){
$calendarService = $this->getServiceLocator()->get('MelisCalendarService');
$id = $responseData = $calendarService->deleteCalendarEvent($postValues);
}
}
$response = array(
'success' => '0',
'textTitle' => 'tr_melistoolcalendar_delete_event_title',
'textMessage' => $textMessage,
'errors' => $errors,
);
return new JsonModel($response);
} | [
"public",
"function",
"searchCalendarEventAction",
"(",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
";",
"$",
"textMessage",
"=",
"''",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"// Default Values",
"$",
"id",
"=",
"null",
";",
"if",
"(",
"$",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"postValues",
"=",
"get_object_vars",
"(",
"$",
"request",
"->",
"getPost",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"postValues",
")",
")",
"{",
"$",
"calendarService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCalendarService'",
")",
";",
"$",
"id",
"=",
"$",
"responseData",
"=",
"$",
"calendarService",
"->",
"deleteCalendarEvent",
"(",
"$",
"postValues",
")",
";",
"}",
"}",
"$",
"response",
"=",
"array",
"(",
"'success'",
"=>",
"'0'",
",",
"'textTitle'",
"=>",
"'tr_melistoolcalendar_delete_event_title'",
",",
"'textMessage'",
"=>",
"$",
"textMessage",
",",
"'errors'",
"=>",
"$",
"errors",
",",
")",
";",
"return",
"new",
"JsonModel",
"(",
"$",
"response",
")",
";",
"}"
] | Retrieving Calendar searched item event data for updating | [
"Retrieving",
"Calendar",
"searched",
"item",
"event",
"data",
"for",
"updating"
] | 1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223 | https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Controller/ToolCalendarController.php#L134-L160 | train |
melisplatform/melis-calendar | src/Controller/ToolCalendarController.php | ToolCalendarController.reschedEventAction | public function reschedEventAction(){
$translator = $this->getServiceLocator()->get('translator');
$request = $this->getRequest();
// Default Values
$id = null;
$status = 0;
$textMessage = '';
$errors = array();
$textMessage = '';
$textTitle = '';
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
if (!empty($postValues)){
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$id = $postValues['cal_id'];
$resultEvent = $calendarTable->getEntryById($id);
if (!empty($resultEvent)){
$event = $resultEvent->current();
if (!empty($event)){
$calendarService = $this->getServiceLocator()->get('MelisCalendarService');
$responseData = $calendarService->reschedCalendarEvent($postValues);
if (!empty($responseData)){
$textMessage = 'tr_melistoolcalendar_save_event_success';
$status = 1;
}
}
}
}
}
$response = array(
'success' => $status,
'textTitle' => 'tr_melistoolcalendar_save_event_title',
'textMessage' => $textMessage,
'errors' => $errors,
);
if ($status){
$this->getEventManager()->trigger('meliscalendar_save_event_end', $this, array_merge($response, array('typeCode' => 'CALENDAR_EVENT_DRAG', 'itemId' => $id)));
}
return new JsonModel($response);
} | php | public function reschedEventAction(){
$translator = $this->getServiceLocator()->get('translator');
$request = $this->getRequest();
// Default Values
$id = null;
$status = 0;
$textMessage = '';
$errors = array();
$textMessage = '';
$textTitle = '';
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
if (!empty($postValues)){
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$id = $postValues['cal_id'];
$resultEvent = $calendarTable->getEntryById($id);
if (!empty($resultEvent)){
$event = $resultEvent->current();
if (!empty($event)){
$calendarService = $this->getServiceLocator()->get('MelisCalendarService');
$responseData = $calendarService->reschedCalendarEvent($postValues);
if (!empty($responseData)){
$textMessage = 'tr_melistoolcalendar_save_event_success';
$status = 1;
}
}
}
}
}
$response = array(
'success' => $status,
'textTitle' => 'tr_melistoolcalendar_save_event_title',
'textMessage' => $textMessage,
'errors' => $errors,
);
if ($status){
$this->getEventManager()->trigger('meliscalendar_save_event_end', $this, array_merge($response, array('typeCode' => 'CALENDAR_EVENT_DRAG', 'itemId' => $id)));
}
return new JsonModel($response);
} | [
"public",
"function",
"reschedEventAction",
"(",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"// Default Values",
"$",
"id",
"=",
"null",
";",
"$",
"status",
"=",
"0",
";",
"$",
"textMessage",
"=",
"''",
";",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"textMessage",
"=",
"''",
";",
"$",
"textTitle",
"=",
"''",
";",
"if",
"(",
"$",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"postValues",
"=",
"get_object_vars",
"(",
"$",
"request",
"->",
"getPost",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"postValues",
")",
")",
"{",
"$",
"calendarTable",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCalendarTable'",
")",
";",
"$",
"id",
"=",
"$",
"postValues",
"[",
"'cal_id'",
"]",
";",
"$",
"resultEvent",
"=",
"$",
"calendarTable",
"->",
"getEntryById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"resultEvent",
")",
")",
"{",
"$",
"event",
"=",
"$",
"resultEvent",
"->",
"current",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
")",
")",
"{",
"$",
"calendarService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCalendarService'",
")",
";",
"$",
"responseData",
"=",
"$",
"calendarService",
"->",
"reschedCalendarEvent",
"(",
"$",
"postValues",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"responseData",
")",
")",
"{",
"$",
"textMessage",
"=",
"'tr_melistoolcalendar_save_event_success'",
";",
"$",
"status",
"=",
"1",
";",
"}",
"}",
"}",
"}",
"}",
"$",
"response",
"=",
"array",
"(",
"'success'",
"=>",
"$",
"status",
",",
"'textTitle'",
"=>",
"'tr_melistoolcalendar_save_event_title'",
",",
"'textMessage'",
"=>",
"$",
"textMessage",
",",
"'errors'",
"=>",
"$",
"errors",
",",
")",
";",
"if",
"(",
"$",
"status",
")",
"{",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"'meliscalendar_save_event_end'",
",",
"$",
"this",
",",
"array_merge",
"(",
"$",
"response",
",",
"array",
"(",
"'typeCode'",
"=>",
"'CALENDAR_EVENT_DRAG'",
",",
"'itemId'",
"=>",
"$",
"id",
")",
")",
")",
";",
"}",
"return",
"new",
"JsonModel",
"(",
"$",
"response",
")",
";",
"}"
] | Updating Calendar Event by resizing Calendar item event
@return \Zend\View\Model\JsonModel | [
"Updating",
"Calendar",
"Event",
"by",
"resizing",
"Calendar",
"item",
"event"
] | 1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223 | https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Controller/ToolCalendarController.php#L166-L219 | train |
melisplatform/melis-calendar | src/Controller/ToolCalendarController.php | ToolCalendarController.deleteEventAction | public function deleteEventAction(){
$translator = $this->getServiceLocator()->get('translator');
$request = $this->getRequest();
// Default Values
$id = null;
$status = 0;
$textMessage = '';
$errors = array();
$textMessage = '';
$textTitle = '';
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
if (!empty($postValues)){
$calendarService = $this->getServiceLocator()->get('MelisCalendarService');
$id = $responseData = $calendarService->deleteCalendarEvent($postValues);
if (!is_null($id)){
$textMessage = 'tr_melistoolcalendar_delete_event_success';
$status = 1;
}else{
$textMessage = 'tr_melistoolcalendar_delete_event_unable';
}
}
}
$response = array(
'success' => $status,
'textTitle' => 'tr_melistoolcalendar_delete_event_title',
'textMessage' => $textMessage,
'errors' => $errors,
);
if ($status){
$this->getEventManager()->trigger('meliscalendar_save_event_end', $this, array_merge($response, array('typeCode' => 'CALENDAR_EVENT_DELETE', 'itemId' => $id)));
}
return new JsonModel($response);
} | php | public function deleteEventAction(){
$translator = $this->getServiceLocator()->get('translator');
$request = $this->getRequest();
// Default Values
$id = null;
$status = 0;
$textMessage = '';
$errors = array();
$textMessage = '';
$textTitle = '';
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
if (!empty($postValues)){
$calendarService = $this->getServiceLocator()->get('MelisCalendarService');
$id = $responseData = $calendarService->deleteCalendarEvent($postValues);
if (!is_null($id)){
$textMessage = 'tr_melistoolcalendar_delete_event_success';
$status = 1;
}else{
$textMessage = 'tr_melistoolcalendar_delete_event_unable';
}
}
}
$response = array(
'success' => $status,
'textTitle' => 'tr_melistoolcalendar_delete_event_title',
'textMessage' => $textMessage,
'errors' => $errors,
);
if ($status){
$this->getEventManager()->trigger('meliscalendar_save_event_end', $this, array_merge($response, array('typeCode' => 'CALENDAR_EVENT_DELETE', 'itemId' => $id)));
}
return new JsonModel($response);
} | [
"public",
"function",
"deleteEventAction",
"(",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"// Default Values",
"$",
"id",
"=",
"null",
";",
"$",
"status",
"=",
"0",
";",
"$",
"textMessage",
"=",
"''",
";",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"textMessage",
"=",
"''",
";",
"$",
"textTitle",
"=",
"''",
";",
"if",
"(",
"$",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"postValues",
"=",
"get_object_vars",
"(",
"$",
"request",
"->",
"getPost",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"postValues",
")",
")",
"{",
"$",
"calendarService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCalendarService'",
")",
";",
"$",
"id",
"=",
"$",
"responseData",
"=",
"$",
"calendarService",
"->",
"deleteCalendarEvent",
"(",
"$",
"postValues",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"id",
")",
")",
"{",
"$",
"textMessage",
"=",
"'tr_melistoolcalendar_delete_event_success'",
";",
"$",
"status",
"=",
"1",
";",
"}",
"else",
"{",
"$",
"textMessage",
"=",
"'tr_melistoolcalendar_delete_event_unable'",
";",
"}",
"}",
"}",
"$",
"response",
"=",
"array",
"(",
"'success'",
"=>",
"$",
"status",
",",
"'textTitle'",
"=>",
"'tr_melistoolcalendar_delete_event_title'",
",",
"'textMessage'",
"=>",
"$",
"textMessage",
",",
"'errors'",
"=>",
"$",
"errors",
",",
")",
";",
"if",
"(",
"$",
"status",
")",
"{",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"'meliscalendar_save_event_end'",
",",
"$",
"this",
",",
"array_merge",
"(",
"$",
"response",
",",
"array",
"(",
"'typeCode'",
"=>",
"'CALENDAR_EVENT_DELETE'",
",",
"'itemId'",
"=>",
"$",
"id",
")",
")",
")",
";",
"}",
"return",
"new",
"JsonModel",
"(",
"$",
"response",
")",
";",
"}"
] | Deleting Calendar item event
@return \Zend\View\Model\JsonModel | [
"Deleting",
"Calendar",
"item",
"event"
] | 1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223 | https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Controller/ToolCalendarController.php#L226-L267 | train |
melisplatform/melis-calendar | src/Controller/ToolCalendarController.php | ToolCalendarController.getEventTitleAction | public function getEventTitleAction(){
$translator = $this->getServiceLocator()->get('translator');
$request = $this->getRequest();
// Default Values
$status = 0;
// This can be override with success if result is success
$textMessage = $translator->translate('tr_melistoolcalendar_unable_get_event');
$errors = array();
$textTitle = '';
$eventData = array();
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
if (!empty($postValues)){
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$resultEvent = $calendarTable->getEntryById($postValues['cal_id']);
if (!empty($resultEvent)){
$eventData = $resultEvent->current();
if (!empty($eventData)){
$textMessage = $translator->translate('tr_melistoolcalendar_get_event_success');
$status = 1;
}
}
}
}
$response = array(
'success' => $status,
'textTitle' => $translator->translate('tr_melistoolcalendar_form_title'),
'textMessage' => $textMessage,
'errors' => $errors,
'eventData' => $eventData
);
return new JsonModel($response);
} | php | public function getEventTitleAction(){
$translator = $this->getServiceLocator()->get('translator');
$request = $this->getRequest();
// Default Values
$status = 0;
// This can be override with success if result is success
$textMessage = $translator->translate('tr_melistoolcalendar_unable_get_event');
$errors = array();
$textTitle = '';
$eventData = array();
if($request->isPost()) {
$postValues = get_object_vars($request->getPost());
if (!empty($postValues)){
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$resultEvent = $calendarTable->getEntryById($postValues['cal_id']);
if (!empty($resultEvent)){
$eventData = $resultEvent->current();
if (!empty($eventData)){
$textMessage = $translator->translate('tr_melistoolcalendar_get_event_success');
$status = 1;
}
}
}
}
$response = array(
'success' => $status,
'textTitle' => $translator->translate('tr_melistoolcalendar_form_title'),
'textMessage' => $textMessage,
'errors' => $errors,
'eventData' => $eventData
);
return new JsonModel($response);
} | [
"public",
"function",
"getEventTitleAction",
"(",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"// Default Values",
"$",
"status",
"=",
"0",
";",
"// This can be override with success if result is success",
"$",
"textMessage",
"=",
"$",
"translator",
"->",
"translate",
"(",
"'tr_melistoolcalendar_unable_get_event'",
")",
";",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"textTitle",
"=",
"''",
";",
"$",
"eventData",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isPost",
"(",
")",
")",
"{",
"$",
"postValues",
"=",
"get_object_vars",
"(",
"$",
"request",
"->",
"getPost",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"postValues",
")",
")",
"{",
"$",
"calendarTable",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCalendarTable'",
")",
";",
"$",
"resultEvent",
"=",
"$",
"calendarTable",
"->",
"getEntryById",
"(",
"$",
"postValues",
"[",
"'cal_id'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"resultEvent",
")",
")",
"{",
"$",
"eventData",
"=",
"$",
"resultEvent",
"->",
"current",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"eventData",
")",
")",
"{",
"$",
"textMessage",
"=",
"$",
"translator",
"->",
"translate",
"(",
"'tr_melistoolcalendar_get_event_success'",
")",
";",
"$",
"status",
"=",
"1",
";",
"}",
"}",
"}",
"}",
"$",
"response",
"=",
"array",
"(",
"'success'",
"=>",
"$",
"status",
",",
"'textTitle'",
"=>",
"$",
"translator",
"->",
"translate",
"(",
"'tr_melistoolcalendar_form_title'",
")",
",",
"'textMessage'",
"=>",
"$",
"textMessage",
",",
"'errors'",
"=>",
"$",
"errors",
",",
"'eventData'",
"=>",
"$",
"eventData",
")",
";",
"return",
"new",
"JsonModel",
"(",
"$",
"response",
")",
";",
"}"
] | Retrieving Calendar item event data for updating
@return \Zend\View\Model\JsonModel | [
"Retrieving",
"Calendar",
"item",
"event",
"data",
"for",
"updating"
] | 1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223 | https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Controller/ToolCalendarController.php#L274-L317 | train |
xelax90/l2p-client | src/L2PClient/TokenManager.php | TokenManager.getRefreshToken | protected function getRefreshToken(){
// check if RefreshToken is already stored
$refreshToken = $this->getConfig()->getStorage()->getRefreshToken();
if(null !== $refreshToken){
return $refreshToken;
}
// get device token required for RefreshToken request
$deviceToken = $this->getDeviceToken();
if($deviceToken !== null && $deviceToken->canPoll()){
// check if token exists and can be polled (depends on interval provided by the server)
$params = array(
'client_id' => $this->getConfig()->getClientId(),
'code' => $deviceToken->getDeviceCode(),
'grant_type' => 'device',
);
// request a RefreshToken
$response = $this->sendPostRequest("oauth2waitress/oauth2.svc/token", $params);
$output = $response['output'];
$httpcode = $response['code'];
// update LastPoll date to assure the correct polling interval
$deviceToken->setLastPoll(new DateTime());
$this->getConfig()->getStorage()->saveDeviceToken($deviceToken);
switch($httpcode){
case "200" :
$responseObject = json_decode($output);
if(empty($responseObject->access_token)){
// no AccessToken provided yet. Authorization is most likely pending.
return null;
}
// AccessToken provided
// create AccessToken and save it
$accessToken = new AccessToken(new DateTime(), $responseObject->access_token, $responseObject->token_type, $responseObject->expires_in);
$this->getConfig()->getStorage()->deleteAccessToken();
$this->getConfig()->getStorage()->saveAccessToken($accessToken);
if($responseObject->refresh_token){
// if a RefreshToken was also provided, we create and save it, too.
$refreshToken = new RefreshToken(new DateTime(), $responseObject->refresh_token);
$this->getConfig()->getStorage()->saveRefreshToken($refreshToken);
}
return $refreshToken;
}
}
return null;
} | php | protected function getRefreshToken(){
// check if RefreshToken is already stored
$refreshToken = $this->getConfig()->getStorage()->getRefreshToken();
if(null !== $refreshToken){
return $refreshToken;
}
// get device token required for RefreshToken request
$deviceToken = $this->getDeviceToken();
if($deviceToken !== null && $deviceToken->canPoll()){
// check if token exists and can be polled (depends on interval provided by the server)
$params = array(
'client_id' => $this->getConfig()->getClientId(),
'code' => $deviceToken->getDeviceCode(),
'grant_type' => 'device',
);
// request a RefreshToken
$response = $this->sendPostRequest("oauth2waitress/oauth2.svc/token", $params);
$output = $response['output'];
$httpcode = $response['code'];
// update LastPoll date to assure the correct polling interval
$deviceToken->setLastPoll(new DateTime());
$this->getConfig()->getStorage()->saveDeviceToken($deviceToken);
switch($httpcode){
case "200" :
$responseObject = json_decode($output);
if(empty($responseObject->access_token)){
// no AccessToken provided yet. Authorization is most likely pending.
return null;
}
// AccessToken provided
// create AccessToken and save it
$accessToken = new AccessToken(new DateTime(), $responseObject->access_token, $responseObject->token_type, $responseObject->expires_in);
$this->getConfig()->getStorage()->deleteAccessToken();
$this->getConfig()->getStorage()->saveAccessToken($accessToken);
if($responseObject->refresh_token){
// if a RefreshToken was also provided, we create and save it, too.
$refreshToken = new RefreshToken(new DateTime(), $responseObject->refresh_token);
$this->getConfig()->getStorage()->saveRefreshToken($refreshToken);
}
return $refreshToken;
}
}
return null;
} | [
"protected",
"function",
"getRefreshToken",
"(",
")",
"{",
"// check if RefreshToken is already stored",
"$",
"refreshToken",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"getRefreshToken",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"refreshToken",
")",
"{",
"return",
"$",
"refreshToken",
";",
"}",
"// get device token required for RefreshToken request",
"$",
"deviceToken",
"=",
"$",
"this",
"->",
"getDeviceToken",
"(",
")",
";",
"if",
"(",
"$",
"deviceToken",
"!==",
"null",
"&&",
"$",
"deviceToken",
"->",
"canPoll",
"(",
")",
")",
"{",
"// check if token exists and can be polled (depends on interval provided by the server)",
"$",
"params",
"=",
"array",
"(",
"'client_id'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getClientId",
"(",
")",
",",
"'code'",
"=>",
"$",
"deviceToken",
"->",
"getDeviceCode",
"(",
")",
",",
"'grant_type'",
"=>",
"'device'",
",",
")",
";",
"// request a RefreshToken",
"$",
"response",
"=",
"$",
"this",
"->",
"sendPostRequest",
"(",
"\"oauth2waitress/oauth2.svc/token\"",
",",
"$",
"params",
")",
";",
"$",
"output",
"=",
"$",
"response",
"[",
"'output'",
"]",
";",
"$",
"httpcode",
"=",
"$",
"response",
"[",
"'code'",
"]",
";",
"// update LastPoll date to assure the correct polling interval",
"$",
"deviceToken",
"->",
"setLastPoll",
"(",
"new",
"DateTime",
"(",
")",
")",
";",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"saveDeviceToken",
"(",
"$",
"deviceToken",
")",
";",
"switch",
"(",
"$",
"httpcode",
")",
"{",
"case",
"\"200\"",
":",
"$",
"responseObject",
"=",
"json_decode",
"(",
"$",
"output",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"responseObject",
"->",
"access_token",
")",
")",
"{",
"// no AccessToken provided yet. Authorization is most likely pending.",
"return",
"null",
";",
"}",
"// AccessToken provided",
"// create AccessToken and save it",
"$",
"accessToken",
"=",
"new",
"AccessToken",
"(",
"new",
"DateTime",
"(",
")",
",",
"$",
"responseObject",
"->",
"access_token",
",",
"$",
"responseObject",
"->",
"token_type",
",",
"$",
"responseObject",
"->",
"expires_in",
")",
";",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"deleteAccessToken",
"(",
")",
";",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"saveAccessToken",
"(",
"$",
"accessToken",
")",
";",
"if",
"(",
"$",
"responseObject",
"->",
"refresh_token",
")",
"{",
"// if a RefreshToken was also provided, we create and save it, too.",
"$",
"refreshToken",
"=",
"new",
"RefreshToken",
"(",
"new",
"DateTime",
"(",
")",
",",
"$",
"responseObject",
"->",
"refresh_token",
")",
";",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"saveRefreshToken",
"(",
"$",
"refreshToken",
")",
";",
"}",
"return",
"$",
"refreshToken",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Tries to retrieve RefreshToken.
@return RefreshToken|null | [
"Tries",
"to",
"retrieve",
"RefreshToken",
"."
] | e4e53dfa1ee6e785acc4d3c632d3ebf70fe3d4fb | https://github.com/xelax90/l2p-client/blob/e4e53dfa1ee6e785acc4d3c632d3ebf70fe3d4fb/src/L2PClient/TokenManager.php#L52-L98 | train |
xelax90/l2p-client | src/L2PClient/TokenManager.php | TokenManager.getAccessTokenWithRefreshToken | protected function getAccessTokenWithRefreshToken(RefreshToken $refreshToken){
// Send post request to authentication service
$params = array(
'client_id' => $this->getConfig()->getClientId(),
'refresh_token' => $refreshToken->getRefreshToken(),
'grant_type' => 'refresh_token',
);
$response = $this->sendPostRequest("oauth2waitress/oauth2.svc/token", $params);
$output = $response['output'];
$httpcode = $response['code'];
switch($httpcode){
case "200" :
$responseObject = json_decode($output);
if(isset($responseObject->error)){
// an error occured, the RefreshToken is most likely invalid
// delete RefreshToken to retrieve new one on next request
$this->getConfig()->getStorage()->deleteRefreshToken();
return null;
}
// create access token and save it
$accessToken = new AccessToken(new DateTime(), $responseObject->access_token, $responseObject->token_type, $responseObject->expires_in);
$this->getConfig()->getStorage()->saveAccessToken($accessToken);
return $accessToken;
}
return null;
} | php | protected function getAccessTokenWithRefreshToken(RefreshToken $refreshToken){
// Send post request to authentication service
$params = array(
'client_id' => $this->getConfig()->getClientId(),
'refresh_token' => $refreshToken->getRefreshToken(),
'grant_type' => 'refresh_token',
);
$response = $this->sendPostRequest("oauth2waitress/oauth2.svc/token", $params);
$output = $response['output'];
$httpcode = $response['code'];
switch($httpcode){
case "200" :
$responseObject = json_decode($output);
if(isset($responseObject->error)){
// an error occured, the RefreshToken is most likely invalid
// delete RefreshToken to retrieve new one on next request
$this->getConfig()->getStorage()->deleteRefreshToken();
return null;
}
// create access token and save it
$accessToken = new AccessToken(new DateTime(), $responseObject->access_token, $responseObject->token_type, $responseObject->expires_in);
$this->getConfig()->getStorage()->saveAccessToken($accessToken);
return $accessToken;
}
return null;
} | [
"protected",
"function",
"getAccessTokenWithRefreshToken",
"(",
"RefreshToken",
"$",
"refreshToken",
")",
"{",
"// Send post request to authentication service",
"$",
"params",
"=",
"array",
"(",
"'client_id'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getClientId",
"(",
")",
",",
"'refresh_token'",
"=>",
"$",
"refreshToken",
"->",
"getRefreshToken",
"(",
")",
",",
"'grant_type'",
"=>",
"'refresh_token'",
",",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"sendPostRequest",
"(",
"\"oauth2waitress/oauth2.svc/token\"",
",",
"$",
"params",
")",
";",
"$",
"output",
"=",
"$",
"response",
"[",
"'output'",
"]",
";",
"$",
"httpcode",
"=",
"$",
"response",
"[",
"'code'",
"]",
";",
"switch",
"(",
"$",
"httpcode",
")",
"{",
"case",
"\"200\"",
":",
"$",
"responseObject",
"=",
"json_decode",
"(",
"$",
"output",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"responseObject",
"->",
"error",
")",
")",
"{",
"// an error occured, the RefreshToken is most likely invalid",
"// delete RefreshToken to retrieve new one on next request",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"deleteRefreshToken",
"(",
")",
";",
"return",
"null",
";",
"}",
"// create access token and save it",
"$",
"accessToken",
"=",
"new",
"AccessToken",
"(",
"new",
"DateTime",
"(",
")",
",",
"$",
"responseObject",
"->",
"access_token",
",",
"$",
"responseObject",
"->",
"token_type",
",",
"$",
"responseObject",
"->",
"expires_in",
")",
";",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"saveAccessToken",
"(",
"$",
"accessToken",
")",
";",
"return",
"$",
"accessToken",
";",
"}",
"return",
"null",
";",
"}"
] | Get new AccessToken using provided RefreshToken
@param RefreshToken $refreshToken
@return AccessToken | [
"Get",
"new",
"AccessToken",
"using",
"provided",
"RefreshToken"
] | e4e53dfa1ee6e785acc4d3c632d3ebf70fe3d4fb | https://github.com/xelax90/l2p-client/blob/e4e53dfa1ee6e785acc4d3c632d3ebf70fe3d4fb/src/L2PClient/TokenManager.php#L140-L166 | train |
xelax90/l2p-client | src/L2PClient/TokenManager.php | TokenManager.getDeviceToken | protected function getDeviceToken(){
// check if valid device token exists
$deviceToken = $this->getConfig()->getStorage()->getDeviceToken();
if(null !== $deviceToken && $deviceToken->isExpired()){
$this->getConfig()->getStorage()->deleteDeviceToken();
$deviceToken = null;
}
if(null === $deviceToken){
// if no token exists, call the code endpoint
$params = array(
'client_id' => $this->getConfig()->getClientId(),
'scope' => $this->getConfig()->getScope(),
);
$response = $this->sendPostRequest("oauth2waitress/oauth2.svc/code", $params);
$output = $response['output'];
$httpcode = $response['code'];
switch($httpcode){
case "200" :
// save the recieved DeviceToken
$responseObject = json_decode($output);
$deviceToken = new DeviceToken(new DateTime(), $responseObject->device_code, $responseObject->expires_in, $responseObject->interval, $responseObject->user_code, $responseObject->verification_url);
$this->getConfig()->getStorage()->saveDeviceToken($deviceToken);
}
}
return $deviceToken;
} | php | protected function getDeviceToken(){
// check if valid device token exists
$deviceToken = $this->getConfig()->getStorage()->getDeviceToken();
if(null !== $deviceToken && $deviceToken->isExpired()){
$this->getConfig()->getStorage()->deleteDeviceToken();
$deviceToken = null;
}
if(null === $deviceToken){
// if no token exists, call the code endpoint
$params = array(
'client_id' => $this->getConfig()->getClientId(),
'scope' => $this->getConfig()->getScope(),
);
$response = $this->sendPostRequest("oauth2waitress/oauth2.svc/code", $params);
$output = $response['output'];
$httpcode = $response['code'];
switch($httpcode){
case "200" :
// save the recieved DeviceToken
$responseObject = json_decode($output);
$deviceToken = new DeviceToken(new DateTime(), $responseObject->device_code, $responseObject->expires_in, $responseObject->interval, $responseObject->user_code, $responseObject->verification_url);
$this->getConfig()->getStorage()->saveDeviceToken($deviceToken);
}
}
return $deviceToken;
} | [
"protected",
"function",
"getDeviceToken",
"(",
")",
"{",
"// check if valid device token exists",
"$",
"deviceToken",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"getDeviceToken",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"deviceToken",
"&&",
"$",
"deviceToken",
"->",
"isExpired",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"deleteDeviceToken",
"(",
")",
";",
"$",
"deviceToken",
"=",
"null",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"deviceToken",
")",
"{",
"// if no token exists, call the code endpoint",
"$",
"params",
"=",
"array",
"(",
"'client_id'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getClientId",
"(",
")",
",",
"'scope'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getScope",
"(",
")",
",",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"sendPostRequest",
"(",
"\"oauth2waitress/oauth2.svc/code\"",
",",
"$",
"params",
")",
";",
"$",
"output",
"=",
"$",
"response",
"[",
"'output'",
"]",
";",
"$",
"httpcode",
"=",
"$",
"response",
"[",
"'code'",
"]",
";",
"switch",
"(",
"$",
"httpcode",
")",
"{",
"case",
"\"200\"",
":",
"// save the recieved DeviceToken",
"$",
"responseObject",
"=",
"json_decode",
"(",
"$",
"output",
")",
";",
"$",
"deviceToken",
"=",
"new",
"DeviceToken",
"(",
"new",
"DateTime",
"(",
")",
",",
"$",
"responseObject",
"->",
"device_code",
",",
"$",
"responseObject",
"->",
"expires_in",
",",
"$",
"responseObject",
"->",
"interval",
",",
"$",
"responseObject",
"->",
"user_code",
",",
"$",
"responseObject",
"->",
"verification_url",
")",
";",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"saveDeviceToken",
"(",
"$",
"deviceToken",
")",
";",
"}",
"}",
"return",
"$",
"deviceToken",
";",
"}"
] | Retrieves DeviceToken contianing the UserCode and DeviceCode
@return DeviceToken | [
"Retrieves",
"DeviceToken",
"contianing",
"the",
"UserCode",
"and",
"DeviceCode"
] | e4e53dfa1ee6e785acc4d3c632d3ebf70fe3d4fb | https://github.com/xelax90/l2p-client/blob/e4e53dfa1ee6e785acc4d3c632d3ebf70fe3d4fb/src/L2PClient/TokenManager.php#L172-L198 | train |
xelax90/l2p-client | src/L2PClient/TokenManager.php | TokenManager.sendPostRequest | protected function sendPostRequest($path, $params){
$url = $this->getConfig()->getAuthUrl().$path;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array('output' => $output, 'code' => $httpcode);
} | php | protected function sendPostRequest($path, $params){
$url = $this->getConfig()->getAuthUrl().$path;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array('output' => $output, 'code' => $httpcode);
} | [
"protected",
"function",
"sendPostRequest",
"(",
"$",
"path",
",",
"$",
"params",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getAuthUrl",
"(",
")",
".",
"$",
"path",
";",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POST",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POSTFIELDS",
",",
"http_build_query",
"(",
"$",
"params",
")",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_TIMEOUT",
",",
"10",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_VERBOSE",
",",
"true",
")",
";",
"$",
"output",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"httpcode",
"=",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"return",
"array",
"(",
"'output'",
"=>",
"$",
"output",
",",
"'code'",
"=>",
"$",
"httpcode",
")",
";",
"}"
] | Sends a POST request to the auth server. Returns array with keys 'output' and 'code'. Output contains the response body, code contains the response code.
@param string $path The endpoint that you want to access
@param string $params The parameters you want to send
@return array | [
"Sends",
"a",
"POST",
"request",
"to",
"the",
"auth",
"server",
".",
"Returns",
"array",
"with",
"keys",
"output",
"and",
"code",
".",
"Output",
"contains",
"the",
"response",
"body",
"code",
"contains",
"the",
"response",
"code",
"."
] | e4e53dfa1ee6e785acc4d3c632d3ebf70fe3d4fb | https://github.com/xelax90/l2p-client/blob/e4e53dfa1ee6e785acc4d3c632d3ebf70fe3d4fb/src/L2PClient/TokenManager.php#L206-L220 | train |
subjective-php/spl-datastructures | src/Bag.php | Bag.add | public function add($element) : BagInterface
{
array_unshift($this->elements, $element);
shuffle($this->elements);
return $this;
} | php | public function add($element) : BagInterface
{
array_unshift($this->elements, $element);
shuffle($this->elements);
return $this;
} | [
"public",
"function",
"add",
"(",
"$",
"element",
")",
":",
"BagInterface",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"elements",
",",
"$",
"element",
")",
";",
"shuffle",
"(",
"$",
"this",
"->",
"elements",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a new element to the bag.
@param mixed $element The element to add.
@return BagInterface | [
"Adds",
"a",
"new",
"element",
"to",
"the",
"bag",
"."
] | 621b0c47be9449299cfd22686d11ef9750f9841d | https://github.com/subjective-php/spl-datastructures/blob/621b0c47be9449299cfd22686d11ef9750f9841d/src/Bag.php#L27-L32 | train |
shrink0r/php-schema | src/Property/SequenceProperty.php | SequenceProperty.validate | public function validate($value)
{
if (!is_array($value)) {
return Error::unit([ Error::NON_ARRAY ]);
}
$errors = [];
foreach ($value as $pos => $item) {
$result = parent::validate($item);
if ($result instanceof Error) {
$errors[$pos] = $result->unwrap();
}
}
return empty($errors) ? Ok::unit() : Error::unit($errors);
} | php | public function validate($value)
{
if (!is_array($value)) {
return Error::unit([ Error::NON_ARRAY ]);
}
$errors = [];
foreach ($value as $pos => $item) {
$result = parent::validate($item);
if ($result instanceof Error) {
$errors[$pos] = $result->unwrap();
}
}
return empty($errors) ? Ok::unit() : Error::unit($errors);
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Error",
"::",
"unit",
"(",
"[",
"Error",
"::",
"NON_ARRAY",
"]",
")",
";",
"}",
"$",
"errors",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"pos",
"=>",
"$",
"item",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"validate",
"(",
"$",
"item",
")",
";",
"if",
"(",
"$",
"result",
"instanceof",
"Error",
")",
"{",
"$",
"errors",
"[",
"$",
"pos",
"]",
"=",
"$",
"result",
"->",
"unwrap",
"(",
")",
";",
"}",
"}",
"return",
"empty",
"(",
"$",
"errors",
")",
"?",
"Ok",
"::",
"unit",
"(",
")",
":",
"Error",
"::",
"unit",
"(",
"$",
"errors",
")",
";",
"}"
] | Tells if a given array's items adhere to any of the property's allowed types.
@param mixed $value
@return ResultInterface Returns Ok if the value is valid, otherwise an Error is returned. | [
"Tells",
"if",
"a",
"given",
"array",
"s",
"items",
"adhere",
"to",
"any",
"of",
"the",
"property",
"s",
"allowed",
"types",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/SequenceProperty.php#L18-L33 | train |
marando/Units | src/Marando/Units/TimeBase.php | TimeBase.fmtRep | protected static function fmtRep($char, &$string, $value)
{
if (preg_match_all('/([0-9]{0,1})' . $char . '/', $string, $m)) {
for ($i = 0; $i < count($m[0]); $i++) {
$val = round($value, (int)$m[1][$i]);
$string = str_replace($m[0][$i], $val, $string);
}
}
} | php | protected static function fmtRep($char, &$string, $value)
{
if (preg_match_all('/([0-9]{0,1})' . $char . '/', $string, $m)) {
for ($i = 0; $i < count($m[0]); $i++) {
$val = round($value, (int)$m[1][$i]);
$string = str_replace($m[0][$i], $val, $string);
}
}
} | [
"protected",
"static",
"function",
"fmtRep",
"(",
"$",
"char",
",",
"&",
"$",
"string",
",",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match_all",
"(",
"'/([0-9]{0,1})'",
".",
"$",
"char",
".",
"'/'",
",",
"$",
"string",
",",
"$",
"m",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"m",
"[",
"0",
"]",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"val",
"=",
"round",
"(",
"$",
"value",
",",
"(",
"int",
")",
"$",
"m",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"m",
"[",
"0",
"]",
"[",
"$",
"i",
"]",
",",
"$",
"val",
",",
"$",
"string",
")",
";",
"}",
"}",
"}"
] | Performs a decimal regular expression string formatter replace that
provides value at a specified decimal precision.
@param $char Character to match for replacing
@param $string String being replaced
@param $value Value to replace | [
"Performs",
"a",
"decimal",
"regular",
"expression",
"string",
"formatter",
"replace",
"that",
"provides",
"value",
"at",
"a",
"specified",
"decimal",
"precision",
"."
] | 1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70 | https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/TimeBase.php#L39-L47 | train |
marando/Units | src/Marando/Units/TimeBase.php | TimeBase.encode | protected static function encode($string, $key)
{
for ($i = 0; $i < strlen($key); $i++) {
$char = $key[$i];
$string = str_replace("\\{$char}", "%{$i}", $string);
}
return $string;
} | php | protected static function encode($string, $key)
{
for ($i = 0; $i < strlen($key); $i++) {
$char = $key[$i];
$string = str_replace("\\{$char}", "%{$i}", $string);
}
return $string;
} | [
"protected",
"static",
"function",
"encode",
"(",
"$",
"string",
",",
"$",
"key",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"key",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"char",
"=",
"$",
"key",
"[",
"$",
"i",
"]",
";",
"$",
"string",
"=",
"str_replace",
"(",
"\"\\\\{$char}\"",
",",
"\"%{$i}\"",
",",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Encodes reserved characters for formatter strings.
@param string $string String to encode
@param string $key Characters to encode
@return string | [
"Encodes",
"reserved",
"characters",
"for",
"formatter",
"strings",
"."
] | 1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70 | https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/TimeBase.php#L73-L81 | train |
marando/Units | src/Marando/Units/TimeBase.php | TimeBase.decode | protected static function decode($string, $key)
{
for ($i = 0; $i < strlen($key); $i++) {
$char = $key[$i];
$string = str_replace("%{$i}", "{$char}", $string);
}
return $string;
} | php | protected static function decode($string, $key)
{
for ($i = 0; $i < strlen($key); $i++) {
$char = $key[$i];
$string = str_replace("%{$i}", "{$char}", $string);
}
return $string;
} | [
"protected",
"static",
"function",
"decode",
"(",
"$",
"string",
",",
"$",
"key",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"key",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"char",
"=",
"$",
"key",
"[",
"$",
"i",
"]",
";",
"$",
"string",
"=",
"str_replace",
"(",
"\"%{$i}\"",
",",
"\"{$char}\"",
",",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Decodes reserved characters for formatter strings.
@param string $string String to decode
@param string $key Characters to decode
@return string | [
"Decodes",
"reserved",
"characters",
"for",
"formatter",
"strings",
"."
] | 1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70 | https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/TimeBase.php#L91-L99 | train |
marando/Units | src/Marando/Units/TimeBase.php | TimeBase.hmsf2sec | protected static function hmsf2sec($h, $m, $s, $f)
{
return static::dmsf2asec($h, $m, $s, $f);
} | php | protected static function hmsf2sec($h, $m, $s, $f)
{
return static::dmsf2asec($h, $m, $s, $f);
} | [
"protected",
"static",
"function",
"hmsf2sec",
"(",
"$",
"h",
",",
"$",
"m",
",",
"$",
"s",
",",
"$",
"f",
")",
"{",
"return",
"static",
"::",
"dmsf2asec",
"(",
"$",
"h",
",",
"$",
"m",
",",
"$",
"s",
",",
"$",
"f",
")",
";",
"}"
] | Composes h m s into seconds.
@param int $h Hour component
@param int $m Minute component
@param int|double $s Second component
@param int|double $f Fractional Second component
@return double | [
"Composes",
"h",
"m",
"s",
"into",
"seconds",
"."
] | 1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70 | https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/TimeBase.php#L206-L209 | train |
freialib/freia.autoloader | src/Filemap.php | Filemap.merge | protected function merge(array &$base, array $overwrite) {
foreach ($overwrite as $key => $value) {
if (is_int($key)) {
// add only if it doesn't exist
if ( ! in_array($overwrite[$key], $base)) {
$base[] = $overwrite[$key];
}
}
else if (is_array($value)) {
if (isset($base[$key]) && is_array($base[$key])) {
$this->merge($base[$key], $value);
}
else { # does not exist or it's a non-array
$base[$key] = $value;
}
}
else { # not an array and not numeric key
$base[$key] = $value;
}
}
} | php | protected function merge(array &$base, array $overwrite) {
foreach ($overwrite as $key => $value) {
if (is_int($key)) {
// add only if it doesn't exist
if ( ! in_array($overwrite[$key], $base)) {
$base[] = $overwrite[$key];
}
}
else if (is_array($value)) {
if (isset($base[$key]) && is_array($base[$key])) {
$this->merge($base[$key], $value);
}
else { # does not exist or it's a non-array
$base[$key] = $value;
}
}
else { # not an array and not numeric key
$base[$key] = $value;
}
}
} | [
"protected",
"function",
"merge",
"(",
"array",
"&",
"$",
"base",
",",
"array",
"$",
"overwrite",
")",
"{",
"foreach",
"(",
"$",
"overwrite",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"// add only if it doesn't exist",
"if",
"(",
"!",
"in_array",
"(",
"$",
"overwrite",
"[",
"$",
"key",
"]",
",",
"$",
"base",
")",
")",
"{",
"$",
"base",
"[",
"]",
"=",
"$",
"overwrite",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"base",
"[",
"$",
"key",
"]",
")",
"&&",
"is_array",
"(",
"$",
"base",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"merge",
"(",
"$",
"base",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"# does not exist or it's a non-array",
"$",
"base",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"# not an array and not numeric key",
"$",
"base",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | Merge configuration arrays.
This function does not return a new array, the first array is simply
processed directly; for effeciency.
Behaviour: numeric key arrays are appended to one another, any other key
and the values will overwrite.
@param array base
@param array overwrite | [
"Merge",
"configuration",
"arrays",
"."
] | 45e0dfcd56d55cf533f12255db647e8a05fcd494 | https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/Filemap.php#L103-L123 | train |
Wedeto/Util | src/Dictionary.php | Dictionary.getType | public function getType($key, $type)
{
if (is_array($key))
{
$args = $key;
}
else
{
$args = func_get_args();
$type = array_pop($args); // Type
}
$val = $this->dget($args);
if ($val === null)
throw new \OutOfRangeException("Key " . implode('.', $args) . " does not exist");
$checker = $type instanceof Type ? $type : new Type($type, ['unstrict' => true]);
try
{
$value = $checker->filter($val);
}
catch (\InvalidArgumentException $e)
{
throw new \DomainException("Key " . implode('.', $args) . " is not " . (string)$checker);
}
return $value;
} | php | public function getType($key, $type)
{
if (is_array($key))
{
$args = $key;
}
else
{
$args = func_get_args();
$type = array_pop($args); // Type
}
$val = $this->dget($args);
if ($val === null)
throw new \OutOfRangeException("Key " . implode('.', $args) . " does not exist");
$checker = $type instanceof Type ? $type : new Type($type, ['unstrict' => true]);
try
{
$value = $checker->filter($val);
}
catch (\InvalidArgumentException $e)
{
throw new \DomainException("Key " . implode('.', $args) . " is not " . (string)$checker);
}
return $value;
} | [
"public",
"function",
"getType",
"(",
"$",
"key",
",",
"$",
"type",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"args",
"=",
"$",
"key",
";",
"}",
"else",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"type",
"=",
"array_pop",
"(",
"$",
"args",
")",
";",
"// Type",
"}",
"$",
"val",
"=",
"$",
"this",
"->",
"dget",
"(",
"$",
"args",
")",
";",
"if",
"(",
"$",
"val",
"===",
"null",
")",
"throw",
"new",
"\\",
"OutOfRangeException",
"(",
"\"Key \"",
".",
"implode",
"(",
"'.'",
",",
"$",
"args",
")",
".",
"\" does not exist\"",
")",
";",
"$",
"checker",
"=",
"$",
"type",
"instanceof",
"Type",
"?",
"$",
"type",
":",
"new",
"Type",
"(",
"$",
"type",
",",
"[",
"'unstrict'",
"=>",
"true",
"]",
")",
";",
"try",
"{",
"$",
"value",
"=",
"$",
"checker",
"->",
"filter",
"(",
"$",
"val",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"\"Key \"",
".",
"implode",
"(",
"'.'",
",",
"$",
"args",
")",
".",
"\" is not \"",
".",
"(",
"string",
")",
"$",
"checker",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Get a value cast to a specific type.
@param $key scalar The key to get. May be repeated to go deeper
@param $type The type (one of the constants in Type)
@return mixed The type as requested | [
"Get",
"a",
"value",
"cast",
"to",
"a",
"specific",
"type",
"."
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Dictionary.php#L184-L211 | train |
Wedeto/Util | src/Dictionary.php | Dictionary.getSection | public function getSection($key)
{
$val = $this->dget(func_get_args());
if ($val instanceof Dictionary)
return $val;
$val = WF::cast_array($val);
return Dictionary::wrap($val);
} | php | public function getSection($key)
{
$val = $this->dget(func_get_args());
if ($val instanceof Dictionary)
return $val;
$val = WF::cast_array($val);
return Dictionary::wrap($val);
} | [
"public",
"function",
"getSection",
"(",
"$",
"key",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"dget",
"(",
"func_get_args",
"(",
")",
")",
";",
"if",
"(",
"$",
"val",
"instanceof",
"Dictionary",
")",
"return",
"$",
"val",
";",
"$",
"val",
"=",
"WF",
"::",
"cast_array",
"(",
"$",
"val",
")",
";",
"return",
"Dictionary",
"::",
"wrap",
"(",
"$",
"val",
")",
";",
"}"
] | Get the parameter as a Dictionary.
@param $key scalar The key to get. May be repeated to go deeper
@return Dictionary The section as a Dictionary. If the key does not
exist, an empty Dictionay is returned. If the key
is not array-like, it will be wrapped in an array. | [
"Get",
"the",
"parameter",
"as",
"a",
"Dictionary",
"."
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Dictionary.php#L260-L267 | train |
Wedeto/Util | src/Dictionary.php | Dictionary.set | public function set($key, $value)
{
if (is_array($key) && $value === null)
$args = $key;
else
$args = func_get_args();
$value = array_pop($args);
$parent = null;
$key = null;
$ref = &$this->values;
foreach ($args as $arg)
{
if (!is_scalar($arg))
throw new \InvalidArgumentException("Keys must be scalar, not: " . WF::str($arg));
if (!is_array($ref))
{
if ($parent !== null)
$parent[$key] = array();
$ref = &$parent[$key];
}
if (!isset($ref[$arg]))
$ref[$arg] = array();
$parent = &$ref;
$key = $arg;
$ref = &$ref[$arg];
}
// Unwrap Dictionary objects
$cl = is_object($value) ? get_class($value) : null;
if ($cl === Dictionary::class)
$ref = $value->getAll();
else
$ref = $value;
return $this;
} | php | public function set($key, $value)
{
if (is_array($key) && $value === null)
$args = $key;
else
$args = func_get_args();
$value = array_pop($args);
$parent = null;
$key = null;
$ref = &$this->values;
foreach ($args as $arg)
{
if (!is_scalar($arg))
throw new \InvalidArgumentException("Keys must be scalar, not: " . WF::str($arg));
if (!is_array($ref))
{
if ($parent !== null)
$parent[$key] = array();
$ref = &$parent[$key];
}
if (!isset($ref[$arg]))
$ref[$arg] = array();
$parent = &$ref;
$key = $arg;
$ref = &$ref[$arg];
}
// Unwrap Dictionary objects
$cl = is_object($value) ? get_class($value) : null;
if ($cl === Dictionary::class)
$ref = $value->getAll();
else
$ref = $value;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
"&&",
"$",
"value",
"===",
"null",
")",
"$",
"args",
"=",
"$",
"key",
";",
"else",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"value",
"=",
"array_pop",
"(",
"$",
"args",
")",
";",
"$",
"parent",
"=",
"null",
";",
"$",
"key",
"=",
"null",
";",
"$",
"ref",
"=",
"&",
"$",
"this",
"->",
"values",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"arg",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Keys must be scalar, not: \"",
".",
"WF",
"::",
"str",
"(",
"$",
"arg",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"ref",
")",
")",
"{",
"if",
"(",
"$",
"parent",
"!==",
"null",
")",
"$",
"parent",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
")",
";",
"$",
"ref",
"=",
"&",
"$",
"parent",
"[",
"$",
"key",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"ref",
"[",
"$",
"arg",
"]",
")",
")",
"$",
"ref",
"[",
"$",
"arg",
"]",
"=",
"array",
"(",
")",
";",
"$",
"parent",
"=",
"&",
"$",
"ref",
";",
"$",
"key",
"=",
"$",
"arg",
";",
"$",
"ref",
"=",
"&",
"$",
"ref",
"[",
"$",
"arg",
"]",
";",
"}",
"// Unwrap Dictionary objects",
"$",
"cl",
"=",
"is_object",
"(",
"$",
"value",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
":",
"null",
";",
"if",
"(",
"$",
"cl",
"===",
"Dictionary",
"::",
"class",
")",
"$",
"ref",
"=",
"$",
"value",
"->",
"getAll",
"(",
")",
";",
"else",
"$",
"ref",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set a value in the dictionary
@param $key scalar The key to set. May be repeated to go deeper
@param $value mixed The value to set
@return Dictionary Provides fluent interface | [
"Set",
"a",
"value",
"in",
"the",
"dictionary"
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Dictionary.php#L314-L354 | train |
Wedeto/Util | src/Dictionary.php | Dictionary.addAll | public function addAll($values)
{
if (!WF::is_array_like($values))
throw new \DomainException("Invalid value to merge: " . WF::str($values));
$this->addAllRecursive($values, $this);
return $this;
} | php | public function addAll($values)
{
if (!WF::is_array_like($values))
throw new \DomainException("Invalid value to merge: " . WF::str($values));
$this->addAllRecursive($values, $this);
return $this;
} | [
"public",
"function",
"addAll",
"(",
"$",
"values",
")",
"{",
"if",
"(",
"!",
"WF",
"::",
"is_array_like",
"(",
"$",
"values",
")",
")",
"throw",
"new",
"\\",
"DomainException",
"(",
"\"Invalid value to merge: \"",
".",
"WF",
"::",
"str",
"(",
"$",
"values",
")",
")",
";",
"$",
"this",
"->",
"addAllRecursive",
"(",
"$",
"values",
",",
"$",
"this",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add all elements in the provided array-like object to the dictionary.
@param Traversable $values The values to add
@return Wedeto\Util\Dictionary Provides fluent interface | [
"Add",
"all",
"elements",
"in",
"the",
"provided",
"array",
"-",
"like",
"object",
"to",
"the",
"dictionary",
"."
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Dictionary.php#L375-L381 | train |
Wedeto/Util | src/Dictionary.php | Dictionary.addAllRecursive | private function addAllRecursive($source, $target, array $path = [])
{
foreach ($source as $key => $value)
{
if (!isset($target[$key]))
{
$target[$key] = $value;
}
else
{
$tgt = $target[$key];
if (is_array($source) || $source instanceof Dictionary)
{
if ($tgt instanceof Dictionary)
$this->addAllRecursive($value, $tgt);
else
$target[$key] = $value;
}
else
$target[$key] = $value;
}
}
} | php | private function addAllRecursive($source, $target, array $path = [])
{
foreach ($source as $key => $value)
{
if (!isset($target[$key]))
{
$target[$key] = $value;
}
else
{
$tgt = $target[$key];
if (is_array($source) || $source instanceof Dictionary)
{
if ($tgt instanceof Dictionary)
$this->addAllRecursive($value, $tgt);
else
$target[$key] = $value;
}
else
$target[$key] = $value;
}
}
} | [
"private",
"function",
"addAllRecursive",
"(",
"$",
"source",
",",
"$",
"target",
",",
"array",
"$",
"path",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"source",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"target",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"target",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"tgt",
"=",
"$",
"target",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"source",
")",
"||",
"$",
"source",
"instanceof",
"Dictionary",
")",
"{",
"if",
"(",
"$",
"tgt",
"instanceof",
"Dictionary",
")",
"$",
"this",
"->",
"addAllRecursive",
"(",
"$",
"value",
",",
"$",
"tgt",
")",
";",
"else",
"$",
"target",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"$",
"target",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | Recursive function to merge all values from a source dictionary or array
into a target dictionary. | [
"Recursive",
"function",
"to",
"merge",
"all",
"values",
"from",
"a",
"source",
"dictionary",
"or",
"array",
"into",
"a",
"target",
"dictionary",
"."
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Dictionary.php#L387-L410 | train |
Wedeto/Util | src/Dictionary.php | Dictionary.clear | public function clear()
{
$keys = array_keys($this->values);
foreach ($keys as $key)
unset($this->values[$key]);
return $this;
} | php | public function clear()
{
$keys = array_keys($this->values);
foreach ($keys as $key)
unset($this->values[$key]);
return $this;
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"values",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"unset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"key",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Remove all elements from the dictionary
@return Wedeto\Util\Dictionary Provides fluent interface | [
"Remove",
"all",
"elements",
"from",
"the",
"dictionary"
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/Dictionary.php#L416-L422 | train |
congraphcms/core | CoreServiceProvider.php | CoreServiceProvider.registerServiceProviders | protected function registerServiceProviders()
{
// Core Bus
// -----------------------------------------------------------------------------
$this->app->register('Congraph\Core\Bus\BusServiceProvider');
// Core Event
// -----------------------------------------------------------------------------
$this->app->register('Congraph\Core\Events\EventsServiceProvider');
// Repositories
// -----------------------------------------------------------------------------
$this->app->register('Congraph\Core\Repositories\RepositoriesServiceProvider');
} | php | protected function registerServiceProviders()
{
// Core Bus
// -----------------------------------------------------------------------------
$this->app->register('Congraph\Core\Bus\BusServiceProvider');
// Core Event
// -----------------------------------------------------------------------------
$this->app->register('Congraph\Core\Events\EventsServiceProvider');
// Repositories
// -----------------------------------------------------------------------------
$this->app->register('Congraph\Core\Repositories\RepositoriesServiceProvider');
} | [
"protected",
"function",
"registerServiceProviders",
"(",
")",
"{",
"// Core Bus",
"// -----------------------------------------------------------------------------",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Congraph\\Core\\Bus\\BusServiceProvider'",
")",
";",
"// Core Event",
"// -----------------------------------------------------------------------------",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Congraph\\Core\\Events\\EventsServiceProvider'",
")",
";",
"// Repositories",
"// -----------------------------------------------------------------------------",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"'Congraph\\Core\\Repositories\\RepositoriesServiceProvider'",
")",
";",
"}"
] | Register Service Providers for this package
@return void | [
"Register",
"Service",
"Providers",
"for",
"this",
"package"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/CoreServiceProvider.php#L54-L67 | train |
pazuzu156/Gravatar | src/Pazuzu156/Gravatar/Profile.php | Profile.getRaw | public function getRaw()
{
$url = $this->_gravatar->generateUrl('profile', $this->_gravatar->getEmail()).'.php';
if (is_null($this->_data)) {
// Let's make a quick check to see if the user exists
// we'll throw an exception if a 404 is returned
$h = get_headers($url, 1)[0];
$code = substr($h, strrpos($h, '404'), strlen($h));
if ($code == '404 Not Found') {
throw new \Exception('404 Error code was thrown. Perhaps invalid email?');
}
// No error? K! Get the contents ;)
$this->_data = file_get_contents($url);
}
return $this->_data;
} | php | public function getRaw()
{
$url = $this->_gravatar->generateUrl('profile', $this->_gravatar->getEmail()).'.php';
if (is_null($this->_data)) {
// Let's make a quick check to see if the user exists
// we'll throw an exception if a 404 is returned
$h = get_headers($url, 1)[0];
$code = substr($h, strrpos($h, '404'), strlen($h));
if ($code == '404 Not Found') {
throw new \Exception('404 Error code was thrown. Perhaps invalid email?');
}
// No error? K! Get the contents ;)
$this->_data = file_get_contents($url);
}
return $this->_data;
} | [
"public",
"function",
"getRaw",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"_gravatar",
"->",
"generateUrl",
"(",
"'profile'",
",",
"$",
"this",
"->",
"_gravatar",
"->",
"getEmail",
"(",
")",
")",
".",
"'.php'",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_data",
")",
")",
"{",
"// Let's make a quick check to see if the user exists",
"// we'll throw an exception if a 404 is returned",
"$",
"h",
"=",
"get_headers",
"(",
"$",
"url",
",",
"1",
")",
"[",
"0",
"]",
";",
"$",
"code",
"=",
"substr",
"(",
"$",
"h",
",",
"strrpos",
"(",
"$",
"h",
",",
"'404'",
")",
",",
"strlen",
"(",
"$",
"h",
")",
")",
";",
"if",
"(",
"$",
"code",
"==",
"'404 Not Found'",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'404 Error code was thrown. Perhaps invalid email?'",
")",
";",
"}",
"// No error? K! Get the contents ;)",
"$",
"this",
"->",
"_data",
"=",
"file_get_contents",
"(",
"$",
"url",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_data",
";",
"}"
] | Returns raw, serialized profile data.
@return string | [
"Returns",
"raw",
"serialized",
"profile",
"data",
"."
] | 7ec5c03f8ada81ec15034c671f2750456c89b6d5 | https://github.com/pazuzu156/Gravatar/blob/7ec5c03f8ada81ec15034c671f2750456c89b6d5/src/Pazuzu156/Gravatar/Profile.php#L58-L77 | train |
pazuzu156/Gravatar | src/Pazuzu156/Gravatar/Profile.php | Profile.convert | public function convert($type, $data)
{
foreach ($data as $k => $v) {
if (is_array($v)) {
$data[$k] = $this->convert($type, $v);
}
}
switch (strtolower($type)) {
case 'array':
return (array) $data;
break;
case 'object':
return (object) $data;
break;
default:
throw new \Exception('Invalid conversion type given!');
}
} | php | public function convert($type, $data)
{
foreach ($data as $k => $v) {
if (is_array($v)) {
$data[$k] = $this->convert($type, $v);
}
}
switch (strtolower($type)) {
case 'array':
return (array) $data;
break;
case 'object':
return (object) $data;
break;
default:
throw new \Exception('Invalid conversion type given!');
}
} | [
"public",
"function",
"convert",
"(",
"$",
"type",
",",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"$",
"data",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"convert",
"(",
"$",
"type",
",",
"$",
"v",
")",
";",
"}",
"}",
"switch",
"(",
"strtolower",
"(",
"$",
"type",
")",
")",
"{",
"case",
"'array'",
":",
"return",
"(",
"array",
")",
"$",
"data",
";",
"break",
";",
"case",
"'object'",
":",
"return",
"(",
"object",
")",
"$",
"data",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid conversion type given!'",
")",
";",
"}",
"}"
] | Converts the data into whichever type specified.
@param string $type - [array/object] Convert into a given type
@param mixed $data - The data to convert
@throws \Exception
@return mixed | [
"Converts",
"the",
"data",
"into",
"whichever",
"type",
"specified",
"."
] | 7ec5c03f8ada81ec15034c671f2750456c89b6d5 | https://github.com/pazuzu156/Gravatar/blob/7ec5c03f8ada81ec15034c671f2750456c89b6d5/src/Pazuzu156/Gravatar/Profile.php#L125-L143 | train |
faizalpribadi/Event | EventDispatcher.php | EventDispatcher.addSubscriber | public function addSubscriber(SubscriberInterface $subscriber)
{
foreach ($subscriber->getSubscriberEvents() as $subscriberEvent => $params) {
if (is_string($params)) {
$this->addListener($subscriberEvent, array($subscriber, $params));
}
if (is_array($params)) {
foreach ($params as $param) {
$this->addListener($subscriberEvent, array($subscriber, $param));
}
}
}
} | php | public function addSubscriber(SubscriberInterface $subscriber)
{
foreach ($subscriber->getSubscriberEvents() as $subscriberEvent => $params) {
if (is_string($params)) {
$this->addListener($subscriberEvent, array($subscriber, $params));
}
if (is_array($params)) {
foreach ($params as $param) {
$this->addListener($subscriberEvent, array($subscriber, $param));
}
}
}
} | [
"public",
"function",
"addSubscriber",
"(",
"SubscriberInterface",
"$",
"subscriber",
")",
"{",
"foreach",
"(",
"$",
"subscriber",
"->",
"getSubscriberEvents",
"(",
")",
"as",
"$",
"subscriberEvent",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"params",
")",
")",
"{",
"$",
"this",
"->",
"addListener",
"(",
"$",
"subscriberEvent",
",",
"array",
"(",
"$",
"subscriber",
",",
"$",
"params",
")",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"this",
"->",
"addListener",
"(",
"$",
"subscriberEvent",
",",
"array",
"(",
"$",
"subscriber",
",",
"$",
"param",
")",
")",
";",
"}",
"}",
"}",
"}"
] | Added subscriber from event configuration
This subscriber allow notified for event
@param SubscriberInterface $subscriber
@return mixed|void
@throws \Exception | [
"Added",
"subscriber",
"from",
"event",
"configuration",
"This",
"subscriber",
"allow",
"notified",
"for",
"event"
] | f1bbd2d018b31b926ede66fd6b0787fbf38e6e99 | https://github.com/faizalpribadi/Event/blob/f1bbd2d018b31b926ede66fd6b0787fbf38e6e99/EventDispatcher.php#L114-L127 | train |
faizalpribadi/Event | EventDispatcher.php | EventDispatcher.removeSubscriber | public function removeSubscriber(SubscriberInterface $subscriber)
{
if (is_array($subscriber->getSubscriberEvents())) {
foreach ($subscriber->getSubscriberEvents() as $subscriberEvent => $params) {
$this->removeListener($subscriberEvent, array($subscriber, $params));
}
}
} | php | public function removeSubscriber(SubscriberInterface $subscriber)
{
if (is_array($subscriber->getSubscriberEvents())) {
foreach ($subscriber->getSubscriberEvents() as $subscriberEvent => $params) {
$this->removeListener($subscriberEvent, array($subscriber, $params));
}
}
} | [
"public",
"function",
"removeSubscriber",
"(",
"SubscriberInterface",
"$",
"subscriber",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"subscriber",
"->",
"getSubscriberEvents",
"(",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"subscriber",
"->",
"getSubscriberEvents",
"(",
")",
"as",
"$",
"subscriberEvent",
"=>",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"removeListener",
"(",
"$",
"subscriberEvent",
",",
"array",
"(",
"$",
"subscriber",
",",
"$",
"params",
")",
")",
";",
"}",
"}",
"}"
] | Remove all subscriber from event configuration
@param SubscriberInterface $subscriber
@return mixed|void | [
"Remove",
"all",
"subscriber",
"from",
"event",
"configuration"
] | f1bbd2d018b31b926ede66fd6b0787fbf38e6e99 | https://github.com/faizalpribadi/Event/blob/f1bbd2d018b31b926ede66fd6b0787fbf38e6e99/EventDispatcher.php#L136-L143 | train |
jooaziz/Jlib | src/Misc/UUID.php | UUID.v3 | public static function v3($namespace, $name)
{
if (!self::is_valid($namespace))
return false;
// Get hexadecimal components of namespace
$nhex = str_replace(array('-', '{', '}'), '', $namespace);
// Binary Value
$nstr = '';
// Convert Namespace UUID to bits
for ($i = 0; $i < strlen($nhex); $i += 2) {
$nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
}
// Calculate hash value
$hash = md5($nstr . $name);
return sprintf('%08s-%04s-%04x-%04x-%12s',
// 32 bits for "time_low"
substr($hash, 0, 8),
// 16 bits for "time_mid"
substr($hash, 8, 4),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 3
(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
// 48 bits for "node"
substr($hash, 20, 12)
);
} | php | public static function v3($namespace, $name)
{
if (!self::is_valid($namespace))
return false;
// Get hexadecimal components of namespace
$nhex = str_replace(array('-', '{', '}'), '', $namespace);
// Binary Value
$nstr = '';
// Convert Namespace UUID to bits
for ($i = 0; $i < strlen($nhex); $i += 2) {
$nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
}
// Calculate hash value
$hash = md5($nstr . $name);
return sprintf('%08s-%04s-%04x-%04x-%12s',
// 32 bits for "time_low"
substr($hash, 0, 8),
// 16 bits for "time_mid"
substr($hash, 8, 4),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 3
(hexdec(substr($hash, 12, 4)) & 0x0fff) | 0x3000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
// 48 bits for "node"
substr($hash, 20, 12)
);
} | [
"public",
"static",
"function",
"v3",
"(",
"$",
"namespace",
",",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"is_valid",
"(",
"$",
"namespace",
")",
")",
"return",
"false",
";",
"// Get hexadecimal components of namespace",
"$",
"nhex",
"=",
"str_replace",
"(",
"array",
"(",
"'-'",
",",
"'{'",
",",
"'}'",
")",
",",
"''",
",",
"$",
"namespace",
")",
";",
"// Binary Value",
"$",
"nstr",
"=",
"''",
";",
"// Convert Namespace UUID to bits",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"nhex",
")",
";",
"$",
"i",
"+=",
"2",
")",
"{",
"$",
"nstr",
".=",
"chr",
"(",
"hexdec",
"(",
"$",
"nhex",
"[",
"$",
"i",
"]",
".",
"$",
"nhex",
"[",
"$",
"i",
"+",
"1",
"]",
")",
")",
";",
"}",
"// Calculate hash value",
"$",
"hash",
"=",
"md5",
"(",
"$",
"nstr",
".",
"$",
"name",
")",
";",
"return",
"sprintf",
"(",
"'%08s-%04s-%04x-%04x-%12s'",
",",
"// 32 bits for \"time_low\"",
"substr",
"(",
"$",
"hash",
",",
"0",
",",
"8",
")",
",",
"// 16 bits for \"time_mid\"",
"substr",
"(",
"$",
"hash",
",",
"8",
",",
"4",
")",
",",
"// 16 bits for \"time_hi_and_version\",",
"// four most significant bits holds version number 3",
"(",
"hexdec",
"(",
"substr",
"(",
"$",
"hash",
",",
"12",
",",
"4",
")",
")",
"&",
"0x0fff",
")",
"|",
"0x3000",
",",
"// 16 bits, 8 bits for \"clk_seq_hi_res\",",
"// 8 bits for \"clk_seq_low\",",
"// two most significant bits holds zero and one for variant DCE1.1",
"(",
"hexdec",
"(",
"substr",
"(",
"$",
"hash",
",",
"16",
",",
"4",
")",
")",
"&",
"0x3fff",
")",
"|",
"0x8000",
",",
"// 48 bits for \"node\"",
"substr",
"(",
"$",
"hash",
",",
"20",
",",
"12",
")",
")",
";",
"}"
] | Generate v3 UUID
Version 3 UUIDs are named based. They require a namespace (another
valid UUID) and a value (the name). Given the same namespace and
name, the output is always the same.
@param uuid $namespace
@param string $name | [
"Generate",
"v3",
"UUID"
] | 1060ab7964690da5ed0660bb4a6cbbd354778463 | https://github.com/jooaziz/Jlib/blob/1060ab7964690da5ed0660bb4a6cbbd354778463/src/Misc/UUID.php#L39-L68 | train |
Kris-Kuiper/sFire-Framework | src/Hash/Token.php | Token.create | public static function create($length = 6, $numbers = true, $letters = false, $capitals = false, $symbols = false) {
if(false === ('-' . intval($length) == '-' . $length)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($length)), E_USER_ERROR);
}
$types = ['numbers', 'letters', 'capitals', 'symbols'];
for($i = 0; $i < count($types); $i++) {
if(null !== ${$types[$i]} && false === is_bool(${$types[$i]})) {
return trigger_error(sprintf('Argument %s passed to %s() must be of the type boolean, "%s" given', ($i + 2), __METHOD__, gettype(${$types[$i]})), E_USER_ERROR);
}
}
$array = [];
$caseinsensitive = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
$casesensitive = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
$numbers_arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
$symbols_arr = ['!', '@', '%', '$', '.', '&', '*', '-', '+', '#'];
$numbers && ($array = array_merge($array, $numbers_arr));
$letters && ($array = array_merge($array, $caseinsensitive));
$capitals && ($array = array_merge($array, $casesensitive));
$symbols && ($array = array_merge($array, $symbols_arr));
$str = '';
if(count($array) > 0) {
for($i = 0; $i < $length; $i++) {
$str .= $array[array_rand($array, 1)];
}
}
return $str;
} | php | public static function create($length = 6, $numbers = true, $letters = false, $capitals = false, $symbols = false) {
if(false === ('-' . intval($length) == '-' . $length)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($length)), E_USER_ERROR);
}
$types = ['numbers', 'letters', 'capitals', 'symbols'];
for($i = 0; $i < count($types); $i++) {
if(null !== ${$types[$i]} && false === is_bool(${$types[$i]})) {
return trigger_error(sprintf('Argument %s passed to %s() must be of the type boolean, "%s" given', ($i + 2), __METHOD__, gettype(${$types[$i]})), E_USER_ERROR);
}
}
$array = [];
$caseinsensitive = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
$casesensitive = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
$numbers_arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
$symbols_arr = ['!', '@', '%', '$', '.', '&', '*', '-', '+', '#'];
$numbers && ($array = array_merge($array, $numbers_arr));
$letters && ($array = array_merge($array, $caseinsensitive));
$capitals && ($array = array_merge($array, $casesensitive));
$symbols && ($array = array_merge($array, $symbols_arr));
$str = '';
if(count($array) > 0) {
for($i = 0; $i < $length; $i++) {
$str .= $array[array_rand($array, 1)];
}
}
return $str;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"length",
"=",
"6",
",",
"$",
"numbers",
"=",
"true",
",",
"$",
"letters",
"=",
"false",
",",
"$",
"capitals",
"=",
"false",
",",
"$",
"symbols",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"length",
")",
"==",
"'-'",
".",
"$",
"length",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"length",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"types",
"=",
"[",
"'numbers'",
",",
"'letters'",
",",
"'capitals'",
",",
"'symbols'",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"types",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"{",
"$",
"types",
"[",
"$",
"i",
"]",
"}",
"&&",
"false",
"===",
"is_bool",
"(",
"$",
"{",
"$",
"types",
"[",
"$",
"i",
"]",
"}",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument %s passed to %s() must be of the type boolean, \"%s\" given'",
",",
"(",
"$",
"i",
"+",
"2",
")",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"{",
"$",
"types",
"[",
"$",
"i",
"]",
"}",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"}",
"$",
"array",
"=",
"[",
"]",
";",
"$",
"caseinsensitive",
"=",
"[",
"'a'",
",",
"'b'",
",",
"'c'",
",",
"'d'",
",",
"'e'",
",",
"'f'",
",",
"'g'",
",",
"'h'",
",",
"'i'",
",",
"'j'",
",",
"'k'",
",",
"'l'",
",",
"'m'",
",",
"'n'",
",",
"'o'",
",",
"'p'",
",",
"'q'",
",",
"'r'",
",",
"'s'",
",",
"'t'",
",",
"'u'",
",",
"'v'",
",",
"'w'",
",",
"'x'",
",",
"'y'",
",",
"'z'",
"]",
";",
"$",
"casesensitive",
"=",
"[",
"'A'",
",",
"'B'",
",",
"'C'",
",",
"'D'",
",",
"'E'",
",",
"'F'",
",",
"'G'",
",",
"'H'",
",",
"'I'",
",",
"'J'",
",",
"'K'",
",",
"'L'",
",",
"'M'",
",",
"'N'",
",",
"'O'",
",",
"'P'",
",",
"'Q'",
",",
"'R'",
",",
"'S'",
",",
"'T'",
",",
"'U'",
",",
"'V'",
",",
"'W'",
",",
"'X'",
",",
"'Y'",
",",
"'Z'",
"]",
";",
"$",
"numbers_arr",
"=",
"[",
"0",
",",
"1",
",",
"2",
",",
"3",
",",
"4",
",",
"5",
",",
"6",
",",
"7",
",",
"8",
",",
"9",
"]",
";",
"$",
"symbols_arr",
"=",
"[",
"'!'",
",",
"'@'",
",",
"'%'",
",",
"'$'",
",",
"'.'",
",",
"'&'",
",",
"'*'",
",",
"'-'",
",",
"'+'",
",",
"'#'",
"]",
";",
"$",
"numbers",
"&&",
"(",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"numbers_arr",
")",
")",
";",
"$",
"letters",
"&&",
"(",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"caseinsensitive",
")",
")",
";",
"$",
"capitals",
"&&",
"(",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"casesensitive",
")",
")",
";",
"$",
"symbols",
"&&",
"(",
"$",
"array",
"=",
"array_merge",
"(",
"$",
"array",
",",
"$",
"symbols_arr",
")",
")",
";",
"$",
"str",
"=",
"''",
";",
"if",
"(",
"count",
"(",
"$",
"array",
")",
">",
"0",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"str",
".=",
"$",
"array",
"[",
"array_rand",
"(",
"$",
"array",
",",
"1",
")",
"]",
";",
"}",
"}",
"return",
"$",
"str",
";",
"}"
] | Create random token
@param int $length
@param boolean $numbers
@param boolean $letters
@param boolean $capitals
@param boolean $symbols
@return string | [
"Create",
"random",
"token"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Hash/Token.php#L42-L78 | train |
SagittariusX/Beluga.IO | src/Beluga/IO/FileAccessError.php | FileAccessError.Read | public static function Read(
string $package, string $file, string $message = null, int $code = \E_USER_ERROR, \Throwable $previous = null )
: FileAccessError
{
return new FileAccessError(
$package,
$file,
static::ACCESS_READ,
$message,
$code,
$previous
);
} | php | public static function Read(
string $package, string $file, string $message = null, int $code = \E_USER_ERROR, \Throwable $previous = null )
: FileAccessError
{
return new FileAccessError(
$package,
$file,
static::ACCESS_READ,
$message,
$code,
$previous
);
} | [
"public",
"static",
"function",
"Read",
"(",
"string",
"$",
"package",
",",
"string",
"$",
"file",
",",
"string",
"$",
"message",
"=",
"null",
",",
"int",
"$",
"code",
"=",
"\\",
"E_USER_ERROR",
",",
"\\",
"Throwable",
"$",
"previous",
"=",
"null",
")",
":",
"FileAccessError",
"{",
"return",
"new",
"FileAccessError",
"(",
"$",
"package",
",",
"$",
"file",
",",
"static",
"::",
"ACCESS_READ",
",",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
")",
";",
"}"
] | Init's a new \Beluga\IO\FileAccessError for file read mode.
@param string $file The file where reading fails.
@param string $message The optional error message.
@param integer $code A optional error code (Defaults to \E_USER_ERROR)
@param \Throwable $previous A Optional previous exception.
@return \Beluga\IO\FileAccessError | [
"Init",
"s",
"a",
"new",
"\\",
"Beluga",
"\\",
"IO",
"\\",
"FileAccessError",
"for",
"file",
"read",
"mode",
"."
] | c8af09a1b3cc8a955e43c89b70779d11b30ae29e | https://github.com/SagittariusX/Beluga.IO/blob/c8af09a1b3cc8a955e43c89b70779d11b30ae29e/src/Beluga/IO/FileAccessError.php#L126-L138 | train |
SagittariusX/Beluga.IO | src/Beluga/IO/FileAccessError.php | FileAccessError.Write | public static function Write(
string $package, string $file, string $message = null, int $code = \E_USER_ERROR, \Throwable $previous = null )
: FileAccessError
{
return new FileAccessError(
$package,
$file,
static::ACCESS_WRITE,
$message,
$code,
$previous
);
} | php | public static function Write(
string $package, string $file, string $message = null, int $code = \E_USER_ERROR, \Throwable $previous = null )
: FileAccessError
{
return new FileAccessError(
$package,
$file,
static::ACCESS_WRITE,
$message,
$code,
$previous
);
} | [
"public",
"static",
"function",
"Write",
"(",
"string",
"$",
"package",
",",
"string",
"$",
"file",
",",
"string",
"$",
"message",
"=",
"null",
",",
"int",
"$",
"code",
"=",
"\\",
"E_USER_ERROR",
",",
"\\",
"Throwable",
"$",
"previous",
"=",
"null",
")",
":",
"FileAccessError",
"{",
"return",
"new",
"FileAccessError",
"(",
"$",
"package",
",",
"$",
"file",
",",
"static",
"::",
"ACCESS_WRITE",
",",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
")",
";",
"}"
] | Init's a new \Beluga\IO\FileAccessError for file write mode.
@param string $file The file where reading fails.
@param string $message The optional error message.
@param integer $code A optional error code (Defaults to \E_USER_ERROR)
@param \Throwable $previous A Optional previous exception.
@return \Beluga\IO\FileAccessError | [
"Init",
"s",
"a",
"new",
"\\",
"Beluga",
"\\",
"IO",
"\\",
"FileAccessError",
"for",
"file",
"write",
"mode",
"."
] | c8af09a1b3cc8a955e43c89b70779d11b30ae29e | https://github.com/SagittariusX/Beluga.IO/blob/c8af09a1b3cc8a955e43c89b70779d11b30ae29e/src/Beluga/IO/FileAccessError.php#L149-L163 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Persister/AssociationPersister.php | AssociationPersister.getDiscriminatedClass | public function getDiscriminatedClass(PropertyMetadata $mapping, $discriminator = null)
{
if ($discriminator === null) {
$discriminator = $mapping->discriminatorDefaultValue;
}
if ($discriminator !== null) {
if (isset($mapping->discriminatorMap[$discriminator])) {
$discriminator = $mapping->discriminatorMap[$discriminator];
}
return $this->dm->getClassMetadata($discriminator);
}
if ($mapping->targetDocument === null) {
throw ODMException::mixedAssociationRequiresDiscriminator();
}
//get the class
$class = $this->dm->getClassMetadata($mapping->targetDocument);
//check for single-table inheritance discriminator
if ($class->discriminatorDefaultValue !== null) {
$discriminator = $class->discriminatorDefaultValue;
}
if ($discriminator !== null) {
if (isset($class->discriminatorMap[$discriminator])) {
$discriminator = $class->discriminatorMap[$discriminator];
}
$class = $this->dm->getClassMetadata($discriminator);
}
return $class;
} | php | public function getDiscriminatedClass(PropertyMetadata $mapping, $discriminator = null)
{
if ($discriminator === null) {
$discriminator = $mapping->discriminatorDefaultValue;
}
if ($discriminator !== null) {
if (isset($mapping->discriminatorMap[$discriminator])) {
$discriminator = $mapping->discriminatorMap[$discriminator];
}
return $this->dm->getClassMetadata($discriminator);
}
if ($mapping->targetDocument === null) {
throw ODMException::mixedAssociationRequiresDiscriminator();
}
//get the class
$class = $this->dm->getClassMetadata($mapping->targetDocument);
//check for single-table inheritance discriminator
if ($class->discriminatorDefaultValue !== null) {
$discriminator = $class->discriminatorDefaultValue;
}
if ($discriminator !== null) {
if (isset($class->discriminatorMap[$discriminator])) {
$discriminator = $class->discriminatorMap[$discriminator];
}
$class = $this->dm->getClassMetadata($discriminator);
}
return $class;
} | [
"public",
"function",
"getDiscriminatedClass",
"(",
"PropertyMetadata",
"$",
"mapping",
",",
"$",
"discriminator",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"discriminator",
"===",
"null",
")",
"{",
"$",
"discriminator",
"=",
"$",
"mapping",
"->",
"discriminatorDefaultValue",
";",
"}",
"if",
"(",
"$",
"discriminator",
"!==",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"mapping",
"->",
"discriminatorMap",
"[",
"$",
"discriminator",
"]",
")",
")",
"{",
"$",
"discriminator",
"=",
"$",
"mapping",
"->",
"discriminatorMap",
"[",
"$",
"discriminator",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"discriminator",
")",
";",
"}",
"if",
"(",
"$",
"mapping",
"->",
"targetDocument",
"===",
"null",
")",
"{",
"throw",
"ODMException",
"::",
"mixedAssociationRequiresDiscriminator",
"(",
")",
";",
"}",
"//get the class",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"mapping",
"->",
"targetDocument",
")",
";",
"//check for single-table inheritance discriminator",
"if",
"(",
"$",
"class",
"->",
"discriminatorDefaultValue",
"!==",
"null",
")",
"{",
"$",
"discriminator",
"=",
"$",
"class",
"->",
"discriminatorDefaultValue",
";",
"}",
"if",
"(",
"$",
"discriminator",
"!==",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"class",
"->",
"discriminatorMap",
"[",
"$",
"discriminator",
"]",
")",
")",
"{",
"$",
"discriminator",
"=",
"$",
"class",
"->",
"discriminatorMap",
"[",
"$",
"discriminator",
"]",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"dm",
"->",
"getClassMetadata",
"(",
"$",
"discriminator",
")",
";",
"}",
"return",
"$",
"class",
";",
"}"
] | Get the class metadata for an association's target, with respect to any
discriminator value.
@param PropertyMetadata $mapping
@param mixed|null $discriminator
@return ClassMetadata
@throws ODMException | [
"Get",
"the",
"class",
"metadata",
"for",
"an",
"association",
"s",
"target",
"with",
"respect",
"to",
"any",
"discriminator",
"value",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Persister/AssociationPersister.php#L55-L90 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.setPolicy | public function setPolicy(string $policy)
{
// allow (all is deny, allow part) | deny (all is allow, deny part) | none (all is allow, ignore part)
if (!in_array($policy, [self::POLICY_NONE, self::POLICY_ALLOW, self::POLICY_DENY])) {
throw new Exception('Unsupported policy type: ' . $policy);
}
$this->policy = $policy;
$this->init(); // init data after set policy (in extension)!
} | php | public function setPolicy(string $policy)
{
// allow (all is deny, allow part) | deny (all is allow, deny part) | none (all is allow, ignore part)
if (!in_array($policy, [self::POLICY_NONE, self::POLICY_ALLOW, self::POLICY_DENY])) {
throw new Exception('Unsupported policy type: ' . $policy);
}
$this->policy = $policy;
$this->init(); // init data after set policy (in extension)!
} | [
"public",
"function",
"setPolicy",
"(",
"string",
"$",
"policy",
")",
"{",
"// allow (all is deny, allow part) | deny (all is allow, deny part) | none (all is allow, ignore part)",
"if",
"(",
"!",
"in_array",
"(",
"$",
"policy",
",",
"[",
"self",
"::",
"POLICY_NONE",
",",
"self",
"::",
"POLICY_ALLOW",
",",
"self",
"::",
"POLICY_DENY",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Unsupported policy type: '",
".",
"$",
"policy",
")",
";",
"}",
"$",
"this",
"->",
"policy",
"=",
"$",
"policy",
";",
"$",
"this",
"->",
"init",
"(",
")",
";",
"// init data after set policy (in extension)!",
"}"
] | Set policy.
@param string $policy
@throws Exception | [
"Set",
"policy",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L69-L78 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.getIdRoleByName | public function getIdRoleByName(string $name): string
{
if (isset($this->role[$name])) {
return (string) $this->role[$name]['id'];
}
return '';
} | php | public function getIdRoleByName(string $name): string
{
if (isset($this->role[$name])) {
return (string) $this->role[$name]['id'];
}
return '';
} | [
"public",
"function",
"getIdRoleByName",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"role",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"role",
"[",
"$",
"name",
"]",
"[",
"'id'",
"]",
";",
"}",
"return",
"''",
";",
"}"
] | Get id role by name.
@param string $name
@return string | [
"Get",
"id",
"role",
"by",
"name",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L120-L126 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.getResource | public function getResource(string $id = null): array
{
if ($id) {
if (is_numeric($id)) {
$filter = array_filter($this->resource, function ($row) use ($id) { return $row['id'] == $id; });
return (array) array_pop($filter);
}
return (array) ($this->resource[$id] ?? []);
}
return $this->resource;
} | php | public function getResource(string $id = null): array
{
if ($id) {
if (is_numeric($id)) {
$filter = array_filter($this->resource, function ($row) use ($id) { return $row['id'] == $id; });
return (array) array_pop($filter);
}
return (array) ($this->resource[$id] ?? []);
}
return $this->resource;
} | [
"public",
"function",
"getResource",
"(",
"string",
"$",
"id",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"filter",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"resource",
",",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"row",
"[",
"'id'",
"]",
"==",
"$",
"id",
";",
"}",
")",
";",
"return",
"(",
"array",
")",
"array_pop",
"(",
"$",
"filter",
")",
";",
"}",
"return",
"(",
"array",
")",
"(",
"$",
"this",
"->",
"resource",
"[",
"$",
"id",
"]",
"??",
"[",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resource",
";",
"}"
] | Get resource.
@param string|null $id
@return array | [
"Get",
"resource",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L135-L145 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.getIdResourceByName | public function getIdResourceByName(string $name): string
{
if (isset($this->resource[$name])) {
return (string) $this->resource[$name]['id'];
}
return '';
} | php | public function getIdResourceByName(string $name): string
{
if (isset($this->resource[$name])) {
return (string) $this->resource[$name]['id'];
}
return '';
} | [
"public",
"function",
"getIdResourceByName",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"resource",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"resource",
"[",
"$",
"name",
"]",
"[",
"'id'",
"]",
";",
"}",
"return",
"''",
";",
"}"
] | Get id resource by name.
@param string $name
@return string | [
"Get",
"id",
"resource",
"by",
"name",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L154-L160 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.getPrivilege | public function getPrivilege(string $id = null): array
{
if ($id) {
if (is_numeric($id)) {
$filter = array_filter($this->privilege, function ($row) use ($id) { return $row['id'] == $id; });
return (array) array_pop($filter);
}
return (array) ($this->privilege[$id] ?? []);
}
return $this->privilege;
} | php | public function getPrivilege(string $id = null): array
{
if ($id) {
if (is_numeric($id)) {
$filter = array_filter($this->privilege, function ($row) use ($id) { return $row['id'] == $id; });
return (array) array_pop($filter);
}
return (array) ($this->privilege[$id] ?? []);
}
return $this->privilege;
} | [
"public",
"function",
"getPrivilege",
"(",
"string",
"$",
"id",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"filter",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"privilege",
",",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"id",
")",
"{",
"return",
"$",
"row",
"[",
"'id'",
"]",
"==",
"$",
"id",
";",
"}",
")",
";",
"return",
"(",
"array",
")",
"array_pop",
"(",
"$",
"filter",
")",
";",
"}",
"return",
"(",
"array",
")",
"(",
"$",
"this",
"->",
"privilege",
"[",
"$",
"id",
"]",
"??",
"[",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"privilege",
";",
"}"
] | Get privilege.
@param string|null $id
@return array | [
"Get",
"privilege",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L169-L179 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.getIdPrivilegeByName | public function getIdPrivilegeByName(string $name): string
{
if (isset($this->privilege[$name])) {
return (string) $this->privilege[$name]['id'];
}
return '';
} | php | public function getIdPrivilegeByName(string $name): string
{
if (isset($this->privilege[$name])) {
return (string) $this->privilege[$name]['id'];
}
return '';
} | [
"public",
"function",
"getIdPrivilegeByName",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"privilege",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"privilege",
"[",
"$",
"name",
"]",
"[",
"'id'",
"]",
";",
"}",
"return",
"''",
";",
"}"
] | Get id privilege by name.
@param string $name
@return string | [
"Get",
"id",
"privilege",
"by",
"name",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L188-L194 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.getAcl | public function getAcl(string $idRole = null, string $idResource = null): array
{
if ($idRole) {
$callback = function ($row) use ($idRole, $idResource) {
if ($idRole && $idResource) {
return $row['id_role'] == $idRole && $row['id_resource'] == $idResource;
}
if ($idRole) {
return $row['id_role'] == $idRole;
}
return true;
};
return array_filter($this->acl, $callback);
}
return $this->acl;
} | php | public function getAcl(string $idRole = null, string $idResource = null): array
{
if ($idRole) {
$callback = function ($row) use ($idRole, $idResource) {
if ($idRole && $idResource) {
return $row['id_role'] == $idRole && $row['id_resource'] == $idResource;
}
if ($idRole) {
return $row['id_role'] == $idRole;
}
return true;
};
return array_filter($this->acl, $callback);
}
return $this->acl;
} | [
"public",
"function",
"getAcl",
"(",
"string",
"$",
"idRole",
"=",
"null",
",",
"string",
"$",
"idResource",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"$",
"idRole",
")",
"{",
"$",
"callback",
"=",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"idRole",
",",
"$",
"idResource",
")",
"{",
"if",
"(",
"$",
"idRole",
"&&",
"$",
"idResource",
")",
"{",
"return",
"$",
"row",
"[",
"'id_role'",
"]",
"==",
"$",
"idRole",
"&&",
"$",
"row",
"[",
"'id_resource'",
"]",
"==",
"$",
"idResource",
";",
"}",
"if",
"(",
"$",
"idRole",
")",
"{",
"return",
"$",
"row",
"[",
"'id_role'",
"]",
"==",
"$",
"idRole",
";",
"}",
"return",
"true",
";",
"}",
";",
"return",
"array_filter",
"(",
"$",
"this",
"->",
"acl",
",",
"$",
"callback",
")",
";",
"}",
"return",
"$",
"this",
"->",
"acl",
";",
"}"
] | Get acl.
@param string|null $idRole
@param string|null $idResource
@return array | [
"Get",
"acl",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L204-L219 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.getAclForm | public function getAclForm(string $idRole): array
{
// support method - for load form
$result = [];
foreach ($this->resource as $item) {
$acl = $this->getAcl($idRole, (string) $item['id']);
if ($this->isAll($idRole, (string) $item['id'])) {
// idRole, idResource, ALL
$result[$item['id']] = 'all';
} else {
$result[$item['id']] = array_values(array_map(function ($row) { return $row['id_privilege']; }, $acl));
}
}
if ($this->isAll($idRole)) {
// idRole, ALL, ALL
$result['all'] = true;
}
return ['idRole' => $idRole] + $result;
} | php | public function getAclForm(string $idRole): array
{
// support method - for load form
$result = [];
foreach ($this->resource as $item) {
$acl = $this->getAcl($idRole, (string) $item['id']);
if ($this->isAll($idRole, (string) $item['id'])) {
// idRole, idResource, ALL
$result[$item['id']] = 'all';
} else {
$result[$item['id']] = array_values(array_map(function ($row) { return $row['id_privilege']; }, $acl));
}
}
if ($this->isAll($idRole)) {
// idRole, ALL, ALL
$result['all'] = true;
}
return ['idRole' => $idRole] + $result;
} | [
"public",
"function",
"getAclForm",
"(",
"string",
"$",
"idRole",
")",
":",
"array",
"{",
"// support method - for load form",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"resource",
"as",
"$",
"item",
")",
"{",
"$",
"acl",
"=",
"$",
"this",
"->",
"getAcl",
"(",
"$",
"idRole",
",",
"(",
"string",
")",
"$",
"item",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isAll",
"(",
"$",
"idRole",
",",
"(",
"string",
")",
"$",
"item",
"[",
"'id'",
"]",
")",
")",
"{",
"// idRole, idResource, ALL",
"$",
"result",
"[",
"$",
"item",
"[",
"'id'",
"]",
"]",
"=",
"'all'",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"item",
"[",
"'id'",
"]",
"]",
"=",
"array_values",
"(",
"array_map",
"(",
"function",
"(",
"$",
"row",
")",
"{",
"return",
"$",
"row",
"[",
"'id_privilege'",
"]",
";",
"}",
",",
"$",
"acl",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"isAll",
"(",
"$",
"idRole",
")",
")",
"{",
"// idRole, ALL, ALL",
"$",
"result",
"[",
"'all'",
"]",
"=",
"true",
";",
"}",
"return",
"[",
"'idRole'",
"=>",
"$",
"idRole",
"]",
"+",
"$",
"result",
";",
"}"
] | Get acl form.
@param string $idRole
@return array | [
"Get",
"acl",
"form",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L228-L248 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.isAll | public function isAll(string $idRole, string $idResource = null): bool
{
$acl = $this->getAcl($idRole);
if ($idResource) {
$callback = function ($row) use ($idResource) {
if ($idResource) {
return $row['id_resource'] == $idResource;
}
return true;
};
$res = array_values(array_filter($acl, $callback));
if (isset($res[0])) {
return $res[0]['id_privilege'] == self::ALL;
}
}
$aclAll = array_values($acl);
if (isset($aclAll[0])) {
return $aclAll[0]['id_resource'] == self::ALL && $aclAll[0]['id_privilege'] == self::ALL;
}
return false;
} | php | public function isAll(string $idRole, string $idResource = null): bool
{
$acl = $this->getAcl($idRole);
if ($idResource) {
$callback = function ($row) use ($idResource) {
if ($idResource) {
return $row['id_resource'] == $idResource;
}
return true;
};
$res = array_values(array_filter($acl, $callback));
if (isset($res[0])) {
return $res[0]['id_privilege'] == self::ALL;
}
}
$aclAll = array_values($acl);
if (isset($aclAll[0])) {
return $aclAll[0]['id_resource'] == self::ALL && $aclAll[0]['id_privilege'] == self::ALL;
}
return false;
} | [
"public",
"function",
"isAll",
"(",
"string",
"$",
"idRole",
",",
"string",
"$",
"idResource",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"acl",
"=",
"$",
"this",
"->",
"getAcl",
"(",
"$",
"idRole",
")",
";",
"if",
"(",
"$",
"idResource",
")",
"{",
"$",
"callback",
"=",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"idResource",
")",
"{",
"if",
"(",
"$",
"idResource",
")",
"{",
"return",
"$",
"row",
"[",
"'id_resource'",
"]",
"==",
"$",
"idResource",
";",
"}",
"return",
"true",
";",
"}",
";",
"$",
"res",
"=",
"array_values",
"(",
"array_filter",
"(",
"$",
"acl",
",",
"$",
"callback",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"res",
"[",
"0",
"]",
")",
")",
"{",
"return",
"$",
"res",
"[",
"0",
"]",
"[",
"'id_privilege'",
"]",
"==",
"self",
"::",
"ALL",
";",
"}",
"}",
"$",
"aclAll",
"=",
"array_values",
"(",
"$",
"acl",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"aclAll",
"[",
"0",
"]",
")",
")",
"{",
"return",
"$",
"aclAll",
"[",
"0",
"]",
"[",
"'id_resource'",
"]",
"==",
"self",
"::",
"ALL",
"&&",
"$",
"aclAll",
"[",
"0",
"]",
"[",
"'id_privilege'",
"]",
"==",
"self",
"::",
"ALL",
";",
"}",
"return",
"false",
";",
"}"
] | Is all.
@param string $idRole
@param string|null $idResource
@return bool | [
"Is",
"all",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L258-L279 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.setAllowed | public function setAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL)
{
if ($this->policy == self::POLICY_ALLOW) {
$this->permission->allow($role, $resource, $privilege);
} else {
$this->permission->deny($role, $resource, $privilege);
}
} | php | public function setAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL)
{
if ($this->policy == self::POLICY_ALLOW) {
$this->permission->allow($role, $resource, $privilege);
} else {
$this->permission->deny($role, $resource, $privilege);
}
} | [
"public",
"function",
"setAllowed",
"(",
"$",
"role",
"=",
"self",
"::",
"ALL",
",",
"$",
"resource",
"=",
"self",
"::",
"ALL",
",",
"$",
"privilege",
"=",
"self",
"::",
"ALL",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"policy",
"==",
"self",
"::",
"POLICY_ALLOW",
")",
"{",
"$",
"this",
"->",
"permission",
"->",
"allow",
"(",
"$",
"role",
",",
"$",
"resource",
",",
"$",
"privilege",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"permission",
"->",
"deny",
"(",
"$",
"role",
",",
"$",
"resource",
",",
"$",
"privilege",
")",
";",
"}",
"}"
] | Set allowed.
@param $role
@param $resource
@param $privilege | [
"Set",
"allowed",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L300-L307 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.getPathListCurrentAcl | private function getPathListCurrentAcl(): string
{
return sprintf(self::PATH_LIST_CURRENT_ACL, $this->appDir, explode('\\', get_class($this))[3]);
} | php | private function getPathListCurrentAcl(): string
{
return sprintf(self::PATH_LIST_CURRENT_ACL, $this->appDir, explode('\\', get_class($this))[3]);
} | [
"private",
"function",
"getPathListCurrentAcl",
"(",
")",
":",
"string",
"{",
"return",
"sprintf",
"(",
"self",
"::",
"PATH_LIST_CURRENT_ACL",
",",
"$",
"this",
"->",
"appDir",
",",
"explode",
"(",
"'\\\\'",
",",
"get_class",
"(",
"$",
"this",
")",
")",
"[",
"3",
"]",
")",
";",
"}"
] | Get path list current acl.
@return string | [
"Get",
"path",
"list",
"current",
"acl",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L356-L359 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.saveListCurrentAcl | public function saveListCurrentAcl(): int
{
$separate = $last = $this->loadListCurrentAcl();
foreach ($this->listCurrentAcl as $item) {
if (!isset($separate[$item['resource']])) {
$separate[$item['resource']] = [];
}
if (!in_array($item['privilege'], $separate[$item['resource']])) {
$separate[$item['resource']][] = $item['privilege'];
}
}
// save only detect change
if ($separate != $last) {
return (int) file_put_contents($this->getPathListCurrentAcl(), Neon::encode($separate, Neon::BLOCK));
}
return 0;
} | php | public function saveListCurrentAcl(): int
{
$separate = $last = $this->loadListCurrentAcl();
foreach ($this->listCurrentAcl as $item) {
if (!isset($separate[$item['resource']])) {
$separate[$item['resource']] = [];
}
if (!in_array($item['privilege'], $separate[$item['resource']])) {
$separate[$item['resource']][] = $item['privilege'];
}
}
// save only detect change
if ($separate != $last) {
return (int) file_put_contents($this->getPathListCurrentAcl(), Neon::encode($separate, Neon::BLOCK));
}
return 0;
} | [
"public",
"function",
"saveListCurrentAcl",
"(",
")",
":",
"int",
"{",
"$",
"separate",
"=",
"$",
"last",
"=",
"$",
"this",
"->",
"loadListCurrentAcl",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"listCurrentAcl",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"separate",
"[",
"$",
"item",
"[",
"'resource'",
"]",
"]",
")",
")",
"{",
"$",
"separate",
"[",
"$",
"item",
"[",
"'resource'",
"]",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"item",
"[",
"'privilege'",
"]",
",",
"$",
"separate",
"[",
"$",
"item",
"[",
"'resource'",
"]",
"]",
")",
")",
"{",
"$",
"separate",
"[",
"$",
"item",
"[",
"'resource'",
"]",
"]",
"[",
"]",
"=",
"$",
"item",
"[",
"'privilege'",
"]",
";",
"}",
"}",
"// save only detect change",
"if",
"(",
"$",
"separate",
"!=",
"$",
"last",
")",
"{",
"return",
"(",
"int",
")",
"file_put_contents",
"(",
"$",
"this",
"->",
"getPathListCurrentAcl",
"(",
")",
",",
"Neon",
"::",
"encode",
"(",
"$",
"separate",
",",
"Neon",
"::",
"BLOCK",
")",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Save list current acl.
@return int | [
"Save",
"list",
"current",
"acl",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L367-L384 | train |
geniv/nette-identity-authorizator | src/Authorizator.php | Authorizator.loadListCurrentAcl | public function loadListCurrentAcl(): array
{
$path = $this->getPathListCurrentAcl();
if (file_exists($path)) {
return Neon::decode(file_get_contents($path));
}
return [];
} | php | public function loadListCurrentAcl(): array
{
$path = $this->getPathListCurrentAcl();
if (file_exists($path)) {
return Neon::decode(file_get_contents($path));
}
return [];
} | [
"public",
"function",
"loadListCurrentAcl",
"(",
")",
":",
"array",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getPathListCurrentAcl",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"Neon",
"::",
"decode",
"(",
"file_get_contents",
"(",
"$",
"path",
")",
")",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Load list current acl.
@return array | [
"Load",
"list",
"current",
"acl",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Authorizator.php#L392-L399 | train |
OliverMonneke/pennePHP | src/Datatype/Collection.php | Collection.merge | public static function merge($array1, $array2, $recursive = false)
{
if (!self::isValid($array1) ||
!self::isValid($array2)) {
return false;
}
if ($recursive) {
return array_merge_recursive($array1, $array2);
} else {
return array_merge($array1, $array2);
}
} | php | public static function merge($array1, $array2, $recursive = false)
{
if (!self::isValid($array1) ||
!self::isValid($array2)) {
return false;
}
if ($recursive) {
return array_merge_recursive($array1, $array2);
} else {
return array_merge($array1, $array2);
}
} | [
"public",
"static",
"function",
"merge",
"(",
"$",
"array1",
",",
"$",
"array2",
",",
"$",
"recursive",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isValid",
"(",
"$",
"array1",
")",
"||",
"!",
"self",
"::",
"isValid",
"(",
"$",
"array2",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"recursive",
")",
"{",
"return",
"array_merge_recursive",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
";",
"}",
"else",
"{",
"return",
"array_merge",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
";",
"}",
"}"
] | Merge 2 arrays
@param array $array1 First array
@param array $array2 Second array
@param bool $recursive Recursive
@return array | [
"Merge",
"2",
"arrays"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/Collection.php#L126-L138 | train |
OliverMonneke/pennePHP | src/Datatype/Collection.php | Collection.existsValue | public static function existsValue($array, $value)
{
if (!self::isValid($array)) {
return false;
}
$returnValue = false;
$length = self::length($array);
for ($i = 0; $i < $length; $i++) {
if ($value === $array[$i]) {
$returnValue = true;
break;
}
}
return $returnValue;
} | php | public static function existsValue($array, $value)
{
if (!self::isValid($array)) {
return false;
}
$returnValue = false;
$length = self::length($array);
for ($i = 0; $i < $length; $i++) {
if ($value === $array[$i]) {
$returnValue = true;
break;
}
}
return $returnValue;
} | [
"public",
"static",
"function",
"existsValue",
"(",
"$",
"array",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isValid",
"(",
"$",
"array",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"returnValue",
"=",
"false",
";",
"$",
"length",
"=",
"self",
"::",
"length",
"(",
"$",
"array",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"$",
"array",
"[",
"$",
"i",
"]",
")",
"{",
"$",
"returnValue",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"$",
"returnValue",
";",
"}"
] | Check if a value exists in an array
@param array $array The array
@param mixed $value The value to look for
@return bool | [
"Check",
"if",
"a",
"value",
"exists",
"in",
"an",
"array"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/Collection.php#L165-L182 | train |
OliverMonneke/pennePHP | src/Datatype/Collection.php | Collection.explode | public static function explode($string, $delimiter)
{
if (!String::isValid($string) ||
String::isEmpty($string)) {
return false;
}
return explode($delimiter, $string);
} | php | public static function explode($string, $delimiter)
{
if (!String::isValid($string) ||
String::isEmpty($string)) {
return false;
}
return explode($delimiter, $string);
} | [
"public",
"static",
"function",
"explode",
"(",
"$",
"string",
",",
"$",
"delimiter",
")",
"{",
"if",
"(",
"!",
"String",
"::",
"isValid",
"(",
"$",
"string",
")",
"||",
"String",
"::",
"isEmpty",
"(",
"$",
"string",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"explode",
"(",
"$",
"delimiter",
",",
"$",
"string",
")",
";",
"}"
] | Convert a string to an array
@param string $string The string
@param string $delimiter The delimiter
@return array | [
"Convert",
"a",
"string",
"to",
"an",
"array"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/Collection.php#L209-L217 | train |
Wedeto/Util | src/LoggerAwareStaticTrait.php | LoggerAwareStaticTrait.getLogger | public static function getLogger()
{
if (self::$logger === null)
{
try
{
$result = Hook::execute(
"Wedeto.Util.GetLogger",
["logger" => null, "class" => static::class]
);
}
catch (RecursionException $e)
{
// Apparently the hook is calling getLogger which is failing, so
// use an emergency logger to log anyway.
$result = ['logger' => new EmergencyLogger];
}
self::$logger = $result['logger'] ?? new NullLogger();
}
return self::$logger;
} | php | public static function getLogger()
{
if (self::$logger === null)
{
try
{
$result = Hook::execute(
"Wedeto.Util.GetLogger",
["logger" => null, "class" => static::class]
);
}
catch (RecursionException $e)
{
// Apparently the hook is calling getLogger which is failing, so
// use an emergency logger to log anyway.
$result = ['logger' => new EmergencyLogger];
}
self::$logger = $result['logger'] ?? new NullLogger();
}
return self::$logger;
} | [
"public",
"static",
"function",
"getLogger",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"logger",
"===",
"null",
")",
"{",
"try",
"{",
"$",
"result",
"=",
"Hook",
"::",
"execute",
"(",
"\"Wedeto.Util.GetLogger\"",
",",
"[",
"\"logger\"",
"=>",
"null",
",",
"\"class\"",
"=>",
"static",
"::",
"class",
"]",
")",
";",
"}",
"catch",
"(",
"RecursionException",
"$",
"e",
")",
"{",
"// Apparently the hook is calling getLogger which is failing, so",
"// use an emergency logger to log anyway.",
"$",
"result",
"=",
"[",
"'logger'",
"=>",
"new",
"EmergencyLogger",
"]",
";",
"}",
"self",
"::",
"$",
"logger",
"=",
"$",
"result",
"[",
"'logger'",
"]",
"??",
"new",
"NullLogger",
"(",
")",
";",
"}",
"return",
"self",
"::",
"$",
"logger",
";",
"}"
] | Get a logger. If not available yet, it will be created using a Hook, or
a NullLogger is instantiated. | [
"Get",
"a",
"logger",
".",
"If",
"not",
"available",
"yet",
"it",
"will",
"be",
"created",
"using",
"a",
"Hook",
"or",
"a",
"NullLogger",
"is",
"instantiated",
"."
] | 0e080251bbaa8e7d91ae8d02eb79c029c976744a | https://github.com/Wedeto/Util/blob/0e080251bbaa8e7d91ae8d02eb79c029c976744a/src/LoggerAwareStaticTrait.php#L67-L88 | train |
koolkode/http | src/Header/AbstractAcceptHeader.php | AbstractAcceptHeader.addValue | public function addValue($value, $q = 1.0)
{
$val = $this->parseValue($value);
$q = floatval($q);
if($q > 1)
{
$q = 1.0;
}
if($q < 0)
{
$q = 0.0;
}
// Ensure an existing element with the same value is removed.
foreach($this->values as $index => $tmp)
{
if($tmp[self::KEY_VAL] == $val)
{
array_splice($this->values, $index, 1);
break;
}
}
// Insert new value at position denoted by q value.
foreach($this->values as $index => $tmp)
{
if($tmp[self::KEY_Q] < $q)
{
array_splice($this->values, $index, 0, [[self::KEY_VAL => $val, self::KEY_Q => $q]]);
return;
}
}
// Append remainder
$this->values[] = [self::KEY_VAL => $val, self::KEY_Q => $q];
} | php | public function addValue($value, $q = 1.0)
{
$val = $this->parseValue($value);
$q = floatval($q);
if($q > 1)
{
$q = 1.0;
}
if($q < 0)
{
$q = 0.0;
}
// Ensure an existing element with the same value is removed.
foreach($this->values as $index => $tmp)
{
if($tmp[self::KEY_VAL] == $val)
{
array_splice($this->values, $index, 1);
break;
}
}
// Insert new value at position denoted by q value.
foreach($this->values as $index => $tmp)
{
if($tmp[self::KEY_Q] < $q)
{
array_splice($this->values, $index, 0, [[self::KEY_VAL => $val, self::KEY_Q => $q]]);
return;
}
}
// Append remainder
$this->values[] = [self::KEY_VAL => $val, self::KEY_Q => $q];
} | [
"public",
"function",
"addValue",
"(",
"$",
"value",
",",
"$",
"q",
"=",
"1.0",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"parseValue",
"(",
"$",
"value",
")",
";",
"$",
"q",
"=",
"floatval",
"(",
"$",
"q",
")",
";",
"if",
"(",
"$",
"q",
">",
"1",
")",
"{",
"$",
"q",
"=",
"1.0",
";",
"}",
"if",
"(",
"$",
"q",
"<",
"0",
")",
"{",
"$",
"q",
"=",
"0.0",
";",
"}",
"// Ensure an existing element with the same value is removed.\r",
"foreach",
"(",
"$",
"this",
"->",
"values",
"as",
"$",
"index",
"=>",
"$",
"tmp",
")",
"{",
"if",
"(",
"$",
"tmp",
"[",
"self",
"::",
"KEY_VAL",
"]",
"==",
"$",
"val",
")",
"{",
"array_splice",
"(",
"$",
"this",
"->",
"values",
",",
"$",
"index",
",",
"1",
")",
";",
"break",
";",
"}",
"}",
"// Insert new value at position denoted by q value.",
"foreach",
"(",
"$",
"this",
"->",
"values",
"as",
"$",
"index",
"=>",
"$",
"tmp",
")",
"{",
"if",
"(",
"$",
"tmp",
"[",
"self",
"::",
"KEY_Q",
"]",
"<",
"$",
"q",
")",
"{",
"array_splice",
"(",
"$",
"this",
"->",
"values",
",",
"$",
"index",
",",
"0",
",",
"[",
"[",
"self",
"::",
"KEY_VAL",
"=>",
"$",
"val",
",",
"self",
"::",
"KEY_Q",
"=>",
"$",
"q",
"]",
"]",
")",
";",
"return",
";",
"}",
"}",
"// Append remainder",
"$",
"this",
"->",
"values",
"[",
"]",
"=",
"[",
"self",
"::",
"KEY_VAL",
"=>",
"$",
"val",
",",
"self",
"::",
"KEY_Q",
"=>",
"$",
"q",
"]",
";",
"}"
] | Add a value to the header, uses a modified version of insertion sort.
@param mixed $value
@param float $q | [
"Add",
"a",
"value",
"to",
"the",
"header",
"uses",
"a",
"modified",
"version",
"of",
"insertion",
"sort",
"."
] | 3c1626d409d5ce5d71d26f0e8f31ae3683a2a966 | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/Header/AbstractAcceptHeader.php#L64-L103 | train |
prolic/HumusSupervisorModule | src/HumusSupervisorModule/SupervisorAbstractServiceFactory.php | SupervisorAbstractServiceFactory.getConfig | protected function getConfig(ServiceLocatorInterface $serviceLocator)
{
if ($this->config !== null) {
return $this->config;
}
/* @var $serviceLocator SupervisorManager */
$services = $serviceLocator->getServiceLocator();
if (!$services->has('Config')) {
$this->config = array();
return $this->config;
}
$config = $services->get('Config');
if (!isset($config[$this->configKey])
|| !is_array($config[$this->configKey])
) {
$this->config = array();
return $this->config;
}
$this->config = $config[$this->configKey];
return $this->config;
} | php | protected function getConfig(ServiceLocatorInterface $serviceLocator)
{
if ($this->config !== null) {
return $this->config;
}
/* @var $serviceLocator SupervisorManager */
$services = $serviceLocator->getServiceLocator();
if (!$services->has('Config')) {
$this->config = array();
return $this->config;
}
$config = $services->get('Config');
if (!isset($config[$this->configKey])
|| !is_array($config[$this->configKey])
) {
$this->config = array();
return $this->config;
}
$this->config = $config[$this->configKey];
return $this->config;
} | [
"protected",
"function",
"getConfig",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"config",
";",
"}",
"/* @var $serviceLocator SupervisorManager */",
"$",
"services",
"=",
"$",
"serviceLocator",
"->",
"getServiceLocator",
"(",
")",
";",
"if",
"(",
"!",
"$",
"services",
"->",
"has",
"(",
"'Config'",
")",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"array",
"(",
")",
";",
"return",
"$",
"this",
"->",
"config",
";",
"}",
"$",
"config",
"=",
"$",
"services",
"->",
"get",
"(",
"'Config'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"$",
"this",
"->",
"configKey",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"config",
"[",
"$",
"this",
"->",
"configKey",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"=",
"array",
"(",
")",
";",
"return",
"$",
"this",
"->",
"config",
";",
"}",
"$",
"this",
"->",
"config",
"=",
"$",
"config",
"[",
"$",
"this",
"->",
"configKey",
"]",
";",
"return",
"$",
"this",
"->",
"config",
";",
"}"
] | Get amqp configuration, if any
@param ServiceLocatorInterface $serviceLocator
@return array | [
"Get",
"amqp",
"configuration",
"if",
"any"
] | b71a7508d9737dbda1ad3b0a1374ed70b77070bd | https://github.com/prolic/HumusSupervisorModule/blob/b71a7508d9737dbda1ad3b0a1374ed70b77070bd/src/HumusSupervisorModule/SupervisorAbstractServiceFactory.php#L102-L126 | train |
zodream/database | src/Schema/Table.php | Table.setAI | public function setAI($arg) {
$this->aiBegin = max($this->aiBegin, intval($arg));
return $this;
} | php | public function setAI($arg) {
$this->aiBegin = max($this->aiBegin, intval($arg));
return $this;
} | [
"public",
"function",
"setAI",
"(",
"$",
"arg",
")",
"{",
"$",
"this",
"->",
"aiBegin",
"=",
"max",
"(",
"$",
"this",
"->",
"aiBegin",
",",
"intval",
"(",
"$",
"arg",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | SET AUTO_INCREMENT BEGIN
@param string $arg
@return $this | [
"SET",
"AUTO_INCREMENT",
"BEGIN"
] | 03712219c057799d07350a3a2650c55bcc92c28e | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Schema/Table.php#L157-L160 | train |
zodream/database | src/Schema/Table.php | Table.fk | public function fk($name, $field, $table, $fkField, $delete = 'NO ACTION', $update = 'NO ACTION') {
$this->foreignKey[$name] = [$field, $table, $fkField, $delete, $update];
return $this;
} | php | public function fk($name, $field, $table, $fkField, $delete = 'NO ACTION', $update = 'NO ACTION') {
$this->foreignKey[$name] = [$field, $table, $fkField, $delete, $update];
return $this;
} | [
"public",
"function",
"fk",
"(",
"$",
"name",
",",
"$",
"field",
",",
"$",
"table",
",",
"$",
"fkField",
",",
"$",
"delete",
"=",
"'NO ACTION'",
",",
"$",
"update",
"=",
"'NO ACTION'",
")",
"{",
"$",
"this",
"->",
"foreignKey",
"[",
"$",
"name",
"]",
"=",
"[",
"$",
"field",
",",
"$",
"table",
",",
"$",
"fkField",
",",
"$",
"delete",
",",
"$",
"update",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | SET FOREIGN KEY
@param string $name
@param string $field
@param string $table
@param string $fkField
@param string $delete
@param string $update
@return $this | [
"SET",
"FOREIGN",
"KEY"
] | 03712219c057799d07350a3a2650c55bcc92c28e | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Schema/Table.php#L172-L175 | train |
zodream/database | src/Schema/Table.php | Table.getAlertSql | public function getAlertSql() {
$sql = [];
foreach ($this->_data as $item) {
$sql[] = $item->getAlterSql();
}
return sprintf('ALTER TABLE %s %s;',
$this->getTable(),
implode(',', $sql));
} | php | public function getAlertSql() {
$sql = [];
foreach ($this->_data as $item) {
$sql[] = $item->getAlterSql();
}
return sprintf('ALTER TABLE %s %s;',
$this->getTable(),
implode(',', $sql));
} | [
"public",
"function",
"getAlertSql",
"(",
")",
"{",
"$",
"sql",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_data",
"as",
"$",
"item",
")",
"{",
"$",
"sql",
"[",
"]",
"=",
"$",
"item",
"->",
"getAlterSql",
"(",
")",
";",
"}",
"return",
"sprintf",
"(",
"'ALTER TABLE %s %s;'",
",",
"$",
"this",
"->",
"getTable",
"(",
")",
",",
"implode",
"(",
"','",
",",
"$",
"sql",
")",
")",
";",
"}"
] | GET ALERT TABLE SQL
@return string | [
"GET",
"ALERT",
"TABLE",
"SQL"
] | 03712219c057799d07350a3a2650c55bcc92c28e | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Schema/Table.php#L454-L462 | train |
zodream/database | src/Schema/Table.php | Table.getSql | public function getSql() {
$sql = "CREATE TABLE IF NOT EXISTS {$this->getTable()} (";
$column = $this->_data;
if (!empty($this->primaryKey)) {
$column[] = "PRIMARY KEY (`{$this->primaryKey}`)";
}
foreach ($this->checks as $key => $item) {
$column[] = (!is_integer($key) ? "CONSTRAINT `{$key}` " : null)." CHECK ({$item})";
}
foreach ($this->index as $key => $item) {
$column[] = (count($item) > 2 ? 'UNIQUE ': null). "INDEX `{$key}` (`{$item[0]}` {$item['1']})";
}
foreach ($this->foreignKey as $key => $item) {
$column[] = "CONSTRAINT `{$key}` FOREIGN KEY (`{$item[0]}`) REFERENCES `{$item[1]}` (`{$item[2]}`) ON DELETE {$item[2]} ON UPDATE {$item[3]}";
}
$sql .= implode(',', $column).") ENGINE={$this->engine}";
if ($this->aiBegin > 1) {
$sql .= ' AUTO_INCREMENT='.$this->aiBegin;
}
return $sql." DEFAULT CHARSET={$this->charset} COMMENT='{$this->comment}';";
} | php | public function getSql() {
$sql = "CREATE TABLE IF NOT EXISTS {$this->getTable()} (";
$column = $this->_data;
if (!empty($this->primaryKey)) {
$column[] = "PRIMARY KEY (`{$this->primaryKey}`)";
}
foreach ($this->checks as $key => $item) {
$column[] = (!is_integer($key) ? "CONSTRAINT `{$key}` " : null)." CHECK ({$item})";
}
foreach ($this->index as $key => $item) {
$column[] = (count($item) > 2 ? 'UNIQUE ': null). "INDEX `{$key}` (`{$item[0]}` {$item['1']})";
}
foreach ($this->foreignKey as $key => $item) {
$column[] = "CONSTRAINT `{$key}` FOREIGN KEY (`{$item[0]}`) REFERENCES `{$item[1]}` (`{$item[2]}`) ON DELETE {$item[2]} ON UPDATE {$item[3]}";
}
$sql .= implode(',', $column).") ENGINE={$this->engine}";
if ($this->aiBegin > 1) {
$sql .= ' AUTO_INCREMENT='.$this->aiBegin;
}
return $sql." DEFAULT CHARSET={$this->charset} COMMENT='{$this->comment}';";
} | [
"public",
"function",
"getSql",
"(",
")",
"{",
"$",
"sql",
"=",
"\"CREATE TABLE IF NOT EXISTS {$this->getTable()} (\"",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"_data",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"primaryKey",
")",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"\"PRIMARY KEY (`{$this->primaryKey}`)\"",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"checks",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"(",
"!",
"is_integer",
"(",
"$",
"key",
")",
"?",
"\"CONSTRAINT `{$key}` \"",
":",
"null",
")",
".",
"\" CHECK ({$item})\"",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"index",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"(",
"count",
"(",
"$",
"item",
")",
">",
"2",
"?",
"'UNIQUE '",
":",
"null",
")",
".",
"\"INDEX `{$key}` (`{$item[0]}` {$item['1']})\"",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"foreignKey",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"column",
"[",
"]",
"=",
"\"CONSTRAINT `{$key}` FOREIGN KEY (`{$item[0]}`) REFERENCES `{$item[1]}` (`{$item[2]}`) ON DELETE {$item[2]} ON UPDATE {$item[3]}\"",
";",
"}",
"$",
"sql",
".=",
"implode",
"(",
"','",
",",
"$",
"column",
")",
".",
"\") ENGINE={$this->engine}\"",
";",
"if",
"(",
"$",
"this",
"->",
"aiBegin",
">",
"1",
")",
"{",
"$",
"sql",
".=",
"' AUTO_INCREMENT='",
".",
"$",
"this",
"->",
"aiBegin",
";",
"}",
"return",
"$",
"sql",
".",
"\" DEFAULT CHARSET={$this->charset} COMMENT='{$this->comment}';\"",
";",
"}"
] | GET CREATE TABLE SQL
@return string | [
"GET",
"CREATE",
"TABLE",
"SQL"
] | 03712219c057799d07350a3a2650c55bcc92c28e | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Schema/Table.php#L494-L514 | train |
nochso/ORM2 | src/Relation.php | Relation.getForeignKey | public function getForeignKey()
{
if ($this->foreignKey !== null) {
return $this->foreignKey;
}
$this->init();
switch ($this->type) {
case self::HAS_MANY:
case self::HAS_ONE:
return $this->owner->getTableName() . '_' . $this->owner->getPrimaryKey();
case self::BELONGS_TO:
return $this->foreign->getPrimaryKey();
default:
throw new \Exception(sprintf("Relation type '%s' is not supported.", $this->type));
}
} | php | public function getForeignKey()
{
if ($this->foreignKey !== null) {
return $this->foreignKey;
}
$this->init();
switch ($this->type) {
case self::HAS_MANY:
case self::HAS_ONE:
return $this->owner->getTableName() . '_' . $this->owner->getPrimaryKey();
case self::BELONGS_TO:
return $this->foreign->getPrimaryKey();
default:
throw new \Exception(sprintf("Relation type '%s' is not supported.", $this->type));
}
} | [
"public",
"function",
"getForeignKey",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"foreignKey",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"foreignKey",
";",
"}",
"$",
"this",
"->",
"init",
"(",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"type",
")",
"{",
"case",
"self",
"::",
"HAS_MANY",
":",
"case",
"self",
"::",
"HAS_ONE",
":",
"return",
"$",
"this",
"->",
"owner",
"->",
"getTableName",
"(",
")",
".",
"'_'",
".",
"$",
"this",
"->",
"owner",
"->",
"getPrimaryKey",
"(",
")",
";",
"case",
"self",
"::",
"BELONGS_TO",
":",
"return",
"$",
"this",
"->",
"foreign",
"->",
"getPrimaryKey",
"(",
")",
";",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"\"Relation type '%s' is not supported.\"",
",",
"$",
"this",
"->",
"type",
")",
")",
";",
"}",
"}"
] | Returns the name of the column that will be filtered on
@return string
@throws \Exception | [
"Returns",
"the",
"name",
"of",
"the",
"column",
"that",
"will",
"be",
"filtered",
"on"
] | 89f9a5c61ad5f575fbdd52990171b52d54f8bfbc | https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/Relation.php#L69-L84 | train |
eureka-framework/component-response | src/Response/Factory.php | Factory.create | public static function create($format = self::FORMAT_JSON, $engine = self::ENGINE_API)
{
$response = '\Eureka\Component\Response';
switch ($format) {
//~ Json
case self::FORMAT_JSON:
$responseFormat = '\Json';
break;
//~ Html
case self::FORMAT_HTML:
$responseFormat = '\Html';
break;
//~ Other
case self::FORMAT_XML:
case self::FORMAT_TEXT:
default:
throw new \DomainException('Unsupported output format !');
}
switch ($engine) {
//~ Api Engine
case self::ENGINE_API:
$response .= $responseFormat . '\Api';
break;
//~ Layout Engine
case self::ENGINE_TEMPLATE:
$response .= $responseFormat . '\Template';
break;
//~ None
case self::ENGINE_NONE:
$response .= $responseFormat . $responseFormat;
//~ Do not add engine name to the class name.
break;
//~ Other
default:
throw new \DomainException('Unsupported output engine !');
}
$responseInstance = new $response();
return $responseInstance;
} | php | public static function create($format = self::FORMAT_JSON, $engine = self::ENGINE_API)
{
$response = '\Eureka\Component\Response';
switch ($format) {
//~ Json
case self::FORMAT_JSON:
$responseFormat = '\Json';
break;
//~ Html
case self::FORMAT_HTML:
$responseFormat = '\Html';
break;
//~ Other
case self::FORMAT_XML:
case self::FORMAT_TEXT:
default:
throw new \DomainException('Unsupported output format !');
}
switch ($engine) {
//~ Api Engine
case self::ENGINE_API:
$response .= $responseFormat . '\Api';
break;
//~ Layout Engine
case self::ENGINE_TEMPLATE:
$response .= $responseFormat . '\Template';
break;
//~ None
case self::ENGINE_NONE:
$response .= $responseFormat . $responseFormat;
//~ Do not add engine name to the class name.
break;
//~ Other
default:
throw new \DomainException('Unsupported output engine !');
}
$responseInstance = new $response();
return $responseInstance;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"format",
"=",
"self",
"::",
"FORMAT_JSON",
",",
"$",
"engine",
"=",
"self",
"::",
"ENGINE_API",
")",
"{",
"$",
"response",
"=",
"'\\Eureka\\Component\\Response'",
";",
"switch",
"(",
"$",
"format",
")",
"{",
"//~ Json",
"case",
"self",
"::",
"FORMAT_JSON",
":",
"$",
"responseFormat",
"=",
"'\\Json'",
";",
"break",
";",
"//~ Html",
"case",
"self",
"::",
"FORMAT_HTML",
":",
"$",
"responseFormat",
"=",
"'\\Html'",
";",
"break",
";",
"//~ Other",
"case",
"self",
"::",
"FORMAT_XML",
":",
"case",
"self",
"::",
"FORMAT_TEXT",
":",
"default",
":",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Unsupported output format !'",
")",
";",
"}",
"switch",
"(",
"$",
"engine",
")",
"{",
"//~ Api Engine",
"case",
"self",
"::",
"ENGINE_API",
":",
"$",
"response",
".=",
"$",
"responseFormat",
".",
"'\\Api'",
";",
"break",
";",
"//~ Layout Engine",
"case",
"self",
"::",
"ENGINE_TEMPLATE",
":",
"$",
"response",
".=",
"$",
"responseFormat",
".",
"'\\Template'",
";",
"break",
";",
"//~ None",
"case",
"self",
"::",
"ENGINE_NONE",
":",
"$",
"response",
".=",
"$",
"responseFormat",
".",
"$",
"responseFormat",
";",
"//~ Do not add engine name to the class name.",
"break",
";",
"//~ Other",
"default",
":",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Unsupported output engine !'",
")",
";",
"}",
"$",
"responseInstance",
"=",
"new",
"$",
"response",
"(",
")",
";",
"return",
"$",
"responseInstance",
";",
"}"
] | Create response object.
@param string $format
@param string $engine
@return Response
@throws \DomainException | [
"Create",
"response",
"object",
"."
] | f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a | https://github.com/eureka-framework/component-response/blob/f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a/src/Response/Factory.php#L62-L104 | train |
CDyWeb/http-adapter | src/cdyweb/http/psr/Uri.php | Uri.filterPath | private function filterPath($path)
{
if ($path != null && substr($path, 0, 1) !== '/') {
$path = '/' . $path;
}
return preg_replace_callback(
'/(?:[^' . self::$charUnreserved . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
function ($match) { return rawurlencode($match[0]); },
$path
);
} | php | private function filterPath($path)
{
if ($path != null && substr($path, 0, 1) !== '/') {
$path = '/' . $path;
}
return preg_replace_callback(
'/(?:[^' . self::$charUnreserved . ':@&=\+\$,\/;%]+|%(?![A-Fa-f0-9]{2}))/',
function ($match) { return rawurlencode($match[0]); },
$path
);
} | [
"private",
"function",
"filterPath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"path",
"!=",
"null",
"&&",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"path",
"=",
"'/'",
".",
"$",
"path",
";",
"}",
"return",
"preg_replace_callback",
"(",
"'/(?:[^'",
".",
"self",
"::",
"$",
"charUnreserved",
".",
"':@&=\\+\\$,\\/;%]+|%(?![A-Fa-f0-9]{2}))/'",
",",
"function",
"(",
"$",
"match",
")",
"{",
"return",
"rawurlencode",
"(",
"$",
"match",
"[",
"0",
"]",
")",
";",
"}",
",",
"$",
"path",
")",
";",
"}"
] | Filters the path of a URI
@param $path
@return string | [
"Filters",
"the",
"path",
"of",
"a",
"URI"
] | 882e2fb8429dd6d55e0a2aba1cca5a8c2b4a47d7 | https://github.com/CDyWeb/http-adapter/blob/882e2fb8429dd6d55e0a2aba1cca5a8c2b4a47d7/src/cdyweb/http/psr/Uri.php#L574-L585 | train |
translationexchange/tml-php-clientsdk | library/Tr8n/RulesEngine/Evaluator.php | Evaluator.reset | function reset() {
foreach ($this->vars as $key=>$val) {
unset($this->env[$key]);
}
$this->vars = array();
} | php | function reset() {
foreach ($this->vars as $key=>$val) {
unset($this->env[$key]);
}
$this->vars = array();
} | [
"function",
"reset",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"vars",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"env",
"[",
"$",
"key",
"]",
")",
";",
"}",
"$",
"this",
"->",
"vars",
"=",
"array",
"(",
")",
";",
"}"
] | Resets evaluator's variables | [
"Resets",
"evaluator",
"s",
"variables"
] | fe51473824e62cfd883c6aa0c6a3783a16ce8425 | https://github.com/translationexchange/tml-php-clientsdk/blob/fe51473824e62cfd883c6aa0c6a3783a16ce8425/library/Tr8n/RulesEngine/Evaluator.php#L173-L178 | train |
kherge-abandoned/lib-psr4 | src/lib/Phine/PSR4/Loader.php | Loader.map | public function map($prefix, $paths)
{
$prefix = ltrim($prefix, '\\');
$paths = (array) $paths;
if (!isset($this->map[$prefix])) {
$this->map[$prefix] = array();
}
foreach ($paths as $path) {
$this->map[$prefix][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
}
return $this;
} | php | public function map($prefix, $paths)
{
$prefix = ltrim($prefix, '\\');
$paths = (array) $paths;
if (!isset($this->map[$prefix])) {
$this->map[$prefix] = array();
}
foreach ($paths as $path) {
$this->map[$prefix][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
}
return $this;
} | [
"public",
"function",
"map",
"(",
"$",
"prefix",
",",
"$",
"paths",
")",
"{",
"$",
"prefix",
"=",
"ltrim",
"(",
"$",
"prefix",
",",
"'\\\\'",
")",
";",
"$",
"paths",
"=",
"(",
"array",
")",
"$",
"paths",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"map",
"[",
"$",
"prefix",
"]",
")",
")",
"{",
"$",
"this",
"->",
"map",
"[",
"$",
"prefix",
"]",
"=",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"map",
"[",
"$",
"prefix",
"]",
"[",
"]",
"=",
"rtrim",
"(",
"$",
"path",
",",
"'\\\\/'",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Maps a namespace prefix to one or more base directory paths.
This method is used to map a single namespace to one or more directory
paths. The `$paths` argument may be a single directory path (string),
or an array of directory paths.
$loader->map('Example\\Prefix', '/single/dir/path');
$loader->map(
'Example\\Prefix',
array(
'/one/directory/path',
'/another/directory/path',
)
);
You may also chain calls to this method together:
$psr4->map(...)->map(...);
@param string $prefix The namespace prefix.
@param array|string $paths The base directory path(s).
@return Loader The instance of this class.
@api | [
"Maps",
"a",
"namespace",
"prefix",
"to",
"one",
"or",
"more",
"base",
"directory",
"paths",
"."
] | 460b7089204fd09051fba13b2c4bfc6caba080e5 | https://github.com/kherge-abandoned/lib-psr4/blob/460b7089204fd09051fba13b2c4bfc6caba080e5/src/lib/Phine/PSR4/Loader.php#L113-L127 | train |
kherge-abandoned/lib-psr4 | src/lib/Phine/PSR4/Loader.php | Loader.getPath | protected function getPath($class)
{
foreach ($this->map as $prefix => $paths) {
if (0 !== strpos($class, $prefix)) {
continue;
}
foreach ($paths as $path) {
$relative = ltrim(substr($class, strlen($prefix)), '\\');
$relative = preg_replace('/\\\\+/', DIRECTORY_SEPARATOR, $relative);
$relative .= '.php';
if (file_exists($path . $relative)) {
return $path . $relative;
}
}
}
return null;
} | php | protected function getPath($class)
{
foreach ($this->map as $prefix => $paths) {
if (0 !== strpos($class, $prefix)) {
continue;
}
foreach ($paths as $path) {
$relative = ltrim(substr($class, strlen($prefix)), '\\');
$relative = preg_replace('/\\\\+/', DIRECTORY_SEPARATOR, $relative);
$relative .= '.php';
if (file_exists($path . $relative)) {
return $path . $relative;
}
}
}
return null;
} | [
"protected",
"function",
"getPath",
"(",
"$",
"class",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"map",
"as",
"$",
"prefix",
"=>",
"$",
"paths",
")",
"{",
"if",
"(",
"0",
"!==",
"strpos",
"(",
"$",
"class",
",",
"$",
"prefix",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"$",
"relative",
"=",
"ltrim",
"(",
"substr",
"(",
"$",
"class",
",",
"strlen",
"(",
"$",
"prefix",
")",
")",
",",
"'\\\\'",
")",
";",
"$",
"relative",
"=",
"preg_replace",
"(",
"'/\\\\\\\\+/'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"relative",
")",
";",
"$",
"relative",
".=",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
".",
"$",
"relative",
")",
")",
"{",
"return",
"$",
"path",
".",
"$",
"relative",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns the file path for the class name.
This method will loop through the mapped namespace prefixes to find a
directory that contains the class. If the file for the class is found,
it will be returned. Otherwise, nothing (`null`) is returned.
@param string $class The name of the class.
@return string The file path, if any.
@api | [
"Returns",
"the",
"file",
"path",
"for",
"the",
"class",
"name",
"."
] | 460b7089204fd09051fba13b2c4bfc6caba080e5 | https://github.com/kherge-abandoned/lib-psr4/blob/460b7089204fd09051fba13b2c4bfc6caba080e5/src/lib/Phine/PSR4/Loader.php#L162-L181 | train |
Sectorr/Core | Sectorr/Core/Input/Validator.php | Validator.passes | public function passes($input, $rules)
{
foreach ($rules as $field => $rule) {
$this->callValidator($input[$field], $field, $rule);
}
return ! $this->failed;
} | php | public function passes($input, $rules)
{
foreach ($rules as $field => $rule) {
$this->callValidator($input[$field], $field, $rule);
}
return ! $this->failed;
} | [
"public",
"function",
"passes",
"(",
"$",
"input",
",",
"$",
"rules",
")",
"{",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"field",
"=>",
"$",
"rule",
")",
"{",
"$",
"this",
"->",
"callValidator",
"(",
"$",
"input",
"[",
"$",
"field",
"]",
",",
"$",
"field",
",",
"$",
"rule",
")",
";",
"}",
"return",
"!",
"$",
"this",
"->",
"failed",
";",
"}"
] | Loops through the rules and checks the current input.
@param $input
@param $rules
@return bool | [
"Loops",
"through",
"the",
"rules",
"and",
"checks",
"the",
"current",
"input",
"."
] | 31df852dc6cc61642b0b87d9f0ae56c8e7da5a27 | https://github.com/Sectorr/Core/blob/31df852dc6cc61642b0b87d9f0ae56c8e7da5a27/Sectorr/Core/Input/Validator.php#L28-L34 | train |
Sectorr/Core | Sectorr/Core/Input/Validator.php | Validator.unique | protected function unique($input, $table, $column)
{
$email = $this->db->get($table, $column, [
$column => $input
]);
if ($email) {
var_dump("error: {$column} not unique");
$this->failed = true;
}
} | php | protected function unique($input, $table, $column)
{
$email = $this->db->get($table, $column, [
$column => $input
]);
if ($email) {
var_dump("error: {$column} not unique");
$this->failed = true;
}
} | [
"protected",
"function",
"unique",
"(",
"$",
"input",
",",
"$",
"table",
",",
"$",
"column",
")",
"{",
"$",
"email",
"=",
"$",
"this",
"->",
"db",
"->",
"get",
"(",
"$",
"table",
",",
"$",
"column",
",",
"[",
"$",
"column",
"=>",
"$",
"input",
"]",
")",
";",
"if",
"(",
"$",
"email",
")",
"{",
"var_dump",
"(",
"\"error: {$column} not unique\"",
")",
";",
"$",
"this",
"->",
"failed",
"=",
"true",
";",
"}",
"}"
] | Check if the given input is unique in the given database table and column.
@param $input
@param $table
@param $column | [
"Check",
"if",
"the",
"given",
"input",
"is",
"unique",
"in",
"the",
"given",
"database",
"table",
"and",
"column",
"."
] | 31df852dc6cc61642b0b87d9f0ae56c8e7da5a27 | https://github.com/Sectorr/Core/blob/31df852dc6cc61642b0b87d9f0ae56c8e7da5a27/Sectorr/Core/Input/Validator.php#L84-L93 | train |
Sectorr/Core | Sectorr/Core/Input/Validator.php | Validator.multiple | protected function multiple($value)
{
$arguments = explode(':', $value);
if (count($arguments) > 1) {
$rule = $arguments[0];
unset($arguments[0]);
return ['multiple' => true, 'rule' => $rule, 'arguments' => array_values($arguments)];
}
return ['multiple' => false];
} | php | protected function multiple($value)
{
$arguments = explode(':', $value);
if (count($arguments) > 1) {
$rule = $arguments[0];
unset($arguments[0]);
return ['multiple' => true, 'rule' => $rule, 'arguments' => array_values($arguments)];
}
return ['multiple' => false];
} | [
"protected",
"function",
"multiple",
"(",
"$",
"value",
")",
"{",
"$",
"arguments",
"=",
"explode",
"(",
"':'",
",",
"$",
"value",
")",
";",
"if",
"(",
"count",
"(",
"$",
"arguments",
")",
">",
"1",
")",
"{",
"$",
"rule",
"=",
"$",
"arguments",
"[",
"0",
"]",
";",
"unset",
"(",
"$",
"arguments",
"[",
"0",
"]",
")",
";",
"return",
"[",
"'multiple'",
"=>",
"true",
",",
"'rule'",
"=>",
"$",
"rule",
",",
"'arguments'",
"=>",
"array_values",
"(",
"$",
"arguments",
")",
"]",
";",
"}",
"return",
"[",
"'multiple'",
"=>",
"false",
"]",
";",
"}"
] | Retrieves multiple arguments from argument string.
@param $arg
@return array|bool | [
"Retrieves",
"multiple",
"arguments",
"from",
"argument",
"string",
"."
] | 31df852dc6cc61642b0b87d9f0ae56c8e7da5a27 | https://github.com/Sectorr/Core/blob/31df852dc6cc61642b0b87d9f0ae56c8e7da5a27/Sectorr/Core/Input/Validator.php#L101-L113 | train |
Sectorr/Core | Sectorr/Core/Input/Validator.php | Validator.callValidator | protected function callValidator($input, $field, $arguments)
{
$arguments = explode('|', $arguments);
foreach ($arguments as $arg) {
if ($this->multiple($arg)['multiple']) {
switch ($this->multiple($arg)['rule']) {
case 'unique':
$table = $this->multiple($arg)['arguments'][0];
$column = $this->multiple($arg)['arguments'][1];
$this->unique($input, $table, $column);
break;
}
} else {
switch ($arg) {
case 'required':
$this->required($field, $input);
break;
case 'email':
$this->email($input);
break;
case 'password':
$this->password($input);
break;
}
}
}
} | php | protected function callValidator($input, $field, $arguments)
{
$arguments = explode('|', $arguments);
foreach ($arguments as $arg) {
if ($this->multiple($arg)['multiple']) {
switch ($this->multiple($arg)['rule']) {
case 'unique':
$table = $this->multiple($arg)['arguments'][0];
$column = $this->multiple($arg)['arguments'][1];
$this->unique($input, $table, $column);
break;
}
} else {
switch ($arg) {
case 'required':
$this->required($field, $input);
break;
case 'email':
$this->email($input);
break;
case 'password':
$this->password($input);
break;
}
}
}
} | [
"protected",
"function",
"callValidator",
"(",
"$",
"input",
",",
"$",
"field",
",",
"$",
"arguments",
")",
"{",
"$",
"arguments",
"=",
"explode",
"(",
"'|'",
",",
"$",
"arguments",
")",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"multiple",
"(",
"$",
"arg",
")",
"[",
"'multiple'",
"]",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"multiple",
"(",
"$",
"arg",
")",
"[",
"'rule'",
"]",
")",
"{",
"case",
"'unique'",
":",
"$",
"table",
"=",
"$",
"this",
"->",
"multiple",
"(",
"$",
"arg",
")",
"[",
"'arguments'",
"]",
"[",
"0",
"]",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"multiple",
"(",
"$",
"arg",
")",
"[",
"'arguments'",
"]",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"unique",
"(",
"$",
"input",
",",
"$",
"table",
",",
"$",
"column",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"switch",
"(",
"$",
"arg",
")",
"{",
"case",
"'required'",
":",
"$",
"this",
"->",
"required",
"(",
"$",
"field",
",",
"$",
"input",
")",
";",
"break",
";",
"case",
"'email'",
":",
"$",
"this",
"->",
"email",
"(",
"$",
"input",
")",
";",
"break",
";",
"case",
"'password'",
":",
"$",
"this",
"->",
"password",
"(",
"$",
"input",
")",
";",
"break",
";",
"}",
"}",
"}",
"}"
] | Loops through all arguments and checks what methods need to be called.
@param $input
@param $field
@param $arguments | [
"Loops",
"through",
"all",
"arguments",
"and",
"checks",
"what",
"methods",
"need",
"to",
"be",
"called",
"."
] | 31df852dc6cc61642b0b87d9f0ae56c8e7da5a27 | https://github.com/Sectorr/Core/blob/31df852dc6cc61642b0b87d9f0ae56c8e7da5a27/Sectorr/Core/Input/Validator.php#L122-L149 | train |
PenoaksDev/Milky-Framework | src/Milky/Validation/DatabasePresenceVerifier.php | DatabasePresenceVerifier.table | protected function table( $table )
{
return $this->db->connection( $this->connection )->table( $table )->useWritePdo();
} | php | protected function table( $table )
{
return $this->db->connection( $this->connection )->table( $table )->useWritePdo();
} | [
"protected",
"function",
"table",
"(",
"$",
"table",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"connection",
"(",
"$",
"this",
"->",
"connection",
")",
"->",
"table",
"(",
"$",
"table",
")",
"->",
"useWritePdo",
"(",
")",
";",
"}"
] | Get a query builder for the given table.
@param string $table
@return Builder | [
"Get",
"a",
"query",
"builder",
"for",
"the",
"given",
"table",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Validation/DatabasePresenceVerifier.php#L117-L120 | train |
ekyna/Resource | Serializer/AbstractTranslatableNormalizer.php | AbstractTranslatableNormalizer.normalizeTranslations | protected function normalizeTranslations(Model\TranslatableInterface $translatable, $format, array $context = [])
{
$data = [];
$groups = isset($context['groups']) ? (array)$context['groups'] : [];
/*if (in_array('Default', $groups)) {
if ($translatable instanceof Model\TranslatableInterface) {
$data['translations'] = array_map(function (Model\TranslationInterface $t) use ($format, $context) {
return $t->getId();
}, $translatable->getTranslations()->toArray());
}
}*/
if (in_array('Search', $groups)) {
if ($translatable instanceof Model\TranslatableInterface) {
$data['translations'] = array_map(function (Model\TranslationInterface $t) use ($format, $context) {
return $this->normalizeObject($t, $format, $context);
}, $translatable->getTranslations()->toArray());
}
}
return $data;
} | php | protected function normalizeTranslations(Model\TranslatableInterface $translatable, $format, array $context = [])
{
$data = [];
$groups = isset($context['groups']) ? (array)$context['groups'] : [];
/*if (in_array('Default', $groups)) {
if ($translatable instanceof Model\TranslatableInterface) {
$data['translations'] = array_map(function (Model\TranslationInterface $t) use ($format, $context) {
return $t->getId();
}, $translatable->getTranslations()->toArray());
}
}*/
if (in_array('Search', $groups)) {
if ($translatable instanceof Model\TranslatableInterface) {
$data['translations'] = array_map(function (Model\TranslationInterface $t) use ($format, $context) {
return $this->normalizeObject($t, $format, $context);
}, $translatable->getTranslations()->toArray());
}
}
return $data;
} | [
"protected",
"function",
"normalizeTranslations",
"(",
"Model",
"\\",
"TranslatableInterface",
"$",
"translatable",
",",
"$",
"format",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"groups",
"=",
"isset",
"(",
"$",
"context",
"[",
"'groups'",
"]",
")",
"?",
"(",
"array",
")",
"$",
"context",
"[",
"'groups'",
"]",
":",
"[",
"]",
";",
"/*if (in_array('Default', $groups)) {\n if ($translatable instanceof Model\\TranslatableInterface) {\n $data['translations'] = array_map(function (Model\\TranslationInterface $t) use ($format, $context) {\n return $t->getId();\n }, $translatable->getTranslations()->toArray());\n }\n }*/",
"if",
"(",
"in_array",
"(",
"'Search'",
",",
"$",
"groups",
")",
")",
"{",
"if",
"(",
"$",
"translatable",
"instanceof",
"Model",
"\\",
"TranslatableInterface",
")",
"{",
"$",
"data",
"[",
"'translations'",
"]",
"=",
"array_map",
"(",
"function",
"(",
"Model",
"\\",
"TranslationInterface",
"$",
"t",
")",
"use",
"(",
"$",
"format",
",",
"$",
"context",
")",
"{",
"return",
"$",
"this",
"->",
"normalizeObject",
"(",
"$",
"t",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
",",
"$",
"translatable",
"->",
"getTranslations",
"(",
")",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Normalizes the translatable's translations.
@param Model\TranslatableInterface $translatable
@param string $format
@param array $context
@return array | [
"Normalizes",
"the",
"translatable",
"s",
"translations",
"."
] | 96ee3d28e02bd9513705408e3bb7f88a76e52f56 | https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Serializer/AbstractTranslatableNormalizer.php#L39-L61 | train |
agentmedia/phine-core | src/Core/Logic/Access/Frontend/MemberGuard.php | MemberGuard.Groups | private function Groups()
{
if ($this->groups === null)
{
$this->groups = array();
if ($this->GetMember())
{
$this->groups = MembergroupUtil::MemberMembergroups($this->GetMember());
}
}
return $this->groups;
} | php | private function Groups()
{
if ($this->groups === null)
{
$this->groups = array();
if ($this->GetMember())
{
$this->groups = MembergroupUtil::MemberMembergroups($this->GetMember());
}
}
return $this->groups;
} | [
"private",
"function",
"Groups",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"groups",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"groups",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"GetMember",
"(",
")",
")",
"{",
"$",
"this",
"->",
"groups",
"=",
"MembergroupUtil",
"::",
"MemberMembergroups",
"(",
"$",
"this",
"->",
"GetMember",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"groups",
";",
"}"
] | The groups of the current member
@return Membergroup[] Returns the groups of the current member | [
"The",
"groups",
"of",
"the",
"current",
"member"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Frontend/MemberGuard.php#L53-L64 | train |
agentmedia/phine-core | src/Core/Logic/Access/Frontend/MemberGuard.php | MemberGuard.Grant | public function Grant(Action $action, $onObject)
{
if ($onObject instanceof Page)
{
return $this->GrantOnPage($onObject);
}
if ($onObject instanceof Content)
{
return $this->GrantOnContent($onObject, $action);
}
else
{
throw new \LogicException('Frontend access check not implemented for type '. get_class($onObject));
}
return GrantResult::Allowed();
} | php | public function Grant(Action $action, $onObject)
{
if ($onObject instanceof Page)
{
return $this->GrantOnPage($onObject);
}
if ($onObject instanceof Content)
{
return $this->GrantOnContent($onObject, $action);
}
else
{
throw new \LogicException('Frontend access check not implemented for type '. get_class($onObject));
}
return GrantResult::Allowed();
} | [
"public",
"function",
"Grant",
"(",
"Action",
"$",
"action",
",",
"$",
"onObject",
")",
"{",
"if",
"(",
"$",
"onObject",
"instanceof",
"Page",
")",
"{",
"return",
"$",
"this",
"->",
"GrantOnPage",
"(",
"$",
"onObject",
")",
";",
"}",
"if",
"(",
"$",
"onObject",
"instanceof",
"Content",
")",
"{",
"return",
"$",
"this",
"->",
"GrantOnContent",
"(",
"$",
"onObject",
",",
"$",
"action",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Frontend access check not implemented for type '",
".",
"get_class",
"(",
"$",
"onObject",
")",
")",
";",
"}",
"return",
"GrantResult",
"::",
"Allowed",
"(",
")",
";",
"}"
] | Check access to an object in the frontend
@param Action $action The action taken on the object
@param mixed $onObject The object; page and contents are currently supported
@return GrantResult Returns the check result | [
"Check",
"access",
"to",
"an",
"object",
"in",
"the",
"frontend"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Frontend/MemberGuard.php#L72-L87 | train |
agentmedia/phine-core | src/Core/Logic/Access/Frontend/MemberGuard.php | MemberGuard.GrantByProperties | private function GrantByProperties($guestsOnly, $publish, Date $from = null, Date $to = null, array $groups = array())
{
if (!PublishDateUtil::IsPublishedNow($publish, $from, $to))
{
return GrantResult::NoAccess();
}
if ($this->GetMember() && $guestsOnly)
{
return GrantResult::NoAccess();
}
if (count($groups) == 0)
{
return GrantResult::Allowed();
}
if (!$this->GetMember())
{
return GrantResult::LoginRequired();
}
$groupIDs = Membergroup::GetKeyList($groups);
$memberGroupIDs = Membergroup::GetKeyList($this->Groups());
return count(array_intersect($groupIDs, $memberGroupIDs)) ? GrantResult::Allowed() :
GrantResult::NoAccess();
} | php | private function GrantByProperties($guestsOnly, $publish, Date $from = null, Date $to = null, array $groups = array())
{
if (!PublishDateUtil::IsPublishedNow($publish, $from, $to))
{
return GrantResult::NoAccess();
}
if ($this->GetMember() && $guestsOnly)
{
return GrantResult::NoAccess();
}
if (count($groups) == 0)
{
return GrantResult::Allowed();
}
if (!$this->GetMember())
{
return GrantResult::LoginRequired();
}
$groupIDs = Membergroup::GetKeyList($groups);
$memberGroupIDs = Membergroup::GetKeyList($this->Groups());
return count(array_intersect($groupIDs, $memberGroupIDs)) ? GrantResult::Allowed() :
GrantResult::NoAccess();
} | [
"private",
"function",
"GrantByProperties",
"(",
"$",
"guestsOnly",
",",
"$",
"publish",
",",
"Date",
"$",
"from",
"=",
"null",
",",
"Date",
"$",
"to",
"=",
"null",
",",
"array",
"$",
"groups",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"PublishDateUtil",
"::",
"IsPublishedNow",
"(",
"$",
"publish",
",",
"$",
"from",
",",
"$",
"to",
")",
")",
"{",
"return",
"GrantResult",
"::",
"NoAccess",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"GetMember",
"(",
")",
"&&",
"$",
"guestsOnly",
")",
"{",
"return",
"GrantResult",
"::",
"NoAccess",
"(",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"groups",
")",
"==",
"0",
")",
"{",
"return",
"GrantResult",
"::",
"Allowed",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"GetMember",
"(",
")",
")",
"{",
"return",
"GrantResult",
"::",
"LoginRequired",
"(",
")",
";",
"}",
"$",
"groupIDs",
"=",
"Membergroup",
"::",
"GetKeyList",
"(",
"$",
"groups",
")",
";",
"$",
"memberGroupIDs",
"=",
"Membergroup",
"::",
"GetKeyList",
"(",
"$",
"this",
"->",
"Groups",
"(",
")",
")",
";",
"return",
"count",
"(",
"array_intersect",
"(",
"$",
"groupIDs",
",",
"$",
"memberGroupIDs",
")",
")",
"?",
"GrantResult",
"::",
"Allowed",
"(",
")",
":",
"GrantResult",
"::",
"NoAccess",
"(",
")",
";",
"}"
] | Checks access to an item by its properties and assigned groups
@param boolean $guestsOnly True if guests only see the item
@param boolean $publish True if item is generally published
@param Date $from The start date of publishing
@param Date $to The end date of publishing
@param Membergroup[] $groups Groups assigned to the item
@return GrantResult | [
"Checks",
"access",
"to",
"an",
"item",
"by",
"its",
"properties",
"and",
"assigned",
"groups"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Frontend/MemberGuard.php#L99-L121 | train |
agentmedia/phine-core | src/Core/Logic/Access/Frontend/MemberGuard.php | MemberGuard.GrantOnPage | private function GrantOnPage(Page $page)
{
$groups = MembergroupUtil::PageMembergroups($page);
return $this->GrantByProperties($page->GetGuestsOnly(), $page->GetPublish(),
$page->GetPublishFrom(), $page->GetPublishTo(), $groups);
} | php | private function GrantOnPage(Page $page)
{
$groups = MembergroupUtil::PageMembergroups($page);
return $this->GrantByProperties($page->GetGuestsOnly(), $page->GetPublish(),
$page->GetPublishFrom(), $page->GetPublishTo(), $groups);
} | [
"private",
"function",
"GrantOnPage",
"(",
"Page",
"$",
"page",
")",
"{",
"$",
"groups",
"=",
"MembergroupUtil",
"::",
"PageMembergroups",
"(",
"$",
"page",
")",
";",
"return",
"$",
"this",
"->",
"GrantByProperties",
"(",
"$",
"page",
"->",
"GetGuestsOnly",
"(",
")",
",",
"$",
"page",
"->",
"GetPublish",
"(",
")",
",",
"$",
"page",
"->",
"GetPublishFrom",
"(",
")",
",",
"$",
"page",
"->",
"GetPublishTo",
"(",
")",
",",
"$",
"groups",
")",
";",
"}"
] | Checks a page for access rights
@param Page $page The page for the access check
@return GrantResult Returns the check result | [
"Checks",
"a",
"page",
"for",
"access",
"rights"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Frontend/MemberGuard.php#L128-L134 | train |
agentmedia/phine-core | src/Core/Logic/Access/Frontend/MemberGuard.php | MemberGuard.GrantOnContent | private function GrantOnContent(Content $content)
{
$groups = MembergroupUtil::ContentMembergroups($content);
return $this->GrantByProperties($content->GetGuestsOnly(), $content->GetPublish(),
$content->GetPublishFrom(), $content->GetPublishTo(), $groups);
} | php | private function GrantOnContent(Content $content)
{
$groups = MembergroupUtil::ContentMembergroups($content);
return $this->GrantByProperties($content->GetGuestsOnly(), $content->GetPublish(),
$content->GetPublishFrom(), $content->GetPublishTo(), $groups);
} | [
"private",
"function",
"GrantOnContent",
"(",
"Content",
"$",
"content",
")",
"{",
"$",
"groups",
"=",
"MembergroupUtil",
"::",
"ContentMembergroups",
"(",
"$",
"content",
")",
";",
"return",
"$",
"this",
"->",
"GrantByProperties",
"(",
"$",
"content",
"->",
"GetGuestsOnly",
"(",
")",
",",
"$",
"content",
"->",
"GetPublish",
"(",
")",
",",
"$",
"content",
"->",
"GetPublishFrom",
"(",
")",
",",
"$",
"content",
"->",
"GetPublishTo",
"(",
")",
",",
"$",
"groups",
")",
";",
"}"
] | Checks access to a content
@param Content $content The content
@return GrantResult The result of the check | [
"Checks",
"access",
"to",
"a",
"content"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Access/Frontend/MemberGuard.php#L141-L146 | train |
pixelpolishers/resolver-php-server | src/PixelPolishers/Resolver/Server/Server.php | Server.run | public function run()
{
$url = parse_url($_SERVER['REQUEST_URI']);
$controller = $this->router->find($url['path']);
if (!$controller instanceof ControllerInterface) {
throw new \RuntimeException('No valid controller found.');
}
$controller->setServer($this);
$result = $controller->execute();
$data = json_encode($result);
if (array_key_exists('callback', $_GET)) {
$data = $_GET['callback'] . '(' . $data . ')';
}
return $data;
} | php | public function run()
{
$url = parse_url($_SERVER['REQUEST_URI']);
$controller = $this->router->find($url['path']);
if (!$controller instanceof ControllerInterface) {
throw new \RuntimeException('No valid controller found.');
}
$controller->setServer($this);
$result = $controller->execute();
$data = json_encode($result);
if (array_key_exists('callback', $_GET)) {
$data = $_GET['callback'] . '(' . $data . ')';
}
return $data;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"url",
"=",
"parse_url",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"router",
"->",
"find",
"(",
"$",
"url",
"[",
"'path'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"controller",
"instanceof",
"ControllerInterface",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'No valid controller found.'",
")",
";",
"}",
"$",
"controller",
"->",
"setServer",
"(",
"$",
"this",
")",
";",
"$",
"result",
"=",
"$",
"controller",
"->",
"execute",
"(",
")",
";",
"$",
"data",
"=",
"json_encode",
"(",
"$",
"result",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'callback'",
",",
"$",
"_GET",
")",
")",
"{",
"$",
"data",
"=",
"$",
"_GET",
"[",
"'callback'",
"]",
".",
"'('",
".",
"$",
"data",
".",
"')'",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Runs the listener.
@throws \RuntimeException | [
"Runs",
"the",
"listener",
"."
] | c07505a768b32b30c7c300b3fb7e41d1776cb6e9 | https://github.com/pixelpolishers/resolver-php-server/blob/c07505a768b32b30c7c300b3fb7e41d1776cb6e9/src/PixelPolishers/Resolver/Server/Server.php#L71-L91 | train |
dann95/ts3-php | TeamSpeak3/Node/Server.php | Server.channelGroupList | public function channelGroupList(array $filter = array())
{
if ($this->cgroupList === null) {
$this->cgroupList = $this->request("channelgrouplist")->toAssocArray("cgid");
foreach ($this->cgroupList as $cgid => $group) {
$this->cgroupList[$cgid] = new Channelgroug($this, $group);
}
uasort($this->cgroupList, array(__CLASS__, "sortGroupList"));
}
return $this->filterList($this->cgroupList, $filter);
} | php | public function channelGroupList(array $filter = array())
{
if ($this->cgroupList === null) {
$this->cgroupList = $this->request("channelgrouplist")->toAssocArray("cgid");
foreach ($this->cgroupList as $cgid => $group) {
$this->cgroupList[$cgid] = new Channelgroug($this, $group);
}
uasort($this->cgroupList, array(__CLASS__, "sortGroupList"));
}
return $this->filterList($this->cgroupList, $filter);
} | [
"public",
"function",
"channelGroupList",
"(",
"array",
"$",
"filter",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cgroupList",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"cgroupList",
"=",
"$",
"this",
"->",
"request",
"(",
"\"channelgrouplist\"",
")",
"->",
"toAssocArray",
"(",
"\"cgid\"",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"cgroupList",
"as",
"$",
"cgid",
"=>",
"$",
"group",
")",
"{",
"$",
"this",
"->",
"cgroupList",
"[",
"$",
"cgid",
"]",
"=",
"new",
"Channelgroug",
"(",
"$",
"this",
",",
"$",
"group",
")",
";",
"}",
"uasort",
"(",
"$",
"this",
"->",
"cgroupList",
",",
"array",
"(",
"__CLASS__",
",",
"\"sortGroupList\"",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filterList",
"(",
"$",
"this",
"->",
"cgroupList",
",",
"$",
"filter",
")",
";",
"}"
] | Returns a list of channel groups available.
@param array $filter
@return array | [
"Returns",
"a",
"list",
"of",
"channel",
"groups",
"available",
"."
] | d4693d78b54be0177a2b5fab316c0ff9d036238d | https://github.com/dann95/ts3-php/blob/d4693d78b54be0177a2b5fab316c0ff9d036238d/TeamSpeak3/Node/Server.php#L1389-L1402 | train |
flextype-components/session | Session.php | Session.delete | public static function delete()
{
// Loop all arguments
foreach (func_get_args() as $argument) {
// Array element
if (is_array($argument)) {
// Loop the keys
foreach ($argument as $key) {
// Unset session key
unset($_SESSION[(string) $key]);
}
} else {
// Remove from array
unset($_SESSION[(string) $argument]);
}
}
} | php | public static function delete()
{
// Loop all arguments
foreach (func_get_args() as $argument) {
// Array element
if (is_array($argument)) {
// Loop the keys
foreach ($argument as $key) {
// Unset session key
unset($_SESSION[(string) $key]);
}
} else {
// Remove from array
unset($_SESSION[(string) $argument]);
}
}
} | [
"public",
"static",
"function",
"delete",
"(",
")",
"{",
"// Loop all arguments",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"// Array element",
"if",
"(",
"is_array",
"(",
"$",
"argument",
")",
")",
"{",
"// Loop the keys",
"foreach",
"(",
"$",
"argument",
"as",
"$",
"key",
")",
"{",
"// Unset session key",
"unset",
"(",
"$",
"_SESSION",
"[",
"(",
"string",
")",
"$",
"key",
"]",
")",
";",
"}",
"}",
"else",
"{",
"// Remove from array",
"unset",
"(",
"$",
"_SESSION",
"[",
"(",
"string",
")",
"$",
"argument",
"]",
")",
";",
"}",
"}",
"}"
] | Deletes one or more session variables.
Session::delete('user'); | [
"Deletes",
"one",
"or",
"more",
"session",
"variables",
"."
] | 9c0ae15c1be39d64164e5abc609ec3bd090edc59 | https://github.com/flextype-components/session/blob/9c0ae15c1be39d64164e5abc609ec3bd090edc59/Session.php#L40-L60 | train |
flextype-components/session | Session.php | Session.exists | public static function exists() : bool
{
// Start session if needed
if (! session_id()) {
Session::start();
}
// Loop all arguments
foreach (func_get_args() as $argument) {
// Array element
if (is_array($argument)) {
// Loop the keys
foreach ($argument as $key) {
// Does NOT exist
if (! isset($_SESSION[(string) $key])) {
return false;
}
}
} else {
// Does NOT exist
if (! isset($_SESSION[(string) $argument])) {
return false;
}
}
}
return true;
} | php | public static function exists() : bool
{
// Start session if needed
if (! session_id()) {
Session::start();
}
// Loop all arguments
foreach (func_get_args() as $argument) {
// Array element
if (is_array($argument)) {
// Loop the keys
foreach ($argument as $key) {
// Does NOT exist
if (! isset($_SESSION[(string) $key])) {
return false;
}
}
} else {
// Does NOT exist
if (! isset($_SESSION[(string) $argument])) {
return false;
}
}
}
return true;
} | [
"public",
"static",
"function",
"exists",
"(",
")",
":",
"bool",
"{",
"// Start session if needed",
"if",
"(",
"!",
"session_id",
"(",
")",
")",
"{",
"Session",
"::",
"start",
"(",
")",
";",
"}",
"// Loop all arguments",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"// Array element",
"if",
"(",
"is_array",
"(",
"$",
"argument",
")",
")",
"{",
"// Loop the keys",
"foreach",
"(",
"$",
"argument",
"as",
"$",
"key",
")",
"{",
"// Does NOT exist",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"(",
"string",
")",
"$",
"key",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"{",
"// Does NOT exist",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"(",
"string",
")",
"$",
"argument",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks if a session variable exists.
if (Session::exists('user')) {
// Do something...
}
@return bool | [
"Checks",
"if",
"a",
"session",
"variable",
"exists",
"."
] | 9c0ae15c1be39d64164e5abc609ec3bd090edc59 | https://github.com/flextype-components/session/blob/9c0ae15c1be39d64164e5abc609ec3bd090edc59/Session.php#L86-L117 | train |
flextype-components/session | Session.php | Session.get | public static function get(string $key)
{
// Start session if needed
if (! session_id()) {
self::start();
}
// Fetch key
if (Session::exists((string) $key)) {
return $_SESSION[(string) $key];
}
// Key doesn't exist
return null;
} | php | public static function get(string $key)
{
// Start session if needed
if (! session_id()) {
self::start();
}
// Fetch key
if (Session::exists((string) $key)) {
return $_SESSION[(string) $key];
}
// Key doesn't exist
return null;
} | [
"public",
"static",
"function",
"get",
"(",
"string",
"$",
"key",
")",
"{",
"// Start session if needed",
"if",
"(",
"!",
"session_id",
"(",
")",
")",
"{",
"self",
"::",
"start",
"(",
")",
";",
"}",
"// Fetch key",
"if",
"(",
"Session",
"::",
"exists",
"(",
"(",
"string",
")",
"$",
"key",
")",
")",
"{",
"return",
"$",
"_SESSION",
"[",
"(",
"string",
")",
"$",
"key",
"]",
";",
"}",
"// Key doesn't exist",
"return",
"null",
";",
"}"
] | Gets a variable that was stored in the session.
echo Session::get('user');
@param string $key The key of the variable to get.
@return mixed | [
"Gets",
"a",
"variable",
"that",
"was",
"stored",
"in",
"the",
"session",
"."
] | 9c0ae15c1be39d64164e5abc609ec3bd090edc59 | https://github.com/flextype-components/session/blob/9c0ae15c1be39d64164e5abc609ec3bd090edc59/Session.php#L127-L141 | train |
flextype-components/session | Session.php | Session.set | public static function set(string $key, $value)
{
// Start session if needed
if (! session_id()) {
self::start();
}
// Set key
$_SESSION[(string) $key] = $value;
} | php | public static function set(string $key, $value)
{
// Start session if needed
if (! session_id()) {
self::start();
}
// Set key
$_SESSION[(string) $key] = $value;
} | [
"public",
"static",
"function",
"set",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
"{",
"// Start session if needed",
"if",
"(",
"!",
"session_id",
"(",
")",
")",
"{",
"self",
"::",
"start",
"(",
")",
";",
"}",
"// Set key",
"$",
"_SESSION",
"[",
"(",
"string",
")",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | Stores a variable in the session.
Session::set('user', 'Awilum');
@param string $key The key for the variable.
@param mixed $value The value to store. | [
"Stores",
"a",
"variable",
"in",
"the",
"session",
"."
] | 9c0ae15c1be39d64164e5abc609ec3bd090edc59 | https://github.com/flextype-components/session/blob/9c0ae15c1be39d64164e5abc609ec3bd090edc59/Session.php#L169-L178 | train |
fxpio/fxp-doctrine-extensions | Validator/Constraints/Util.php | Util.getFormattedIdentifier | public static function getFormattedIdentifier(ClassMetadata $relatedClass, array $criteria, $fieldName, $value)
{
$isObject = \is_object($criteria[$fieldName]);
return $isObject && null === $value
? self::formatEmptyIdentifier($relatedClass)
: $value;
} | php | public static function getFormattedIdentifier(ClassMetadata $relatedClass, array $criteria, $fieldName, $value)
{
$isObject = \is_object($criteria[$fieldName]);
return $isObject && null === $value
? self::formatEmptyIdentifier($relatedClass)
: $value;
} | [
"public",
"static",
"function",
"getFormattedIdentifier",
"(",
"ClassMetadata",
"$",
"relatedClass",
",",
"array",
"$",
"criteria",
",",
"$",
"fieldName",
",",
"$",
"value",
")",
"{",
"$",
"isObject",
"=",
"\\",
"is_object",
"(",
"$",
"criteria",
"[",
"$",
"fieldName",
"]",
")",
";",
"return",
"$",
"isObject",
"&&",
"null",
"===",
"$",
"value",
"?",
"self",
"::",
"formatEmptyIdentifier",
"(",
"$",
"relatedClass",
")",
":",
"$",
"value",
";",
"}"
] | Get the formatted identifier.
@param ClassMetadata $relatedClass The metadata of related class
@param array $criteria The validator criteria
@param string $fieldName The field name
@param null|int|string $value The identifier value
@return int|string | [
"Get",
"the",
"formatted",
"identifier",
"."
] | 82942f51d47cdd79a20a5725ee1b3ecfc69e9d77 | https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Validator/Constraints/Util.php#L38-L45 | train |
fxpio/fxp-doctrine-extensions | Validator/Constraints/Util.php | Util.formatEmptyIdentifier | public static function formatEmptyIdentifier(ClassMetadata $meta)
{
$type = $meta->getTypeOfField(current($meta->getIdentifier()));
switch ($type) {
case 'bigint':
case 'decimal':
case 'integer':
case 'smallint':
case 'float':
return 0;
case 'guid':
return '00000000-0000-0000-0000-000000000000';
default:
return '';
}
} | php | public static function formatEmptyIdentifier(ClassMetadata $meta)
{
$type = $meta->getTypeOfField(current($meta->getIdentifier()));
switch ($type) {
case 'bigint':
case 'decimal':
case 'integer':
case 'smallint':
case 'float':
return 0;
case 'guid':
return '00000000-0000-0000-0000-000000000000';
default:
return '';
}
} | [
"public",
"static",
"function",
"formatEmptyIdentifier",
"(",
"ClassMetadata",
"$",
"meta",
")",
"{",
"$",
"type",
"=",
"$",
"meta",
"->",
"getTypeOfField",
"(",
"current",
"(",
"$",
"meta",
"->",
"getIdentifier",
"(",
")",
")",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'bigint'",
":",
"case",
"'decimal'",
":",
"case",
"'integer'",
":",
"case",
"'smallint'",
":",
"case",
"'float'",
":",
"return",
"0",
";",
"case",
"'guid'",
":",
"return",
"'00000000-0000-0000-0000-000000000000'",
";",
"default",
":",
"return",
"''",
";",
"}",
"}"
] | Format the empty identifier value for entity with relation.
@param ClassMetadata $meta The class metadata of entity relation
@return int|string | [
"Format",
"the",
"empty",
"identifier",
"value",
"for",
"entity",
"with",
"relation",
"."
] | 82942f51d47cdd79a20a5725ee1b3ecfc69e9d77 | https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Validator/Constraints/Util.php#L54-L70 | train |
fxpio/fxp-doctrine-extensions | Validator/Constraints/Util.php | Util.getObjectManager | public static function getObjectManager(ManagerRegistry $registry, $entity, Constraint $constraint)
{
self::validateConstraint($constraint);
/* @var UniqueEntity $constraint */
return self::findObjectManager($registry, $entity, $constraint);
} | php | public static function getObjectManager(ManagerRegistry $registry, $entity, Constraint $constraint)
{
self::validateConstraint($constraint);
/* @var UniqueEntity $constraint */
return self::findObjectManager($registry, $entity, $constraint);
} | [
"public",
"static",
"function",
"getObjectManager",
"(",
"ManagerRegistry",
"$",
"registry",
",",
"$",
"entity",
",",
"Constraint",
"$",
"constraint",
")",
"{",
"self",
"::",
"validateConstraint",
"(",
"$",
"constraint",
")",
";",
"/* @var UniqueEntity $constraint */",
"return",
"self",
"::",
"findObjectManager",
"(",
"$",
"registry",
",",
"$",
"entity",
",",
"$",
"constraint",
")",
";",
"}"
] | Pre validate entity.
@param ManagerRegistry $registry
@param object $entity
@param Constraint $constraint
@throws UnexpectedTypeException
@throws ConstraintDefinitionException
@return ObjectManager | [
"Pre",
"validate",
"entity",
"."
] | 82942f51d47cdd79a20a5725ee1b3ecfc69e9d77 | https://github.com/fxpio/fxp-doctrine-extensions/blob/82942f51d47cdd79a20a5725ee1b3ecfc69e9d77/Validator/Constraints/Util.php#L84-L90 | train |
field-interactive/cito-bundle | Composer/ScriptHandler.php | ScriptHandler.updateCito | public static function updateCito(Event $event)
{
$options = static::getOptions($event);
$configDir = $options['symfony-config-dir'];
$templateDir = $options['symfony-template-dir'];
$fs = new Filesystem();
/*
* Update config/packages/cito.yaml
*/
$yaml = Yaml::parseFile($configDir . '/packages/cito.yaml');
if (!array_key_exists('user_agent_enabled', $yaml['cito'])) {
$yaml['cito']['user_agent_enabled'] = false;
}
if (!array_key_exists('default_user_agent', $yaml['cito'])) {
$yaml['cito']['default_user_agent'] = 'new';
}
if (!array_key_exists('user_agent_routing', $yaml['cito'])) {
$yaml['cito']['user_agent_routing'] = [
'new' => 'ie 11, opera > 52',
'old' => 'ie < 11, opera < 52'
];
}
if (!array_key_exists('translation_enabled', $yaml['cito'])) {
$yaml['cito']['translation_enabled'] = false;
}
if (!array_key_exists('translation_support', $yaml['cito'])) {
$yaml['cito']['translation_support'] = [
'de' => 'Deutsch',
'en' => 'Englisch'
];
}
$fs->remove($configDir . '/packages/cito.yaml');
$fs->dumpFile($configDir . '/packages/cito.yaml', Yaml::dump($yaml, 99));
} | php | public static function updateCito(Event $event)
{
$options = static::getOptions($event);
$configDir = $options['symfony-config-dir'];
$templateDir = $options['symfony-template-dir'];
$fs = new Filesystem();
/*
* Update config/packages/cito.yaml
*/
$yaml = Yaml::parseFile($configDir . '/packages/cito.yaml');
if (!array_key_exists('user_agent_enabled', $yaml['cito'])) {
$yaml['cito']['user_agent_enabled'] = false;
}
if (!array_key_exists('default_user_agent', $yaml['cito'])) {
$yaml['cito']['default_user_agent'] = 'new';
}
if (!array_key_exists('user_agent_routing', $yaml['cito'])) {
$yaml['cito']['user_agent_routing'] = [
'new' => 'ie 11, opera > 52',
'old' => 'ie < 11, opera < 52'
];
}
if (!array_key_exists('translation_enabled', $yaml['cito'])) {
$yaml['cito']['translation_enabled'] = false;
}
if (!array_key_exists('translation_support', $yaml['cito'])) {
$yaml['cito']['translation_support'] = [
'de' => 'Deutsch',
'en' => 'Englisch'
];
}
$fs->remove($configDir . '/packages/cito.yaml');
$fs->dumpFile($configDir . '/packages/cito.yaml', Yaml::dump($yaml, 99));
} | [
"public",
"static",
"function",
"updateCito",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"options",
"=",
"static",
"::",
"getOptions",
"(",
"$",
"event",
")",
";",
"$",
"configDir",
"=",
"$",
"options",
"[",
"'symfony-config-dir'",
"]",
";",
"$",
"templateDir",
"=",
"$",
"options",
"[",
"'symfony-template-dir'",
"]",
";",
"$",
"fs",
"=",
"new",
"Filesystem",
"(",
")",
";",
"/*\n * Update config/packages/cito.yaml\n */",
"$",
"yaml",
"=",
"Yaml",
"::",
"parseFile",
"(",
"$",
"configDir",
".",
"'/packages/cito.yaml'",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'user_agent_enabled'",
",",
"$",
"yaml",
"[",
"'cito'",
"]",
")",
")",
"{",
"$",
"yaml",
"[",
"'cito'",
"]",
"[",
"'user_agent_enabled'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'default_user_agent'",
",",
"$",
"yaml",
"[",
"'cito'",
"]",
")",
")",
"{",
"$",
"yaml",
"[",
"'cito'",
"]",
"[",
"'default_user_agent'",
"]",
"=",
"'new'",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'user_agent_routing'",
",",
"$",
"yaml",
"[",
"'cito'",
"]",
")",
")",
"{",
"$",
"yaml",
"[",
"'cito'",
"]",
"[",
"'user_agent_routing'",
"]",
"=",
"[",
"'new'",
"=>",
"'ie 11, opera > 52'",
",",
"'old'",
"=>",
"'ie < 11, opera < 52'",
"]",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'translation_enabled'",
",",
"$",
"yaml",
"[",
"'cito'",
"]",
")",
")",
"{",
"$",
"yaml",
"[",
"'cito'",
"]",
"[",
"'translation_enabled'",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'translation_support'",
",",
"$",
"yaml",
"[",
"'cito'",
"]",
")",
")",
"{",
"$",
"yaml",
"[",
"'cito'",
"]",
"[",
"'translation_support'",
"]",
"=",
"[",
"'de'",
"=>",
"'Deutsch'",
",",
"'en'",
"=>",
"'Englisch'",
"]",
";",
"}",
"$",
"fs",
"->",
"remove",
"(",
"$",
"configDir",
".",
"'/packages/cito.yaml'",
")",
";",
"$",
"fs",
"->",
"dumpFile",
"(",
"$",
"configDir",
".",
"'/packages/cito.yaml'",
",",
"Yaml",
"::",
"dump",
"(",
"$",
"yaml",
",",
"99",
")",
")",
";",
"}"
] | Update the Cito files without delete user changes
@param Event $event | [
"Update",
"the",
"Cito",
"files",
"without",
"delete",
"user",
"changes"
] | 41cab570f960d964916e278c616720b17de258c1 | https://github.com/field-interactive/cito-bundle/blob/41cab570f960d964916e278c616720b17de258c1/Composer/ScriptHandler.php#L183-L218 | train |
cubicmushroom/valueobjects | src/DateTime/TimeZone.php | TimeZone.sameValueAs | public function sameValueAs(ValueObjectInterface $timezone)
{
if (false === Util::classEquals($this, $timezone)) {
return false;
}
return $this->getName()->sameValueAs($timezone->getName());
} | php | public function sameValueAs(ValueObjectInterface $timezone)
{
if (false === Util::classEquals($this, $timezone)) {
return false;
}
return $this->getName()->sameValueAs($timezone->getName());
} | [
"public",
"function",
"sameValueAs",
"(",
"ValueObjectInterface",
"$",
"timezone",
")",
"{",
"if",
"(",
"false",
"===",
"Util",
"::",
"classEquals",
"(",
"$",
"this",
",",
"$",
"timezone",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"getName",
"(",
")",
"->",
"sameValueAs",
"(",
"$",
"timezone",
"->",
"getName",
"(",
")",
")",
";",
"}"
] | Tells whether two DateTimeZone are equal by comparing their names
@param ValueObjectInterface $timezone
@return bool | [
"Tells",
"whether",
"two",
"DateTimeZone",
"are",
"equal",
"by",
"comparing",
"their",
"names"
] | 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/DateTime/TimeZone.php#L82-L89 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Query.php | Query.setQuery | public function setQuery($query)
{
$raw = SqlFormatter::removeComments($query);
if ($this->noSplit) {
$queries = array($raw);
} else {
$queries = SqlFormatter::splitQuery($raw);
}
foreach ($queries as $index => $q) {
$this->addOrReplace($index, $q);
}
$this->removeFromIndex(count($queries));
} | php | public function setQuery($query)
{
$raw = SqlFormatter::removeComments($query);
if ($this->noSplit) {
$queries = array($raw);
} else {
$queries = SqlFormatter::splitQuery($raw);
}
foreach ($queries as $index => $q) {
$this->addOrReplace($index, $q);
}
$this->removeFromIndex(count($queries));
} | [
"public",
"function",
"setQuery",
"(",
"$",
"query",
")",
"{",
"$",
"raw",
"=",
"SqlFormatter",
"::",
"removeComments",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"this",
"->",
"noSplit",
")",
"{",
"$",
"queries",
"=",
"array",
"(",
"$",
"raw",
")",
";",
"}",
"else",
"{",
"$",
"queries",
"=",
"SqlFormatter",
"::",
"splitQuery",
"(",
"$",
"raw",
")",
";",
"}",
"foreach",
"(",
"$",
"queries",
"as",
"$",
"index",
"=>",
"$",
"q",
")",
"{",
"$",
"this",
"->",
"addOrReplace",
"(",
"$",
"index",
",",
"$",
"q",
")",
";",
"}",
"$",
"this",
"->",
"removeFromIndex",
"(",
"count",
"(",
"$",
"queries",
")",
")",
";",
"}"
] | Set SQL Query.
@param string $query | [
"Set",
"SQL",
"Query",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Query.php#L138-L152 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Query.php | Query.setResultDataType | public function setResultDataType($resultDataType)
{
if (is_string($resultDataType) && class_exists($resultDataType)) {
$resultDataType = new $resultDataType();
}
if ($resultDataType instanceof DataInterface) {
$this->resultDataType = $resultDataType;
}
$objectType = is_object($resultDataType) ? get_class($resultDataType) : gettype($resultDataType);
if (is_array($this->resultDataType)) {
throw new \Exception(sprintf('Result data type must be instanceof %s, %s given.',
DataInterface::class,
$objectType
));
}
} | php | public function setResultDataType($resultDataType)
{
if (is_string($resultDataType) && class_exists($resultDataType)) {
$resultDataType = new $resultDataType();
}
if ($resultDataType instanceof DataInterface) {
$this->resultDataType = $resultDataType;
}
$objectType = is_object($resultDataType) ? get_class($resultDataType) : gettype($resultDataType);
if (is_array($this->resultDataType)) {
throw new \Exception(sprintf('Result data type must be instanceof %s, %s given.',
DataInterface::class,
$objectType
));
}
} | [
"public",
"function",
"setResultDataType",
"(",
"$",
"resultDataType",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"resultDataType",
")",
"&&",
"class_exists",
"(",
"$",
"resultDataType",
")",
")",
"{",
"$",
"resultDataType",
"=",
"new",
"$",
"resultDataType",
"(",
")",
";",
"}",
"if",
"(",
"$",
"resultDataType",
"instanceof",
"DataInterface",
")",
"{",
"$",
"this",
"->",
"resultDataType",
"=",
"$",
"resultDataType",
";",
"}",
"$",
"objectType",
"=",
"is_object",
"(",
"$",
"resultDataType",
")",
"?",
"get_class",
"(",
"$",
"resultDataType",
")",
":",
"gettype",
"(",
"$",
"resultDataType",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"resultDataType",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Result data type must be instanceof %s, %s given.'",
",",
"DataInterface",
"::",
"class",
",",
"$",
"objectType",
")",
")",
";",
"}",
"}"
] | Set Result Data Type.
@param srting|\Realboard\Component\Database\DBInstance\DBInterface\DataInterface $resultDataType | [
"Set",
"Result",
"Data",
"Type",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Query.php#L159-L177 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Query.php | Query.setInitializer | public function setInitializer(QueryInitializer $initial)
{
$this->initial = $initial;
for ($i = 0; $i < $this->length(); ++$i) {
if ($this->offsetExists($i)) {
$this->offsetGet($i)->setInitializer($this->initial);
}
}
} | php | public function setInitializer(QueryInitializer $initial)
{
$this->initial = $initial;
for ($i = 0; $i < $this->length(); ++$i) {
if ($this->offsetExists($i)) {
$this->offsetGet($i)->setInitializer($this->initial);
}
}
} | [
"public",
"function",
"setInitializer",
"(",
"QueryInitializer",
"$",
"initial",
")",
"{",
"$",
"this",
"->",
"initial",
"=",
"$",
"initial",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"length",
"(",
")",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"i",
")",
")",
"{",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"i",
")",
"->",
"setInitializer",
"(",
"$",
"this",
"->",
"initial",
")",
";",
"}",
"}",
"}"
] | Set Initializer Class.
@param \Realboard\Component\Database\DBInstance\QueryInitializer $initial | [
"Set",
"Initializer",
"Class",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Query.php#L194-L202 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Query.php | Query.add | public function add(SQLInterface $sql)
{
$this->raw[] = $sql->toString();
if (!$sql->getId()) {
$sql->setId($this->count() + 1);
}
$sql->setInitializer($this->initial);
$this->append($sql);
} | php | public function add(SQLInterface $sql)
{
$this->raw[] = $sql->toString();
if (!$sql->getId()) {
$sql->setId($this->count() + 1);
}
$sql->setInitializer($this->initial);
$this->append($sql);
} | [
"public",
"function",
"add",
"(",
"SQLInterface",
"$",
"sql",
")",
"{",
"$",
"this",
"->",
"raw",
"[",
"]",
"=",
"$",
"sql",
"->",
"toString",
"(",
")",
";",
"if",
"(",
"!",
"$",
"sql",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"sql",
"->",
"setId",
"(",
"$",
"this",
"->",
"count",
"(",
")",
"+",
"1",
")",
";",
"}",
"$",
"sql",
"->",
"setInitializer",
"(",
"$",
"this",
"->",
"initial",
")",
";",
"$",
"this",
"->",
"append",
"(",
"$",
"sql",
")",
";",
"}"
] | Append SQL Object.
@param \Realboard\Component\Database\DBInstance\DBInterface\SQLInterface $sql | [
"Append",
"SQL",
"Object",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Query.php#L219-L228 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Query.php | Query.toArray | public function toArray()
{
$arrayResult = array();
for ($i = 0; $i < $this->length(); ++$i) {
if ($this->offsetExists($i)) {
$arrayResult[] = $this->offsetGet($i)->toArray();
}
}
return $arrayResult;
} | php | public function toArray()
{
$arrayResult = array();
for ($i = 0; $i < $this->length(); ++$i) {
if ($this->offsetExists($i)) {
$arrayResult[] = $this->offsetGet($i)->toArray();
}
}
return $arrayResult;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"arrayResult",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"length",
"(",
")",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"i",
")",
")",
"{",
"$",
"arrayResult",
"[",
"]",
"=",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"i",
")",
"->",
"toArray",
"(",
")",
";",
"}",
"}",
"return",
"$",
"arrayResult",
";",
"}"
] | Get All SQL Query as an array.
@return array | [
"Get",
"All",
"SQL",
"Query",
"as",
"an",
"array",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Query.php#L255-L265 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Query.php | Query.clear | public function clear()
{
for ($i = 0; $i < $this->length(); ++$i) {
if ($this->offsetExists($i)) {
$this->offsetUnset($i);
}
}
} | php | public function clear()
{
for ($i = 0; $i < $this->length(); ++$i) {
if ($this->offsetExists($i)) {
$this->offsetUnset($i);
}
}
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"length",
"(",
")",
";",
"++",
"$",
"i",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"i",
")",
")",
"{",
"$",
"this",
"->",
"offsetUnset",
"(",
"$",
"i",
")",
";",
"}",
"}",
"}"
] | Clear all sql queries. | [
"Clear",
"all",
"sql",
"queries",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Query.php#L270-L277 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Query.php | Query.last | public function last()
{
$lastIndex = $this->count() - 1;
if ($this->offsetExists($lastIndex)) {
return $this->offsetGet($lastIndex);
}
} | php | public function last()
{
$lastIndex = $this->count() - 1;
if ($this->offsetExists($lastIndex)) {
return $this->offsetGet($lastIndex);
}
} | [
"public",
"function",
"last",
"(",
")",
"{",
"$",
"lastIndex",
"=",
"$",
"this",
"->",
"count",
"(",
")",
"-",
"1",
";",
"if",
"(",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"lastIndex",
")",
")",
"{",
"return",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"lastIndex",
")",
";",
"}",
"}"
] | Get last sql query if single query will return first query.
@return \Realboard\Component\Database\DBInstance\Sql | [
"Get",
"last",
"sql",
"query",
"if",
"single",
"query",
"will",
"return",
"first",
"query",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Query.php#L296-L302 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Query.php | Query.addOrReplace | public function addOrReplace($index, $stringSql)
{
if (!$stringSql) {
return;
}
$sql = null;
if ($this->offsetExists($index)) {
$sql = $this->offsetGet($index);
$sql->setSql($stringSql);
} else {
$sql = new Sql($stringSql);
$this->add($sql);
}
return $sql;
} | php | public function addOrReplace($index, $stringSql)
{
if (!$stringSql) {
return;
}
$sql = null;
if ($this->offsetExists($index)) {
$sql = $this->offsetGet($index);
$sql->setSql($stringSql);
} else {
$sql = new Sql($stringSql);
$this->add($sql);
}
return $sql;
} | [
"public",
"function",
"addOrReplace",
"(",
"$",
"index",
",",
"$",
"stringSql",
")",
"{",
"if",
"(",
"!",
"$",
"stringSql",
")",
"{",
"return",
";",
"}",
"$",
"sql",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"index",
")",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"index",
")",
";",
"$",
"sql",
"->",
"setSql",
"(",
"$",
"stringSql",
")",
";",
"}",
"else",
"{",
"$",
"sql",
"=",
"new",
"Sql",
"(",
"$",
"stringSql",
")",
";",
"$",
"this",
"->",
"add",
"(",
"$",
"sql",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Add Or Replace old query.
@param int $index
@param string $stringSql | [
"Add",
"Or",
"Replace",
"old",
"query",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Query.php#L360-L375 | train |
fuelphp-storage/session | src/Driver.php | Driver.regenerate | public function regenerate()
{
// generate a new random session id
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$sessionId = '';
for ($i=0; $i < 32; $i++)
{
$sessionId .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
// store the new session id
$this->setSessionId($sessionId);
} | php | public function regenerate()
{
// generate a new random session id
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$sessionId = '';
for ($i=0; $i < 32; $i++)
{
$sessionId .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
}
// store the new session id
$this->setSessionId($sessionId);
} | [
"public",
"function",
"regenerate",
"(",
")",
"{",
"// generate a new random session id",
"$",
"pool",
"=",
"'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'",
";",
"$",
"sessionId",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"32",
";",
"$",
"i",
"++",
")",
"{",
"$",
"sessionId",
".=",
"substr",
"(",
"$",
"pool",
",",
"mt_rand",
"(",
"0",
",",
"strlen",
"(",
"$",
"pool",
")",
"-",
"1",
")",
",",
"1",
")",
";",
"}",
"// store the new session id",
"$",
"this",
"->",
"setSessionId",
"(",
"$",
"sessionId",
")",
";",
"}"
] | Regenerates the session id | [
"Regenerates",
"the",
"session",
"id"
] | 948fd2b45286e65e7fababf65de89ca6aaca3c4a | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver.php#L152-L164 | train |
fuelphp-storage/session | src/Driver.php | Driver.setInstances | public function setInstances(Manager $manager, DataContainer $data, FlashContainer $flash)
{
$this->manager = $manager;
$this->data = $data;
$this->flash = $flash;
} | php | public function setInstances(Manager $manager, DataContainer $data, FlashContainer $flash)
{
$this->manager = $manager;
$this->data = $data;
$this->flash = $flash;
} | [
"public",
"function",
"setInstances",
"(",
"Manager",
"$",
"manager",
",",
"DataContainer",
"$",
"data",
",",
"FlashContainer",
"$",
"flash",
")",
"{",
"$",
"this",
"->",
"manager",
"=",
"$",
"manager",
";",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"flash",
"=",
"$",
"flash",
";",
"}"
] | Sets the manager that manages this driver and container instances for this session
@param Manager $manager
@param DataContainer $data
@param FlashContainer $data | [
"Sets",
"the",
"manager",
"that",
"manages",
"this",
"driver",
"and",
"container",
"instances",
"for",
"this",
"session"
] | 948fd2b45286e65e7fababf65de89ca6aaca3c4a | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver.php#L173-L178 | train |
fuelphp-storage/session | src/Driver.php | Driver.findSessionId | protected function findSessionId()
{
// check for a posted session id
if ( ! empty($this->config['post_cookie_name']) and isset($_POST[$this->config['post_cookie_name']]))
{
$this->sessionId = $_POST[$this->config['post_cookie_name']];
}
// else check for a regular cookie
elseif ( ! empty($this->config['enable_cookie']) and isset($_COOKIE[$this->name]))
{
$this->sessionId = $_COOKIE[$this->name];
}
// else check for a session id in the URL
elseif (isset($_GET[$this->name]))
{
$this->sessionId = $_GET[$this->name];
}
// TODO: else check the HTTP headers for the session id
return $this->sessionId ?: null;
} | php | protected function findSessionId()
{
// check for a posted session id
if ( ! empty($this->config['post_cookie_name']) and isset($_POST[$this->config['post_cookie_name']]))
{
$this->sessionId = $_POST[$this->config['post_cookie_name']];
}
// else check for a regular cookie
elseif ( ! empty($this->config['enable_cookie']) and isset($_COOKIE[$this->name]))
{
$this->sessionId = $_COOKIE[$this->name];
}
// else check for a session id in the URL
elseif (isset($_GET[$this->name]))
{
$this->sessionId = $_GET[$this->name];
}
// TODO: else check the HTTP headers for the session id
return $this->sessionId ?: null;
} | [
"protected",
"function",
"findSessionId",
"(",
")",
"{",
"// check for a posted session id",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'post_cookie_name'",
"]",
")",
"and",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"this",
"->",
"config",
"[",
"'post_cookie_name'",
"]",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sessionId",
"=",
"$",
"_POST",
"[",
"$",
"this",
"->",
"config",
"[",
"'post_cookie_name'",
"]",
"]",
";",
"}",
"// else check for a regular cookie",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'enable_cookie'",
"]",
")",
"and",
"isset",
"(",
"$",
"_COOKIE",
"[",
"$",
"this",
"->",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sessionId",
"=",
"$",
"_COOKIE",
"[",
"$",
"this",
"->",
"name",
"]",
";",
"}",
"// else check for a session id in the URL",
"elseif",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"$",
"this",
"->",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sessionId",
"=",
"$",
"_GET",
"[",
"$",
"this",
"->",
"name",
"]",
";",
"}",
"// TODO: else check the HTTP headers for the session id",
"return",
"$",
"this",
"->",
"sessionId",
"?",
":",
"null",
";",
"}"
] | Finds the current session id | [
"Finds",
"the",
"current",
"session",
"id"
] | 948fd2b45286e65e7fababf65de89ca6aaca3c4a | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver.php#L243-L266 | train |
fuelphp-storage/session | src/Driver.php | Driver.setCookie | protected function setCookie($name, $value)
{
// add the current time so we have an offset
$expiration = $this->expiration > 0 ? $this->expiration + time() : 0;
return setcookie($name, $value, $expiration, $this->config['cookie_path'], $this->config['cookie_domain'], $this->config['cookie_secure'], $this->config['cookie_http_only']);
} | php | protected function setCookie($name, $value)
{
// add the current time so we have an offset
$expiration = $this->expiration > 0 ? $this->expiration + time() : 0;
return setcookie($name, $value, $expiration, $this->config['cookie_path'], $this->config['cookie_domain'], $this->config['cookie_secure'], $this->config['cookie_http_only']);
} | [
"protected",
"function",
"setCookie",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"// add the current time so we have an offset",
"$",
"expiration",
"=",
"$",
"this",
"->",
"expiration",
">",
"0",
"?",
"$",
"this",
"->",
"expiration",
"+",
"time",
"(",
")",
":",
"0",
";",
"return",
"setcookie",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"expiration",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie_path'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie_domain'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie_secure'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie_http_only'",
"]",
")",
";",
"}"
] | Sets a cookie. Note that all cookie values must be strings and no
automatic serialization will be performed!
@param string $name
@param string $value
@return boolean | [
"Sets",
"a",
"cookie",
".",
"Note",
"that",
"all",
"cookie",
"values",
"must",
"be",
"strings",
"and",
"no",
"automatic",
"serialization",
"will",
"be",
"performed!"
] | 948fd2b45286e65e7fababf65de89ca6aaca3c4a | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver.php#L342-L348 | train |
fuelphp-storage/session | src/Driver.php | Driver.deleteCookie | protected function deleteCookie($name)
{
// Remove the cookie
unset($_COOKIE[$name]);
// Nullify the cookie and make it expire
return setcookie($name, null, -86400, $this->config['cookie_path'], $this->config['cookie_domain'], $this->config['cookie_secure'], $this->config['cookie_http_only']);
} | php | protected function deleteCookie($name)
{
// Remove the cookie
unset($_COOKIE[$name]);
// Nullify the cookie and make it expire
return setcookie($name, null, -86400, $this->config['cookie_path'], $this->config['cookie_domain'], $this->config['cookie_secure'], $this->config['cookie_http_only']);
} | [
"protected",
"function",
"deleteCookie",
"(",
"$",
"name",
")",
"{",
"// Remove the cookie",
"unset",
"(",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
")",
";",
"// Nullify the cookie and make it expire",
"return",
"setcookie",
"(",
"$",
"name",
",",
"null",
",",
"-",
"86400",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie_path'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie_domain'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie_secure'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie_http_only'",
"]",
")",
";",
"}"
] | Deletes a cookie by making the value null and expiring it
@param string $na,e
@return boolean | [
"Deletes",
"a",
"cookie",
"by",
"making",
"the",
"value",
"null",
"and",
"expiring",
"it"
] | 948fd2b45286e65e7fababf65de89ca6aaca3c4a | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver.php#L357-L364 | train |
Subscribo/klarna-invoice-sdk-wrapped | src/pclasses/xmlstorage.class.php | XMLStorage.createFields | protected function createFields($pclass)
{
$fields = array();
//This is to prevent HTMLEntities to be converted to the real character.
$fields[] = $this->dom->createElement('description');
end($fields)->appendChild(
$this->dom->createTextNode($pclass->getDescription())
);
$fields[] = $this->dom->createElement(
'months', $pclass->getMonths()
);
$fields[] = $this->dom->createElement(
'startfee', $pclass->getStartFee()
);
$fields[] = $this->dom->createElement(
'invoicefee', $pclass->getInvoiceFee()
);
$fields[] = $this->dom->createElement(
'interestrate', $pclass->getInterestRate()
);
$fields[] = $this->dom->createElement(
'minamount', $pclass->getMinAmount()
);
$fields[] = $this->dom->createElement(
'country', $pclass->getCountry()
);
$fields[] = $this->dom->createElement(
'expire', $pclass->getExpire()
);
return $fields;
} | php | protected function createFields($pclass)
{
$fields = array();
//This is to prevent HTMLEntities to be converted to the real character.
$fields[] = $this->dom->createElement('description');
end($fields)->appendChild(
$this->dom->createTextNode($pclass->getDescription())
);
$fields[] = $this->dom->createElement(
'months', $pclass->getMonths()
);
$fields[] = $this->dom->createElement(
'startfee', $pclass->getStartFee()
);
$fields[] = $this->dom->createElement(
'invoicefee', $pclass->getInvoiceFee()
);
$fields[] = $this->dom->createElement(
'interestrate', $pclass->getInterestRate()
);
$fields[] = $this->dom->createElement(
'minamount', $pclass->getMinAmount()
);
$fields[] = $this->dom->createElement(
'country', $pclass->getCountry()
);
$fields[] = $this->dom->createElement(
'expire', $pclass->getExpire()
);
return $fields;
} | [
"protected",
"function",
"createFields",
"(",
"$",
"pclass",
")",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"//This is to prevent HTMLEntities to be converted to the real character.",
"$",
"fields",
"[",
"]",
"=",
"$",
"this",
"->",
"dom",
"->",
"createElement",
"(",
"'description'",
")",
";",
"end",
"(",
"$",
"fields",
")",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"dom",
"->",
"createTextNode",
"(",
"$",
"pclass",
"->",
"getDescription",
"(",
")",
")",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"this",
"->",
"dom",
"->",
"createElement",
"(",
"'months'",
",",
"$",
"pclass",
"->",
"getMonths",
"(",
")",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"this",
"->",
"dom",
"->",
"createElement",
"(",
"'startfee'",
",",
"$",
"pclass",
"->",
"getStartFee",
"(",
")",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"this",
"->",
"dom",
"->",
"createElement",
"(",
"'invoicefee'",
",",
"$",
"pclass",
"->",
"getInvoiceFee",
"(",
")",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"this",
"->",
"dom",
"->",
"createElement",
"(",
"'interestrate'",
",",
"$",
"pclass",
"->",
"getInterestRate",
"(",
")",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"this",
"->",
"dom",
"->",
"createElement",
"(",
"'minamount'",
",",
"$",
"pclass",
"->",
"getMinAmount",
"(",
")",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"this",
"->",
"dom",
"->",
"createElement",
"(",
"'country'",
",",
"$",
"pclass",
"->",
"getCountry",
"(",
")",
")",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"this",
"->",
"dom",
"->",
"createElement",
"(",
"'expire'",
",",
"$",
"pclass",
"->",
"getExpire",
"(",
")",
")",
";",
"return",
"$",
"fields",
";",
"}"
] | Creates DOMElement for all fields for specified PClass.
@param KlarnaPClass $pclass pclass object
@return array Array of DOMElements. | [
"Creates",
"DOMElement",
"for",
"all",
"fields",
"for",
"specified",
"PClass",
"."
] | 4a45ddd9ec444f5a6d02628ad65e635a3e12611c | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/pclasses/xmlstorage.class.php#L170-L202 | train |
n2n/n2n-io | src/app/n2n/io/img/ImageResource.php | ImageResource.watermark | public function watermark(ImageResource $watermark, $watermarkPos = 4, $watermarkMargin = 10) {
switch($watermarkPos) {
// center
case 0:
$watermarkdestX = $this->width/2 - $watermark->getWidth()/2;
$watermarkdestY = $this->height/2 - $watermark->getHeight()/2;
break;
// top left
case 1:
$watermarkdestX = $watermarkMargin;
$watermarkdestY = $watermarkMargin;
break;
// top right
case 2:
$watermarkdestX = $this->width - $watermark->getWidth() - $watermarkMargin;
$watermarkdestY = $watermarkMargin;
break;
// bottom left
case 3:
$watermarkdestX = $watermarkMargin;
$watermarkdestY = $this->height - $watermark->getHeight() - $watermarkMargin;
break;
// bottom right
case 4:
default:
$watermarkdestX = $this->width - $watermark->getWidth() - $watermarkMargin;
$watermarkdestY = $this->height - $watermark->getHeight() - $watermarkMargin;
break;
}
// set transparency true
imagealphablending($this->resource, true);
$watermarkRes = $watermark->getResource();
imagealphablending($watermarkRes, true);
imagecopy($this->resource, $watermarkRes, $watermarkdestX, $watermarkdestY, 0, 0, $watermark->getWidth(), $watermark->getHeight());
} | php | public function watermark(ImageResource $watermark, $watermarkPos = 4, $watermarkMargin = 10) {
switch($watermarkPos) {
// center
case 0:
$watermarkdestX = $this->width/2 - $watermark->getWidth()/2;
$watermarkdestY = $this->height/2 - $watermark->getHeight()/2;
break;
// top left
case 1:
$watermarkdestX = $watermarkMargin;
$watermarkdestY = $watermarkMargin;
break;
// top right
case 2:
$watermarkdestX = $this->width - $watermark->getWidth() - $watermarkMargin;
$watermarkdestY = $watermarkMargin;
break;
// bottom left
case 3:
$watermarkdestX = $watermarkMargin;
$watermarkdestY = $this->height - $watermark->getHeight() - $watermarkMargin;
break;
// bottom right
case 4:
default:
$watermarkdestX = $this->width - $watermark->getWidth() - $watermarkMargin;
$watermarkdestY = $this->height - $watermark->getHeight() - $watermarkMargin;
break;
}
// set transparency true
imagealphablending($this->resource, true);
$watermarkRes = $watermark->getResource();
imagealphablending($watermarkRes, true);
imagecopy($this->resource, $watermarkRes, $watermarkdestX, $watermarkdestY, 0, 0, $watermark->getWidth(), $watermark->getHeight());
} | [
"public",
"function",
"watermark",
"(",
"ImageResource",
"$",
"watermark",
",",
"$",
"watermarkPos",
"=",
"4",
",",
"$",
"watermarkMargin",
"=",
"10",
")",
"{",
"switch",
"(",
"$",
"watermarkPos",
")",
"{",
"// center\r",
"case",
"0",
":",
"$",
"watermarkdestX",
"=",
"$",
"this",
"->",
"width",
"/",
"2",
"-",
"$",
"watermark",
"->",
"getWidth",
"(",
")",
"/",
"2",
";",
"$",
"watermarkdestY",
"=",
"$",
"this",
"->",
"height",
"/",
"2",
"-",
"$",
"watermark",
"->",
"getHeight",
"(",
")",
"/",
"2",
";",
"break",
";",
"// top left\r",
"case",
"1",
":",
"$",
"watermarkdestX",
"=",
"$",
"watermarkMargin",
";",
"$",
"watermarkdestY",
"=",
"$",
"watermarkMargin",
";",
"break",
";",
"// top right\r",
"case",
"2",
":",
"$",
"watermarkdestX",
"=",
"$",
"this",
"->",
"width",
"-",
"$",
"watermark",
"->",
"getWidth",
"(",
")",
"-",
"$",
"watermarkMargin",
";",
"$",
"watermarkdestY",
"=",
"$",
"watermarkMargin",
";",
"break",
";",
"// bottom left\r",
"case",
"3",
":",
"$",
"watermarkdestX",
"=",
"$",
"watermarkMargin",
";",
"$",
"watermarkdestY",
"=",
"$",
"this",
"->",
"height",
"-",
"$",
"watermark",
"->",
"getHeight",
"(",
")",
"-",
"$",
"watermarkMargin",
";",
"break",
";",
"// bottom right\r",
"case",
"4",
":",
"default",
":",
"$",
"watermarkdestX",
"=",
"$",
"this",
"->",
"width",
"-",
"$",
"watermark",
"->",
"getWidth",
"(",
")",
"-",
"$",
"watermarkMargin",
";",
"$",
"watermarkdestY",
"=",
"$",
"this",
"->",
"height",
"-",
"$",
"watermark",
"->",
"getHeight",
"(",
")",
"-",
"$",
"watermarkMargin",
";",
"break",
";",
"}",
"// set transparency true\r",
"imagealphablending",
"(",
"$",
"this",
"->",
"resource",
",",
"true",
")",
";",
"$",
"watermarkRes",
"=",
"$",
"watermark",
"->",
"getResource",
"(",
")",
";",
"imagealphablending",
"(",
"$",
"watermarkRes",
",",
"true",
")",
";",
"imagecopy",
"(",
"$",
"this",
"->",
"resource",
",",
"$",
"watermarkRes",
",",
"$",
"watermarkdestX",
",",
"$",
"watermarkdestY",
",",
"0",
",",
"0",
",",
"$",
"watermark",
"->",
"getWidth",
"(",
")",
",",
"$",
"watermark",
"->",
"getHeight",
"(",
")",
")",
";",
"}"
] | adds a watermark to the image
@param ImageResource $watermark
@param int $watermarkPos
@param int $watermarkMargin | [
"adds",
"a",
"watermark",
"to",
"the",
"image"
] | ff642e195f0c0db1273b6c067eff1192cf2cd987 | https://github.com/n2n/n2n-io/blob/ff642e195f0c0db1273b6c067eff1192cf2cd987/src/app/n2n/io/img/ImageResource.php#L87-L122 | train |
WellCommerce/PaymentBundle | Client/Przelewy24.php | Przelewy24.trnRegister | public function trnRegister($redirect = false)
{
$crc = md5($this->postData["p24_session_id"]."|".$this->posId."|".$this->postData["p24_amount"]."|".$this->postData["p24_currency"]."|".$this->salt);
$this->addValue("p24_sign", $crc);
$RES = $this->callUrl("trnRegister", $this->postData);
if ($RES["error"] == "0") {
$token = $RES["token"];
} else {
return $RES;
}
if ($redirect) {
$this->trnRequest($token);
}
return ["error" => 0, "token" => $token];
} | php | public function trnRegister($redirect = false)
{
$crc = md5($this->postData["p24_session_id"]."|".$this->posId."|".$this->postData["p24_amount"]."|".$this->postData["p24_currency"]."|".$this->salt);
$this->addValue("p24_sign", $crc);
$RES = $this->callUrl("trnRegister", $this->postData);
if ($RES["error"] == "0") {
$token = $RES["token"];
} else {
return $RES;
}
if ($redirect) {
$this->trnRequest($token);
}
return ["error" => 0, "token" => $token];
} | [
"public",
"function",
"trnRegister",
"(",
"$",
"redirect",
"=",
"false",
")",
"{",
"$",
"crc",
"=",
"md5",
"(",
"$",
"this",
"->",
"postData",
"[",
"\"p24_session_id\"",
"]",
".",
"\"|\"",
".",
"$",
"this",
"->",
"posId",
".",
"\"|\"",
".",
"$",
"this",
"->",
"postData",
"[",
"\"p24_amount\"",
"]",
".",
"\"|\"",
".",
"$",
"this",
"->",
"postData",
"[",
"\"p24_currency\"",
"]",
".",
"\"|\"",
".",
"$",
"this",
"->",
"salt",
")",
";",
"$",
"this",
"->",
"addValue",
"(",
"\"p24_sign\"",
",",
"$",
"crc",
")",
";",
"$",
"RES",
"=",
"$",
"this",
"->",
"callUrl",
"(",
"\"trnRegister\"",
",",
"$",
"this",
"->",
"postData",
")",
";",
"if",
"(",
"$",
"RES",
"[",
"\"error\"",
"]",
"==",
"\"0\"",
")",
"{",
"$",
"token",
"=",
"$",
"RES",
"[",
"\"token\"",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"RES",
";",
"}",
"if",
"(",
"$",
"redirect",
")",
"{",
"$",
"this",
"->",
"trnRequest",
"(",
"$",
"token",
")",
";",
"}",
"return",
"[",
"\"error\"",
"=>",
"0",
",",
"\"token\"",
"=>",
"$",
"token",
"]",
";",
"}"
] | Prepare a transaction request
@param bool $redirect Set true to redirect to Przelewy24 after transaction registration
@return array array(INT Error code, STRING Token) | [
"Prepare",
"a",
"transaction",
"request"
] | 7fdeb0b5155646f2b638082d2135bec05eb8be98 | https://github.com/WellCommerce/PaymentBundle/blob/7fdeb0b5155646f2b638082d2135bec05eb8be98/Client/Przelewy24.php#L144-L168 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.