id
int32
0
241k
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
10,200
phlexible/task-bundle
Controller/TaskController.php
TaskController.commentAction
public function commentAction(Request $request) { $id = $request->get('id'); $comment = $request->get('comment'); if ($comment) { $comment = urldecode($comment); } $taskManager = $this->get('phlexible_task.task_manager'); $task = $taskManager->find($id); $taskManager->updateTask($task, $this->getUser(), null, null, $comment); return new ResultResponse(true, 'Task comment created.', array('task' => $this->serializeTask($task))); }
php
public function commentAction(Request $request) { $id = $request->get('id'); $comment = $request->get('comment'); if ($comment) { $comment = urldecode($comment); } $taskManager = $this->get('phlexible_task.task_manager'); $task = $taskManager->find($id); $taskManager->updateTask($task, $this->getUser(), null, null, $comment); return new ResultResponse(true, 'Task comment created.', array('task' => $this->serializeTask($task))); }
[ "public", "function", "commentAction", "(", "Request", "$", "request", ")", "{", "$", "id", "=", "$", "request", "->", "get", "(", "'id'", ")", ";", "$", "comment", "=", "$", "request", "->", "get", "(", "'comment'", ")", ";", "if", "(", "$", "comment", ")", "{", "$", "comment", "=", "urldecode", "(", "$", "comment", ")", ";", "}", "$", "taskManager", "=", "$", "this", "->", "get", "(", "'phlexible_task.task_manager'", ")", ";", "$", "task", "=", "$", "taskManager", "->", "find", "(", "$", "id", ")", ";", "$", "taskManager", "->", "updateTask", "(", "$", "task", ",", "$", "this", "->", "getUser", "(", ")", ",", "null", ",", "null", ",", "$", "comment", ")", ";", "return", "new", "ResultResponse", "(", "true", ",", "'Task comment created.'", ",", "array", "(", "'task'", "=>", "$", "this", "->", "serializeTask", "(", "$", "task", ")", ")", ")", ";", "}" ]
Create task comment. @param Request $request @return ResultResponse @Route("/create/comment", name="tasks_create_comment") @Method({"GET", "POST"}) @ApiDoc( description="Create status", requirements={ {"name"="id", "dataType"="string", "required"=true, "description"="Task ID"}, {"name"="comment", "dataType"="string", "required"=true, "description"="Comment"} } )
[ "Create", "task", "comment", "." ]
7f111ba992d40b30a1ae99ca4f06bcbed3fc6af2
https://github.com/phlexible/task-bundle/blob/7f111ba992d40b30a1ae99ca4f06bcbed3fc6af2/Controller/TaskController.php#L293-L308
10,201
phlexible/task-bundle
Controller/TaskController.php
TaskController.transitionAction
public function transitionAction(Request $request) { $id = $request->get('id'); $assignedUserId = $request->get('recipient'); $name = $request->get('name'); $comment = $request->get('comment'); if ($comment) { $comment = urldecode($comment); } $taskManager = $this->get('phlexible_task.task_manager'); $userManager = $this->get('phlexible_user.user_manager'); $assignUser = null; if ($assignedUserId) { $assignUser = $userManager->find($assignedUserId); } $task = $taskManager->find($id); $taskManager->updateTask($task, $this->getUser(), $name, $assignUser, $comment); return new ResultResponse(true, 'Task transition created.', array('task' => $this->serializeTask($task))); }
php
public function transitionAction(Request $request) { $id = $request->get('id'); $assignedUserId = $request->get('recipient'); $name = $request->get('name'); $comment = $request->get('comment'); if ($comment) { $comment = urldecode($comment); } $taskManager = $this->get('phlexible_task.task_manager'); $userManager = $this->get('phlexible_user.user_manager'); $assignUser = null; if ($assignedUserId) { $assignUser = $userManager->find($assignedUserId); } $task = $taskManager->find($id); $taskManager->updateTask($task, $this->getUser(), $name, $assignUser, $comment); return new ResultResponse(true, 'Task transition created.', array('task' => $this->serializeTask($task))); }
[ "public", "function", "transitionAction", "(", "Request", "$", "request", ")", "{", "$", "id", "=", "$", "request", "->", "get", "(", "'id'", ")", ";", "$", "assignedUserId", "=", "$", "request", "->", "get", "(", "'recipient'", ")", ";", "$", "name", "=", "$", "request", "->", "get", "(", "'name'", ")", ";", "$", "comment", "=", "$", "request", "->", "get", "(", "'comment'", ")", ";", "if", "(", "$", "comment", ")", "{", "$", "comment", "=", "urldecode", "(", "$", "comment", ")", ";", "}", "$", "taskManager", "=", "$", "this", "->", "get", "(", "'phlexible_task.task_manager'", ")", ";", "$", "userManager", "=", "$", "this", "->", "get", "(", "'phlexible_user.user_manager'", ")", ";", "$", "assignUser", "=", "null", ";", "if", "(", "$", "assignedUserId", ")", "{", "$", "assignUser", "=", "$", "userManager", "->", "find", "(", "$", "assignedUserId", ")", ";", "}", "$", "task", "=", "$", "taskManager", "->", "find", "(", "$", "id", ")", ";", "$", "taskManager", "->", "updateTask", "(", "$", "task", ",", "$", "this", "->", "getUser", "(", ")", ",", "$", "name", ",", "$", "assignUser", ",", "$", "comment", ")", ";", "return", "new", "ResultResponse", "(", "true", ",", "'Task transition created.'", ",", "array", "(", "'task'", "=>", "$", "this", "->", "serializeTask", "(", "$", "task", ")", ")", ")", ";", "}" ]
Create task transition. @param Request $request @return ResultResponse @Route("/create/transition", name="tasks_create_transition") @Method({"GET", "POST"}) @ApiDoc( description="Create status", requirements={ {"name"="id", "dataType"="string", "required"=true, "description"="Task ID"}, {"name"="recipient", "dataType"="string", "required"=false, "description"="Recipient"}, {"name"="name", "dataType"="string", "required"=true, "description"="Transition name"}, {"name"="comment", "dataType"="string", "required"=false, "description"="Comment"} } )
[ "Create", "task", "transition", "." ]
7f111ba992d40b30a1ae99ca4f06bcbed3fc6af2
https://github.com/phlexible/task-bundle/blob/7f111ba992d40b30a1ae99ca4f06bcbed3fc6af2/Controller/TaskController.php#L328-L351
10,202
phlexible/task-bundle
Controller/TaskController.php
TaskController.viewAction
public function viewAction(Request $request) { $id = $request->get('id'); $taskManager = $this->get('phlexible_task.task_manager'); $types = $this->get('phlexible_task.types'); $userManager = $this->get('phlexible_user.user_manager'); $task = $taskManager->find($id); $createUser = $userManager->find($task->getCreateUserId()); $assignedUser = $userManager->find($task->getAssignedUserId()); $transitions = []; foreach ($task->getTransitions() as $transition) { $transitionUser = $userManager->find($transition->getCreateUserId()); $history[] = [ 'create_date' => $transition->getCreatedAt()->format('Y-m-d H:i:s'), 'name' => $transitionUser->getDisplayName(), 'status' => $transition->getNewState(), 'latest' => 1, ]; } $transitions = array_reverse($transitions); $comments = []; foreach ($task->getComments() as $comment) { $commentUser = $userManager->find($comment->getCreateUserId()); $history[] = [ 'create_date' => $comment->getCreatedAt()->format('Y-m-d H:i:s'), 'name' => $commentUser->getDisplayName(), 'status' => $comment->getCurrentState(), 'comment' => $comment->getComment(), 'latest' => 1, ]; } $type = $types->get($task->getType()); $data = [ 'id' => $task->getId(), 'type' => $task->getType(), 'title' => $type->getTitle($task), 'text' => $type->getText($task), 'component' => $type->getComponent(), 'created' => $task->getCreateUserId() === $this->getUser()->getId() ? 1 : 0, 'assigned' => $task->getAssignedUserId() === $this->getUser()->getId() ? 1 : 0, 'assigned_user' => $assignedUser->getDisplayName(), 'assigned_uid' => $task->getAssignedUserId(), 'create_user' => $createUser->getDisplayName(), 'create_uid' => $task->getCreateUserId(), 'create_date' => $task->getCreatedAt()->format('Y-m-d H:i:s'), 'latest_status' => $task->getFiniteState(), 'latest_comment' => '', //$latestStatus->getComment(), 'latest_user' => '', //$assignedUser->getDisplayName(), 'latest_uid' => '', //$latestStatus->getCreateUserId(), 'latest_date' => '', //$latestStatus->getCreatedAt()->format('Y-m-d H:i:s'), //'recipient_uid' => $task->getRecipientUserId(), //'latest_id' => $latestStatus->getId(), 'transitions' => $transitions, 'comments' => $comments, ]; return new JsonResponse($data); }
php
public function viewAction(Request $request) { $id = $request->get('id'); $taskManager = $this->get('phlexible_task.task_manager'); $types = $this->get('phlexible_task.types'); $userManager = $this->get('phlexible_user.user_manager'); $task = $taskManager->find($id); $createUser = $userManager->find($task->getCreateUserId()); $assignedUser = $userManager->find($task->getAssignedUserId()); $transitions = []; foreach ($task->getTransitions() as $transition) { $transitionUser = $userManager->find($transition->getCreateUserId()); $history[] = [ 'create_date' => $transition->getCreatedAt()->format('Y-m-d H:i:s'), 'name' => $transitionUser->getDisplayName(), 'status' => $transition->getNewState(), 'latest' => 1, ]; } $transitions = array_reverse($transitions); $comments = []; foreach ($task->getComments() as $comment) { $commentUser = $userManager->find($comment->getCreateUserId()); $history[] = [ 'create_date' => $comment->getCreatedAt()->format('Y-m-d H:i:s'), 'name' => $commentUser->getDisplayName(), 'status' => $comment->getCurrentState(), 'comment' => $comment->getComment(), 'latest' => 1, ]; } $type = $types->get($task->getType()); $data = [ 'id' => $task->getId(), 'type' => $task->getType(), 'title' => $type->getTitle($task), 'text' => $type->getText($task), 'component' => $type->getComponent(), 'created' => $task->getCreateUserId() === $this->getUser()->getId() ? 1 : 0, 'assigned' => $task->getAssignedUserId() === $this->getUser()->getId() ? 1 : 0, 'assigned_user' => $assignedUser->getDisplayName(), 'assigned_uid' => $task->getAssignedUserId(), 'create_user' => $createUser->getDisplayName(), 'create_uid' => $task->getCreateUserId(), 'create_date' => $task->getCreatedAt()->format('Y-m-d H:i:s'), 'latest_status' => $task->getFiniteState(), 'latest_comment' => '', //$latestStatus->getComment(), 'latest_user' => '', //$assignedUser->getDisplayName(), 'latest_uid' => '', //$latestStatus->getCreateUserId(), 'latest_date' => '', //$latestStatus->getCreatedAt()->format('Y-m-d H:i:s'), //'recipient_uid' => $task->getRecipientUserId(), //'latest_id' => $latestStatus->getId(), 'transitions' => $transitions, 'comments' => $comments, ]; return new JsonResponse($data); }
[ "public", "function", "viewAction", "(", "Request", "$", "request", ")", "{", "$", "id", "=", "$", "request", "->", "get", "(", "'id'", ")", ";", "$", "taskManager", "=", "$", "this", "->", "get", "(", "'phlexible_task.task_manager'", ")", ";", "$", "types", "=", "$", "this", "->", "get", "(", "'phlexible_task.types'", ")", ";", "$", "userManager", "=", "$", "this", "->", "get", "(", "'phlexible_user.user_manager'", ")", ";", "$", "task", "=", "$", "taskManager", "->", "find", "(", "$", "id", ")", ";", "$", "createUser", "=", "$", "userManager", "->", "find", "(", "$", "task", "->", "getCreateUserId", "(", ")", ")", ";", "$", "assignedUser", "=", "$", "userManager", "->", "find", "(", "$", "task", "->", "getAssignedUserId", "(", ")", ")", ";", "$", "transitions", "=", "[", "]", ";", "foreach", "(", "$", "task", "->", "getTransitions", "(", ")", "as", "$", "transition", ")", "{", "$", "transitionUser", "=", "$", "userManager", "->", "find", "(", "$", "transition", "->", "getCreateUserId", "(", ")", ")", ";", "$", "history", "[", "]", "=", "[", "'create_date'", "=>", "$", "transition", "->", "getCreatedAt", "(", ")", "->", "format", "(", "'Y-m-d H:i:s'", ")", ",", "'name'", "=>", "$", "transitionUser", "->", "getDisplayName", "(", ")", ",", "'status'", "=>", "$", "transition", "->", "getNewState", "(", ")", ",", "'latest'", "=>", "1", ",", "]", ";", "}", "$", "transitions", "=", "array_reverse", "(", "$", "transitions", ")", ";", "$", "comments", "=", "[", "]", ";", "foreach", "(", "$", "task", "->", "getComments", "(", ")", "as", "$", "comment", ")", "{", "$", "commentUser", "=", "$", "userManager", "->", "find", "(", "$", "comment", "->", "getCreateUserId", "(", ")", ")", ";", "$", "history", "[", "]", "=", "[", "'create_date'", "=>", "$", "comment", "->", "getCreatedAt", "(", ")", "->", "format", "(", "'Y-m-d H:i:s'", ")", ",", "'name'", "=>", "$", "commentUser", "->", "getDisplayName", "(", ")", ",", "'status'", "=>", "$", "comment", "->", "getCurrentState", "(", ")", ",", "'comment'", "=>", "$", "comment", "->", "getComment", "(", ")", ",", "'latest'", "=>", "1", ",", "]", ";", "}", "$", "type", "=", "$", "types", "->", "get", "(", "$", "task", "->", "getType", "(", ")", ")", ";", "$", "data", "=", "[", "'id'", "=>", "$", "task", "->", "getId", "(", ")", ",", "'type'", "=>", "$", "task", "->", "getType", "(", ")", ",", "'title'", "=>", "$", "type", "->", "getTitle", "(", "$", "task", ")", ",", "'text'", "=>", "$", "type", "->", "getText", "(", "$", "task", ")", ",", "'component'", "=>", "$", "type", "->", "getComponent", "(", ")", ",", "'created'", "=>", "$", "task", "->", "getCreateUserId", "(", ")", "===", "$", "this", "->", "getUser", "(", ")", "->", "getId", "(", ")", "?", "1", ":", "0", ",", "'assigned'", "=>", "$", "task", "->", "getAssignedUserId", "(", ")", "===", "$", "this", "->", "getUser", "(", ")", "->", "getId", "(", ")", "?", "1", ":", "0", ",", "'assigned_user'", "=>", "$", "assignedUser", "->", "getDisplayName", "(", ")", ",", "'assigned_uid'", "=>", "$", "task", "->", "getAssignedUserId", "(", ")", ",", "'create_user'", "=>", "$", "createUser", "->", "getDisplayName", "(", ")", ",", "'create_uid'", "=>", "$", "task", "->", "getCreateUserId", "(", ")", ",", "'create_date'", "=>", "$", "task", "->", "getCreatedAt", "(", ")", "->", "format", "(", "'Y-m-d H:i:s'", ")", ",", "'latest_status'", "=>", "$", "task", "->", "getFiniteState", "(", ")", ",", "'latest_comment'", "=>", "''", ",", "//$latestStatus->getComment(),", "'latest_user'", "=>", "''", ",", "//$assignedUser->getDisplayName(),", "'latest_uid'", "=>", "''", ",", "//$latestStatus->getCreateUserId(),", "'latest_date'", "=>", "''", ",", "//$latestStatus->getCreatedAt()->format('Y-m-d H:i:s'),", "//'recipient_uid' => $task->getRecipientUserId(),", "//'latest_id' => $latestStatus->getId(),", "'transitions'", "=>", "$", "transitions", ",", "'comments'", "=>", "$", "comments", ",", "]", ";", "return", "new", "JsonResponse", "(", "$", "data", ")", ";", "}" ]
View task. @param Request $request @return JsonResponse @Route("/view", name="tasks_view") @Method({"GET", "POST"}) @ApiDoc( description="View", requirements={ {"name"="id", "dataType"="string", "required"=true, "description"="Task ID"} } )
[ "View", "task", "." ]
7f111ba992d40b30a1ae99ca4f06bcbed3fc6af2
https://github.com/phlexible/task-bundle/blob/7f111ba992d40b30a1ae99ca4f06bcbed3fc6af2/Controller/TaskController.php#L406-L470
10,203
agalbourdin/agl-core
src/Mvc/Controller/Controller.php
Controller._getCacheInfo
private function _getCacheInfo() { $request = Agl::getRequest(); $module = $request->getModule(); $view = $request->getView(); $action = $request->getAction(); $cacheInfo = array(); $cacheConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '#' . $view . '#action#' . $action . '/' . ConfigInterface::CONFIG_CACHE_NAME); if ($cacheConfig === NULL) { $cacheConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '#' . $view . '/' . ConfigInterface::CONFIG_CACHE_NAME); } if ($cacheConfig === NULL) { $cacheConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '/' . ConfigInterface::CONFIG_CACHE_NAME); } if ($cacheConfig === NULL) { $cacheConfig = Agl::app()->getConfig('core-layout/modules/' . ConfigInterface::CONFIG_CACHE_NAME); } if (is_array($cacheConfig)) { $configCacheTtlName = ConfigInterface::CONFIG_CACHE_TTL_NAME; $configCacheTypeName = ConfigInterface::CONFIG_CACHE_TYPE_NAME; $cacheInfo[$configCacheTtlName] = (isset($cacheConfig[$configCacheTtlName]) and ctype_digit($cacheConfig[$configCacheTtlName])) ? (int)$cacheConfig[$configCacheTtlName] : 0; $type = (isset($cacheConfig[$configCacheTypeName])) ? $cacheConfig[$configCacheTypeName] : ConfigInterface::CONFIG_CACHE_TYPE_STATIC; $cacheInfo[CacheInterface::CACHE_KEY] = ViewInterface::CACHE_FILE_PREFIX . $module . CacheInterface::CACHE_KEY_SEPARATOR . $view . CacheInterface::CACHE_KEY_SEPARATOR . $action; if (Agl::isModuleLoaded(Agl::AGL_MORE_POOL . '/locale/locale')) { $cacheInfo[CacheInterface::CACHE_KEY] .= CacheInterface::CACHE_KEY_SEPARATOR . Agl::getSingleton(Agl::AGL_MORE_POOL . '/locale')->getLanguage(); } if ($type == ConfigInterface::CONFIG_CACHE_TYPE_DYNAMIC) { $cacheInfo[CacheInterface::CACHE_KEY] .= CacheInterface::CACHE_KEY_SEPARATOR . StringData::rewrite($request->getReq()); if (Request::isAjax()) { $cacheInfo[CacheInterface::CACHE_KEY] .= CacheInterface::CACHE_KEY_SEPARATOR . ConfigInterface::CONFIG_CACHE_KEY_AJAX; } } } return $cacheInfo; }
php
private function _getCacheInfo() { $request = Agl::getRequest(); $module = $request->getModule(); $view = $request->getView(); $action = $request->getAction(); $cacheInfo = array(); $cacheConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '#' . $view . '#action#' . $action . '/' . ConfigInterface::CONFIG_CACHE_NAME); if ($cacheConfig === NULL) { $cacheConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '#' . $view . '/' . ConfigInterface::CONFIG_CACHE_NAME); } if ($cacheConfig === NULL) { $cacheConfig = Agl::app()->getConfig('core-layout/modules/' . $module . '/' . ConfigInterface::CONFIG_CACHE_NAME); } if ($cacheConfig === NULL) { $cacheConfig = Agl::app()->getConfig('core-layout/modules/' . ConfigInterface::CONFIG_CACHE_NAME); } if (is_array($cacheConfig)) { $configCacheTtlName = ConfigInterface::CONFIG_CACHE_TTL_NAME; $configCacheTypeName = ConfigInterface::CONFIG_CACHE_TYPE_NAME; $cacheInfo[$configCacheTtlName] = (isset($cacheConfig[$configCacheTtlName]) and ctype_digit($cacheConfig[$configCacheTtlName])) ? (int)$cacheConfig[$configCacheTtlName] : 0; $type = (isset($cacheConfig[$configCacheTypeName])) ? $cacheConfig[$configCacheTypeName] : ConfigInterface::CONFIG_CACHE_TYPE_STATIC; $cacheInfo[CacheInterface::CACHE_KEY] = ViewInterface::CACHE_FILE_PREFIX . $module . CacheInterface::CACHE_KEY_SEPARATOR . $view . CacheInterface::CACHE_KEY_SEPARATOR . $action; if (Agl::isModuleLoaded(Agl::AGL_MORE_POOL . '/locale/locale')) { $cacheInfo[CacheInterface::CACHE_KEY] .= CacheInterface::CACHE_KEY_SEPARATOR . Agl::getSingleton(Agl::AGL_MORE_POOL . '/locale')->getLanguage(); } if ($type == ConfigInterface::CONFIG_CACHE_TYPE_DYNAMIC) { $cacheInfo[CacheInterface::CACHE_KEY] .= CacheInterface::CACHE_KEY_SEPARATOR . StringData::rewrite($request->getReq()); if (Request::isAjax()) { $cacheInfo[CacheInterface::CACHE_KEY] .= CacheInterface::CACHE_KEY_SEPARATOR . ConfigInterface::CONFIG_CACHE_KEY_AJAX; } } } return $cacheInfo; }
[ "private", "function", "_getCacheInfo", "(", ")", "{", "$", "request", "=", "Agl", "::", "getRequest", "(", ")", ";", "$", "module", "=", "$", "request", "->", "getModule", "(", ")", ";", "$", "view", "=", "$", "request", "->", "getView", "(", ")", ";", "$", "action", "=", "$", "request", "->", "getAction", "(", ")", ";", "$", "cacheInfo", "=", "array", "(", ")", ";", "$", "cacheConfig", "=", "Agl", "::", "app", "(", ")", "->", "getConfig", "(", "'core-layout/modules/'", ".", "$", "module", ".", "'#'", ".", "$", "view", ".", "'#action#'", ".", "$", "action", ".", "'/'", ".", "ConfigInterface", "::", "CONFIG_CACHE_NAME", ")", ";", "if", "(", "$", "cacheConfig", "===", "NULL", ")", "{", "$", "cacheConfig", "=", "Agl", "::", "app", "(", ")", "->", "getConfig", "(", "'core-layout/modules/'", ".", "$", "module", ".", "'#'", ".", "$", "view", ".", "'/'", ".", "ConfigInterface", "::", "CONFIG_CACHE_NAME", ")", ";", "}", "if", "(", "$", "cacheConfig", "===", "NULL", ")", "{", "$", "cacheConfig", "=", "Agl", "::", "app", "(", ")", "->", "getConfig", "(", "'core-layout/modules/'", ".", "$", "module", ".", "'/'", ".", "ConfigInterface", "::", "CONFIG_CACHE_NAME", ")", ";", "}", "if", "(", "$", "cacheConfig", "===", "NULL", ")", "{", "$", "cacheConfig", "=", "Agl", "::", "app", "(", ")", "->", "getConfig", "(", "'core-layout/modules/'", ".", "ConfigInterface", "::", "CONFIG_CACHE_NAME", ")", ";", "}", "if", "(", "is_array", "(", "$", "cacheConfig", ")", ")", "{", "$", "configCacheTtlName", "=", "ConfigInterface", "::", "CONFIG_CACHE_TTL_NAME", ";", "$", "configCacheTypeName", "=", "ConfigInterface", "::", "CONFIG_CACHE_TYPE_NAME", ";", "$", "cacheInfo", "[", "$", "configCacheTtlName", "]", "=", "(", "isset", "(", "$", "cacheConfig", "[", "$", "configCacheTtlName", "]", ")", "and", "ctype_digit", "(", "$", "cacheConfig", "[", "$", "configCacheTtlName", "]", ")", ")", "?", "(", "int", ")", "$", "cacheConfig", "[", "$", "configCacheTtlName", "]", ":", "0", ";", "$", "type", "=", "(", "isset", "(", "$", "cacheConfig", "[", "$", "configCacheTypeName", "]", ")", ")", "?", "$", "cacheConfig", "[", "$", "configCacheTypeName", "]", ":", "ConfigInterface", "::", "CONFIG_CACHE_TYPE_STATIC", ";", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", "=", "ViewInterface", "::", "CACHE_FILE_PREFIX", ".", "$", "module", ".", "CacheInterface", "::", "CACHE_KEY_SEPARATOR", ".", "$", "view", ".", "CacheInterface", "::", "CACHE_KEY_SEPARATOR", ".", "$", "action", ";", "if", "(", "Agl", "::", "isModuleLoaded", "(", "Agl", "::", "AGL_MORE_POOL", ".", "'/locale/locale'", ")", ")", "{", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", ".=", "CacheInterface", "::", "CACHE_KEY_SEPARATOR", ".", "Agl", "::", "getSingleton", "(", "Agl", "::", "AGL_MORE_POOL", ".", "'/locale'", ")", "->", "getLanguage", "(", ")", ";", "}", "if", "(", "$", "type", "==", "ConfigInterface", "::", "CONFIG_CACHE_TYPE_DYNAMIC", ")", "{", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", ".=", "CacheInterface", "::", "CACHE_KEY_SEPARATOR", ".", "StringData", "::", "rewrite", "(", "$", "request", "->", "getReq", "(", ")", ")", ";", "if", "(", "Request", "::", "isAjax", "(", ")", ")", "{", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", ".=", "CacheInterface", "::", "CACHE_KEY_SEPARATOR", ".", "ConfigInterface", "::", "CONFIG_CACHE_KEY_AJAX", ";", "}", "}", "}", "return", "$", "cacheInfo", ";", "}" ]
Return a TTL and a cache key composed of the module, the view, the actions and of the locale code and the request string if required. @return array
[ "Return", "a", "TTL", "and", "a", "cache", "key", "composed", "of", "the", "module", "the", "view", "the", "actions", "and", "of", "the", "locale", "code", "and", "the", "request", "string", "if", "required", "." ]
1db556f9a49488aa9fab6887fefb7141a79ad97d
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mvc/Controller/Controller.php#L66-L118
10,204
agalbourdin/agl-core
src/Mvc/Controller/Controller.php
Controller._getView
protected function _getView() { if ($viewInstance = Registry::get('view')) { return $viewInstance; } $request = Agl::getRequest(); $module = $request->getModule(); $view = $request->getView(); $viewPath = APP_PATH . Agl::APP_PHP_DIR . ViewInterface::APP_PHP_DIR . DS . $module . DS . $view . Agl::PHP_EXT; if (file_exists($viewPath)) { $className = $module . ucfirst($view) . ViewInterface::APP_VIEW_SUFFIX; $viewInstance = Agl::getInstance($className); } else { $viewInstance = new View(); } $viewInstance->setFile($module . DS . $view); Registry::set('view', $viewInstance); return $viewInstance; }
php
protected function _getView() { if ($viewInstance = Registry::get('view')) { return $viewInstance; } $request = Agl::getRequest(); $module = $request->getModule(); $view = $request->getView(); $viewPath = APP_PATH . Agl::APP_PHP_DIR . ViewInterface::APP_PHP_DIR . DS . $module . DS . $view . Agl::PHP_EXT; if (file_exists($viewPath)) { $className = $module . ucfirst($view) . ViewInterface::APP_VIEW_SUFFIX; $viewInstance = Agl::getInstance($className); } else { $viewInstance = new View(); } $viewInstance->setFile($module . DS . $view); Registry::set('view', $viewInstance); return $viewInstance; }
[ "protected", "function", "_getView", "(", ")", "{", "if", "(", "$", "viewInstance", "=", "Registry", "::", "get", "(", "'view'", ")", ")", "{", "return", "$", "viewInstance", ";", "}", "$", "request", "=", "Agl", "::", "getRequest", "(", ")", ";", "$", "module", "=", "$", "request", "->", "getModule", "(", ")", ";", "$", "view", "=", "$", "request", "->", "getView", "(", ")", ";", "$", "viewPath", "=", "APP_PATH", ".", "Agl", "::", "APP_PHP_DIR", ".", "ViewInterface", "::", "APP_PHP_DIR", ".", "DS", ".", "$", "module", ".", "DS", ".", "$", "view", ".", "Agl", "::", "PHP_EXT", ";", "if", "(", "file_exists", "(", "$", "viewPath", ")", ")", "{", "$", "className", "=", "$", "module", ".", "ucfirst", "(", "$", "view", ")", ".", "ViewInterface", "::", "APP_VIEW_SUFFIX", ";", "$", "viewInstance", "=", "Agl", "::", "getInstance", "(", "$", "className", ")", ";", "}", "else", "{", "$", "viewInstance", "=", "new", "View", "(", ")", ";", "}", "$", "viewInstance", "->", "setFile", "(", "$", "module", ".", "DS", ".", "$", "view", ")", ";", "Registry", "::", "set", "(", "'view'", ",", "$", "viewInstance", ")", ";", "return", "$", "viewInstance", ";", "}" ]
Create and return the current view instance. @return mixed
[ "Create", "and", "return", "the", "current", "view", "instance", "." ]
1db556f9a49488aa9fab6887fefb7141a79ad97d
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mvc/Controller/Controller.php#L125-L156
10,205
agalbourdin/agl-core
src/Mvc/Controller/Controller.php
Controller._renderView
protected function _renderView() { $isCacheEnabled = Agl::app()->isCacheEnabled(); if ($isCacheEnabled) { $cacheInfo = $this->_getCacheInfo(); if (! empty($cacheInfo) and $cacheInstance = Agl::getCache() and $cacheInstance->has($cacheInfo[CacheInterface::CACHE_KEY])) { return $cacheInstance->get($cacheInfo[CacheInterface::CACHE_KEY]); } } $viewModel = $this->_getView(); $content = $viewModel ->startBuffer() ->render(); if ($isCacheEnabled and ! empty($cacheInfo)) { $cacheInstance->set($cacheInfo[CacheInterface::CACHE_KEY], $content, $cacheInfo[ConfigInterface::CONFIG_CACHE_TTL_NAME]); } return $content; }
php
protected function _renderView() { $isCacheEnabled = Agl::app()->isCacheEnabled(); if ($isCacheEnabled) { $cacheInfo = $this->_getCacheInfo(); if (! empty($cacheInfo) and $cacheInstance = Agl::getCache() and $cacheInstance->has($cacheInfo[CacheInterface::CACHE_KEY])) { return $cacheInstance->get($cacheInfo[CacheInterface::CACHE_KEY]); } } $viewModel = $this->_getView(); $content = $viewModel ->startBuffer() ->render(); if ($isCacheEnabled and ! empty($cacheInfo)) { $cacheInstance->set($cacheInfo[CacheInterface::CACHE_KEY], $content, $cacheInfo[ConfigInterface::CONFIG_CACHE_TTL_NAME]); } return $content; }
[ "protected", "function", "_renderView", "(", ")", "{", "$", "isCacheEnabled", "=", "Agl", "::", "app", "(", ")", "->", "isCacheEnabled", "(", ")", ";", "if", "(", "$", "isCacheEnabled", ")", "{", "$", "cacheInfo", "=", "$", "this", "->", "_getCacheInfo", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "cacheInfo", ")", "and", "$", "cacheInstance", "=", "Agl", "::", "getCache", "(", ")", "and", "$", "cacheInstance", "->", "has", "(", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", ")", ")", "{", "return", "$", "cacheInstance", "->", "get", "(", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", ")", ";", "}", "}", "$", "viewModel", "=", "$", "this", "->", "_getView", "(", ")", ";", "$", "content", "=", "$", "viewModel", "->", "startBuffer", "(", ")", "->", "render", "(", ")", ";", "if", "(", "$", "isCacheEnabled", "and", "!", "empty", "(", "$", "cacheInfo", ")", ")", "{", "$", "cacheInstance", "->", "set", "(", "$", "cacheInfo", "[", "CacheInterface", "::", "CACHE_KEY", "]", ",", "$", "content", ",", "$", "cacheInfo", "[", "ConfigInterface", "::", "CONFIG_CACHE_TTL_NAME", "]", ")", ";", "}", "return", "$", "content", ";", "}" ]
Render the view page. @return Controller
[ "Render", "the", "view", "page", "." ]
1db556f9a49488aa9fab6887fefb7141a79ad97d
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Mvc/Controller/Controller.php#L163-L188
10,206
sebastianmonzel/webfiles-framework-php
source/core/datasystem/database/MDatabaseTable.php
MDatabaseTable.addColumn
public function addColumn($name, $type, $length = null) { $column = new MDatabaseTableColumn($name, $type, $length); array_push($this->columns, $column); }
php
public function addColumn($name, $type, $length = null) { $column = new MDatabaseTableColumn($name, $type, $length); array_push($this->columns, $column); }
[ "public", "function", "addColumn", "(", "$", "name", ",", "$", "type", ",", "$", "length", "=", "null", ")", "{", "$", "column", "=", "new", "MDatabaseTableColumn", "(", "$", "name", ",", "$", "type", ",", "$", "length", ")", ";", "array_push", "(", "$", "this", "->", "columns", ",", "$", "column", ")", ";", "}" ]
Adds a new column to the actual database representation. @param string $name @param string $type @param int $length
[ "Adds", "a", "new", "column", "to", "the", "actual", "database", "representation", "." ]
5ac1fc99e8e9946080e3ba877b2320cd6a3e5b5d
https://github.com/sebastianmonzel/webfiles-framework-php/blob/5ac1fc99e8e9946080e3ba877b2320cd6a3e5b5d/source/core/datasystem/database/MDatabaseTable.php#L106-L110
10,207
broeser/wellid
src/ValidatableTrait.php
ValidatableTrait.validate
public function validate() { if($this instanceof Cache\CacheableValidatableInterface && $this->isValidationCacheEnabled() && $this->lastValidationResult instanceof ValidationResultSet) { return $this->lastValidationResult; } $validationResultSet = $this->validateValue($this->getValue()); if($this instanceof Cache\CacheableValidatableInterface && $this->isValidationCacheEnabled()) { $this->lastValidationResult = $validationResultSet; } return $validationResultSet; }
php
public function validate() { if($this instanceof Cache\CacheableValidatableInterface && $this->isValidationCacheEnabled() && $this->lastValidationResult instanceof ValidationResultSet) { return $this->lastValidationResult; } $validationResultSet = $this->validateValue($this->getValue()); if($this instanceof Cache\CacheableValidatableInterface && $this->isValidationCacheEnabled()) { $this->lastValidationResult = $validationResultSet; } return $validationResultSet; }
[ "public", "function", "validate", "(", ")", "{", "if", "(", "$", "this", "instanceof", "Cache", "\\", "CacheableValidatableInterface", "&&", "$", "this", "->", "isValidationCacheEnabled", "(", ")", "&&", "$", "this", "->", "lastValidationResult", "instanceof", "ValidationResultSet", ")", "{", "return", "$", "this", "->", "lastValidationResult", ";", "}", "$", "validationResultSet", "=", "$", "this", "->", "validateValue", "(", "$", "this", "->", "getValue", "(", ")", ")", ";", "if", "(", "$", "this", "instanceof", "Cache", "\\", "CacheableValidatableInterface", "&&", "$", "this", "->", "isValidationCacheEnabled", "(", ")", ")", "{", "$", "this", "->", "lastValidationResult", "=", "$", "validationResultSet", ";", "}", "return", "$", "validationResultSet", ";", "}" ]
Validates this against all given Validators @return ValidationResultSet
[ "Validates", "this", "against", "all", "given", "Validators" ]
0de2e6119382530221f4f7285158f19d45c78704
https://github.com/broeser/wellid/blob/0de2e6119382530221f4f7285158f19d45c78704/src/ValidatableTrait.php#L42-L54
10,208
Opifer/RulesEngineBundle
Provider/EntityProvider.php
EntityProvider.getEntity
protected function getEntity(Rule $rule) { if ($rule instanceof RuleSet) { foreach ($rule->getChildren() as $child) { return $child->getEntity(); } throw new \Exception(sprintf('The rule %s and non of its children have an entity', get_class($rule))); } return $rule->getEntity(); }
php
protected function getEntity(Rule $rule) { if ($rule instanceof RuleSet) { foreach ($rule->getChildren() as $child) { return $child->getEntity(); } throw new \Exception(sprintf('The rule %s and non of its children have an entity', get_class($rule))); } return $rule->getEntity(); }
[ "protected", "function", "getEntity", "(", "Rule", "$", "rule", ")", "{", "if", "(", "$", "rule", "instanceof", "RuleSet", ")", "{", "foreach", "(", "$", "rule", "->", "getChildren", "(", ")", "as", "$", "child", ")", "{", "return", "$", "child", "->", "getEntity", "(", ")", ";", "}", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'The rule %s and non of its children have an entity'", ",", "get_class", "(", "$", "rule", ")", ")", ")", ";", "}", "return", "$", "rule", "->", "getEntity", "(", ")", ";", "}" ]
Get the entity from the passed rule @param Rule $rule
[ "Get", "the", "entity", "from", "the", "passed", "rule" ]
a7975576d4e3203b1af6614369840c30b1af2312
https://github.com/Opifer/RulesEngineBundle/blob/a7975576d4e3203b1af6614369840c30b1af2312/Provider/EntityProvider.php#L116-L127
10,209
Opifer/RulesEngineBundle
Provider/EntityProvider.php
EntityProvider.setQueryParams
public function setQueryParams($id, $params = []) { $requestQuery = $this->request->query->get('query_id'); if(isset($requestQuery[$id])) { $paramsQuery = $requestQuery[$id]; } elseif(isset($params['query'])) { $paramsQuery = $params['query']; } else { $paramsQuery = []; } $query = array_merge([ 'limit' => null, 'offset' => null, 'orderby' => null, 'order' => null ], $paramsQuery); if($query['offset'] !== null && $query['offset'] >= $this->paramDefaults['offset']) { $this->qb->setFirstResult($query['offset']); } if($query['limit'] !== null && $query['limit'] >= $this->paramDefaults['limit']) { $this->qb->setMaxResults($query['limit']); } if(in_array($query['orderby'], $this->paramDefaults['orderby'])) { $order = in_array(strtoupper($query['order']), $this->paramDefaults['order']) ? $query['order'] : $this->paramDefaults['order'][0]; $this->qb->orderBy('a.'.Inflector::camelize($query['orderby']), strtoupper($order)); } }
php
public function setQueryParams($id, $params = []) { $requestQuery = $this->request->query->get('query_id'); if(isset($requestQuery[$id])) { $paramsQuery = $requestQuery[$id]; } elseif(isset($params['query'])) { $paramsQuery = $params['query']; } else { $paramsQuery = []; } $query = array_merge([ 'limit' => null, 'offset' => null, 'orderby' => null, 'order' => null ], $paramsQuery); if($query['offset'] !== null && $query['offset'] >= $this->paramDefaults['offset']) { $this->qb->setFirstResult($query['offset']); } if($query['limit'] !== null && $query['limit'] >= $this->paramDefaults['limit']) { $this->qb->setMaxResults($query['limit']); } if(in_array($query['orderby'], $this->paramDefaults['orderby'])) { $order = in_array(strtoupper($query['order']), $this->paramDefaults['order']) ? $query['order'] : $this->paramDefaults['order'][0]; $this->qb->orderBy('a.'.Inflector::camelize($query['orderby']), strtoupper($order)); } }
[ "public", "function", "setQueryParams", "(", "$", "id", ",", "$", "params", "=", "[", "]", ")", "{", "$", "requestQuery", "=", "$", "this", "->", "request", "->", "query", "->", "get", "(", "'query_id'", ")", ";", "if", "(", "isset", "(", "$", "requestQuery", "[", "$", "id", "]", ")", ")", "{", "$", "paramsQuery", "=", "$", "requestQuery", "[", "$", "id", "]", ";", "}", "elseif", "(", "isset", "(", "$", "params", "[", "'query'", "]", ")", ")", "{", "$", "paramsQuery", "=", "$", "params", "[", "'query'", "]", ";", "}", "else", "{", "$", "paramsQuery", "=", "[", "]", ";", "}", "$", "query", "=", "array_merge", "(", "[", "'limit'", "=>", "null", ",", "'offset'", "=>", "null", ",", "'orderby'", "=>", "null", ",", "'order'", "=>", "null", "]", ",", "$", "paramsQuery", ")", ";", "if", "(", "$", "query", "[", "'offset'", "]", "!==", "null", "&&", "$", "query", "[", "'offset'", "]", ">=", "$", "this", "->", "paramDefaults", "[", "'offset'", "]", ")", "{", "$", "this", "->", "qb", "->", "setFirstResult", "(", "$", "query", "[", "'offset'", "]", ")", ";", "}", "if", "(", "$", "query", "[", "'limit'", "]", "!==", "null", "&&", "$", "query", "[", "'limit'", "]", ">=", "$", "this", "->", "paramDefaults", "[", "'limit'", "]", ")", "{", "$", "this", "->", "qb", "->", "setMaxResults", "(", "$", "query", "[", "'limit'", "]", ")", ";", "}", "if", "(", "in_array", "(", "$", "query", "[", "'orderby'", "]", ",", "$", "this", "->", "paramDefaults", "[", "'orderby'", "]", ")", ")", "{", "$", "order", "=", "in_array", "(", "strtoupper", "(", "$", "query", "[", "'order'", "]", ")", ",", "$", "this", "->", "paramDefaults", "[", "'order'", "]", ")", "?", "$", "query", "[", "'order'", "]", ":", "$", "this", "->", "paramDefaults", "[", "'order'", "]", "[", "0", "]", ";", "$", "this", "->", "qb", "->", "orderBy", "(", "'a.'", ".", "Inflector", "::", "camelize", "(", "$", "query", "[", "'orderby'", "]", ")", ",", "strtoupper", "(", "$", "order", ")", ")", ";", "}", "}" ]
Update query builder to include additional parameters @param integer $id @param array $params
[ "Update", "query", "builder", "to", "include", "additional", "parameters" ]
a7975576d4e3203b1af6614369840c30b1af2312
https://github.com/Opifer/RulesEngineBundle/blob/a7975576d4e3203b1af6614369840c30b1af2312/Provider/EntityProvider.php#L135-L167
10,210
razielsd/webdriverlib
WebDriver/WebDriver/Exception/Protocol.php
WebDriver_Exception_Protocol.getCommandDescription
public static function getCommandDescription(WebDriver_Command $command) { $commandDescriptionList = [ "Command: {$command->getCommandName()}", "Method: {$command->getMethod()}", "URL: {$command->getUrl()}" ]; $paramList = $command->getParameters(); if (!empty($paramList)) { $commandDescriptionList = array_merge( $commandDescriptionList, ["Parameters:", var_export($paramList, true)] ); } return implode("\n", $commandDescriptionList); }
php
public static function getCommandDescription(WebDriver_Command $command) { $commandDescriptionList = [ "Command: {$command->getCommandName()}", "Method: {$command->getMethod()}", "URL: {$command->getUrl()}" ]; $paramList = $command->getParameters(); if (!empty($paramList)) { $commandDescriptionList = array_merge( $commandDescriptionList, ["Parameters:", var_export($paramList, true)] ); } return implode("\n", $commandDescriptionList); }
[ "public", "static", "function", "getCommandDescription", "(", "WebDriver_Command", "$", "command", ")", "{", "$", "commandDescriptionList", "=", "[", "\"Command: {$command->getCommandName()}\"", ",", "\"Method: {$command->getMethod()}\"", ",", "\"URL: {$command->getUrl()}\"", "]", ";", "$", "paramList", "=", "$", "command", "->", "getParameters", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "paramList", ")", ")", "{", "$", "commandDescriptionList", "=", "array_merge", "(", "$", "commandDescriptionList", ",", "[", "\"Parameters:\"", ",", "var_export", "(", "$", "paramList", ",", "true", ")", "]", ")", ";", "}", "return", "implode", "(", "\"\\n\"", ",", "$", "commandDescriptionList", ")", ";", "}" ]
Returns webdriver command description. @param WebDriver_Command $command @return string
[ "Returns", "webdriver", "command", "description", "." ]
e498afc36a8cdeab5b6ca95016420557baf32f36
https://github.com/razielsd/webdriverlib/blob/e498afc36a8cdeab5b6ca95016420557baf32f36/WebDriver/WebDriver/Exception/Protocol.php#L35-L50
10,211
razielsd/webdriverlib
WebDriver/WebDriver/Exception/Protocol.php
WebDriver_Exception_Protocol.factory
public static function factory(WebDriver_Command $command, array $infoList = [], $rawResponse = null) { $httpStatusCode = isset($infoList['http_code']) ? $infoList['http_code'] : 0; switch ($httpStatusCode) { case WebDriver_Http::CLIENT_ERROR_NOT_FOUND: case WebDriver_Http::SERVER_ERROR_NOT_IMPLEMENTED: case WebDriver_Http::CLIENT_ERROR_METHOD_NOT_ALLOWED: case WebDriver_Http::CLIENT_ERROR_BAD_REQUEST: return WebDriver_Exception_InvalidRequest::factory($command, $infoList, $rawResponse); case WebDriver_Http::SERVER_ERROR_INTERNAL: $decodedJsonList = json_decode($rawResponse, true); $messageList = ["Internal Server Error"]; if ($decodedJsonList === null) { $messageList[] = "Cant decode response JSON:"; $messageList[] = json_last_error_msg(); $messageList[] = $rawResponse; $exception = new WebDriver_Exception_Protocol(implode("\n", $messageList)); $exception->httpStatusCode = $httpStatusCode; return $exception; } $exception = WebDriver_Exception_FailedCommand::factory( $command, $infoList, $rawResponse, $decodedJsonList ); $exception->httpStatusCode = $httpStatusCode; return $exception; default: $messageList = [ "Unknown error: {$httpStatusCode}", $rawResponse, static::getCommandDescription($command) ]; $exception = new WebDriver_Exception_Protocol(implode("\n", $messageList)); $exception->httpStatusCode = $httpStatusCode; return $exception; } }
php
public static function factory(WebDriver_Command $command, array $infoList = [], $rawResponse = null) { $httpStatusCode = isset($infoList['http_code']) ? $infoList['http_code'] : 0; switch ($httpStatusCode) { case WebDriver_Http::CLIENT_ERROR_NOT_FOUND: case WebDriver_Http::SERVER_ERROR_NOT_IMPLEMENTED: case WebDriver_Http::CLIENT_ERROR_METHOD_NOT_ALLOWED: case WebDriver_Http::CLIENT_ERROR_BAD_REQUEST: return WebDriver_Exception_InvalidRequest::factory($command, $infoList, $rawResponse); case WebDriver_Http::SERVER_ERROR_INTERNAL: $decodedJsonList = json_decode($rawResponse, true); $messageList = ["Internal Server Error"]; if ($decodedJsonList === null) { $messageList[] = "Cant decode response JSON:"; $messageList[] = json_last_error_msg(); $messageList[] = $rawResponse; $exception = new WebDriver_Exception_Protocol(implode("\n", $messageList)); $exception->httpStatusCode = $httpStatusCode; return $exception; } $exception = WebDriver_Exception_FailedCommand::factory( $command, $infoList, $rawResponse, $decodedJsonList ); $exception->httpStatusCode = $httpStatusCode; return $exception; default: $messageList = [ "Unknown error: {$httpStatusCode}", $rawResponse, static::getCommandDescription($command) ]; $exception = new WebDriver_Exception_Protocol(implode("\n", $messageList)); $exception->httpStatusCode = $httpStatusCode; return $exception; } }
[ "public", "static", "function", "factory", "(", "WebDriver_Command", "$", "command", ",", "array", "$", "infoList", "=", "[", "]", ",", "$", "rawResponse", "=", "null", ")", "{", "$", "httpStatusCode", "=", "isset", "(", "$", "infoList", "[", "'http_code'", "]", ")", "?", "$", "infoList", "[", "'http_code'", "]", ":", "0", ";", "switch", "(", "$", "httpStatusCode", ")", "{", "case", "WebDriver_Http", "::", "CLIENT_ERROR_NOT_FOUND", ":", "case", "WebDriver_Http", "::", "SERVER_ERROR_NOT_IMPLEMENTED", ":", "case", "WebDriver_Http", "::", "CLIENT_ERROR_METHOD_NOT_ALLOWED", ":", "case", "WebDriver_Http", "::", "CLIENT_ERROR_BAD_REQUEST", ":", "return", "WebDriver_Exception_InvalidRequest", "::", "factory", "(", "$", "command", ",", "$", "infoList", ",", "$", "rawResponse", ")", ";", "case", "WebDriver_Http", "::", "SERVER_ERROR_INTERNAL", ":", "$", "decodedJsonList", "=", "json_decode", "(", "$", "rawResponse", ",", "true", ")", ";", "$", "messageList", "=", "[", "\"Internal Server Error\"", "]", ";", "if", "(", "$", "decodedJsonList", "===", "null", ")", "{", "$", "messageList", "[", "]", "=", "\"Cant decode response JSON:\"", ";", "$", "messageList", "[", "]", "=", "json_last_error_msg", "(", ")", ";", "$", "messageList", "[", "]", "=", "$", "rawResponse", ";", "$", "exception", "=", "new", "WebDriver_Exception_Protocol", "(", "implode", "(", "\"\\n\"", ",", "$", "messageList", ")", ")", ";", "$", "exception", "->", "httpStatusCode", "=", "$", "httpStatusCode", ";", "return", "$", "exception", ";", "}", "$", "exception", "=", "WebDriver_Exception_FailedCommand", "::", "factory", "(", "$", "command", ",", "$", "infoList", ",", "$", "rawResponse", ",", "$", "decodedJsonList", ")", ";", "$", "exception", "->", "httpStatusCode", "=", "$", "httpStatusCode", ";", "return", "$", "exception", ";", "default", ":", "$", "messageList", "=", "[", "\"Unknown error: {$httpStatusCode}\"", ",", "$", "rawResponse", ",", "static", "::", "getCommandDescription", "(", "$", "command", ")", "]", ";", "$", "exception", "=", "new", "WebDriver_Exception_Protocol", "(", "implode", "(", "\"\\n\"", ",", "$", "messageList", ")", ")", ";", "$", "exception", "->", "httpStatusCode", "=", "$", "httpStatusCode", ";", "return", "$", "exception", ";", "}", "}" ]
Factory for protocol errors. @param WebDriver_Command $command @param array $infoList @param null|string $rawResponse @return static
[ "Factory", "for", "protocol", "errors", "." ]
e498afc36a8cdeab5b6ca95016420557baf32f36
https://github.com/razielsd/webdriverlib/blob/e498afc36a8cdeab5b6ca95016420557baf32f36/WebDriver/WebDriver/Exception/Protocol.php#L61-L99
10,212
InnoGr/FivePercent-Api
src/Doc/Formatter/JsonRpc/JsonRpcFormatter.php
JsonRpcFormatter.formatActionResponseProperty
public function formatActionResponseProperty(ResponseProperty $responseProperty) { $info = [ 'name' => $responseProperty->getName(), 'type' => $responseProperty->getType(), 'description' => $responseProperty->getDescription() ]; if ($responseProperty->isObject() || $responseProperty->isCollection()) { foreach ($responseProperty->getChild() as $resProperty) { $info['properties'][$resProperty->getName()] = $this->formatActionResponseProperty($resProperty); } } return $info; }
php
public function formatActionResponseProperty(ResponseProperty $responseProperty) { $info = [ 'name' => $responseProperty->getName(), 'type' => $responseProperty->getType(), 'description' => $responseProperty->getDescription() ]; if ($responseProperty->isObject() || $responseProperty->isCollection()) { foreach ($responseProperty->getChild() as $resProperty) { $info['properties'][$resProperty->getName()] = $this->formatActionResponseProperty($resProperty); } } return $info; }
[ "public", "function", "formatActionResponseProperty", "(", "ResponseProperty", "$", "responseProperty", ")", "{", "$", "info", "=", "[", "'name'", "=>", "$", "responseProperty", "->", "getName", "(", ")", ",", "'type'", "=>", "$", "responseProperty", "->", "getType", "(", ")", ",", "'description'", "=>", "$", "responseProperty", "->", "getDescription", "(", ")", "]", ";", "if", "(", "$", "responseProperty", "->", "isObject", "(", ")", "||", "$", "responseProperty", "->", "isCollection", "(", ")", ")", "{", "foreach", "(", "$", "responseProperty", "->", "getChild", "(", ")", "as", "$", "resProperty", ")", "{", "$", "info", "[", "'properties'", "]", "[", "$", "resProperty", "->", "getName", "(", ")", "]", "=", "$", "this", "->", "formatActionResponseProperty", "(", "$", "resProperty", ")", ";", "}", "}", "return", "$", "info", ";", "}" ]
Format action response property @param ResponseProperty $responseProperty @return array
[ "Format", "action", "response", "property" ]
57b78ddc3c9d91a7139c276711e5792824ceab9c
https://github.com/InnoGr/FivePercent-Api/blob/57b78ddc3c9d91a7139c276711e5792824ceab9c/src/Doc/Formatter/JsonRpc/JsonRpcFormatter.php#L108-L123
10,213
hametuha/hametwoo
src/Hametuha/HametWoo/Utility/OrderHandler.php
OrderHandler.restore_stock
public static function restore_stock( $order ) { $order = wc_get_order( $order ); if ( ! $order || 'yes' !== get_option( 'woocommerce_manage_stock' ) || ! apply_filters( 'woocommerce_can_reduce_order_stock', true, $order ) || 1 > count( $order->get_items() ) ) { // No item to restore. return false; } $restored = false; foreach ( $order->get_items( 'line_item' ) as $item ) { /* @var \WC_Order_Item_Product $item Order item. */ $qty = $item->get_quantity(); $product = $item->get_product(); if ( ! $qty || ! $product || ! $product->managing_stock() ) { continue; } $name = $product->get_formatted_name(); $current_stock = $product->get_stock_quantity(); $new_stock = wc_update_product_stock( $product, $qty, 'increase' ); if ( ! $new_stock ) { // Oops, failed to update stock. continue; } // Add order note. // translators: %1$s item name, %2$d current stock quantity, %3$d new stock quantity. $order->add_order_note( sprintf( __( '%1$s stock increased from %2$d to %3$d.', 'hametwoo' ), $name, $current_stock, $new_stock ) ); $restored = true; } return $restored; }
php
public static function restore_stock( $order ) { $order = wc_get_order( $order ); if ( ! $order || 'yes' !== get_option( 'woocommerce_manage_stock' ) || ! apply_filters( 'woocommerce_can_reduce_order_stock', true, $order ) || 1 > count( $order->get_items() ) ) { // No item to restore. return false; } $restored = false; foreach ( $order->get_items( 'line_item' ) as $item ) { /* @var \WC_Order_Item_Product $item Order item. */ $qty = $item->get_quantity(); $product = $item->get_product(); if ( ! $qty || ! $product || ! $product->managing_stock() ) { continue; } $name = $product->get_formatted_name(); $current_stock = $product->get_stock_quantity(); $new_stock = wc_update_product_stock( $product, $qty, 'increase' ); if ( ! $new_stock ) { // Oops, failed to update stock. continue; } // Add order note. // translators: %1$s item name, %2$d current stock quantity, %3$d new stock quantity. $order->add_order_note( sprintf( __( '%1$s stock increased from %2$d to %3$d.', 'hametwoo' ), $name, $current_stock, $new_stock ) ); $restored = true; } return $restored; }
[ "public", "static", "function", "restore_stock", "(", "$", "order", ")", "{", "$", "order", "=", "wc_get_order", "(", "$", "order", ")", ";", "if", "(", "!", "$", "order", "||", "'yes'", "!==", "get_option", "(", "'woocommerce_manage_stock'", ")", "||", "!", "apply_filters", "(", "'woocommerce_can_reduce_order_stock'", ",", "true", ",", "$", "order", ")", "||", "1", ">", "count", "(", "$", "order", "->", "get_items", "(", ")", ")", ")", "{", "// No item to restore.", "return", "false", ";", "}", "$", "restored", "=", "false", ";", "foreach", "(", "$", "order", "->", "get_items", "(", "'line_item'", ")", "as", "$", "item", ")", "{", "/* @var \\WC_Order_Item_Product $item Order item. */", "$", "qty", "=", "$", "item", "->", "get_quantity", "(", ")", ";", "$", "product", "=", "$", "item", "->", "get_product", "(", ")", ";", "if", "(", "!", "$", "qty", "||", "!", "$", "product", "||", "!", "$", "product", "->", "managing_stock", "(", ")", ")", "{", "continue", ";", "}", "$", "name", "=", "$", "product", "->", "get_formatted_name", "(", ")", ";", "$", "current_stock", "=", "$", "product", "->", "get_stock_quantity", "(", ")", ";", "$", "new_stock", "=", "wc_update_product_stock", "(", "$", "product", ",", "$", "qty", ",", "'increase'", ")", ";", "if", "(", "!", "$", "new_stock", ")", "{", "// Oops, failed to update stock.", "continue", ";", "}", "// Add order note.", "// translators: %1$s item name, %2$d current stock quantity, %3$d new stock quantity.", "$", "order", "->", "add_order_note", "(", "sprintf", "(", "__", "(", "'%1$s stock increased from %2$d to %3$d.'", ",", "'hametwoo'", ")", ",", "$", "name", ",", "$", "current_stock", ",", "$", "new_stock", ")", ")", ";", "$", "restored", "=", "true", ";", "}", "return", "$", "restored", ";", "}" ]
Restore stock. @param int|\WC_Order|null $order Order object. @return bool
[ "Restore", "stock", "." ]
bcd5948ea53d6ca2181873a9f9d0d221c346592e
https://github.com/hametuha/hametwoo/blob/bcd5948ea53d6ca2181873a9f9d0d221c346592e/src/Hametuha/HametWoo/Utility/OrderHandler.php#L20-L52
10,214
Daveawb/Repos
src/Repository.php
Repository.create
public function create($data, $flush = self::FLUSH) { if ($flush === self::FLUSH) { $this->flushModel(); } if (is_callable($data)) { $model = $this->model; call_user_func($data, $model); $model->push(); } else { $model = $this->model->create($data); } return $model; }
php
public function create($data, $flush = self::FLUSH) { if ($flush === self::FLUSH) { $this->flushModel(); } if (is_callable($data)) { $model = $this->model; call_user_func($data, $model); $model->push(); } else { $model = $this->model->create($data); } return $model; }
[ "public", "function", "create", "(", "$", "data", ",", "$", "flush", "=", "self", "::", "FLUSH", ")", "{", "if", "(", "$", "flush", "===", "self", "::", "FLUSH", ")", "{", "$", "this", "->", "flushModel", "(", ")", ";", "}", "if", "(", "is_callable", "(", "$", "data", ")", ")", "{", "$", "model", "=", "$", "this", "->", "model", ";", "call_user_func", "(", "$", "data", ",", "$", "model", ")", ";", "$", "model", "->", "push", "(", ")", ";", "}", "else", "{", "$", "model", "=", "$", "this", "->", "model", "->", "create", "(", "$", "data", ")", ";", "}", "return", "$", "model", ";", "}" ]
Persist a new set of data @param array|callable $data @param int $flush @return Model|Builder
[ "Persist", "a", "new", "set", "of", "data" ]
f11ab47bec71becf894265cb607779fae67261bb
https://github.com/Daveawb/Repos/blob/f11ab47bec71becf894265cb607779fae67261bb/src/Repository.php#L127-L144
10,215
Daveawb/Repos
src/Repository.php
Repository.updateModel
public function updateModel(array $data, Model $model) { $model = $model->fill($data); return $model->isDirty() && $model->update($data); }
php
public function updateModel(array $data, Model $model) { $model = $model->fill($data); return $model->isDirty() && $model->update($data); }
[ "public", "function", "updateModel", "(", "array", "$", "data", ",", "Model", "$", "model", ")", "{", "$", "model", "=", "$", "model", "->", "fill", "(", "$", "data", ")", ";", "return", "$", "model", "->", "isDirty", "(", ")", "&&", "$", "model", "->", "update", "(", "$", "data", ")", ";", "}" ]
Update a model passed in. Returns a boolean indicating whether the model has been modified or not. @param array $data @param Model $model @return bool @throws RepositoryException
[ "Update", "a", "model", "passed", "in", ".", "Returns", "a", "boolean", "indicating", "whether", "the", "model", "has", "been", "modified", "or", "not", "." ]
f11ab47bec71becf894265cb607779fae67261bb
https://github.com/Daveawb/Repos/blob/f11ab47bec71becf894265cb607779fae67261bb/src/Repository.php#L175-L180
10,216
Daveawb/Repos
src/Repository.php
Repository.newModel
public function newModel($override = null) { $model = $this->model(); if ($override) $model = $override; $class = '\\'.ltrim($model, '\\'); return $this->app->make($class); }
php
public function newModel($override = null) { $model = $this->model(); if ($override) $model = $override; $class = '\\'.ltrim($model, '\\'); return $this->app->make($class); }
[ "public", "function", "newModel", "(", "$", "override", "=", "null", ")", "{", "$", "model", "=", "$", "this", "->", "model", "(", ")", ";", "if", "(", "$", "override", ")", "$", "model", "=", "$", "override", ";", "$", "class", "=", "'\\\\'", ".", "ltrim", "(", "$", "model", ",", "'\\\\'", ")", ";", "return", "$", "this", "->", "app", "->", "make", "(", "$", "class", ")", ";", "}" ]
Make a new model and attach it to the repository @param null $override @return \Illuminate\Database\Eloquent\Model|mixed
[ "Make", "a", "new", "model", "and", "attach", "it", "to", "the", "repository" ]
f11ab47bec71becf894265cb607779fae67261bb
https://github.com/Daveawb/Repos/blob/f11ab47bec71becf894265cb607779fae67261bb/src/Repository.php#L219-L228
10,217
polary/polary
src/polary/base/Object.php
Object.createObject
public static function createObject($type, $defaultClass, $instanceOf = false, $param = []) { if (is_string($type)) { $type = ['class' => $type]; } if (is_array($type) && ! isset($type['class']) && !empty($defaultClass)) { $type['class'] = $defaultClass; } if ( ! is_object($type)) { $type = Yii::createObject($type, $param); } if ($instanceOf === true) { $instanceOf = $defaultClass; } if ($instanceOf && ! $type instanceof $instanceOf) { throw new InvalidArgumentException(get_class($type) . " not instance of $instanceOf"); } return $type; }
php
public static function createObject($type, $defaultClass, $instanceOf = false, $param = []) { if (is_string($type)) { $type = ['class' => $type]; } if (is_array($type) && ! isset($type['class']) && !empty($defaultClass)) { $type['class'] = $defaultClass; } if ( ! is_object($type)) { $type = Yii::createObject($type, $param); } if ($instanceOf === true) { $instanceOf = $defaultClass; } if ($instanceOf && ! $type instanceof $instanceOf) { throw new InvalidArgumentException(get_class($type) . " not instance of $instanceOf"); } return $type; }
[ "public", "static", "function", "createObject", "(", "$", "type", ",", "$", "defaultClass", ",", "$", "instanceOf", "=", "false", ",", "$", "param", "=", "[", "]", ")", "{", "if", "(", "is_string", "(", "$", "type", ")", ")", "{", "$", "type", "=", "[", "'class'", "=>", "$", "type", "]", ";", "}", "if", "(", "is_array", "(", "$", "type", ")", "&&", "!", "isset", "(", "$", "type", "[", "'class'", "]", ")", "&&", "!", "empty", "(", "$", "defaultClass", ")", ")", "{", "$", "type", "[", "'class'", "]", "=", "$", "defaultClass", ";", "}", "if", "(", "!", "is_object", "(", "$", "type", ")", ")", "{", "$", "type", "=", "Yii", "::", "createObject", "(", "$", "type", ",", "$", "param", ")", ";", "}", "if", "(", "$", "instanceOf", "===", "true", ")", "{", "$", "instanceOf", "=", "$", "defaultClass", ";", "}", "if", "(", "$", "instanceOf", "&&", "!", "$", "type", "instanceof", "$", "instanceOf", ")", "{", "throw", "new", "InvalidArgumentException", "(", "get_class", "(", "$", "type", ")", ".", "\" not instance of $instanceOf\"", ")", ";", "}", "return", "$", "type", ";", "}" ]
Create object with set default class and check parent class. @param array|string|callable $type @param string $defaultClass @param string|bool $instanceOf @param array $param @return object
[ "Create", "object", "with", "set", "default", "class", "and", "check", "parent", "class", "." ]
683212e631e59faedce488f0d2cea82c94a83aae
https://github.com/polary/polary/blob/683212e631e59faedce488f0d2cea82c94a83aae/src/polary/base/Object.php#L26-L45
10,218
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.Initialize
public function Initialize() { $this->Head = new HeadModule($this); $this->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex')); $this->AddJsFile('jquery.js'); $this->AddJsFile('jquery.livequery.js'); $this->AddJsFile('jquery.form.js'); $this->AddJsFile('jquery.popup.js'); $this->AddJsFile('jquery.gardenhandleajaxform.js'); $this->AddJsFile('global.js'); $this->AddCssFile('style.css'); parent::Initialize(); Gdn_Theme::Section('Entry'); }
php
public function Initialize() { $this->Head = new HeadModule($this); $this->Head->AddTag('meta', array('name' => 'robots', 'content' => 'noindex')); $this->AddJsFile('jquery.js'); $this->AddJsFile('jquery.livequery.js'); $this->AddJsFile('jquery.form.js'); $this->AddJsFile('jquery.popup.js'); $this->AddJsFile('jquery.gardenhandleajaxform.js'); $this->AddJsFile('global.js'); $this->AddCssFile('style.css'); parent::Initialize(); Gdn_Theme::Section('Entry'); }
[ "public", "function", "Initialize", "(", ")", "{", "$", "this", "->", "Head", "=", "new", "HeadModule", "(", "$", "this", ")", ";", "$", "this", "->", "Head", "->", "AddTag", "(", "'meta'", ",", "array", "(", "'name'", "=>", "'robots'", ",", "'content'", "=>", "'noindex'", ")", ")", ";", "$", "this", "->", "AddJsFile", "(", "'jquery.js'", ")", ";", "$", "this", "->", "AddJsFile", "(", "'jquery.livequery.js'", ")", ";", "$", "this", "->", "AddJsFile", "(", "'jquery.form.js'", ")", ";", "$", "this", "->", "AddJsFile", "(", "'jquery.popup.js'", ")", ";", "$", "this", "->", "AddJsFile", "(", "'jquery.gardenhandleajaxform.js'", ")", ";", "$", "this", "->", "AddJsFile", "(", "'global.js'", ")", ";", "$", "this", "->", "AddCssFile", "(", "'style.css'", ")", ";", "parent", "::", "Initialize", "(", ")", ";", "Gdn_Theme", "::", "Section", "(", "'Entry'", ")", ";", "}" ]
Include JS and CSS used by all methods. Always called by dispatcher before controller's requested method. @since 2.0.0 @access public
[ "Include", "JS", "and", "CSS", "used", "by", "all", "methods", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L89-L103
10,219
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.CheckOverride
protected function CheckOverride($Type, $Target, $TransientKey = NULL) { if (!$this->Request->Get('override', TRUE)) return; $Provider = Gdn_AuthenticationProviderModel::GetDefault(); if (!$Provider) return; $this->EventArguments['Target'] = $Target; $this->EventArguments['DefaultProvider'] =& $Provider; $this->EventArguments['TransientKey'] = $TransientKey; $this->FireEvent("Override{$Type}"); $Url = $Provider[$Type.'Url']; if ($Url) { switch ($Type) { case 'Register': case 'SignIn': // When the other page comes back it needs to go through /sso to force a sso check. $Target = '/sso?target='.urlencode($Target); break; case 'SignOut': $Cookie = C('Garden.Cookie.Name'); if (strpos($Url, '?') === FALSE) $Url .= '?vfcookie='.urlencode($Cookie); else $Url .= '&vfcookie='.urlencode($Cookie); // Check to sign out here. $SignedOut = !Gdn::Session()->IsValid(); if (!$SignedOut && (Gdn::Session()->ValidateTransientKey($TransientKey) || $this->Form->IsPostBack())) { Gdn::Session()->End(); $SignedOut = TRUE; } // Sign out is a bit of a tricky thing so we configure the way it works. $SignoutType = C('Garden.SSO.Signout'); switch ($SignoutType) { case 'redirect-only': // Just redirect to the url. break; case 'post-only': $this->SetData('Method', 'POST'); break; case 'post': // Post to the url after signing out here. if (!$SignedOut) return; $this->SetData('Method', 'POST'); break; case 'none': return; case 'redirect': default: if (!$SignedOut) return; break; } break; default: throw new Exception("Unknown entry type $Type."); } $Url = str_ireplace('{target}', rawurlencode(Url($Target, TRUE)), $Url); if ($this->DeliveryType() == DELIVERY_TYPE_ALL && strcasecmp($this->Data('Method'), 'POST') != 0) Redirect($Url, 302); else { $this->SetData('Url', $Url); $this->Render('Redirect', 'Utility'); die(); } } }
php
protected function CheckOverride($Type, $Target, $TransientKey = NULL) { if (!$this->Request->Get('override', TRUE)) return; $Provider = Gdn_AuthenticationProviderModel::GetDefault(); if (!$Provider) return; $this->EventArguments['Target'] = $Target; $this->EventArguments['DefaultProvider'] =& $Provider; $this->EventArguments['TransientKey'] = $TransientKey; $this->FireEvent("Override{$Type}"); $Url = $Provider[$Type.'Url']; if ($Url) { switch ($Type) { case 'Register': case 'SignIn': // When the other page comes back it needs to go through /sso to force a sso check. $Target = '/sso?target='.urlencode($Target); break; case 'SignOut': $Cookie = C('Garden.Cookie.Name'); if (strpos($Url, '?') === FALSE) $Url .= '?vfcookie='.urlencode($Cookie); else $Url .= '&vfcookie='.urlencode($Cookie); // Check to sign out here. $SignedOut = !Gdn::Session()->IsValid(); if (!$SignedOut && (Gdn::Session()->ValidateTransientKey($TransientKey) || $this->Form->IsPostBack())) { Gdn::Session()->End(); $SignedOut = TRUE; } // Sign out is a bit of a tricky thing so we configure the way it works. $SignoutType = C('Garden.SSO.Signout'); switch ($SignoutType) { case 'redirect-only': // Just redirect to the url. break; case 'post-only': $this->SetData('Method', 'POST'); break; case 'post': // Post to the url after signing out here. if (!$SignedOut) return; $this->SetData('Method', 'POST'); break; case 'none': return; case 'redirect': default: if (!$SignedOut) return; break; } break; default: throw new Exception("Unknown entry type $Type."); } $Url = str_ireplace('{target}', rawurlencode(Url($Target, TRUE)), $Url); if ($this->DeliveryType() == DELIVERY_TYPE_ALL && strcasecmp($this->Data('Method'), 'POST') != 0) Redirect($Url, 302); else { $this->SetData('Url', $Url); $this->Render('Redirect', 'Utility'); die(); } } }
[ "protected", "function", "CheckOverride", "(", "$", "Type", ",", "$", "Target", ",", "$", "TransientKey", "=", "NULL", ")", "{", "if", "(", "!", "$", "this", "->", "Request", "->", "Get", "(", "'override'", ",", "TRUE", ")", ")", "return", ";", "$", "Provider", "=", "Gdn_AuthenticationProviderModel", "::", "GetDefault", "(", ")", ";", "if", "(", "!", "$", "Provider", ")", "return", ";", "$", "this", "->", "EventArguments", "[", "'Target'", "]", "=", "$", "Target", ";", "$", "this", "->", "EventArguments", "[", "'DefaultProvider'", "]", "=", "&", "$", "Provider", ";", "$", "this", "->", "EventArguments", "[", "'TransientKey'", "]", "=", "$", "TransientKey", ";", "$", "this", "->", "FireEvent", "(", "\"Override{$Type}\"", ")", ";", "$", "Url", "=", "$", "Provider", "[", "$", "Type", ".", "'Url'", "]", ";", "if", "(", "$", "Url", ")", "{", "switch", "(", "$", "Type", ")", "{", "case", "'Register'", ":", "case", "'SignIn'", ":", "// When the other page comes back it needs to go through /sso to force a sso check.", "$", "Target", "=", "'/sso?target='", ".", "urlencode", "(", "$", "Target", ")", ";", "break", ";", "case", "'SignOut'", ":", "$", "Cookie", "=", "C", "(", "'Garden.Cookie.Name'", ")", ";", "if", "(", "strpos", "(", "$", "Url", ",", "'?'", ")", "===", "FALSE", ")", "$", "Url", ".=", "'?vfcookie='", ".", "urlencode", "(", "$", "Cookie", ")", ";", "else", "$", "Url", ".=", "'&vfcookie='", ".", "urlencode", "(", "$", "Cookie", ")", ";", "// Check to sign out here.", "$", "SignedOut", "=", "!", "Gdn", "::", "Session", "(", ")", "->", "IsValid", "(", ")", ";", "if", "(", "!", "$", "SignedOut", "&&", "(", "Gdn", "::", "Session", "(", ")", "->", "ValidateTransientKey", "(", "$", "TransientKey", ")", "||", "$", "this", "->", "Form", "->", "IsPostBack", "(", ")", ")", ")", "{", "Gdn", "::", "Session", "(", ")", "->", "End", "(", ")", ";", "$", "SignedOut", "=", "TRUE", ";", "}", "// Sign out is a bit of a tricky thing so we configure the way it works.", "$", "SignoutType", "=", "C", "(", "'Garden.SSO.Signout'", ")", ";", "switch", "(", "$", "SignoutType", ")", "{", "case", "'redirect-only'", ":", "// Just redirect to the url.", "break", ";", "case", "'post-only'", ":", "$", "this", "->", "SetData", "(", "'Method'", ",", "'POST'", ")", ";", "break", ";", "case", "'post'", ":", "// Post to the url after signing out here.", "if", "(", "!", "$", "SignedOut", ")", "return", ";", "$", "this", "->", "SetData", "(", "'Method'", ",", "'POST'", ")", ";", "break", ";", "case", "'none'", ":", "return", ";", "case", "'redirect'", ":", "default", ":", "if", "(", "!", "$", "SignedOut", ")", "return", ";", "break", ";", "}", "break", ";", "default", ":", "throw", "new", "Exception", "(", "\"Unknown entry type $Type.\"", ")", ";", "}", "$", "Url", "=", "str_ireplace", "(", "'{target}'", ",", "rawurlencode", "(", "Url", "(", "$", "Target", ",", "TRUE", ")", ")", ",", "$", "Url", ")", ";", "if", "(", "$", "this", "->", "DeliveryType", "(", ")", "==", "DELIVERY_TYPE_ALL", "&&", "strcasecmp", "(", "$", "this", "->", "Data", "(", "'Method'", ")", ",", "'POST'", ")", "!=", "0", ")", "Redirect", "(", "$", "Url", ",", "302", ")", ";", "else", "{", "$", "this", "->", "SetData", "(", "'Url'", ",", "$", "Url", ")", ";", "$", "this", "->", "Render", "(", "'Redirect'", ",", "'Utility'", ")", ";", "die", "(", ")", ";", "}", "}", "}" ]
Check the default provider to see if it overrides one of the entry methods and then redirect. @param string $Type One of the following. - SignIn - Register - SignOut (not complete)
[ "Check", "the", "default", "provider", "to", "see", "if", "it", "overrides", "one", "of", "the", "entry", "methods", "and", "then", "redirect", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L285-L359
10,220
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController._SetRedirect
protected function _SetRedirect($CheckPopup = FALSE) { $Url = Url($this->RedirectTo(), TRUE); $this->RedirectUrl = $Url; $this->MasterView = 'popup'; $this->View = 'redirect'; if ($this->_RealDeliveryType != DELIVERY_TYPE_ALL && $this->DeliveryType() != DELIVERY_TYPE_ALL) { $this->DeliveryMethod(DELIVERY_METHOD_JSON); $this->SetHeader('Content-Type', 'application/json'); } elseif ($CheckPopup) { $this->AddDefinition('CheckPopup', $CheckPopup); } else { Redirect(Url($this->RedirectUrl)); } }
php
protected function _SetRedirect($CheckPopup = FALSE) { $Url = Url($this->RedirectTo(), TRUE); $this->RedirectUrl = $Url; $this->MasterView = 'popup'; $this->View = 'redirect'; if ($this->_RealDeliveryType != DELIVERY_TYPE_ALL && $this->DeliveryType() != DELIVERY_TYPE_ALL) { $this->DeliveryMethod(DELIVERY_METHOD_JSON); $this->SetHeader('Content-Type', 'application/json'); } elseif ($CheckPopup) { $this->AddDefinition('CheckPopup', $CheckPopup); } else { Redirect(Url($this->RedirectUrl)); } }
[ "protected", "function", "_SetRedirect", "(", "$", "CheckPopup", "=", "FALSE", ")", "{", "$", "Url", "=", "Url", "(", "$", "this", "->", "RedirectTo", "(", ")", ",", "TRUE", ")", ";", "$", "this", "->", "RedirectUrl", "=", "$", "Url", ";", "$", "this", "->", "MasterView", "=", "'popup'", ";", "$", "this", "->", "View", "=", "'redirect'", ";", "if", "(", "$", "this", "->", "_RealDeliveryType", "!=", "DELIVERY_TYPE_ALL", "&&", "$", "this", "->", "DeliveryType", "(", ")", "!=", "DELIVERY_TYPE_ALL", ")", "{", "$", "this", "->", "DeliveryMethod", "(", "DELIVERY_METHOD_JSON", ")", ";", "$", "this", "->", "SetHeader", "(", "'Content-Type'", ",", "'application/json'", ")", ";", "}", "elseif", "(", "$", "CheckPopup", ")", "{", "$", "this", "->", "AddDefinition", "(", "'CheckPopup'", ",", "$", "CheckPopup", ")", ";", "}", "else", "{", "Redirect", "(", "Url", "(", "$", "this", "->", "RedirectUrl", ")", ")", ";", "}", "}" ]
After sign in, send them along. @since 2.0.0 @access protected @param bool $CheckPopup
[ "After", "sign", "in", "send", "them", "along", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L726-L741
10,221
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.SignOut
public function SignOut($TransientKey = "") { $this->CheckOverride('SignOut', $this->Target(), $TransientKey); if (Gdn::Session()->ValidateTransientKey($TransientKey) || $this->Form->IsPostBack()) { $User = Gdn::Session()->User; $this->EventArguments['SignoutUser'] = $User; $this->FireEvent("BeforeSignOut"); // Sign the user right out. Gdn::Session()->End(); $this->SetData('SignedOut', TRUE); $this->EventArguments['SignoutUser'] = $User; $this->FireEvent("SignOut"); $this->_SetRedirect(); } elseif (!Gdn::Session()->IsValid()) $this->_SetRedirect(); $this->SetData('Target', $this->Target()); $this->Leaving = FALSE; $this->Render(); }
php
public function SignOut($TransientKey = "") { $this->CheckOverride('SignOut', $this->Target(), $TransientKey); if (Gdn::Session()->ValidateTransientKey($TransientKey) || $this->Form->IsPostBack()) { $User = Gdn::Session()->User; $this->EventArguments['SignoutUser'] = $User; $this->FireEvent("BeforeSignOut"); // Sign the user right out. Gdn::Session()->End(); $this->SetData('SignedOut', TRUE); $this->EventArguments['SignoutUser'] = $User; $this->FireEvent("SignOut"); $this->_SetRedirect(); } elseif (!Gdn::Session()->IsValid()) $this->_SetRedirect(); $this->SetData('Target', $this->Target()); $this->Leaving = FALSE; $this->Render(); }
[ "public", "function", "SignOut", "(", "$", "TransientKey", "=", "\"\"", ")", "{", "$", "this", "->", "CheckOverride", "(", "'SignOut'", ",", "$", "this", "->", "Target", "(", ")", ",", "$", "TransientKey", ")", ";", "if", "(", "Gdn", "::", "Session", "(", ")", "->", "ValidateTransientKey", "(", "$", "TransientKey", ")", "||", "$", "this", "->", "Form", "->", "IsPostBack", "(", ")", ")", "{", "$", "User", "=", "Gdn", "::", "Session", "(", ")", "->", "User", ";", "$", "this", "->", "EventArguments", "[", "'SignoutUser'", "]", "=", "$", "User", ";", "$", "this", "->", "FireEvent", "(", "\"BeforeSignOut\"", ")", ";", "// Sign the user right out.", "Gdn", "::", "Session", "(", ")", "->", "End", "(", ")", ";", "$", "this", "->", "SetData", "(", "'SignedOut'", ",", "TRUE", ")", ";", "$", "this", "->", "EventArguments", "[", "'SignoutUser'", "]", "=", "$", "User", ";", "$", "this", "->", "FireEvent", "(", "\"SignOut\"", ")", ";", "$", "this", "->", "_SetRedirect", "(", ")", ";", "}", "elseif", "(", "!", "Gdn", "::", "Session", "(", ")", "->", "IsValid", "(", ")", ")", "$", "this", "->", "_SetRedirect", "(", ")", ";", "$", "this", "->", "SetData", "(", "'Target'", ",", "$", "this", "->", "Target", "(", ")", ")", ";", "$", "this", "->", "Leaving", "=", "FALSE", ";", "$", "this", "->", "Render", "(", ")", ";", "}" ]
Good afternoon, good evening, and goodnight. Events: SignOut @access public @since 2.0.0 @param string $TransientKey (default: "")
[ "Good", "afternoon", "good", "evening", "and", "goodnight", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L787-L810
10,222
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.Register
public function Register($InvitationCode = '') { if (!$this->Request->IsPostBack()) $this->CheckOverride('Register', $this->Target()); $this->FireEvent("Register"); $this->Form->SetModel($this->UserModel); // Define gender dropdown options $this->GenderOptions = array( 'u' => T('Unspecified'), 'm' => T('Male'), 'f' => T('Female') ); // Make sure that the hour offset for new users gets defined when their account is created $this->AddJsFile('entry.js'); $this->Form->AddHidden('ClientHour', date('Y-m-d H:00')); // Use the server's current hour as a default $this->Form->AddHidden('Target', $this->Target()); $this->SetData('NoEmail', UserModel::NoEmail()); $RegistrationMethod = $this->_RegistrationView(); $this->View = $RegistrationMethod; $this->$RegistrationMethod($InvitationCode); }
php
public function Register($InvitationCode = '') { if (!$this->Request->IsPostBack()) $this->CheckOverride('Register', $this->Target()); $this->FireEvent("Register"); $this->Form->SetModel($this->UserModel); // Define gender dropdown options $this->GenderOptions = array( 'u' => T('Unspecified'), 'm' => T('Male'), 'f' => T('Female') ); // Make sure that the hour offset for new users gets defined when their account is created $this->AddJsFile('entry.js'); $this->Form->AddHidden('ClientHour', date('Y-m-d H:00')); // Use the server's current hour as a default $this->Form->AddHidden('Target', $this->Target()); $this->SetData('NoEmail', UserModel::NoEmail()); $RegistrationMethod = $this->_RegistrationView(); $this->View = $RegistrationMethod; $this->$RegistrationMethod($InvitationCode); }
[ "public", "function", "Register", "(", "$", "InvitationCode", "=", "''", ")", "{", "if", "(", "!", "$", "this", "->", "Request", "->", "IsPostBack", "(", ")", ")", "$", "this", "->", "CheckOverride", "(", "'Register'", ",", "$", "this", "->", "Target", "(", ")", ")", ";", "$", "this", "->", "FireEvent", "(", "\"Register\"", ")", ";", "$", "this", "->", "Form", "->", "SetModel", "(", "$", "this", "->", "UserModel", ")", ";", "// Define gender dropdown options", "$", "this", "->", "GenderOptions", "=", "array", "(", "'u'", "=>", "T", "(", "'Unspecified'", ")", ",", "'m'", "=>", "T", "(", "'Male'", ")", ",", "'f'", "=>", "T", "(", "'Female'", ")", ")", ";", "// Make sure that the hour offset for new users gets defined when their account is created", "$", "this", "->", "AddJsFile", "(", "'entry.js'", ")", ";", "$", "this", "->", "Form", "->", "AddHidden", "(", "'ClientHour'", ",", "date", "(", "'Y-m-d H:00'", ")", ")", ";", "// Use the server's current hour as a default", "$", "this", "->", "Form", "->", "AddHidden", "(", "'Target'", ",", "$", "this", "->", "Target", "(", ")", ")", ";", "$", "this", "->", "SetData", "(", "'NoEmail'", ",", "UserModel", "::", "NoEmail", "(", ")", ")", ";", "$", "RegistrationMethod", "=", "$", "this", "->", "_RegistrationView", "(", ")", ";", "$", "this", "->", "View", "=", "$", "RegistrationMethod", ";", "$", "this", "->", "$", "RegistrationMethod", "(", "$", "InvitationCode", ")", ";", "}" ]
Calls the appropriate registration method based on the configuration setting. Events: Register @access public @since 2.0.0 @param string $InvitationCode Unique code given to invited user.
[ "Calls", "the", "appropriate", "registration", "method", "based", "on", "the", "configuration", "setting", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L1172-L1198
10,223
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.RegisterApproval
private function RegisterApproval() { Gdn::UserModel()->AddPasswordStrength($this); // If the form has been posted back... if ($this->Form->IsPostBack()) { // Add validation rules that are not enforced by the model $this->UserModel->DefineSchema(); $this->UserModel->Validation->ApplyRule('Name', 'Username', $this->UsernameError); $this->UserModel->Validation->ApplyRule('TermsOfService', 'Required', T('You must agree to the terms of service.')); $this->UserModel->Validation->ApplyRule('Password', 'Required'); $this->UserModel->Validation->ApplyRule('Password', 'Strength'); $this->UserModel->Validation->ApplyRule('Password', 'Match'); $this->UserModel->Validation->ApplyRule('DiscoveryText', 'Required', 'Tell us why you want to join!'); // $this->UserModel->Validation->ApplyRule('DateOfBirth', 'MinimumAge'); $this->FireEvent('RegisterValidation'); try { $Values = $this->Form->FormValues(); unset($Values['Roles']); $AuthUserID = $this->UserModel->Register($Values); if (!$AuthUserID) { $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } else { // The user has been created successfully, so sign in now. Gdn::Session()->Start($AuthUserID); if ($this->Form->GetFormValue('RememberMe')) Gdn::Authenticator()->SetIdentity($AuthUserID, TRUE); // Notification text $Label = T('NewApplicantEmail', 'New applicant:'); $Story = Anchor(Gdn_Format::Text($Label.' '.$Values['Name']), ExternalUrl('dashboard/user/applicants')); $this->EventArguments['AuthUserID'] = $AuthUserID; $this->EventArguments['Story'] = &$Story; $this->FireEvent('RegistrationPending'); $this->View = "RegisterThanks"; // Tell the user their application will be reviewed by an administrator. // Grab all of the users that need to be notified. $Data = Gdn::Database()->SQL()->GetWhere('UserMeta', array('Name' => 'Preferences.Email.Applicant'))->ResultArray(); $ActivityModel = new ActivityModel(); foreach ($Data as $Row) { $ActivityModel->Add($AuthUserID, 'Applicant', $Story, $Row['UserID'], '', '/dashboard/user/applicants', 'Only'); } } } catch (Exception $Ex) { $this->Form->AddError($Ex); } } $this->Render(); }
php
private function RegisterApproval() { Gdn::UserModel()->AddPasswordStrength($this); // If the form has been posted back... if ($this->Form->IsPostBack()) { // Add validation rules that are not enforced by the model $this->UserModel->DefineSchema(); $this->UserModel->Validation->ApplyRule('Name', 'Username', $this->UsernameError); $this->UserModel->Validation->ApplyRule('TermsOfService', 'Required', T('You must agree to the terms of service.')); $this->UserModel->Validation->ApplyRule('Password', 'Required'); $this->UserModel->Validation->ApplyRule('Password', 'Strength'); $this->UserModel->Validation->ApplyRule('Password', 'Match'); $this->UserModel->Validation->ApplyRule('DiscoveryText', 'Required', 'Tell us why you want to join!'); // $this->UserModel->Validation->ApplyRule('DateOfBirth', 'MinimumAge'); $this->FireEvent('RegisterValidation'); try { $Values = $this->Form->FormValues(); unset($Values['Roles']); $AuthUserID = $this->UserModel->Register($Values); if (!$AuthUserID) { $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } else { // The user has been created successfully, so sign in now. Gdn::Session()->Start($AuthUserID); if ($this->Form->GetFormValue('RememberMe')) Gdn::Authenticator()->SetIdentity($AuthUserID, TRUE); // Notification text $Label = T('NewApplicantEmail', 'New applicant:'); $Story = Anchor(Gdn_Format::Text($Label.' '.$Values['Name']), ExternalUrl('dashboard/user/applicants')); $this->EventArguments['AuthUserID'] = $AuthUserID; $this->EventArguments['Story'] = &$Story; $this->FireEvent('RegistrationPending'); $this->View = "RegisterThanks"; // Tell the user their application will be reviewed by an administrator. // Grab all of the users that need to be notified. $Data = Gdn::Database()->SQL()->GetWhere('UserMeta', array('Name' => 'Preferences.Email.Applicant'))->ResultArray(); $ActivityModel = new ActivityModel(); foreach ($Data as $Row) { $ActivityModel->Add($AuthUserID, 'Applicant', $Story, $Row['UserID'], '', '/dashboard/user/applicants', 'Only'); } } } catch (Exception $Ex) { $this->Form->AddError($Ex); } } $this->Render(); }
[ "private", "function", "RegisterApproval", "(", ")", "{", "Gdn", "::", "UserModel", "(", ")", "->", "AddPasswordStrength", "(", "$", "this", ")", ";", "// If the form has been posted back...", "if", "(", "$", "this", "->", "Form", "->", "IsPostBack", "(", ")", ")", "{", "// Add validation rules that are not enforced by the model", "$", "this", "->", "UserModel", "->", "DefineSchema", "(", ")", ";", "$", "this", "->", "UserModel", "->", "Validation", "->", "ApplyRule", "(", "'Name'", ",", "'Username'", ",", "$", "this", "->", "UsernameError", ")", ";", "$", "this", "->", "UserModel", "->", "Validation", "->", "ApplyRule", "(", "'TermsOfService'", ",", "'Required'", ",", "T", "(", "'You must agree to the terms of service.'", ")", ")", ";", "$", "this", "->", "UserModel", "->", "Validation", "->", "ApplyRule", "(", "'Password'", ",", "'Required'", ")", ";", "$", "this", "->", "UserModel", "->", "Validation", "->", "ApplyRule", "(", "'Password'", ",", "'Strength'", ")", ";", "$", "this", "->", "UserModel", "->", "Validation", "->", "ApplyRule", "(", "'Password'", ",", "'Match'", ")", ";", "$", "this", "->", "UserModel", "->", "Validation", "->", "ApplyRule", "(", "'DiscoveryText'", ",", "'Required'", ",", "'Tell us why you want to join!'", ")", ";", "// $this->UserModel->Validation->ApplyRule('DateOfBirth', 'MinimumAge');", "$", "this", "->", "FireEvent", "(", "'RegisterValidation'", ")", ";", "try", "{", "$", "Values", "=", "$", "this", "->", "Form", "->", "FormValues", "(", ")", ";", "unset", "(", "$", "Values", "[", "'Roles'", "]", ")", ";", "$", "AuthUserID", "=", "$", "this", "->", "UserModel", "->", "Register", "(", "$", "Values", ")", ";", "if", "(", "!", "$", "AuthUserID", ")", "{", "$", "this", "->", "Form", "->", "SetValidationResults", "(", "$", "this", "->", "UserModel", "->", "ValidationResults", "(", ")", ")", ";", "}", "else", "{", "// The user has been created successfully, so sign in now.", "Gdn", "::", "Session", "(", ")", "->", "Start", "(", "$", "AuthUserID", ")", ";", "if", "(", "$", "this", "->", "Form", "->", "GetFormValue", "(", "'RememberMe'", ")", ")", "Gdn", "::", "Authenticator", "(", ")", "->", "SetIdentity", "(", "$", "AuthUserID", ",", "TRUE", ")", ";", "// Notification text", "$", "Label", "=", "T", "(", "'NewApplicantEmail'", ",", "'New applicant:'", ")", ";", "$", "Story", "=", "Anchor", "(", "Gdn_Format", "::", "Text", "(", "$", "Label", ".", "' '", ".", "$", "Values", "[", "'Name'", "]", ")", ",", "ExternalUrl", "(", "'dashboard/user/applicants'", ")", ")", ";", "$", "this", "->", "EventArguments", "[", "'AuthUserID'", "]", "=", "$", "AuthUserID", ";", "$", "this", "->", "EventArguments", "[", "'Story'", "]", "=", "&", "$", "Story", ";", "$", "this", "->", "FireEvent", "(", "'RegistrationPending'", ")", ";", "$", "this", "->", "View", "=", "\"RegisterThanks\"", ";", "// Tell the user their application will be reviewed by an administrator.", "// Grab all of the users that need to be notified.", "$", "Data", "=", "Gdn", "::", "Database", "(", ")", "->", "SQL", "(", ")", "->", "GetWhere", "(", "'UserMeta'", ",", "array", "(", "'Name'", "=>", "'Preferences.Email.Applicant'", ")", ")", "->", "ResultArray", "(", ")", ";", "$", "ActivityModel", "=", "new", "ActivityModel", "(", ")", ";", "foreach", "(", "$", "Data", "as", "$", "Row", ")", "{", "$", "ActivityModel", "->", "Add", "(", "$", "AuthUserID", ",", "'Applicant'", ",", "$", "Story", ",", "$", "Row", "[", "'UserID'", "]", ",", "''", ",", "'/dashboard/user/applicants'", ",", "'Only'", ")", ";", "}", "}", "}", "catch", "(", "Exception", "$", "Ex", ")", "{", "$", "this", "->", "Form", "->", "AddError", "(", "$", "Ex", ")", ";", "}", "}", "$", "this", "->", "Render", "(", ")", ";", "}" ]
Registration that requires approval. Events: RegistrationPending @access private @since 2.0.0
[ "Registration", "that", "requires", "approval", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L1224-L1276
10,224
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.PasswordRequest
public function PasswordRequest() { Gdn::Locale()->SetTranslation('Email', T(UserModel::SigninLabelCode())); if ($this->Form->IsPostBack() === TRUE) { $this->Form->ValidateRule('Email', 'ValidateRequired'); if ($this->Form->ErrorCount() == 0) { try { $Email = $this->Form->GetFormValue('Email'); if (!$this->UserModel->PasswordRequest($Email)) { $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } } catch (Exception $ex) { $this->Form->AddError($ex->getMessage()); } if ($this->Form->ErrorCount() == 0) { $this->Form->AddError('Success!'); $this->View = 'passwordrequestsent'; } } else { if ($this->Form->ErrorCount() == 0) $this->Form->AddError("Couldn't find an account associated with that email/username."); } } $this->Render(); }
php
public function PasswordRequest() { Gdn::Locale()->SetTranslation('Email', T(UserModel::SigninLabelCode())); if ($this->Form->IsPostBack() === TRUE) { $this->Form->ValidateRule('Email', 'ValidateRequired'); if ($this->Form->ErrorCount() == 0) { try { $Email = $this->Form->GetFormValue('Email'); if (!$this->UserModel->PasswordRequest($Email)) { $this->Form->SetValidationResults($this->UserModel->ValidationResults()); } } catch (Exception $ex) { $this->Form->AddError($ex->getMessage()); } if ($this->Form->ErrorCount() == 0) { $this->Form->AddError('Success!'); $this->View = 'passwordrequestsent'; } } else { if ($this->Form->ErrorCount() == 0) $this->Form->AddError("Couldn't find an account associated with that email/username."); } } $this->Render(); }
[ "public", "function", "PasswordRequest", "(", ")", "{", "Gdn", "::", "Locale", "(", ")", "->", "SetTranslation", "(", "'Email'", ",", "T", "(", "UserModel", "::", "SigninLabelCode", "(", ")", ")", ")", ";", "if", "(", "$", "this", "->", "Form", "->", "IsPostBack", "(", ")", "===", "TRUE", ")", "{", "$", "this", "->", "Form", "->", "ValidateRule", "(", "'Email'", ",", "'ValidateRequired'", ")", ";", "if", "(", "$", "this", "->", "Form", "->", "ErrorCount", "(", ")", "==", "0", ")", "{", "try", "{", "$", "Email", "=", "$", "this", "->", "Form", "->", "GetFormValue", "(", "'Email'", ")", ";", "if", "(", "!", "$", "this", "->", "UserModel", "->", "PasswordRequest", "(", "$", "Email", ")", ")", "{", "$", "this", "->", "Form", "->", "SetValidationResults", "(", "$", "this", "->", "UserModel", "->", "ValidationResults", "(", ")", ")", ";", "}", "}", "catch", "(", "Exception", "$", "ex", ")", "{", "$", "this", "->", "Form", "->", "AddError", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "Form", "->", "ErrorCount", "(", ")", "==", "0", ")", "{", "$", "this", "->", "Form", "->", "AddError", "(", "'Success!'", ")", ";", "$", "this", "->", "View", "=", "'passwordrequestsent'", ";", "}", "}", "else", "{", "if", "(", "$", "this", "->", "Form", "->", "ErrorCount", "(", ")", "==", "0", ")", "$", "this", "->", "Form", "->", "AddError", "(", "\"Couldn't find an account associated with that email/username.\"", ")", ";", "}", "}", "$", "this", "->", "Render", "(", ")", ";", "}" ]
Request password reset. @access public @since 2.0.0
[ "Request", "password", "reset", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L1496-L1520
10,225
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.PasswordReset
public function PasswordReset($UserID = '', $PasswordResetKey = '') { if (!is_numeric($UserID) || $PasswordResetKey == '' || $this->UserModel->GetAttribute($UserID, 'PasswordResetKey', '') != $PasswordResetKey ) $this->Form->AddError('Failed to authenticate your password reset request. Try using the reset request form again.'); if ($this->Form->ErrorCount() == 0) { $User = $this->UserModel->GetID($UserID, DATASET_TYPE_ARRAY); if ($User) { $User = ArrayTranslate($User, array('UserID', 'Name', 'Email')); $this->SetData('User', $User); } } if ($this->Form->ErrorCount() == 0 && $this->Form->IsPostBack() === TRUE ) { $Password = $this->Form->GetFormValue('Password', ''); $Confirm = $this->Form->GetFormValue('Confirm', ''); if ($Password == '') $this->Form->AddError('Your new password is invalid'); else if ($Password != $Confirm) $this->Form->AddError('Your passwords did not match.'); if ($this->Form->ErrorCount() == 0) { $User = $this->UserModel->PasswordReset($UserID, $Password); Gdn::Session()->Start($User->UserID, TRUE); // $Authenticator = Gdn::Authenticator()->AuthenticateWith('password'); // $Authenticator->FetchData($Authenticator, array('Email' => $User->Email, 'Password' => $Password, 'RememberMe' => FALSE)); // $AuthUserID = $Authenticator->Authenticate(); Redirect('/'); } } $this->Render(); }
php
public function PasswordReset($UserID = '', $PasswordResetKey = '') { if (!is_numeric($UserID) || $PasswordResetKey == '' || $this->UserModel->GetAttribute($UserID, 'PasswordResetKey', '') != $PasswordResetKey ) $this->Form->AddError('Failed to authenticate your password reset request. Try using the reset request form again.'); if ($this->Form->ErrorCount() == 0) { $User = $this->UserModel->GetID($UserID, DATASET_TYPE_ARRAY); if ($User) { $User = ArrayTranslate($User, array('UserID', 'Name', 'Email')); $this->SetData('User', $User); } } if ($this->Form->ErrorCount() == 0 && $this->Form->IsPostBack() === TRUE ) { $Password = $this->Form->GetFormValue('Password', ''); $Confirm = $this->Form->GetFormValue('Confirm', ''); if ($Password == '') $this->Form->AddError('Your new password is invalid'); else if ($Password != $Confirm) $this->Form->AddError('Your passwords did not match.'); if ($this->Form->ErrorCount() == 0) { $User = $this->UserModel->PasswordReset($UserID, $Password); Gdn::Session()->Start($User->UserID, TRUE); // $Authenticator = Gdn::Authenticator()->AuthenticateWith('password'); // $Authenticator->FetchData($Authenticator, array('Email' => $User->Email, 'Password' => $Password, 'RememberMe' => FALSE)); // $AuthUserID = $Authenticator->Authenticate(); Redirect('/'); } } $this->Render(); }
[ "public", "function", "PasswordReset", "(", "$", "UserID", "=", "''", ",", "$", "PasswordResetKey", "=", "''", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "UserID", ")", "||", "$", "PasswordResetKey", "==", "''", "||", "$", "this", "->", "UserModel", "->", "GetAttribute", "(", "$", "UserID", ",", "'PasswordResetKey'", ",", "''", ")", "!=", "$", "PasswordResetKey", ")", "$", "this", "->", "Form", "->", "AddError", "(", "'Failed to authenticate your password reset request. Try using the reset request form again.'", ")", ";", "if", "(", "$", "this", "->", "Form", "->", "ErrorCount", "(", ")", "==", "0", ")", "{", "$", "User", "=", "$", "this", "->", "UserModel", "->", "GetID", "(", "$", "UserID", ",", "DATASET_TYPE_ARRAY", ")", ";", "if", "(", "$", "User", ")", "{", "$", "User", "=", "ArrayTranslate", "(", "$", "User", ",", "array", "(", "'UserID'", ",", "'Name'", ",", "'Email'", ")", ")", ";", "$", "this", "->", "SetData", "(", "'User'", ",", "$", "User", ")", ";", "}", "}", "if", "(", "$", "this", "->", "Form", "->", "ErrorCount", "(", ")", "==", "0", "&&", "$", "this", "->", "Form", "->", "IsPostBack", "(", ")", "===", "TRUE", ")", "{", "$", "Password", "=", "$", "this", "->", "Form", "->", "GetFormValue", "(", "'Password'", ",", "''", ")", ";", "$", "Confirm", "=", "$", "this", "->", "Form", "->", "GetFormValue", "(", "'Confirm'", ",", "''", ")", ";", "if", "(", "$", "Password", "==", "''", ")", "$", "this", "->", "Form", "->", "AddError", "(", "'Your new password is invalid'", ")", ";", "else", "if", "(", "$", "Password", "!=", "$", "Confirm", ")", "$", "this", "->", "Form", "->", "AddError", "(", "'Your passwords did not match.'", ")", ";", "if", "(", "$", "this", "->", "Form", "->", "ErrorCount", "(", ")", "==", "0", ")", "{", "$", "User", "=", "$", "this", "->", "UserModel", "->", "PasswordReset", "(", "$", "UserID", ",", "$", "Password", ")", ";", "Gdn", "::", "Session", "(", ")", "->", "Start", "(", "$", "User", "->", "UserID", ",", "TRUE", ")", ";", "// $Authenticator = Gdn::Authenticator()->AuthenticateWith('password');", "// $Authenticator->FetchData($Authenticator, array('Email' => $User->Email, 'Password' => $Password, 'RememberMe' => FALSE));", "// $AuthUserID = $Authenticator->Authenticate();", "Redirect", "(", "'/'", ")", ";", "}", "}", "$", "this", "->", "Render", "(", ")", ";", "}" ]
Do password reset. @access public @since 2.0.0 @param int $UserID Unique. @param string $PasswordResetKey Authenticate with unique, 1-time code sent via email.
[ "Do", "password", "reset", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L1531-L1565
10,226
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.EmailConfirm
public function EmailConfirm($UserID, $EmailKey = '') { $User = $this->UserModel->GetID($UserID); if (!$User) throw NotFoundException('User'); $EmailConfirmed = $this->UserModel->ConfirmEmail($User, $EmailKey); $this->Form->SetValidationResults($this->UserModel->ValidationResults()); if ($EmailConfirmed) { $UserID = GetValue('UserID', $User); Gdn::Session()->Start($UserID); } $this->SetData('EmailConfirmed', $EmailConfirmed); $this->SetData('Email', $User->Email); $this->Render(); }
php
public function EmailConfirm($UserID, $EmailKey = '') { $User = $this->UserModel->GetID($UserID); if (!$User) throw NotFoundException('User'); $EmailConfirmed = $this->UserModel->ConfirmEmail($User, $EmailKey); $this->Form->SetValidationResults($this->UserModel->ValidationResults()); if ($EmailConfirmed) { $UserID = GetValue('UserID', $User); Gdn::Session()->Start($UserID); } $this->SetData('EmailConfirmed', $EmailConfirmed); $this->SetData('Email', $User->Email); $this->Render(); }
[ "public", "function", "EmailConfirm", "(", "$", "UserID", ",", "$", "EmailKey", "=", "''", ")", "{", "$", "User", "=", "$", "this", "->", "UserModel", "->", "GetID", "(", "$", "UserID", ")", ";", "if", "(", "!", "$", "User", ")", "throw", "NotFoundException", "(", "'User'", ")", ";", "$", "EmailConfirmed", "=", "$", "this", "->", "UserModel", "->", "ConfirmEmail", "(", "$", "User", ",", "$", "EmailKey", ")", ";", "$", "this", "->", "Form", "->", "SetValidationResults", "(", "$", "this", "->", "UserModel", "->", "ValidationResults", "(", ")", ")", ";", "if", "(", "$", "EmailConfirmed", ")", "{", "$", "UserID", "=", "GetValue", "(", "'UserID'", ",", "$", "User", ")", ";", "Gdn", "::", "Session", "(", ")", "->", "Start", "(", "$", "UserID", ")", ";", "}", "$", "this", "->", "SetData", "(", "'EmailConfirmed'", ",", "$", "EmailConfirmed", ")", ";", "$", "this", "->", "SetData", "(", "'Email'", ",", "$", "User", "->", "Email", ")", ";", "$", "this", "->", "Render", "(", ")", ";", "}" ]
Confirm email address is valid via sent code. @access public @since 2.0.0 @param int $UserID @param string $EmailKey Authenticate with unique, 1-time code sent via email.
[ "Confirm", "email", "address", "is", "valid", "via", "sent", "code", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L1576-L1593
10,227
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.EmailConfirmRequest
public function EmailConfirmRequest($UserID = '') { if ($UserID && !Gdn::Session()->CheckPermission('Garden.Users.Edit')) $UserID = ''; try { $this->UserModel->SendEmailConfirmationEmail($UserID); } catch (Exception $Ex) {} $this->Form->SetValidationResults($this->UserModel->ValidationResults()); $this->Render(); }
php
public function EmailConfirmRequest($UserID = '') { if ($UserID && !Gdn::Session()->CheckPermission('Garden.Users.Edit')) $UserID = ''; try { $this->UserModel->SendEmailConfirmationEmail($UserID); } catch (Exception $Ex) {} $this->Form->SetValidationResults($this->UserModel->ValidationResults()); $this->Render(); }
[ "public", "function", "EmailConfirmRequest", "(", "$", "UserID", "=", "''", ")", "{", "if", "(", "$", "UserID", "&&", "!", "Gdn", "::", "Session", "(", ")", "->", "CheckPermission", "(", "'Garden.Users.Edit'", ")", ")", "$", "UserID", "=", "''", ";", "try", "{", "$", "this", "->", "UserModel", "->", "SendEmailConfirmationEmail", "(", "$", "UserID", ")", ";", "}", "catch", "(", "Exception", "$", "Ex", ")", "{", "}", "$", "this", "->", "Form", "->", "SetValidationResults", "(", "$", "this", "->", "UserModel", "->", "ValidationResults", "(", ")", ")", ";", "$", "this", "->", "Render", "(", ")", ";", "}" ]
Send email confirmation message to user. @access public @since 2.0.? @param int $UserID
[ "Send", "email", "confirmation", "message", "to", "user", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L1603-L1613
10,228
bishopb/vanilla
applications/dashboard/controllers/class.entrycontroller.php
EntryController.Target
public function Target($Target = FALSE) { if ($Target === FALSE) { $Target = $this->Form->GetFormValue('Target', FALSE); if (!$Target) $Target = $this->Request->Get('Target', '/'); } // Make sure that the target is a valid url. if (!preg_match('`(^https?://)`', $Target)) { $Target = '/'.ltrim($Target, '/'); // Never redirect back to signin. if (preg_match('`^/entry/signin`i', $Target)) $Target = '/'; } else { $MyHostname = parse_url(Gdn::Request()->Domain(),PHP_URL_HOST); $TargetHostname = parse_url($Target, PHP_URL_HOST); // Only allow external redirects to trusted domains. $TrustedDomains = C('Garden.TrustedDomains', TRUE); if (is_array($TrustedDomains)) { // Add this domain to the trusted hosts. $TrustedDomains[] = $MyHostname; $Sender->EventArguments['TrustedDomains'] = &$TrustedDomains; $this->FireEvent('BeforeTargetReturn'); } if ($TrustedDomains === TRUE) { return $Target; } elseif (count($TrustedDomains) == 0) { // Only allow http redirects if they are to the same host name. if ($MyHostname != $TargetHostname) $Target = ''; } else { // Loop the trusted domains looking for a match $Match = FALSE; foreach ($TrustedDomains as $TrustedDomain) { if (StringEndsWith($TargetHostname, $TrustedDomain, TRUE)) $Match = TRUE; } if (!$Match) $Target = ''; } } return $Target; }
php
public function Target($Target = FALSE) { if ($Target === FALSE) { $Target = $this->Form->GetFormValue('Target', FALSE); if (!$Target) $Target = $this->Request->Get('Target', '/'); } // Make sure that the target is a valid url. if (!preg_match('`(^https?://)`', $Target)) { $Target = '/'.ltrim($Target, '/'); // Never redirect back to signin. if (preg_match('`^/entry/signin`i', $Target)) $Target = '/'; } else { $MyHostname = parse_url(Gdn::Request()->Domain(),PHP_URL_HOST); $TargetHostname = parse_url($Target, PHP_URL_HOST); // Only allow external redirects to trusted domains. $TrustedDomains = C('Garden.TrustedDomains', TRUE); if (is_array($TrustedDomains)) { // Add this domain to the trusted hosts. $TrustedDomains[] = $MyHostname; $Sender->EventArguments['TrustedDomains'] = &$TrustedDomains; $this->FireEvent('BeforeTargetReturn'); } if ($TrustedDomains === TRUE) { return $Target; } elseif (count($TrustedDomains) == 0) { // Only allow http redirects if they are to the same host name. if ($MyHostname != $TargetHostname) $Target = ''; } else { // Loop the trusted domains looking for a match $Match = FALSE; foreach ($TrustedDomains as $TrustedDomain) { if (StringEndsWith($TargetHostname, $TrustedDomain, TRUE)) $Match = TRUE; } if (!$Match) $Target = ''; } } return $Target; }
[ "public", "function", "Target", "(", "$", "Target", "=", "FALSE", ")", "{", "if", "(", "$", "Target", "===", "FALSE", ")", "{", "$", "Target", "=", "$", "this", "->", "Form", "->", "GetFormValue", "(", "'Target'", ",", "FALSE", ")", ";", "if", "(", "!", "$", "Target", ")", "$", "Target", "=", "$", "this", "->", "Request", "->", "Get", "(", "'Target'", ",", "'/'", ")", ";", "}", "// Make sure that the target is a valid url.", "if", "(", "!", "preg_match", "(", "'`(^https?://)`'", ",", "$", "Target", ")", ")", "{", "$", "Target", "=", "'/'", ".", "ltrim", "(", "$", "Target", ",", "'/'", ")", ";", "// Never redirect back to signin.", "if", "(", "preg_match", "(", "'`^/entry/signin`i'", ",", "$", "Target", ")", ")", "$", "Target", "=", "'/'", ";", "}", "else", "{", "$", "MyHostname", "=", "parse_url", "(", "Gdn", "::", "Request", "(", ")", "->", "Domain", "(", ")", ",", "PHP_URL_HOST", ")", ";", "$", "TargetHostname", "=", "parse_url", "(", "$", "Target", ",", "PHP_URL_HOST", ")", ";", "// Only allow external redirects to trusted domains.", "$", "TrustedDomains", "=", "C", "(", "'Garden.TrustedDomains'", ",", "TRUE", ")", ";", "if", "(", "is_array", "(", "$", "TrustedDomains", ")", ")", "{", "// Add this domain to the trusted hosts.", "$", "TrustedDomains", "[", "]", "=", "$", "MyHostname", ";", "$", "Sender", "->", "EventArguments", "[", "'TrustedDomains'", "]", "=", "&", "$", "TrustedDomains", ";", "$", "this", "->", "FireEvent", "(", "'BeforeTargetReturn'", ")", ";", "}", "if", "(", "$", "TrustedDomains", "===", "TRUE", ")", "{", "return", "$", "Target", ";", "}", "elseif", "(", "count", "(", "$", "TrustedDomains", ")", "==", "0", ")", "{", "// Only allow http redirects if they are to the same host name.", "if", "(", "$", "MyHostname", "!=", "$", "TargetHostname", ")", "$", "Target", "=", "''", ";", "}", "else", "{", "// Loop the trusted domains looking for a match", "$", "Match", "=", "FALSE", ";", "foreach", "(", "$", "TrustedDomains", "as", "$", "TrustedDomain", ")", "{", "if", "(", "StringEndsWith", "(", "$", "TargetHostname", ",", "$", "TrustedDomain", ",", "TRUE", ")", ")", "$", "Match", "=", "TRUE", ";", "}", "if", "(", "!", "$", "Match", ")", "$", "Target", "=", "''", ";", "}", "}", "return", "$", "Target", ";", "}" ]
Set where to go after signin. @access public @since 2.0.0 @param string $Target Where we're requested to go to. @return string URL to actually go to (validated & safe).
[ "Set", "where", "to", "go", "after", "signin", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/controllers/class.entrycontroller.php#L1722-L1768
10,229
sgtlambda/jvwp
src/components/WpMediaUploader.php
WpMediaUploader.getHTML
public function getHTML ($showLabel = true) { return parent::getHTML(false) . Templates::getTemplate($this->getTemplateLocation())->render(array( 'id' => $this->getId(), 'showLabel' => $showLabel || $this->overrideShowLabel, 'label' => $this->label, 'resolution' => $this->resolution, 'displaySize' => $this->displaySize )); }
php
public function getHTML ($showLabel = true) { return parent::getHTML(false) . Templates::getTemplate($this->getTemplateLocation())->render(array( 'id' => $this->getId(), 'showLabel' => $showLabel || $this->overrideShowLabel, 'label' => $this->label, 'resolution' => $this->resolution, 'displaySize' => $this->displaySize )); }
[ "public", "function", "getHTML", "(", "$", "showLabel", "=", "true", ")", "{", "return", "parent", "::", "getHTML", "(", "false", ")", ".", "Templates", "::", "getTemplate", "(", "$", "this", "->", "getTemplateLocation", "(", ")", ")", "->", "render", "(", "array", "(", "'id'", "=>", "$", "this", "->", "getId", "(", ")", ",", "'showLabel'", "=>", "$", "showLabel", "||", "$", "this", "->", "overrideShowLabel", ",", "'label'", "=>", "$", "this", "->", "label", ",", "'resolution'", "=>", "$", "this", "->", "resolution", ",", "'displaySize'", "=>", "$", "this", "->", "displaySize", ")", ")", ";", "}" ]
Gets the HTML markup of the component @param bool $showLabel @return mixed
[ "Gets", "the", "HTML", "markup", "of", "the", "component" ]
85dba59281216ccb9cff580d26063d304350bbe0
https://github.com/sgtlambda/jvwp/blob/85dba59281216ccb9cff580d26063d304350bbe0/src/components/WpMediaUploader.php#L115-L125
10,230
bytic/translation
src/Translator/Traits/LegacyCodeTrait.php
LegacyCodeTrait.getLanguage
public function getLanguage() { if (!$this->selectedLanguage) { $language = false; if (isset($_SESSION['language']) && $this->isValidLanguage($_SESSION['language'])) { $language = $_SESSION['language']; } $requestLanguage = $this->getRequest()->get('language'); if ($requestLanguage && $this->isValidLanguage($requestLanguage)) { $language = $requestLanguage; } if ($language) { $this->setLanguage($language); } else { $this->setLanguage($this->getDefaultLanguage()); } } return $this->selectedLanguage; }
php
public function getLanguage() { if (!$this->selectedLanguage) { $language = false; if (isset($_SESSION['language']) && $this->isValidLanguage($_SESSION['language'])) { $language = $_SESSION['language']; } $requestLanguage = $this->getRequest()->get('language'); if ($requestLanguage && $this->isValidLanguage($requestLanguage)) { $language = $requestLanguage; } if ($language) { $this->setLanguage($language); } else { $this->setLanguage($this->getDefaultLanguage()); } } return $this->selectedLanguage; }
[ "public", "function", "getLanguage", "(", ")", "{", "if", "(", "!", "$", "this", "->", "selectedLanguage", ")", "{", "$", "language", "=", "false", ";", "if", "(", "isset", "(", "$", "_SESSION", "[", "'language'", "]", ")", "&&", "$", "this", "->", "isValidLanguage", "(", "$", "_SESSION", "[", "'language'", "]", ")", ")", "{", "$", "language", "=", "$", "_SESSION", "[", "'language'", "]", ";", "}", "$", "requestLanguage", "=", "$", "this", "->", "getRequest", "(", ")", "->", "get", "(", "'language'", ")", ";", "if", "(", "$", "requestLanguage", "&&", "$", "this", "->", "isValidLanguage", "(", "$", "requestLanguage", ")", ")", "{", "$", "language", "=", "$", "requestLanguage", ";", "}", "if", "(", "$", "language", ")", "{", "$", "this", "->", "setLanguage", "(", "$", "language", ")", ";", "}", "else", "{", "$", "this", "->", "setLanguage", "(", "$", "this", "->", "getDefaultLanguage", "(", ")", ")", ";", "}", "}", "return", "$", "this", "->", "selectedLanguage", ";", "}" ]
Checks SESSION, GET and Nip_Request and selects requested language If language not requested, falls back to default @return string @deprecated Use getLocale instead
[ "Checks", "SESSION", "GET", "and", "Nip_Request", "and", "selects", "requested", "language", "If", "language", "not", "requested", "falls", "back", "to", "default" ]
974e57099d901126c4117010f4a269fe1f80b651
https://github.com/bytic/translation/blob/974e57099d901126c4117010f4a269fe1f80b651/src/Translator/Traits/LegacyCodeTrait.php#L38-L60
10,231
bytic/translation
src/Translator/Traits/LegacyCodeTrait.php
LegacyCodeTrait.setLanguage
public function setLanguage($language) { $this->setLocale($language); $code = $this->getLanguageCode($language); putenv('LC_ALL=' . $code); setlocale(LC_ALL, $code); setlocale(LC_NUMERIC, 'en_US'); return $this; }
php
public function setLanguage($language) { $this->setLocale($language); $code = $this->getLanguageCode($language); putenv('LC_ALL=' . $code); setlocale(LC_ALL, $code); setlocale(LC_NUMERIC, 'en_US'); return $this; }
[ "public", "function", "setLanguage", "(", "$", "language", ")", "{", "$", "this", "->", "setLocale", "(", "$", "language", ")", ";", "$", "code", "=", "$", "this", "->", "getLanguageCode", "(", "$", "language", ")", ";", "putenv", "(", "'LC_ALL='", ".", "$", "code", ")", ";", "setlocale", "(", "LC_ALL", ",", "$", "code", ")", ";", "setlocale", "(", "LC_NUMERIC", ",", "'en_US'", ")", ";", "return", "$", "this", ";", "}" ]
Selects a language to be used when translating @param string $language @return $this
[ "Selects", "a", "language", "to", "be", "used", "when", "translating" ]
974e57099d901126c4117010f4a269fe1f80b651
https://github.com/bytic/translation/blob/974e57099d901126c4117010f4a269fe1f80b651/src/Translator/Traits/LegacyCodeTrait.php#L68-L79
10,232
bytic/translation
src/Translator/Traits/LegacyCodeTrait.php
LegacyCodeTrait.getDefaultLanguage
public function getDefaultLanguage() { if (!$this->defaultLanguage) { $language = substr(setlocale(LC_ALL, 0), 0, 2); $languages = $this->getLanguages(); $languageDefault = reset($languages); $language = $this->isValidLanguage($language) ? $language : $languageDefault; $this->setDefaultLanguage($language); } return $this->defaultLanguage; }
php
public function getDefaultLanguage() { if (!$this->defaultLanguage) { $language = substr(setlocale(LC_ALL, 0), 0, 2); $languages = $this->getLanguages(); $languageDefault = reset($languages); $language = $this->isValidLanguage($language) ? $language : $languageDefault; $this->setDefaultLanguage($language); } return $this->defaultLanguage; }
[ "public", "function", "getDefaultLanguage", "(", ")", "{", "if", "(", "!", "$", "this", "->", "defaultLanguage", ")", "{", "$", "language", "=", "substr", "(", "setlocale", "(", "LC_ALL", ",", "0", ")", ",", "0", ",", "2", ")", ";", "$", "languages", "=", "$", "this", "->", "getLanguages", "(", ")", ";", "$", "languageDefault", "=", "reset", "(", "$", "languages", ")", ";", "$", "language", "=", "$", "this", "->", "isValidLanguage", "(", "$", "language", ")", "?", "$", "language", ":", "$", "languageDefault", ";", "$", "this", "->", "setDefaultLanguage", "(", "$", "language", ")", ";", "}", "return", "$", "this", "->", "defaultLanguage", ";", "}" ]
gets the default language to be used when translating @return boolean $language
[ "gets", "the", "default", "language", "to", "be", "used", "when", "translating" ]
974e57099d901126c4117010f4a269fe1f80b651
https://github.com/bytic/translation/blob/974e57099d901126c4117010f4a269fe1f80b651/src/Translator/Traits/LegacyCodeTrait.php#L107-L118
10,233
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.findUserById
public function findUserById($id) { if ($id instanceof UserInterface) { return $id; } $result = $this->userProvider->findById($id); if ($result) { return $result; } $exceptionMessage = "A user with the ID '%(id)s' cannot be found."; throw new UserNotFound(isprintf($exceptionMessage, compact('id'))); }
php
public function findUserById($id) { if ($id instanceof UserInterface) { return $id; } $result = $this->userProvider->findById($id); if ($result) { return $result; } $exceptionMessage = "A user with the ID '%(id)s' cannot be found."; throw new UserNotFound(isprintf($exceptionMessage, compact('id'))); }
[ "public", "function", "findUserById", "(", "$", "id", ")", "{", "if", "(", "$", "id", "instanceof", "UserInterface", ")", "{", "return", "$", "id", ";", "}", "$", "result", "=", "$", "this", "->", "userProvider", "->", "findById", "(", "$", "id", ")", ";", "if", "(", "$", "result", ")", "{", "return", "$", "result", ";", "}", "$", "exceptionMessage", "=", "\"A user with the ID '%(id)s' cannot be found.\"", ";", "throw", "new", "UserNotFound", "(", "isprintf", "(", "$", "exceptionMessage", ",", "compact", "(", "'id'", ")", ")", ")", ";", "}" ]
Find a user by their ID @param integer|Reflex\Lockdown\Users\UserInterface $id @return Reflex\Lockdown\Users\UserInterface @throws Reflex\Lockdown\UserNotFoundException If User isn't found
[ "Find", "a", "user", "by", "their", "ID" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L152-L166
10,234
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.findUserByLogin
public function findUserByLogin($login) { if ($login instanceof UserInterface) { return $login; } $result = $this->userProvider->findByLogin($login); if ($result) { return $result; } $exceptionMessage = "A user with the login '%(login)s' cannot be found."; throw new UserNotFound(isprintf($exceptionMessage, compact('login'))); }
php
public function findUserByLogin($login) { if ($login instanceof UserInterface) { return $login; } $result = $this->userProvider->findByLogin($login); if ($result) { return $result; } $exceptionMessage = "A user with the login '%(login)s' cannot be found."; throw new UserNotFound(isprintf($exceptionMessage, compact('login'))); }
[ "public", "function", "findUserByLogin", "(", "$", "login", ")", "{", "if", "(", "$", "login", "instanceof", "UserInterface", ")", "{", "return", "$", "login", ";", "}", "$", "result", "=", "$", "this", "->", "userProvider", "->", "findByLogin", "(", "$", "login", ")", ";", "if", "(", "$", "result", ")", "{", "return", "$", "result", ";", "}", "$", "exceptionMessage", "=", "\"A user with the login '%(login)s' cannot be found.\"", ";", "throw", "new", "UserNotFound", "(", "isprintf", "(", "$", "exceptionMessage", ",", "compact", "(", "'login'", ")", ")", ")", ";", "}" ]
Find a user by their login @param string|Reflex\Lockdown\Users\UserInterface $id @return Reflex\Lockdown\Users\UserInterface @throws UserNotFoundException If User not found
[ "Find", "a", "user", "by", "their", "login" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L174-L188
10,235
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.giveRolePermission
public function giveRolePermission($role, $permission, $level = 'allow') { $this->checkPermissionLevel($level); $role = $this->findRoleByKey($role); $permission = $this->findPermissionByKey($permission); return $role->give($permission, $level); }
php
public function giveRolePermission($role, $permission, $level = 'allow') { $this->checkPermissionLevel($level); $role = $this->findRoleByKey($role); $permission = $this->findPermissionByKey($permission); return $role->give($permission, $level); }
[ "public", "function", "giveRolePermission", "(", "$", "role", ",", "$", "permission", ",", "$", "level", "=", "'allow'", ")", "{", "$", "this", "->", "checkPermissionLevel", "(", "$", "level", ")", ";", "$", "role", "=", "$", "this", "->", "findRoleByKey", "(", "$", "role", ")", ";", "$", "permission", "=", "$", "this", "->", "findPermissionByKey", "(", "$", "permission", ")", ";", "return", "$", "role", "->", "give", "(", "$", "permission", ",", "$", "level", ")", ";", "}" ]
Give a role a permission @param Reflex\Lockdown\Roles\RoleInterface|string $role @param Reflex\Lockdown\Permissions\PermissionInterface|string $permission @param string $level @return boolean
[ "Give", "a", "role", "a", "permission" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L224-L232
10,236
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.removeRolePermission
public function removeRolePermission($role, $permission) { $role = $this->findRoleByKey($role); $permission = $this->findPermissionByKey($permission); return $role->remove($permission); }
php
public function removeRolePermission($role, $permission) { $role = $this->findRoleByKey($role); $permission = $this->findPermissionByKey($permission); return $role->remove($permission); }
[ "public", "function", "removeRolePermission", "(", "$", "role", ",", "$", "permission", ")", "{", "$", "role", "=", "$", "this", "->", "findRoleByKey", "(", "$", "role", ")", ";", "$", "permission", "=", "$", "this", "->", "findPermissionByKey", "(", "$", "permission", ")", ";", "return", "$", "role", "->", "remove", "(", "$", "permission", ")", ";", "}" ]
Remove a permission from a role @param Reflex\Lockdown\Roles\RoleInterface|string $role @param Reflex\Lockdown\Permission\PermissionInterface|string $permission @return boolean
[ "Remove", "a", "permission", "from", "a", "role" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L240-L246
10,237
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.giveUserPermission
public function giveUserPermission($user, $permission, $level = 'allow') { $this->checkPermissionLevel($level); $user = $this->findUserById($user); $permission = $this->findPermissionByKey($permission); return $user->give($permission, $level); }
php
public function giveUserPermission($user, $permission, $level = 'allow') { $this->checkPermissionLevel($level); $user = $this->findUserById($user); $permission = $this->findPermissionByKey($permission); return $user->give($permission, $level); }
[ "public", "function", "giveUserPermission", "(", "$", "user", ",", "$", "permission", ",", "$", "level", "=", "'allow'", ")", "{", "$", "this", "->", "checkPermissionLevel", "(", "$", "level", ")", ";", "$", "user", "=", "$", "this", "->", "findUserById", "(", "$", "user", ")", ";", "$", "permission", "=", "$", "this", "->", "findPermissionByKey", "(", "$", "permission", ")", ";", "return", "$", "user", "->", "give", "(", "$", "permission", ",", "$", "level", ")", ";", "}" ]
Give a user a permission @param Reflex\Lockdown\Users\UserInterface|string $user @param Reflex\Lockdown\Permissions\PermissionInterface|string $permission @param string $level @return boolean
[ "Give", "a", "user", "a", "permission" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L255-L263
10,238
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.removeUserPermission
public function removeUserPermission($user, $permission) { $permissions= $this->findPermissionByKey($permission); $user = $this->findUserById($user); return $user->remove($permission); }
php
public function removeUserPermission($user, $permission) { $permissions= $this->findPermissionByKey($permission); $user = $this->findUserById($user); return $user->remove($permission); }
[ "public", "function", "removeUserPermission", "(", "$", "user", ",", "$", "permission", ")", "{", "$", "permissions", "=", "$", "this", "->", "findPermissionByKey", "(", "$", "permission", ")", ";", "$", "user", "=", "$", "this", "->", "findUserById", "(", "$", "user", ")", ";", "return", "$", "user", "->", "remove", "(", "$", "permission", ")", ";", "}" ]
Remove a permission from a user @param Reflex\Lockdown\Users\UserInterface|string $user @param Reflex\Lockdown\Permissions\PermissionInterface|string $permission @return boolean
[ "Remove", "a", "permission", "from", "a", "user" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L271-L277
10,239
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.giveUserRole
public function giveUserRole($user, $role) { $user = $this->findUserById($user); $role = $this->findRoleByKey($role); if ($user->is($role->key)) { return true; } return $user->join($role); }
php
public function giveUserRole($user, $role) { $user = $this->findUserById($user); $role = $this->findRoleByKey($role); if ($user->is($role->key)) { return true; } return $user->join($role); }
[ "public", "function", "giveUserRole", "(", "$", "user", ",", "$", "role", ")", "{", "$", "user", "=", "$", "this", "->", "findUserById", "(", "$", "user", ")", ";", "$", "role", "=", "$", "this", "->", "findRoleByKey", "(", "$", "role", ")", ";", "if", "(", "$", "user", "->", "is", "(", "$", "role", "->", "key", ")", ")", "{", "return", "true", ";", "}", "return", "$", "user", "->", "join", "(", "$", "role", ")", ";", "}" ]
Give a user a role @param Reflex\Lockdown\Users\UserInterface|string $user @param Reflex\Lockdown\Roles\RoleInterface|string $role @return boolean
[ "Give", "a", "user", "a", "role" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L285-L295
10,240
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.removeUserRole
public function removeUserRole($user, $role) { $user = $this->findUserById($user); $role = $this->findRoleByKey($role); if ($user->not($role->key)) { return true; } return $user->leave($role); }
php
public function removeUserRole($user, $role) { $user = $this->findUserById($user); $role = $this->findRoleByKey($role); if ($user->not($role->key)) { return true; } return $user->leave($role); }
[ "public", "function", "removeUserRole", "(", "$", "user", ",", "$", "role", ")", "{", "$", "user", "=", "$", "this", "->", "findUserById", "(", "$", "user", ")", ";", "$", "role", "=", "$", "this", "->", "findRoleByKey", "(", "$", "role", ")", ";", "if", "(", "$", "user", "->", "not", "(", "$", "role", "->", "key", ")", ")", "{", "return", "true", ";", "}", "return", "$", "user", "->", "leave", "(", "$", "role", ")", ";", "}" ]
Remove a role from a user @param Reflex\Lockdown\Users\UserInterface|string $user @param Reflex\Lockdown\Roles\RoleInterface|string $role @return boolean
[ "Remove", "a", "role", "from", "a", "user" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L303-L313
10,241
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.createPermission
public function createPermission($name, $key = null, $description = null) { $key = snake_case(isset($key) ? $key : $name); $description= isset($description) ? $description : $name; $values = compact('name', 'key', 'description'); return $this->permissionProvider->create($values); }
php
public function createPermission($name, $key = null, $description = null) { $key = snake_case(isset($key) ? $key : $name); $description= isset($description) ? $description : $name; $values = compact('name', 'key', 'description'); return $this->permissionProvider->create($values); }
[ "public", "function", "createPermission", "(", "$", "name", ",", "$", "key", "=", "null", ",", "$", "description", "=", "null", ")", "{", "$", "key", "=", "snake_case", "(", "isset", "(", "$", "key", ")", "?", "$", "key", ":", "$", "name", ")", ";", "$", "description", "=", "isset", "(", "$", "description", ")", "?", "$", "description", ":", "$", "name", ";", "$", "values", "=", "compact", "(", "'name'", ",", "'key'", ",", "'description'", ")", ";", "return", "$", "this", "->", "permissionProvider", "->", "create", "(", "$", "values", ")", ";", "}" ]
Create a permission @param string $name @param string $key @param string $description @return boolean
[ "Create", "a", "permission" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L348-L355
10,242
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.has
public function has($id, $permission, $all = true) { if (! $user = $this->findUserById($id)) { return false; } return $user->has($permission, $all); }
php
public function has($id, $permission, $all = true) { if (! $user = $this->findUserById($id)) { return false; } return $user->has($permission, $all); }
[ "public", "function", "has", "(", "$", "id", ",", "$", "permission", ",", "$", "all", "=", "true", ")", "{", "if", "(", "!", "$", "user", "=", "$", "this", "->", "findUserById", "(", "$", "id", ")", ")", "{", "return", "false", ";", "}", "return", "$", "user", "->", "has", "(", "$", "permission", ",", "$", "all", ")", ";", "}" ]
Does the user have a permission? @param integer $id @param string $permission @param boolean $all @return boolean
[ "Does", "the", "user", "have", "a", "permission?" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L374-L381
10,243
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.hasnt
public function hasnt($id, $permission, $all = true) { return false === $this->has($id, $permission, $all); }
php
public function hasnt($id, $permission, $all = true) { return false === $this->has($id, $permission, $all); }
[ "public", "function", "hasnt", "(", "$", "id", ",", "$", "permission", ",", "$", "all", "=", "true", ")", "{", "return", "false", "===", "$", "this", "->", "has", "(", "$", "id", ",", "$", "permission", ",", "$", "all", ")", ";", "}" ]
Does the user not have a permission @param integer $id @param string $permission @param boolean $all @return boolean
[ "Does", "the", "user", "not", "have", "a", "permission" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L390-L393
10,244
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.is
public function is($id, $role, $all = true) { if (! $user = $this->findUserById($id)) { return false; } return $user->is($role, $all); }
php
public function is($id, $role, $all = true) { if (! $user = $this->findUserById($id)) { return false; } return $user->is($role, $all); }
[ "public", "function", "is", "(", "$", "id", ",", "$", "role", ",", "$", "all", "=", "true", ")", "{", "if", "(", "!", "$", "user", "=", "$", "this", "->", "findUserById", "(", "$", "id", ")", ")", "{", "return", "false", ";", "}", "return", "$", "user", "->", "is", "(", "$", "role", ",", "$", "all", ")", ";", "}" ]
Is the user part of a role? @param integer $id @param string $role @param boolean $all @return boolean
[ "Is", "the", "user", "part", "of", "a", "role?" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L402-L409
10,245
reflex-php/lockdown
src/Reflex/Lockdown/Lockdown.php
Lockdown.not
public function not($id, $role, $all = true) { return false === $this->is($id, $role, $all); }
php
public function not($id, $role, $all = true) { return false === $this->is($id, $role, $all); }
[ "public", "function", "not", "(", "$", "id", ",", "$", "role", ",", "$", "all", "=", "true", ")", "{", "return", "false", "===", "$", "this", "->", "is", "(", "$", "id", ",", "$", "role", ",", "$", "all", ")", ";", "}" ]
Is the user not part of a role? @param integer $id @param string $role @param boolean $all @return boolean
[ "Is", "the", "user", "not", "part", "of", "a", "role?" ]
2798e448608eef469f2924d75013deccfd6aca44
https://github.com/reflex-php/lockdown/blob/2798e448608eef469f2924d75013deccfd6aca44/src/Reflex/Lockdown/Lockdown.php#L418-L421
10,246
nia-php/validation
sources/TimeValidator.php
TimeValidator.checktime
private function checktime(int $hour, int $minute, int $second) { if ($hour < 0 || $hour > 23) { return false; } elseif ($minute < 0 || $minute > 59) { return false; } elseif ($second < 0 || $second > 59) { return false; } return true; }
php
private function checktime(int $hour, int $minute, int $second) { if ($hour < 0 || $hour > 23) { return false; } elseif ($minute < 0 || $minute > 59) { return false; } elseif ($second < 0 || $second > 59) { return false; } return true; }
[ "private", "function", "checktime", "(", "int", "$", "hour", ",", "int", "$", "minute", ",", "int", "$", "second", ")", "{", "if", "(", "$", "hour", "<", "0", "||", "$", "hour", ">", "23", ")", "{", "return", "false", ";", "}", "elseif", "(", "$", "minute", "<", "0", "||", "$", "minute", ">", "59", ")", "{", "return", "false", ";", "}", "elseif", "(", "$", "second", "<", "0", "||", "$", "second", ">", "59", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks whether the passed time is a valid time. @param int $hour The hour. @param int $minute The minute. @param int $second The second. @return bool Returns 'true' if the passed time is a valid time, otherwise 'false' will be returned.
[ "Checks", "whether", "the", "passed", "time", "is", "a", "valid", "time", "." ]
49e9edc4589721e475be6099213aaf563638b056
https://github.com/nia-php/validation/blob/49e9edc4589721e475be6099213aaf563638b056/sources/TimeValidator.php#L66-L77
10,247
webforge-labs/webforge-utils
src/php/Webforge/Common/ArrayUtil.php
ArrayUtil.join
public static function join(Array $pieces, $glue) { $s = NULL; foreach ($pieces as $key =>$piece) { if (is_array($piece)) $piece = 'Array'; $s .= sprintf($glue, $piece, $key); } return $s; }
php
public static function join(Array $pieces, $glue) { $s = NULL; foreach ($pieces as $key =>$piece) { if (is_array($piece)) $piece = 'Array'; $s .= sprintf($glue, $piece, $key); } return $s; }
[ "public", "static", "function", "join", "(", "Array", "$", "pieces", ",", "$", "glue", ")", "{", "$", "s", "=", "NULL", ";", "foreach", "(", "$", "pieces", "as", "$", "key", "=>", "$", "piece", ")", "{", "if", "(", "is_array", "(", "$", "piece", ")", ")", "$", "piece", "=", "'Array'", ";", "$", "s", ".=", "sprintf", "(", "$", "glue", ",", "$", "piece", ",", "$", "key", ")", ";", "}", "return", "$", "s", ";", "}" ]
Joins an array to string Aus einem Array ein geschriebenes Array machen: print '$GLOBALS'.A::join(array('conf','default','db'), "['%s']"); // $GLOBALS['conf']['default']['db'] das erste %s ist der Wert aus dem Array das zweite %s ist der Schlüssel aus dem Array. Diese können mit %1$s (wert) %2$s (schlüssel) addressiert werden @param array $pieces die Elemente die zusammengefügt werden sollen @param string $glue der String welcher die Elemente umgeben soll. Er muss %s enthalten. An dieser Stelle wird das Array Element ersetzt
[ "Joins", "an", "array", "to", "string" ]
a476eeec046c22ad91794b0ab9fe15a1d3f92bfc
https://github.com/webforge-labs/webforge-utils/blob/a476eeec046c22ad91794b0ab9fe15a1d3f92bfc/src/php/Webforge/Common/ArrayUtil.php#L23-L31
10,248
webforge-labs/webforge-utils
src/php/Webforge/Common/ArrayUtil.php
ArrayUtil.remove
public static function remove(Array &$array, $item, $searchStrict = TRUE) { if (($key = array_search($item, $array, $searchStrict)) !== FALSE) { array_splice($array, $key, 1); } return $array; }
php
public static function remove(Array &$array, $item, $searchStrict = TRUE) { if (($key = array_search($item, $array, $searchStrict)) !== FALSE) { array_splice($array, $key, 1); } return $array; }
[ "public", "static", "function", "remove", "(", "Array", "&", "$", "array", ",", "$", "item", ",", "$", "searchStrict", "=", "TRUE", ")", "{", "if", "(", "(", "$", "key", "=", "array_search", "(", "$", "item", ",", "$", "array", ",", "$", "searchStrict", ")", ")", "!==", "FALSE", ")", "{", "array_splice", "(", "$", "array", ",", "$", "key", ",", "1", ")", ";", "}", "return", "$", "array", ";", "}" ]
Remove an element from an array the item is searched and removed, numeric arrays are renumbered only the first item matched will be removed @TODO FIXME: boolean trap @param bool $searchStrict if false only the value will be replace @return array
[ "Remove", "an", "element", "from", "an", "array" ]
a476eeec046c22ad91794b0ab9fe15a1d3f92bfc
https://github.com/webforge-labs/webforge-utils/blob/a476eeec046c22ad91794b0ab9fe15a1d3f92bfc/src/php/Webforge/Common/ArrayUtil.php#L151-L157
10,249
webforge-labs/webforge-utils
src/php/Webforge/Common/ArrayUtil.php
ArrayUtil.filterKeys
public static function filterKeys(Array $array, Closure $filter) { $filtered = array(); //@TODO maybe something with array_filter as callback is faster here? benchmark? foreach ($array as $key => $value) { if ($filter($key, $value)) { $filtered[$key] = $value; } } return $filtered; }
php
public static function filterKeys(Array $array, Closure $filter) { $filtered = array(); //@TODO maybe something with array_filter as callback is faster here? benchmark? foreach ($array as $key => $value) { if ($filter($key, $value)) { $filtered[$key] = $value; } } return $filtered; }
[ "public", "static", "function", "filterKeys", "(", "Array", "$", "array", ",", "Closure", "$", "filter", ")", "{", "$", "filtered", "=", "array", "(", ")", ";", "//@TODO maybe something with array_filter as callback is faster here? benchmark?", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "filter", "(", "$", "key", ",", "$", "value", ")", ")", "{", "$", "filtered", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "filtered", ";", "}" ]
Filters the keys and values from an array there is only one callback allowed that should return truthy if the value SHOULD exist in the new array the first parameter of the callback is the key and the second is the key but this function has the keys passed as second parameter the new array is NOT renumbered @param array $array will not be modified @param closure $filter bool function($key, $value) @return array with same keys as the input array (if not filtered)
[ "Filters", "the", "keys", "and", "values", "from", "an", "array" ]
a476eeec046c22ad91794b0ab9fe15a1d3f92bfc
https://github.com/webforge-labs/webforge-utils/blob/a476eeec046c22ad91794b0ab9fe15a1d3f92bfc/src/php/Webforge/Common/ArrayUtil.php#L337-L348
10,250
webforge-labs/webforge-utils
src/php/Webforge/Common/ArrayUtil.php
ArrayUtil.indexBy
public static function indexBy(Array $array, $property) { $ret = array(); if (count($array) > 0) { $index = Util::castGetterFromSample($property, current($array)); foreach ($array as $item) { $ret[$index($item)] = $item; } } return $ret; }
php
public static function indexBy(Array $array, $property) { $ret = array(); if (count($array) > 0) { $index = Util::castGetterFromSample($property, current($array)); foreach ($array as $item) { $ret[$index($item)] = $item; } } return $ret; }
[ "public", "static", "function", "indexBy", "(", "Array", "$", "array", ",", "$", "property", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "if", "(", "count", "(", "$", "array", ")", ">", "0", ")", "{", "$", "index", "=", "Util", "::", "castGetterFromSample", "(", "$", "property", ",", "current", "(", "$", "array", ")", ")", ";", "foreach", "(", "$", "array", "as", "$", "item", ")", "{", "$", "ret", "[", "$", "index", "(", "$", "item", ")", "]", "=", "$", "item", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Returns an array with the index constructred from objects in the collection @param mixed $property see pluck() for details @return array
[ "Returns", "an", "array", "with", "the", "index", "constructred", "from", "objects", "in", "the", "collection" ]
a476eeec046c22ad91794b0ab9fe15a1d3f92bfc
https://github.com/webforge-labs/webforge-utils/blob/a476eeec046c22ad91794b0ab9fe15a1d3f92bfc/src/php/Webforge/Common/ArrayUtil.php#L356-L368
10,251
neontabs-drupal8/nt8property
src/Service/NT8PropertyService.php
NT8PropertyService.getAttributeDataFromTabs
public function getAttributeDataFromTabs(array $limit = []) { $api_root_data = json_decode($this->nt8RestService->get('/')); $attrib_data = $api_root_data->constants->attributes; if (count($limit) > 0) { $attrib_data = array_filter($attrib_data, function ($value) use ($limit) { $attr_code = $value->code ?: ''; if (in_array($attr_code, $limit)) { return TRUE; } return FALSE; }); } return $attrib_data; }
php
public function getAttributeDataFromTabs(array $limit = []) { $api_root_data = json_decode($this->nt8RestService->get('/')); $attrib_data = $api_root_data->constants->attributes; if (count($limit) > 0) { $attrib_data = array_filter($attrib_data, function ($value) use ($limit) { $attr_code = $value->code ?: ''; if (in_array($attr_code, $limit)) { return TRUE; } return FALSE; }); } return $attrib_data; }
[ "public", "function", "getAttributeDataFromTabs", "(", "array", "$", "limit", "=", "[", "]", ")", "{", "$", "api_root_data", "=", "json_decode", "(", "$", "this", "->", "nt8RestService", "->", "get", "(", "'/'", ")", ")", ";", "$", "attrib_data", "=", "$", "api_root_data", "->", "constants", "->", "attributes", ";", "if", "(", "count", "(", "$", "limit", ")", ">", "0", ")", "{", "$", "attrib_data", "=", "array_filter", "(", "$", "attrib_data", ",", "function", "(", "$", "value", ")", "use", "(", "$", "limit", ")", "{", "$", "attr_code", "=", "$", "value", "->", "code", "?", ":", "''", ";", "if", "(", "in_array", "(", "$", "attr_code", ",", "$", "limit", ")", ")", "{", "return", "TRUE", ";", "}", "return", "FALSE", ";", "}", ")", ";", "}", "return", "$", "attrib_data", ";", "}" ]
Fetches data for the specified attributes from Tabs. @param array $limit Limit the returned results by attribute code. Example: $limit = [ 'ATTR01', 'ATTR02' ] This will only return data for those attributes from the API. If an empty array is passed all of the data will be returned. @return array Data for each attribute contained in an array.
[ "Fetches", "data", "for", "the", "specified", "attributes", "from", "Tabs", "." ]
53b630a612c6dc7c90a8ca1ce4ceb41568473447
https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Service/NT8PropertyService.php#L56-L72
10,252
neontabs-drupal8/nt8property
src/Service/NT8PropertyService.php
NT8PropertyService.createAttributesFromTabs
public function createAttributesFromTabs(array $attrib_data = []) { // Return value. $updatedAttrs = ""; $save_status = FALSE; foreach ($attrib_data as $attr_key => $attribute) { $attr_array = [ 'field_attribute_code' => ['value' => $attribute->code], 'field_attribute_brand' => ['value' => $attribute->brand], 'field_attribute_labl' => ['value' => $attribute->label], 'field_attribute_group' => ['value' => $attribute->group], 'field_attribute_type' => ['value' => $attribute->type], ]; // TODO: make this a configurable option or let the admin specify it. $attr_array['vid'] = $this::ATTRIBUTE_VOCAB_ID; // The name is needed by the Drupal Taxonomy API. $attr_array['name'] = $attribute->label; $term = Term::create($attr_array); // Modify terms of the same name if they already exist. $terms = self::loadTermsByNames($this::ATTRIBUTE_VOCAB_ID, [$attr_array['name']], function (&$term) use ($attr_array, &$save_status) { $term->get('field_attribute_code')->setValue($attr_array['field_attribute_code']); $term->get('field_attribute_brand')->setValue($attr_array['field_attribute_brand']); $term->get('field_attribute_labl')->setValue($attr_array['field_attribute_labl']); $term->get('field_attribute_group')->setValue($attr_array['field_attribute_group']); $term->get('field_attribute_type')->setValue($attr_array['field_attribute_type']); $save_status = $term->save(); }); if (is_null($terms)) { // @codeCoverageIgnoreStart $save_status = $term->save(); // @codeCoverageIgnoreEnd } if ($save_status) { $updatedAttrs .= $attr_array['field_attribute_code']['value'] . ", "; } } return $updatedAttrs; }
php
public function createAttributesFromTabs(array $attrib_data = []) { // Return value. $updatedAttrs = ""; $save_status = FALSE; foreach ($attrib_data as $attr_key => $attribute) { $attr_array = [ 'field_attribute_code' => ['value' => $attribute->code], 'field_attribute_brand' => ['value' => $attribute->brand], 'field_attribute_labl' => ['value' => $attribute->label], 'field_attribute_group' => ['value' => $attribute->group], 'field_attribute_type' => ['value' => $attribute->type], ]; // TODO: make this a configurable option or let the admin specify it. $attr_array['vid'] = $this::ATTRIBUTE_VOCAB_ID; // The name is needed by the Drupal Taxonomy API. $attr_array['name'] = $attribute->label; $term = Term::create($attr_array); // Modify terms of the same name if they already exist. $terms = self::loadTermsByNames($this::ATTRIBUTE_VOCAB_ID, [$attr_array['name']], function (&$term) use ($attr_array, &$save_status) { $term->get('field_attribute_code')->setValue($attr_array['field_attribute_code']); $term->get('field_attribute_brand')->setValue($attr_array['field_attribute_brand']); $term->get('field_attribute_labl')->setValue($attr_array['field_attribute_labl']); $term->get('field_attribute_group')->setValue($attr_array['field_attribute_group']); $term->get('field_attribute_type')->setValue($attr_array['field_attribute_type']); $save_status = $term->save(); }); if (is_null($terms)) { // @codeCoverageIgnoreStart $save_status = $term->save(); // @codeCoverageIgnoreEnd } if ($save_status) { $updatedAttrs .= $attr_array['field_attribute_code']['value'] . ", "; } } return $updatedAttrs; }
[ "public", "function", "createAttributesFromTabs", "(", "array", "$", "attrib_data", "=", "[", "]", ")", "{", "// Return value.", "$", "updatedAttrs", "=", "\"\"", ";", "$", "save_status", "=", "FALSE", ";", "foreach", "(", "$", "attrib_data", "as", "$", "attr_key", "=>", "$", "attribute", ")", "{", "$", "attr_array", "=", "[", "'field_attribute_code'", "=>", "[", "'value'", "=>", "$", "attribute", "->", "code", "]", ",", "'field_attribute_brand'", "=>", "[", "'value'", "=>", "$", "attribute", "->", "brand", "]", ",", "'field_attribute_labl'", "=>", "[", "'value'", "=>", "$", "attribute", "->", "label", "]", ",", "'field_attribute_group'", "=>", "[", "'value'", "=>", "$", "attribute", "->", "group", "]", ",", "'field_attribute_type'", "=>", "[", "'value'", "=>", "$", "attribute", "->", "type", "]", ",", "]", ";", "// TODO: make this a configurable option or let the admin specify it.", "$", "attr_array", "[", "'vid'", "]", "=", "$", "this", "::", "ATTRIBUTE_VOCAB_ID", ";", "// The name is needed by the Drupal Taxonomy API.", "$", "attr_array", "[", "'name'", "]", "=", "$", "attribute", "->", "label", ";", "$", "term", "=", "Term", "::", "create", "(", "$", "attr_array", ")", ";", "// Modify terms of the same name if they already exist.", "$", "terms", "=", "self", "::", "loadTermsByNames", "(", "$", "this", "::", "ATTRIBUTE_VOCAB_ID", ",", "[", "$", "attr_array", "[", "'name'", "]", "]", ",", "function", "(", "&", "$", "term", ")", "use", "(", "$", "attr_array", ",", "&", "$", "save_status", ")", "{", "$", "term", "->", "get", "(", "'field_attribute_code'", ")", "->", "setValue", "(", "$", "attr_array", "[", "'field_attribute_code'", "]", ")", ";", "$", "term", "->", "get", "(", "'field_attribute_brand'", ")", "->", "setValue", "(", "$", "attr_array", "[", "'field_attribute_brand'", "]", ")", ";", "$", "term", "->", "get", "(", "'field_attribute_labl'", ")", "->", "setValue", "(", "$", "attr_array", "[", "'field_attribute_labl'", "]", ")", ";", "$", "term", "->", "get", "(", "'field_attribute_group'", ")", "->", "setValue", "(", "$", "attr_array", "[", "'field_attribute_group'", "]", ")", ";", "$", "term", "->", "get", "(", "'field_attribute_type'", ")", "->", "setValue", "(", "$", "attr_array", "[", "'field_attribute_type'", "]", ")", ";", "$", "save_status", "=", "$", "term", "->", "save", "(", ")", ";", "}", ")", ";", "if", "(", "is_null", "(", "$", "terms", ")", ")", "{", "// @codeCoverageIgnoreStart", "$", "save_status", "=", "$", "term", "->", "save", "(", ")", ";", "// @codeCoverageIgnoreEnd", "}", "if", "(", "$", "save_status", ")", "{", "$", "updatedAttrs", ".=", "$", "attr_array", "[", "'field_attribute_code'", "]", "[", "'value'", "]", ".", "\", \"", ";", "}", "}", "return", "$", "updatedAttrs", ";", "}" ]
Populates the cottage_attributes taxonomy with data from TABS. @param array $attrib_data The response array retrieved from TABS. @return string A comma separated list of created/updated entries in the taxonomy. @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException @throws \Drupal\Core\Entity\EntityStorageException @throws \Drupal\Core\Entity\Exception\AmbiguousEntityClassException @throws \Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException
[ "Populates", "the", "cottage_attributes", "taxonomy", "with", "data", "from", "TABS", "." ]
53b630a612c6dc7c90a8ca1ce4ceb41568473447
https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Service/NT8PropertyService.php#L309-L355
10,253
neontabs-drupal8/nt8property
src/Service/NT8PropertyService.php
NT8PropertyService.loadNodesFromProprefs
public function loadNodesFromProprefs(array $proprefs) { $loadedNodes = []; foreach ($proprefs as $propref) { $nodes = $this->loadNodesFromPropref($propref) ?: []; if (count($nodes) > 0) { foreach ($nodes as $node) { $loadedNodes[$propref][] = $node; } } } return $loadedNodes; }
php
public function loadNodesFromProprefs(array $proprefs) { $loadedNodes = []; foreach ($proprefs as $propref) { $nodes = $this->loadNodesFromPropref($propref) ?: []; if (count($nodes) > 0) { foreach ($nodes as $node) { $loadedNodes[$propref][] = $node; } } } return $loadedNodes; }
[ "public", "function", "loadNodesFromProprefs", "(", "array", "$", "proprefs", ")", "{", "$", "loadedNodes", "=", "[", "]", ";", "foreach", "(", "$", "proprefs", "as", "$", "propref", ")", "{", "$", "nodes", "=", "$", "this", "->", "loadNodesFromPropref", "(", "$", "propref", ")", "?", ":", "[", "]", ";", "if", "(", "count", "(", "$", "nodes", ")", ">", "0", ")", "{", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "$", "loadedNodes", "[", "$", "propref", "]", "[", "]", "=", "$", "node", ";", "}", "}", "}", "return", "$", "loadedNodes", ";", "}" ]
Load node objects from an array of property references. @param array $proprefs Property references. @return array Loaded property nodes.
[ "Load", "node", "objects", "from", "an", "array", "of", "property", "references", "." ]
53b630a612c6dc7c90a8ca1ce4ceb41568473447
https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Service/NT8PropertyService.php#L366-L380
10,254
neontabs-drupal8/nt8property
src/Service/NT8PropertyService.php
NT8PropertyService.loadNodesFromPropref
public function loadNodesFromPropref(string $propref, bool $load = TRUE) { // Get the nodes to update with this data. $nodeQuery = $this->entityQuery->get('node'); $nodeStorage = $this->entityTypeManager->getStorage('node'); $nids = $nodeQuery->condition('field_cottage_reference_code.value', $propref, '=')->execute(); if (!$load) { return $nids; } $nodes = $nodeStorage->loadMultiple($nids); if (count($nodes) === 0) { \Drupal::logger('NT8PropertyService')->notice("Could not load a node for this propref: @propref", ['@propref' => print_r($propref, TRUE)]); $nodes = NULL; } return $nodes; }
php
public function loadNodesFromPropref(string $propref, bool $load = TRUE) { // Get the nodes to update with this data. $nodeQuery = $this->entityQuery->get('node'); $nodeStorage = $this->entityTypeManager->getStorage('node'); $nids = $nodeQuery->condition('field_cottage_reference_code.value', $propref, '=')->execute(); if (!$load) { return $nids; } $nodes = $nodeStorage->loadMultiple($nids); if (count($nodes) === 0) { \Drupal::logger('NT8PropertyService')->notice("Could not load a node for this propref: @propref", ['@propref' => print_r($propref, TRUE)]); $nodes = NULL; } return $nodes; }
[ "public", "function", "loadNodesFromPropref", "(", "string", "$", "propref", ",", "bool", "$", "load", "=", "TRUE", ")", "{", "// Get the nodes to update with this data.", "$", "nodeQuery", "=", "$", "this", "->", "entityQuery", "->", "get", "(", "'node'", ")", ";", "$", "nodeStorage", "=", "$", "this", "->", "entityTypeManager", "->", "getStorage", "(", "'node'", ")", ";", "$", "nids", "=", "$", "nodeQuery", "->", "condition", "(", "'field_cottage_reference_code.value'", ",", "$", "propref", ",", "'='", ")", "->", "execute", "(", ")", ";", "if", "(", "!", "$", "load", ")", "{", "return", "$", "nids", ";", "}", "$", "nodes", "=", "$", "nodeStorage", "->", "loadMultiple", "(", "$", "nids", ")", ";", "if", "(", "count", "(", "$", "nodes", ")", "===", "0", ")", "{", "\\", "Drupal", "::", "logger", "(", "'NT8PropertyService'", ")", "->", "notice", "(", "\"Could not load a node for this propref: @propref\"", ",", "[", "'@propref'", "=>", "print_r", "(", "$", "propref", ",", "TRUE", ")", "]", ")", ";", "$", "nodes", "=", "NULL", ";", "}", "return", "$", "nodes", ";", "}" ]
Loads property nodes which have the same propref as the one provided. @param string $propref Property reference to query for. @param bool $load True: Return loaded node objects. False: Make no attempt to load and return an array of NIDs. @return array|\Drupal\Core\Entity\EntityInterface[]|int|null An array of loaded property entities indexed by NID if $load = true otherwise an array of NIDs. @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
[ "Loads", "property", "nodes", "which", "have", "the", "same", "propref", "as", "the", "one", "provided", "." ]
53b630a612c6dc7c90a8ca1ce4ceb41568473447
https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Service/NT8PropertyService.php#L397-L415
10,255
neontabs-drupal8/nt8property
src/Service/NT8PropertyService.php
NT8PropertyService.updateNodeInstancesFromData
public function updateNodeInstancesFromData(\stdClass $data) { $updatedProperties = []; $nids = self::loadNodesFromPropref($data->propertyRef, FALSE); $updatedValues = self::generateUpdateArray($data, FALSE); if (count($nids) > 0) { $nodes = $this->entityTypeManager->getStorage('node')->loadMultiple($nids); foreach ($nodes as $node) { $updated = $this->updateNodeInstanceFromData($updatedValues, $node); if ($updated) { $updatedProperties[] = $data->propertyRef; $node->save(); } } } return $updatedProperties; }
php
public function updateNodeInstancesFromData(\stdClass $data) { $updatedProperties = []; $nids = self::loadNodesFromPropref($data->propertyRef, FALSE); $updatedValues = self::generateUpdateArray($data, FALSE); if (count($nids) > 0) { $nodes = $this->entityTypeManager->getStorage('node')->loadMultiple($nids); foreach ($nodes as $node) { $updated = $this->updateNodeInstanceFromData($updatedValues, $node); if ($updated) { $updatedProperties[] = $data->propertyRef; $node->save(); } } } return $updatedProperties; }
[ "public", "function", "updateNodeInstancesFromData", "(", "\\", "stdClass", "$", "data", ")", "{", "$", "updatedProperties", "=", "[", "]", ";", "$", "nids", "=", "self", "::", "loadNodesFromPropref", "(", "$", "data", "->", "propertyRef", ",", "FALSE", ")", ";", "$", "updatedValues", "=", "self", "::", "generateUpdateArray", "(", "$", "data", ",", "FALSE", ")", ";", "if", "(", "count", "(", "$", "nids", ")", ">", "0", ")", "{", "$", "nodes", "=", "$", "this", "->", "entityTypeManager", "->", "getStorage", "(", "'node'", ")", "->", "loadMultiple", "(", "$", "nids", ")", ";", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "$", "updated", "=", "$", "this", "->", "updateNodeInstanceFromData", "(", "$", "updatedValues", ",", "$", "node", ")", ";", "if", "(", "$", "updated", ")", "{", "$", "updatedProperties", "[", "]", "=", "$", "data", "->", "propertyRef", ";", "$", "node", "->", "save", "(", ")", ";", "}", "}", "}", "return", "$", "updatedProperties", ";", "}" ]
Updates all matching nodes with data provided by the TABS api. Example Usage: $data = json_decode($api_property_data_response_string); updateNodeInstancesFromData($data); @param \stdClass $data Property data as returned from the API. @return array Returns an array of all of the successfully updated properties' NIDs. @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException @throws \Drupal\Core\Entity\EntityStorageException
[ "Updates", "all", "matching", "nodes", "with", "data", "provided", "by", "the", "TABS", "api", "." ]
53b630a612c6dc7c90a8ca1ce4ceb41568473447
https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Service/NT8PropertyService.php#L433-L453
10,256
neontabs-drupal8/nt8property
src/Service/NT8PropertyService.php
NT8PropertyService.getNodeFieldValue
public static function getNodeFieldValue( EntityInterface $node, string $fieldName, int $index = -1, string $keyname = 'value' ) { $field_instance = static::getNodeField($node, $fieldName); $field_instance_value = $field_instance->getValue(); if ($index > -1) { $field_instance_value = $field_instance_value[$index][$keyname]; } return $field_instance_value; }
php
public static function getNodeFieldValue( EntityInterface $node, string $fieldName, int $index = -1, string $keyname = 'value' ) { $field_instance = static::getNodeField($node, $fieldName); $field_instance_value = $field_instance->getValue(); if ($index > -1) { $field_instance_value = $field_instance_value[$index][$keyname]; } return $field_instance_value; }
[ "public", "static", "function", "getNodeFieldValue", "(", "EntityInterface", "$", "node", ",", "string", "$", "fieldName", ",", "int", "$", "index", "=", "-", "1", ",", "string", "$", "keyname", "=", "'value'", ")", "{", "$", "field_instance", "=", "static", "::", "getNodeField", "(", "$", "node", ",", "$", "fieldName", ")", ";", "$", "field_instance_value", "=", "$", "field_instance", "->", "getValue", "(", ")", ";", "if", "(", "$", "index", ">", "-", "1", ")", "{", "$", "field_instance_value", "=", "$", "field_instance_value", "[", "$", "index", "]", "[", "$", "keyname", "]", ";", "}", "return", "$", "field_instance_value", ";", "}" ]
Retrieves a field value from a specified node. @param \Drupal\Core\Entity\EntityInterface $node Loaded property node. @param string $fieldName Field to load. @param int $index Load $index of the field instance array. @param string $keyname Load $keyname of the specified $index of the field instance array. @return mixed The field value as specified by the parameters.
[ "Retrieves", "a", "field", "value", "from", "a", "specified", "node", "." ]
53b630a612c6dc7c90a8ca1ce4ceb41568473447
https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Service/NT8PropertyService.php#L474-L488
10,257
neontabs-drupal8/nt8property
src/Service/NT8PropertyService.php
NT8PropertyService.getTidFromTermName
public static function getTidFromTermName($term_name, $vocab_name) { $tid = -1; if ($terms = taxonomy_term_load_multiple_by_name($term_name, $vocab_name)) { $term = reset($terms); $tid = $term->id(); } return $tid; }
php
public static function getTidFromTermName($term_name, $vocab_name) { $tid = -1; if ($terms = taxonomy_term_load_multiple_by_name($term_name, $vocab_name)) { $term = reset($terms); $tid = $term->id(); } return $tid; }
[ "public", "static", "function", "getTidFromTermName", "(", "$", "term_name", ",", "$", "vocab_name", ")", "{", "$", "tid", "=", "-", "1", ";", "if", "(", "$", "terms", "=", "taxonomy_term_load_multiple_by_name", "(", "$", "term_name", ",", "$", "vocab_name", ")", ")", "{", "$", "term", "=", "reset", "(", "$", "terms", ")", ";", "$", "tid", "=", "$", "term", "->", "id", "(", ")", ";", "}", "return", "$", "tid", ";", "}" ]
Retrieves a TID for a given term name. Rturns -1 if term couldn't be found.
[ "Retrieves", "a", "TID", "for", "a", "given", "term", "name", ".", "Rturns", "-", "1", "if", "term", "couldn", "t", "be", "found", "." ]
53b630a612c6dc7c90a8ca1ce4ceb41568473447
https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Service/NT8PropertyService.php#L508-L516
10,258
neontabs-drupal8/nt8property
src/Service/NT8PropertyService.php
NT8PropertyService.updateNodeInstanceFromData
public function updateNodeInstanceFromData(array $updatedValues, EntityInterface &$nodeInstance) { $updated = FALSE; // Compare for differences and update if a difference is found. foreach ($updatedValues as $updatedValueKey => $updatedValue) { $currentNodeField = static::getNodeFieldValue($nodeInstance, $updatedValueKey); $length_of_update_fields = count($updatedValue); $updateIndex = 0; // For each field on the current node. // Iterate through the child entries attached to the field. // This works for all fields even those with cardinality: 1. foreach ($currentNodeField as $index => $nodeFieldValue) { $comparisonUpdate = $updatedValue; // If the field has more than 1 entries. // Set the comparison to the value of the current entry. // We keep track of current entry by incrementing the `updateIndex` var. if ($length_of_update_fields > 1) { $comparisonUpdate = $updatedValue[$updateIndex++] ?? $updatedValue; } // Sometimes the data to compare is nested another level deep. // This retrieves it and lets us continue as if it were a flat array. $nestedComparison = $comparisonUpdate[0] ?? NULL; if ($nestedComparison && is_array($nestedComparison)) { // @codeCoverageIgnoreStart $comparisonUpdate = $nestedComparison; // @codeCoverageIgnoreEnd } // Sort both arrays so the equality check below evaluates correctly. sort($comparisonUpdate); sort($nodeFieldValue); // Compare the two field entries for differences. $difference = ($comparisonUpdate == $nodeFieldValue); if ($difference == 0) { // If a difference is found update the whole field entry. $fieldRef = static::getNodeField($nodeInstance, $updatedValueKey); $fieldRef->setValue($updatedValue); // We should only save if $updated is equal to TRUE. $updated = TRUE; } } } return $updated; }
php
public function updateNodeInstanceFromData(array $updatedValues, EntityInterface &$nodeInstance) { $updated = FALSE; // Compare for differences and update if a difference is found. foreach ($updatedValues as $updatedValueKey => $updatedValue) { $currentNodeField = static::getNodeFieldValue($nodeInstance, $updatedValueKey); $length_of_update_fields = count($updatedValue); $updateIndex = 0; // For each field on the current node. // Iterate through the child entries attached to the field. // This works for all fields even those with cardinality: 1. foreach ($currentNodeField as $index => $nodeFieldValue) { $comparisonUpdate = $updatedValue; // If the field has more than 1 entries. // Set the comparison to the value of the current entry. // We keep track of current entry by incrementing the `updateIndex` var. if ($length_of_update_fields > 1) { $comparisonUpdate = $updatedValue[$updateIndex++] ?? $updatedValue; } // Sometimes the data to compare is nested another level deep. // This retrieves it and lets us continue as if it were a flat array. $nestedComparison = $comparisonUpdate[0] ?? NULL; if ($nestedComparison && is_array($nestedComparison)) { // @codeCoverageIgnoreStart $comparisonUpdate = $nestedComparison; // @codeCoverageIgnoreEnd } // Sort both arrays so the equality check below evaluates correctly. sort($comparisonUpdate); sort($nodeFieldValue); // Compare the two field entries for differences. $difference = ($comparisonUpdate == $nodeFieldValue); if ($difference == 0) { // If a difference is found update the whole field entry. $fieldRef = static::getNodeField($nodeInstance, $updatedValueKey); $fieldRef->setValue($updatedValue); // We should only save if $updated is equal to TRUE. $updated = TRUE; } } } return $updated; }
[ "public", "function", "updateNodeInstanceFromData", "(", "array", "$", "updatedValues", ",", "EntityInterface", "&", "$", "nodeInstance", ")", "{", "$", "updated", "=", "FALSE", ";", "// Compare for differences and update if a difference is found.", "foreach", "(", "$", "updatedValues", "as", "$", "updatedValueKey", "=>", "$", "updatedValue", ")", "{", "$", "currentNodeField", "=", "static", "::", "getNodeFieldValue", "(", "$", "nodeInstance", ",", "$", "updatedValueKey", ")", ";", "$", "length_of_update_fields", "=", "count", "(", "$", "updatedValue", ")", ";", "$", "updateIndex", "=", "0", ";", "// For each field on the current node.", "// Iterate through the child entries attached to the field.", "// This works for all fields even those with cardinality: 1.", "foreach", "(", "$", "currentNodeField", "as", "$", "index", "=>", "$", "nodeFieldValue", ")", "{", "$", "comparisonUpdate", "=", "$", "updatedValue", ";", "// If the field has more than 1 entries.", "// Set the comparison to the value of the current entry.", "// We keep track of current entry by incrementing the `updateIndex` var.", "if", "(", "$", "length_of_update_fields", ">", "1", ")", "{", "$", "comparisonUpdate", "=", "$", "updatedValue", "[", "$", "updateIndex", "++", "]", "??", "$", "updatedValue", ";", "}", "// Sometimes the data to compare is nested another level deep.", "// This retrieves it and lets us continue as if it were a flat array.", "$", "nestedComparison", "=", "$", "comparisonUpdate", "[", "0", "]", "??", "NULL", ";", "if", "(", "$", "nestedComparison", "&&", "is_array", "(", "$", "nestedComparison", ")", ")", "{", "// @codeCoverageIgnoreStart", "$", "comparisonUpdate", "=", "$", "nestedComparison", ";", "// @codeCoverageIgnoreEnd", "}", "// Sort both arrays so the equality check below evaluates correctly.", "sort", "(", "$", "comparisonUpdate", ")", ";", "sort", "(", "$", "nodeFieldValue", ")", ";", "// Compare the two field entries for differences.", "$", "difference", "=", "(", "$", "comparisonUpdate", "==", "$", "nodeFieldValue", ")", ";", "if", "(", "$", "difference", "==", "0", ")", "{", "// If a difference is found update the whole field entry.", "$", "fieldRef", "=", "static", "::", "getNodeField", "(", "$", "nodeInstance", ",", "$", "updatedValueKey", ")", ";", "$", "fieldRef", "->", "setValue", "(", "$", "updatedValue", ")", ";", "// We should only save if $updated is equal to TRUE.", "$", "updated", "=", "TRUE", ";", "}", "}", "}", "return", "$", "updated", ";", "}" ]
Updates an EntityInterface from a provided array of updated values. @param array $updatedValues Array of updated values to be compared against. @param \Drupal\Core\Entity\EntityInterface $nodeInstance Instance of the node which has the fields to compare against. @return bool Indicates that field(s) have been changed on the node.
[ "Updates", "an", "EntityInterface", "from", "a", "provided", "array", "of", "updated", "values", "." ]
53b630a612c6dc7c90a8ca1ce4ceb41568473447
https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Service/NT8PropertyService.php#L531-L583
10,259
neontabs-drupal8/nt8property
src/Service/NT8PropertyService.php
NT8PropertyService.createNodeInstanceFromPropref
public function createNodeInstanceFromPropref(string $propRef = "") { $data = $this->getPropertyFromApi($propRef); $created_node = NULL; if ($data && $data instanceof \stdClass) { $created_node = $this->createNodeInstanceFromData($data, TRUE); } return $created_node; }
php
public function createNodeInstanceFromPropref(string $propRef = "") { $data = $this->getPropertyFromApi($propRef); $created_node = NULL; if ($data && $data instanceof \stdClass) { $created_node = $this->createNodeInstanceFromData($data, TRUE); } return $created_node; }
[ "public", "function", "createNodeInstanceFromPropref", "(", "string", "$", "propRef", "=", "\"\"", ")", "{", "$", "data", "=", "$", "this", "->", "getPropertyFromApi", "(", "$", "propRef", ")", ";", "$", "created_node", "=", "NULL", ";", "if", "(", "$", "data", "&&", "$", "data", "instanceof", "\\", "stdClass", ")", "{", "$", "created_node", "=", "$", "this", "->", "createNodeInstanceFromData", "(", "$", "data", ",", "TRUE", ")", ";", "}", "return", "$", "created_node", ";", "}" ]
Creates a property node populated with data returned from the API. @param string $propRef propRef to load into a property node. @return \Drupal\Core\Entity\EntityInterface|null The created property entity. @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException @throws \Drupal\Core\Entity\EntityStorageException @throws \Exception
[ "Creates", "a", "property", "node", "populated", "with", "data", "returned", "from", "the", "API", "." ]
53b630a612c6dc7c90a8ca1ce4ceb41568473447
https://github.com/neontabs-drupal8/nt8property/blob/53b630a612c6dc7c90a8ca1ce4ceb41568473447/src/Service/NT8PropertyService.php#L643-L652
10,260
phPoirot/Module-MongoDriver
src/MongoDriver/Actions/MongoDriverAction.php
MongoDriverAction.setClient
function setClient($clientName, MongoDB\Client $clientMongo) { if ($this->hasClient($clientName)) throw new \Exception(sprintf('Client with name (%s) already exists and cant be replaced.', $clientName)); $this->clients[$clientName] = $clientMongo; return $this; }
php
function setClient($clientName, MongoDB\Client $clientMongo) { if ($this->hasClient($clientName)) throw new \Exception(sprintf('Client with name (%s) already exists and cant be replaced.', $clientName)); $this->clients[$clientName] = $clientMongo; return $this; }
[ "function", "setClient", "(", "$", "clientName", ",", "MongoDB", "\\", "Client", "$", "clientMongo", ")", "{", "if", "(", "$", "this", "->", "hasClient", "(", "$", "clientName", ")", ")", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'Client with name (%s) already exists and cant be replaced.'", ",", "$", "clientName", ")", ")", ";", "$", "this", "->", "clients", "[", "$", "clientName", "]", "=", "$", "clientMongo", ";", "return", "$", "this", ";", "}" ]
Add Client Connection Options: 'db' => (string) default database to query on @param string $clientName @param MongoDB\Client $clientMongo @return $this @throws \Exception
[ "Add", "Client", "Connection" ]
5c11c01676f10e88b0af899971fcd86ca23e81bd
https://github.com/phPoirot/Module-MongoDriver/blob/5c11c01676f10e88b0af899971fcd86ca23e81bd/src/MongoDriver/Actions/MongoDriverAction.php#L55-L63
10,261
phPoirot/Module-MongoDriver
src/MongoDriver/Actions/MongoDriverAction.php
MongoDriverAction.getClient
function getClient($clientName) { if (! isset($this->clients[$clientName]) ) // if not client constructed look for lazy options: $this->clients[$clientName] = $this->_attainClient($clientName); return $this->clients[$clientName]; }
php
function getClient($clientName) { if (! isset($this->clients[$clientName]) ) // if not client constructed look for lazy options: $this->clients[$clientName] = $this->_attainClient($clientName); return $this->clients[$clientName]; }
[ "function", "getClient", "(", "$", "clientName", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "clients", "[", "$", "clientName", "]", ")", ")", "// if not client constructed look for lazy options:", "$", "this", "->", "clients", "[", "$", "clientName", "]", "=", "$", "this", "->", "_attainClient", "(", "$", "clientName", ")", ";", "return", "$", "this", "->", "clients", "[", "$", "clientName", "]", ";", "}" ]
Attain Client By Name @param string $clientName @return MongoDB\Client @throws \Exception
[ "Attain", "Client", "By", "Name" ]
5c11c01676f10e88b0af899971fcd86ca23e81bd
https://github.com/phPoirot/Module-MongoDriver/blob/5c11c01676f10e88b0af899971fcd86ca23e81bd/src/MongoDriver/Actions/MongoDriverAction.php#L73-L81
10,262
phPoirot/Module-MongoDriver
src/MongoDriver/Actions/MongoDriverAction.php
MongoDriverAction.hasClient
function hasClient($clientName) { if (! isset($this->clients[$clientName]) ) { // Lookup for lazy client options try { $exists = true; $this->getClient($clientName); } catch (\Exception $e) { $exists = false; } return $exists; } $exists = array_key_exists($clientName, $this->lazyClientOptions); return $exists; }
php
function hasClient($clientName) { if (! isset($this->clients[$clientName]) ) { // Lookup for lazy client options try { $exists = true; $this->getClient($clientName); } catch (\Exception $e) { $exists = false; } return $exists; } $exists = array_key_exists($clientName, $this->lazyClientOptions); return $exists; }
[ "function", "hasClient", "(", "$", "clientName", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "clients", "[", "$", "clientName", "]", ")", ")", "{", "// Lookup for lazy client options", "try", "{", "$", "exists", "=", "true", ";", "$", "this", "->", "getClient", "(", "$", "clientName", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "exists", "=", "false", ";", "}", "return", "$", "exists", ";", "}", "$", "exists", "=", "array_key_exists", "(", "$", "clientName", ",", "$", "this", "->", "lazyClientOptions", ")", ";", "return", "$", "exists", ";", "}" ]
Has Client Connection? @param string $clientName @return boolean
[ "Has", "Client", "Connection?" ]
5c11c01676f10e88b0af899971fcd86ca23e81bd
https://github.com/phPoirot/Module-MongoDriver/blob/5c11c01676f10e88b0af899971fcd86ca23e81bd/src/MongoDriver/Actions/MongoDriverAction.php#L90-L106
10,263
phPoirot/Module-MongoDriver
src/MongoDriver/Actions/MongoDriverAction.php
MongoDriverAction._attainClient
protected function _attainClient($clientName) { if (! isset($this->lazyClientOptions[$clientName]) ) throw new \Exception(sprintf('MongoDB Client (%s) not Registered.', $clientName)); $conf = $this->lazyClientOptions[$clientName]; if (! isset($conf['host']) ) throw new \Exception(sprintf( '"host" Option for Client (%s) not given.' , $clientName , \Poirot\Std\flatten($conf) )); $uri = $conf['host']; $uriOptions = (isset($conf['options_uri'])) ? $conf['options_uri'] : array(); $options = (isset($conf['options_driver'])) ? $conf['options_driver'] : array(); $client = new MongoDB\Client($uri, $uriOptions, $options); return $client; }
php
protected function _attainClient($clientName) { if (! isset($this->lazyClientOptions[$clientName]) ) throw new \Exception(sprintf('MongoDB Client (%s) not Registered.', $clientName)); $conf = $this->lazyClientOptions[$clientName]; if (! isset($conf['host']) ) throw new \Exception(sprintf( '"host" Option for Client (%s) not given.' , $clientName , \Poirot\Std\flatten($conf) )); $uri = $conf['host']; $uriOptions = (isset($conf['options_uri'])) ? $conf['options_uri'] : array(); $options = (isset($conf['options_driver'])) ? $conf['options_driver'] : array(); $client = new MongoDB\Client($uri, $uriOptions, $options); return $client; }
[ "protected", "function", "_attainClient", "(", "$", "clientName", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "lazyClientOptions", "[", "$", "clientName", "]", ")", ")", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'MongoDB Client (%s) not Registered.'", ",", "$", "clientName", ")", ")", ";", "$", "conf", "=", "$", "this", "->", "lazyClientOptions", "[", "$", "clientName", "]", ";", "if", "(", "!", "isset", "(", "$", "conf", "[", "'host'", "]", ")", ")", "throw", "new", "\\", "Exception", "(", "sprintf", "(", "'\"host\" Option for Client (%s) not given.'", ",", "$", "clientName", ",", "\\", "Poirot", "\\", "Std", "\\", "flatten", "(", "$", "conf", ")", ")", ")", ";", "$", "uri", "=", "$", "conf", "[", "'host'", "]", ";", "$", "uriOptions", "=", "(", "isset", "(", "$", "conf", "[", "'options_uri'", "]", ")", ")", "?", "$", "conf", "[", "'options_uri'", "]", ":", "array", "(", ")", ";", "$", "options", "=", "(", "isset", "(", "$", "conf", "[", "'options_driver'", "]", ")", ")", "?", "$", "conf", "[", "'options_driver'", "]", ":", "array", "(", ")", ";", "$", "client", "=", "new", "MongoDB", "\\", "Client", "(", "$", "uri", ",", "$", "uriOptions", ",", "$", "options", ")", ";", "return", "$", "client", ";", "}" ]
Attain Client Instance from LazyConfigs @param $clientName @return MongoDB\Client @throws \Exception
[ "Attain", "Client", "Instance", "from", "LazyConfigs" ]
5c11c01676f10e88b0af899971fcd86ca23e81bd
https://github.com/phPoirot/Module-MongoDriver/blob/5c11c01676f10e88b0af899971fcd86ca23e81bd/src/MongoDriver/Actions/MongoDriverAction.php#L169-L189
10,264
RhubarbPHP/Module.Leaf.SearchPanel
src/Leaves/SearchPanel.php
SearchPanel.getSearchControlValues
public function getSearchControlValues() { $data = $this->model->searchValues; $controlData = []; foreach ($this->model->searchControls as $control) { $controlName = $control->getName(); if (isset($data[$controlName])) { $controlData[$controlName] = $data[$controlName]; } } return $controlData; }
php
public function getSearchControlValues() { $data = $this->model->searchValues; $controlData = []; foreach ($this->model->searchControls as $control) { $controlName = $control->getName(); if (isset($data[$controlName])) { $controlData[$controlName] = $data[$controlName]; } } return $controlData; }
[ "public", "function", "getSearchControlValues", "(", ")", "{", "$", "data", "=", "$", "this", "->", "model", "->", "searchValues", ";", "$", "controlData", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "model", "->", "searchControls", "as", "$", "control", ")", "{", "$", "controlName", "=", "$", "control", "->", "getName", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "$", "controlName", "]", ")", ")", "{", "$", "controlData", "[", "$", "controlName", "]", "=", "$", "data", "[", "$", "controlName", "]", ";", "}", "}", "return", "$", "controlData", ";", "}" ]
Returns a key value pair array of each control name and it's value @return string[]
[ "Returns", "a", "key", "value", "pair", "array", "of", "each", "control", "name", "and", "it", "s", "value" ]
8136023d37e07806f88de31c7c69a98cf900169d
https://github.com/RhubarbPHP/Module.Leaf.SearchPanel/blob/8136023d37e07806f88de31c7c69a98cf900169d/src/Leaves/SearchPanel.php#L100-L114
10,265
RhubarbPHP/Module.Leaf.SearchPanel
src/Leaves/SearchPanel.php
SearchPanel.setSearchControlValues
public function setSearchControlValues($controlValues = [], $rememberPrevious = false) { if ($rememberPrevious){ $this->previousSearchValues = $this->model->searchValues; } else { if ($this->previousSearchValues) { $this->model->searchValues = $this->previousSearchValues; $this->previousSearchValues = null; return; } } $controlValues = array_merge($this->defaultControlValues, $controlValues); foreach ($this->model->searchControls as $control) { $controlName = $control->getName(); if (isset($controlValues[$controlName])) { $this->model->searchValues[$controlName] = $controlValues[$controlName]; } } $this->reRender(); $this->searchedEvent->raise(); }
php
public function setSearchControlValues($controlValues = [], $rememberPrevious = false) { if ($rememberPrevious){ $this->previousSearchValues = $this->model->searchValues; } else { if ($this->previousSearchValues) { $this->model->searchValues = $this->previousSearchValues; $this->previousSearchValues = null; return; } } $controlValues = array_merge($this->defaultControlValues, $controlValues); foreach ($this->model->searchControls as $control) { $controlName = $control->getName(); if (isset($controlValues[$controlName])) { $this->model->searchValues[$controlName] = $controlValues[$controlName]; } } $this->reRender(); $this->searchedEvent->raise(); }
[ "public", "function", "setSearchControlValues", "(", "$", "controlValues", "=", "[", "]", ",", "$", "rememberPrevious", "=", "false", ")", "{", "if", "(", "$", "rememberPrevious", ")", "{", "$", "this", "->", "previousSearchValues", "=", "$", "this", "->", "model", "->", "searchValues", ";", "}", "else", "{", "if", "(", "$", "this", "->", "previousSearchValues", ")", "{", "$", "this", "->", "model", "->", "searchValues", "=", "$", "this", "->", "previousSearchValues", ";", "$", "this", "->", "previousSearchValues", "=", "null", ";", "return", ";", "}", "}", "$", "controlValues", "=", "array_merge", "(", "$", "this", "->", "defaultControlValues", ",", "$", "controlValues", ")", ";", "foreach", "(", "$", "this", "->", "model", "->", "searchControls", "as", "$", "control", ")", "{", "$", "controlName", "=", "$", "control", "->", "getName", "(", ")", ";", "if", "(", "isset", "(", "$", "controlValues", "[", "$", "controlName", "]", ")", ")", "{", "$", "this", "->", "model", "->", "searchValues", "[", "$", "controlName", "]", "=", "$", "controlValues", "[", "$", "controlName", "]", ";", "}", "}", "$", "this", "->", "reRender", "(", ")", ";", "$", "this", "->", "searchedEvent", "->", "raise", "(", ")", ";", "}" ]
Sets the values of the search controls. @param array $controlValues A key value pair array.
[ "Sets", "the", "values", "of", "the", "search", "controls", "." ]
8136023d37e07806f88de31c7c69a98cf900169d
https://github.com/RhubarbPHP/Module.Leaf.SearchPanel/blob/8136023d37e07806f88de31c7c69a98cf900169d/src/Leaves/SearchPanel.php#L123-L148
10,266
RhubarbPHP/Module.Leaf.SearchPanel
src/Leaves/SearchPanel.php
SearchPanel.getUrlStateNames
protected function getUrlStateNames(array $searchControls) { $names = []; foreach ($searchControls as $control) { $name = $control->getName(); $names[$name] = StringTools::camelCaseToSeparated($name); } return $names; }
php
protected function getUrlStateNames(array $searchControls) { $names = []; foreach ($searchControls as $control) { $name = $control->getName(); $names[$name] = StringTools::camelCaseToSeparated($name); } return $names; }
[ "protected", "function", "getUrlStateNames", "(", "array", "$", "searchControls", ")", "{", "$", "names", "=", "[", "]", ";", "foreach", "(", "$", "searchControls", "as", "$", "control", ")", "{", "$", "name", "=", "$", "control", "->", "getName", "(", ")", ";", "$", "names", "[", "$", "name", "]", "=", "StringTools", "::", "camelCaseToSeparated", "(", "$", "name", ")", ";", "}", "return", "$", "names", ";", "}" ]
Return URL GET param names for the controls in this panel @param Control[] $searchControls @return \string[] An array with keys matching the control names and values defining the GET param names
[ "Return", "URL", "GET", "param", "names", "for", "the", "controls", "in", "this", "panel" ]
8136023d37e07806f88de31c7c69a98cf900169d
https://github.com/RhubarbPHP/Module.Leaf.SearchPanel/blob/8136023d37e07806f88de31c7c69a98cf900169d/src/Leaves/SearchPanel.php#L225-L234
10,267
Dhii/php-cs-fixer-config
src/Config.php
Config.getApplicableRules
public static function getApplicableRules() { $rules = [ FixerInterface::PSR2_LEVEL => static::getPsr2Rules(), FixerInterface::SYMFONY_LEVEL => static::getSymfonyRules(), FixerInterface::CONTRIB_LEVEL => static::getContribRules(), ]; return static::_prepareRules($rules); }
php
public static function getApplicableRules() { $rules = [ FixerInterface::PSR2_LEVEL => static::getPsr2Rules(), FixerInterface::SYMFONY_LEVEL => static::getSymfonyRules(), FixerInterface::CONTRIB_LEVEL => static::getContribRules(), ]; return static::_prepareRules($rules); }
[ "public", "static", "function", "getApplicableRules", "(", ")", "{", "$", "rules", "=", "[", "FixerInterface", "::", "PSR2_LEVEL", "=>", "static", "::", "getPsr2Rules", "(", ")", ",", "FixerInterface", "::", "SYMFONY_LEVEL", "=>", "static", "::", "getSymfonyRules", "(", ")", ",", "FixerInterface", "::", "CONTRIB_LEVEL", "=>", "static", "::", "getContribRules", "(", ")", ",", "]", ";", "return", "static", "::", "_prepareRules", "(", "$", "rules", ")", ";", "}" ]
Return all the rules that should be part of the config. @return array Format for version <2.0 is numeric array of strings. @since [*next-version*]
[ "Return", "all", "the", "rules", "that", "should", "be", "part", "of", "the", "config", "." ]
fc2f45d1f822bff7d871ba3c4c9750ad66f5ab0c
https://github.com/Dhii/php-cs-fixer-config/blob/fc2f45d1f822bff7d871ba3c4c9750ad66f5ab0c/src/Config.php#L56-L65
10,268
Dhii/php-cs-fixer-config
src/Config.php
Config._prepareRules
protected static function _prepareRules($rules) { foreach ($rules as $_name => $_rules) { $rules[$_name] = array_flip($_rules); } $rules = call_user_func_array('array_merge', $rules); return array_keys($rules); }
php
protected static function _prepareRules($rules) { foreach ($rules as $_name => $_rules) { $rules[$_name] = array_flip($_rules); } $rules = call_user_func_array('array_merge', $rules); return array_keys($rules); }
[ "protected", "static", "function", "_prepareRules", "(", "$", "rules", ")", "{", "foreach", "(", "$", "rules", "as", "$", "_name", "=>", "$", "_rules", ")", "{", "$", "rules", "[", "$", "_name", "]", "=", "array_flip", "(", "$", "_rules", ")", ";", "}", "$", "rules", "=", "call_user_func_array", "(", "'array_merge'", ",", "$", "rules", ")", ";", "return", "array_keys", "(", "$", "rules", ")", ";", "}" ]
Combines a map of rule levels to rule lists into one list. @since [*next-version*] @param array $rules Map of rule level to rule list, where rule list is a numeric array of string names. @return array A unique list of all rules combined in a numeric array of strings.
[ "Combines", "a", "map", "of", "rule", "levels", "to", "rule", "lists", "into", "one", "list", "." ]
fc2f45d1f822bff7d871ba3c4c9750ad66f5ab0c
https://github.com/Dhii/php-cs-fixer-config/blob/fc2f45d1f822bff7d871ba3c4c9750ad66f5ab0c/src/Config.php#L76-L85
10,269
Dhii/php-cs-fixer-config
src/Config.php
Config.getSymfonyRules20
public static function getSymfonyRules20() { return [ 'blank_line_after_opening_tag' => true, 'blank_line_before_return' => true, 'cast_spaces' => true, 'concat_without_spaces' => false, 'function_typehint_space' => true, 'hash_to_slash_comment' => true, 'heredoc_to_nowdoc' => false, 'include' => true, 'lowercase_cast' => true, 'method_separation' => true, 'native_function_casing' => true, 'new_with_braces' => true, 'no_alias_functions' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_consecutive_blank_lines' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_multiline_whitespace_around_double_arrow' => true, 'no_short_bool_cast' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_inside_offset' => true, 'no_trailing_comma_in_list_call' => true, 'no_trailing_comma_in_singleline_array' => true, 'no_unneeded_control_parentheses' => true, 'no_unreachable_default_argument_value' => true, 'no_unused_imports' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_lines' => true, 'object_operator_without_whitespace' => true, 'phpdoc_align' => true, 'phpdoc_indent' => true, 'phpdoc_inline_tag' => true, 'phpdoc_no_access' => true, 'phpdoc_no_empty_return' => true, 'phpdoc_no_package' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_single_line_var_spacing' => true, 'phpdoc_summary' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_type_to_var' => true, 'phpdoc_types' => true, 'phpdoc_var_without_name' => true, 'pre_increment' => true, 'print_to_echo' => false, 'self_accessor' => false, 'short_scalar_cast' => true, 'simplified_null_return' => true, 'single_blank_line_before_namespace' => true, 'single_quote' => true, 'space_after_semicolon' => true, 'standardize_not_equals' => true, 'ternary_operator_spaces' => true, 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unalign_double_arrow' => true, 'unalign_equals' => true, 'unary_operator_spaces' => true, 'whitespace_after_comma_in_array' => true, ]; }
php
public static function getSymfonyRules20() { return [ 'blank_line_after_opening_tag' => true, 'blank_line_before_return' => true, 'cast_spaces' => true, 'concat_without_spaces' => false, 'function_typehint_space' => true, 'hash_to_slash_comment' => true, 'heredoc_to_nowdoc' => false, 'include' => true, 'lowercase_cast' => true, 'method_separation' => true, 'native_function_casing' => true, 'new_with_braces' => true, 'no_alias_functions' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_consecutive_blank_lines' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_multiline_whitespace_around_double_arrow' => true, 'no_short_bool_cast' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_inside_offset' => true, 'no_trailing_comma_in_list_call' => true, 'no_trailing_comma_in_singleline_array' => true, 'no_unneeded_control_parentheses' => true, 'no_unreachable_default_argument_value' => true, 'no_unused_imports' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_lines' => true, 'object_operator_without_whitespace' => true, 'phpdoc_align' => true, 'phpdoc_indent' => true, 'phpdoc_inline_tag' => true, 'phpdoc_no_access' => true, 'phpdoc_no_empty_return' => true, 'phpdoc_no_package' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_single_line_var_spacing' => true, 'phpdoc_summary' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_type_to_var' => true, 'phpdoc_types' => true, 'phpdoc_var_without_name' => true, 'pre_increment' => true, 'print_to_echo' => false, 'self_accessor' => false, 'short_scalar_cast' => true, 'simplified_null_return' => true, 'single_blank_line_before_namespace' => true, 'single_quote' => true, 'space_after_semicolon' => true, 'standardize_not_equals' => true, 'ternary_operator_spaces' => true, 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unalign_double_arrow' => true, 'unalign_equals' => true, 'unary_operator_spaces' => true, 'whitespace_after_comma_in_array' => true, ]; }
[ "public", "static", "function", "getSymfonyRules20", "(", ")", "{", "return", "[", "'blank_line_after_opening_tag'", "=>", "true", ",", "'blank_line_before_return'", "=>", "true", ",", "'cast_spaces'", "=>", "true", ",", "'concat_without_spaces'", "=>", "false", ",", "'function_typehint_space'", "=>", "true", ",", "'hash_to_slash_comment'", "=>", "true", ",", "'heredoc_to_nowdoc'", "=>", "false", ",", "'include'", "=>", "true", ",", "'lowercase_cast'", "=>", "true", ",", "'method_separation'", "=>", "true", ",", "'native_function_casing'", "=>", "true", ",", "'new_with_braces'", "=>", "true", ",", "'no_alias_functions'", "=>", "true", ",", "'no_blank_lines_after_class_opening'", "=>", "true", ",", "'no_blank_lines_after_phpdoc'", "=>", "true", ",", "'no_empty_statement'", "=>", "true", ",", "'no_extra_consecutive_blank_lines'", "=>", "true", ",", "'no_leading_import_slash'", "=>", "true", ",", "'no_leading_namespace_whitespace'", "=>", "true", ",", "'no_multiline_whitespace_around_double_arrow'", "=>", "true", ",", "'no_short_bool_cast'", "=>", "true", ",", "'no_singleline_whitespace_before_semicolons'", "=>", "true", ",", "'no_spaces_inside_offset'", "=>", "true", ",", "'no_trailing_comma_in_list_call'", "=>", "true", ",", "'no_trailing_comma_in_singleline_array'", "=>", "true", ",", "'no_unneeded_control_parentheses'", "=>", "true", ",", "'no_unreachable_default_argument_value'", "=>", "true", ",", "'no_unused_imports'", "=>", "true", ",", "'no_whitespace_before_comma_in_array'", "=>", "true", ",", "'no_whitespace_in_blank_lines'", "=>", "true", ",", "'object_operator_without_whitespace'", "=>", "true", ",", "'phpdoc_align'", "=>", "true", ",", "'phpdoc_indent'", "=>", "true", ",", "'phpdoc_inline_tag'", "=>", "true", ",", "'phpdoc_no_access'", "=>", "true", ",", "'phpdoc_no_empty_return'", "=>", "true", ",", "'phpdoc_no_package'", "=>", "true", ",", "'phpdoc_scalar'", "=>", "true", ",", "'phpdoc_separation'", "=>", "true", ",", "'phpdoc_single_line_var_spacing'", "=>", "true", ",", "'phpdoc_summary'", "=>", "true", ",", "'phpdoc_to_comment'", "=>", "true", ",", "'phpdoc_trim'", "=>", "true", ",", "'phpdoc_type_to_var'", "=>", "true", ",", "'phpdoc_types'", "=>", "true", ",", "'phpdoc_var_without_name'", "=>", "true", ",", "'pre_increment'", "=>", "true", ",", "'print_to_echo'", "=>", "false", ",", "'self_accessor'", "=>", "false", ",", "'short_scalar_cast'", "=>", "true", ",", "'simplified_null_return'", "=>", "true", ",", "'single_blank_line_before_namespace'", "=>", "true", ",", "'single_quote'", "=>", "true", ",", "'space_after_semicolon'", "=>", "true", ",", "'standardize_not_equals'", "=>", "true", ",", "'ternary_operator_spaces'", "=>", "true", ",", "'trailing_comma_in_multiline_array'", "=>", "true", ",", "'trim_array_spaces'", "=>", "true", ",", "'unalign_double_arrow'", "=>", "true", ",", "'unalign_equals'", "=>", "true", ",", "'unary_operator_spaces'", "=>", "true", ",", "'whitespace_after_comma_in_array'", "=>", "true", ",", "]", ";", "}" ]
Gets rules of the Symfony level that are applicable to this config. @todo Rename to `getSymfonyRules()` and use when using CS Fixer >= 2.0 @return array Map of rule name (strig) to enabled/disabled (bool) @since [*next-version*]
[ "Gets", "rules", "of", "the", "Symfony", "level", "that", "are", "applicable", "to", "this", "config", "." ]
fc2f45d1f822bff7d871ba3c4c9750ad66f5ab0c
https://github.com/Dhii/php-cs-fixer-config/blob/fc2f45d1f822bff7d871ba3c4c9750ad66f5ab0c/src/Config.php#L147-L213
10,270
Hifone/Dashboard
src/Frozennode/Administrator/Menu.php
Menu.getMenu
public function getMenu($subMenu = null) { $menu = array(); if (!$subMenu) { $arr = include __DIR__.'/../../config/administrator.php'; $subMenu = $arr['menu']; } //iterate over the menu to build the return array of valid menu items foreach ($subMenu as $key => $item) { //if the item is a string, find its config if (is_string($item)) { //fetch the appropriate config file $config = $this->configFactory->make($item); //if a config object was returned and if the permission passes, add the item to the menu if (is_a($config, 'Frozennode\Administrator\Config\Config') && $config->getOption('permission')) { $menu[$item] = $config->getOption('title'); } //otherwise if this is a custom page, add it to the menu elseif ($config === true) { $menu[$item] = $key; } } //if the item is an array, recursively run this method on it elseif (is_array($item)) { $menu[$key] = $this->getMenu($item); //if the submenu is empty, unset it if (empty($menu[$key])) { unset($menu[$key]); } } } return $menu; }
php
public function getMenu($subMenu = null) { $menu = array(); if (!$subMenu) { $arr = include __DIR__.'/../../config/administrator.php'; $subMenu = $arr['menu']; } //iterate over the menu to build the return array of valid menu items foreach ($subMenu as $key => $item) { //if the item is a string, find its config if (is_string($item)) { //fetch the appropriate config file $config = $this->configFactory->make($item); //if a config object was returned and if the permission passes, add the item to the menu if (is_a($config, 'Frozennode\Administrator\Config\Config') && $config->getOption('permission')) { $menu[$item] = $config->getOption('title'); } //otherwise if this is a custom page, add it to the menu elseif ($config === true) { $menu[$item] = $key; } } //if the item is an array, recursively run this method on it elseif (is_array($item)) { $menu[$key] = $this->getMenu($item); //if the submenu is empty, unset it if (empty($menu[$key])) { unset($menu[$key]); } } } return $menu; }
[ "public", "function", "getMenu", "(", "$", "subMenu", "=", "null", ")", "{", "$", "menu", "=", "array", "(", ")", ";", "if", "(", "!", "$", "subMenu", ")", "{", "$", "arr", "=", "include", "__DIR__", ".", "'/../../config/administrator.php'", ";", "$", "subMenu", "=", "$", "arr", "[", "'menu'", "]", ";", "}", "//iterate over the menu to build the return array of valid menu items", "foreach", "(", "$", "subMenu", "as", "$", "key", "=>", "$", "item", ")", "{", "//if the item is a string, find its config", "if", "(", "is_string", "(", "$", "item", ")", ")", "{", "//fetch the appropriate config file", "$", "config", "=", "$", "this", "->", "configFactory", "->", "make", "(", "$", "item", ")", ";", "//if a config object was returned and if the permission passes, add the item to the menu", "if", "(", "is_a", "(", "$", "config", ",", "'Frozennode\\Administrator\\Config\\Config'", ")", "&&", "$", "config", "->", "getOption", "(", "'permission'", ")", ")", "{", "$", "menu", "[", "$", "item", "]", "=", "$", "config", "->", "getOption", "(", "'title'", ")", ";", "}", "//otherwise if this is a custom page, add it to the menu", "elseif", "(", "$", "config", "===", "true", ")", "{", "$", "menu", "[", "$", "item", "]", "=", "$", "key", ";", "}", "}", "//if the item is an array, recursively run this method on it", "elseif", "(", "is_array", "(", "$", "item", ")", ")", "{", "$", "menu", "[", "$", "key", "]", "=", "$", "this", "->", "getMenu", "(", "$", "item", ")", ";", "//if the submenu is empty, unset it", "if", "(", "empty", "(", "$", "menu", "[", "$", "key", "]", ")", ")", "{", "unset", "(", "$", "menu", "[", "$", "key", "]", ")", ";", "}", "}", "}", "return", "$", "menu", ";", "}" ]
Gets the menu items indexed by their name with a value of the title. @param array $subMenu (used for recursion) @return array
[ "Gets", "the", "menu", "items", "indexed", "by", "their", "name", "with", "a", "value", "of", "the", "title", "." ]
45b35879e74d99164db9c8a34da40cdb53d25e90
https://github.com/Hifone/Dashboard/blob/45b35879e74d99164db9c8a34da40cdb53d25e90/src/Frozennode/Administrator/Menu.php#L43-L80
10,271
asbsoft/yii2-common_2_170212
models/BaseDataModel.php
BaseDataModel.calcPage
public function calcPage($currentQuery = null) { $page = 1; $primaryKeys = static::primaryKey(); if (isset($primaryKeys[0])) { $primaryKey = $primaryKeys[0]; $num = $this->getOrderNumber($this->$primaryKey, $currentQuery); if ($num > 0) { $page = (int) ceil($num / $this->pageSize); } } return $page; }
php
public function calcPage($currentQuery = null) { $page = 1; $primaryKeys = static::primaryKey(); if (isset($primaryKeys[0])) { $primaryKey = $primaryKeys[0]; $num = $this->getOrderNumber($this->$primaryKey, $currentQuery); if ($num > 0) { $page = (int) ceil($num / $this->pageSize); } } return $page; }
[ "public", "function", "calcPage", "(", "$", "currentQuery", "=", "null", ")", "{", "$", "page", "=", "1", ";", "$", "primaryKeys", "=", "static", "::", "primaryKey", "(", ")", ";", "if", "(", "isset", "(", "$", "primaryKeys", "[", "0", "]", ")", ")", "{", "$", "primaryKey", "=", "$", "primaryKeys", "[", "0", "]", ";", "$", "num", "=", "$", "this", "->", "getOrderNumber", "(", "$", "this", "->", "$", "primaryKey", ",", "$", "currentQuery", ")", ";", "if", "(", "$", "num", ">", "0", ")", "{", "$", "page", "=", "(", "int", ")", "ceil", "(", "$", "num", "/", "$", "this", "->", "pageSize", ")", ";", "}", "}", "return", "$", "page", ";", "}" ]
Calculate page number for current record.
[ "Calculate", "page", "number", "for", "current", "record", "." ]
6c58012ff89225d7d4e42b200cf39e009e9d9dac
https://github.com/asbsoft/yii2-common_2_170212/blob/6c58012ff89225d7d4e42b200cf39e009e9d9dac/models/BaseDataModel.php#L168-L180
10,272
asbsoft/yii2-common_2_170212
models/BaseDataModel.php
BaseDataModel.moduleClass
public static function moduleClass($moduleName = 'Module') { $result = false; $className = get_called_class(); $refClass = new ReflectionClass($className); $ns = $refClass->getNamespaceName(); $len = strlen($ns) - strlen(UniModule::$modelsSubdir); if (strrpos($ns, UniModule::$modelsSubdir) == $len) { $ns = substr($ns, 0, $len); $result = $ns . $moduleName; } return $result; }
php
public static function moduleClass($moduleName = 'Module') { $result = false; $className = get_called_class(); $refClass = new ReflectionClass($className); $ns = $refClass->getNamespaceName(); $len = strlen($ns) - strlen(UniModule::$modelsSubdir); if (strrpos($ns, UniModule::$modelsSubdir) == $len) { $ns = substr($ns, 0, $len); $result = $ns . $moduleName; } return $result; }
[ "public", "static", "function", "moduleClass", "(", "$", "moduleName", "=", "'Module'", ")", "{", "$", "result", "=", "false", ";", "$", "className", "=", "get_called_class", "(", ")", ";", "$", "refClass", "=", "new", "ReflectionClass", "(", "$", "className", ")", ";", "$", "ns", "=", "$", "refClass", "->", "getNamespaceName", "(", ")", ";", "$", "len", "=", "strlen", "(", "$", "ns", ")", "-", "strlen", "(", "UniModule", "::", "$", "modelsSubdir", ")", ";", "if", "(", "strrpos", "(", "$", "ns", ",", "UniModule", "::", "$", "modelsSubdir", ")", "==", "$", "len", ")", "{", "$", "ns", "=", "substr", "(", "$", "ns", ",", "0", ",", "$", "len", ")", ";", "$", "result", "=", "$", "ns", ".", "$", "moduleName", ";", "}", "return", "$", "result", ";", "}" ]
Try to get module class this model belong to. Get latest module in inheritance chain. @return string|false class name.
[ "Try", "to", "get", "module", "class", "this", "model", "belong", "to", ".", "Get", "latest", "module", "in", "inheritance", "chain", "." ]
6c58012ff89225d7d4e42b200cf39e009e9d9dac
https://github.com/asbsoft/yii2-common_2_170212/blob/6c58012ff89225d7d4e42b200cf39e009e9d9dac/models/BaseDataModel.php#L230-L245
10,273
asbsoft/yii2-common_2_170212
models/BaseDataModel.php
BaseDataModel.swapPrio
public function swapPrio($id1, $id2, $orderField = 'prio') { $item1 = self::findOne(['id' => $id1]); if (!empty($item1->$orderField)) { $prio1 = $item1->$orderField; } else { return false; } $item2 = self::findOne(['id' => $id2]); if (!empty($item2->$orderField)) { $prio2 = $item2->$orderField; } else { return false; } $transaction = Yii::$app->db->beginTransaction(); try { $item1->$orderField = $prio2; $n1 = $item1->updateInternal(); $item2->$orderField = $prio1; $n2 = $item2->updateInternal(); if ($n1 && $n2) $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); Yii::error($e); if (YII_DEBUG) throw $e; } return true; }
php
public function swapPrio($id1, $id2, $orderField = 'prio') { $item1 = self::findOne(['id' => $id1]); if (!empty($item1->$orderField)) { $prio1 = $item1->$orderField; } else { return false; } $item2 = self::findOne(['id' => $id2]); if (!empty($item2->$orderField)) { $prio2 = $item2->$orderField; } else { return false; } $transaction = Yii::$app->db->beginTransaction(); try { $item1->$orderField = $prio2; $n1 = $item1->updateInternal(); $item2->$orderField = $prio1; $n2 = $item2->updateInternal(); if ($n1 && $n2) $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); Yii::error($e); if (YII_DEBUG) throw $e; } return true; }
[ "public", "function", "swapPrio", "(", "$", "id1", ",", "$", "id2", ",", "$", "orderField", "=", "'prio'", ")", "{", "$", "item1", "=", "self", "::", "findOne", "(", "[", "'id'", "=>", "$", "id1", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "item1", "->", "$", "orderField", ")", ")", "{", "$", "prio1", "=", "$", "item1", "->", "$", "orderField", ";", "}", "else", "{", "return", "false", ";", "}", "$", "item2", "=", "self", "::", "findOne", "(", "[", "'id'", "=>", "$", "id2", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "item2", "->", "$", "orderField", ")", ")", "{", "$", "prio2", "=", "$", "item2", "->", "$", "orderField", ";", "}", "else", "{", "return", "false", ";", "}", "$", "transaction", "=", "Yii", "::", "$", "app", "->", "db", "->", "beginTransaction", "(", ")", ";", "try", "{", "$", "item1", "->", "$", "orderField", "=", "$", "prio2", ";", "$", "n1", "=", "$", "item1", "->", "updateInternal", "(", ")", ";", "$", "item2", "->", "$", "orderField", "=", "$", "prio1", ";", "$", "n2", "=", "$", "item2", "->", "updateInternal", "(", ")", ";", "if", "(", "$", "n1", "&&", "$", "n2", ")", "$", "transaction", "->", "commit", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "transaction", "->", "rollBack", "(", ")", ";", "Yii", "::", "error", "(", "$", "e", ")", ";", "if", "(", "YII_DEBUG", ")", "throw", "$", "e", ";", "}", "return", "true", ";", "}" ]
Swap order field values for @param integer $id1 @param integer $id2 @param string $orderField @return boolean
[ "Swap", "order", "field", "values", "for" ]
6c58012ff89225d7d4e42b200cf39e009e9d9dac
https://github.com/asbsoft/yii2-common_2_170212/blob/6c58012ff89225d7d4e42b200cf39e009e9d9dac/models/BaseDataModel.php#L317-L345
10,274
eFrane/Transfugio
src/Http/ResponseBuilder.php
ResponseBuilder.respondWithEmpty
public function respondWithEmpty($message = "The requested result set is empty.", $status = 204) { if ($this->options['format'] === 'html') { $status = 200; } return $this->respondWithError($message, $status); }
php
public function respondWithEmpty($message = "The requested result set is empty.", $status = 204) { if ($this->options['format'] === 'html') { $status = 200; } return $this->respondWithError($message, $status); }
[ "public", "function", "respondWithEmpty", "(", "$", "message", "=", "\"The requested result set is empty.\"", ",", "$", "status", "=", "204", ")", "{", "if", "(", "$", "this", "->", "options", "[", "'format'", "]", "===", "'html'", ")", "{", "$", "status", "=", "200", ";", "}", "return", "$", "this", "->", "respondWithError", "(", "$", "message", ",", "$", "status", ")", ";", "}" ]
Return an empty response. APIs should never return nothing, thus a response stating that there is no content is returned. The issue is, that the correct HTTP Status code for "No Content" is 204, which is being used for all machine-readable output formats, however, if the output will be a web view, 200 is set as status code in order to get browsers to actually display the data. @param string $message @param int $status @return null
[ "Return", "an", "empty", "response", "." ]
c213b3c0e3649150d0c6675167e781930fda9125
https://github.com/eFrane/Transfugio/blob/c213b3c0e3649150d0c6675167e781930fda9125/src/Http/ResponseBuilder.php#L153-L160
10,275
webriq/core
module/Customize/src/Grid/Customize/Model/Exporter.php
Exporter.setDomainList
protected function setDomainList( DomainList $domainList ) { $this->urlPattern = null; $this->domainList = $domainList; return $this; }
php
protected function setDomainList( DomainList $domainList ) { $this->urlPattern = null; $this->domainList = $domainList; return $this; }
[ "protected", "function", "setDomainList", "(", "DomainList", "$", "domainList", ")", "{", "$", "this", "->", "urlPattern", "=", "null", ";", "$", "this", "->", "domainList", "=", "$", "domainList", ";", "return", "$", "this", ";", "}" ]
Set the domain-list @param DomainList $domainList @return Exporter
[ "Set", "the", "domain", "-", "list" ]
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Customize/src/Grid/Customize/Model/Exporter.php#L47-L52
10,276
webriq/core
module/Customize/src/Grid/Customize/Model/Exporter.php
Exporter.getUrlPattern
protected function getUrlPattern() { if ( $this->urlPattern ) { return $this->urlPattern; } $domains = iterator_to_array( $this->getDomainList() ); if ( empty( $domains ) ) { $domains = array( 'localhost' ); } return $this->urlPattern = '(|(https?:)?//([^/]+\.)?(' . implode( '|', array_map( 'preg_quote', $domains ) ) . ')(:\d+)?)'; }
php
protected function getUrlPattern() { if ( $this->urlPattern ) { return $this->urlPattern; } $domains = iterator_to_array( $this->getDomainList() ); if ( empty( $domains ) ) { $domains = array( 'localhost' ); } return $this->urlPattern = '(|(https?:)?//([^/]+\.)?(' . implode( '|', array_map( 'preg_quote', $domains ) ) . ')(:\d+)?)'; }
[ "protected", "function", "getUrlPattern", "(", ")", "{", "if", "(", "$", "this", "->", "urlPattern", ")", "{", "return", "$", "this", "->", "urlPattern", ";", "}", "$", "domains", "=", "iterator_to_array", "(", "$", "this", "->", "getDomainList", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "domains", ")", ")", "{", "$", "domains", "=", "array", "(", "'localhost'", ")", ";", "}", "return", "$", "this", "->", "urlPattern", "=", "'(|(https?:)?//([^/]+\\.)?('", ".", "implode", "(", "'|'", ",", "array_map", "(", "'preg_quote'", ",", "$", "domains", ")", ")", ".", "')(:\\d+)?)'", ";", "}" ]
Get url pattern @return string
[ "Get", "url", "pattern" ]
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Customize/src/Grid/Customize/Model/Exporter.php#L59-L76
10,277
bishopb/vanilla
applications/dashboard/models/class.vbulletinimportmodel.php
vBulletinImportModel.ProfileExtenderPrep
public function ProfileExtenderPrep() { $ProfileKeyData = $this->SQL->Select('m.Name')->Distinct()->From('UserMeta m')->Like('m.Name', 'Profile_%')->Get(); $ExistingKeys = array_filter((array)explode(',', C('Plugins.ProfileExtender.ProfileFields', ''))); foreach ($ProfileKeyData->Result() as $Key) { $Name = str_replace('Profile.', '', $Key->Name); if (!in_array($Name, $ExistingKeys)) { $ExistingKeys[] = $Name; } } if (count($ExistingKeys)) SaveToConfig('Plugins.ProfileExtender.ProfileFields', implode(',', $ExistingKeys)); }
php
public function ProfileExtenderPrep() { $ProfileKeyData = $this->SQL->Select('m.Name')->Distinct()->From('UserMeta m')->Like('m.Name', 'Profile_%')->Get(); $ExistingKeys = array_filter((array)explode(',', C('Plugins.ProfileExtender.ProfileFields', ''))); foreach ($ProfileKeyData->Result() as $Key) { $Name = str_replace('Profile.', '', $Key->Name); if (!in_array($Name, $ExistingKeys)) { $ExistingKeys[] = $Name; } } if (count($ExistingKeys)) SaveToConfig('Plugins.ProfileExtender.ProfileFields', implode(',', $ExistingKeys)); }
[ "public", "function", "ProfileExtenderPrep", "(", ")", "{", "$", "ProfileKeyData", "=", "$", "this", "->", "SQL", "->", "Select", "(", "'m.Name'", ")", "->", "Distinct", "(", ")", "->", "From", "(", "'UserMeta m'", ")", "->", "Like", "(", "'m.Name'", ",", "'Profile_%'", ")", "->", "Get", "(", ")", ";", "$", "ExistingKeys", "=", "array_filter", "(", "(", "array", ")", "explode", "(", "','", ",", "C", "(", "'Plugins.ProfileExtender.ProfileFields'", ",", "''", ")", ")", ")", ";", "foreach", "(", "$", "ProfileKeyData", "->", "Result", "(", ")", "as", "$", "Key", ")", "{", "$", "Name", "=", "str_replace", "(", "'Profile.'", ",", "''", ",", "$", "Key", "->", "Name", ")", ";", "if", "(", "!", "in_array", "(", "$", "Name", ",", "$", "ExistingKeys", ")", ")", "{", "$", "ExistingKeys", "[", "]", "=", "$", "Name", ";", "}", "}", "if", "(", "count", "(", "$", "ExistingKeys", ")", ")", "SaveToConfig", "(", "'Plugins.ProfileExtender.ProfileFields'", ",", "implode", "(", "','", ",", "$", "ExistingKeys", ")", ")", ";", "}" ]
Get profile fields imported and add to ProfileFields list.
[ "Get", "profile", "fields", "imported", "and", "add", "to", "ProfileFields", "list", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/dashboard/models/class.vbulletinimportmodel.php#L111-L122
10,278
sirgrimorum/crudgenerator
src/Traits/CrudConfig.php
CrudConfig.hasTipo
public static function hasTipo($array, $tipo) { foreach ($array['campos'] as $campo => $configCampo) { if (is_array($tipo)) { foreach ($tipo as $miniTipo) { if (strtolower($configCampo['tipo']) == strtolower($miniTipo)) { return true; } } } elseif (strtolower($configCampo['tipo']) == strtolower($tipo)) { return true; } } return false; }
php
public static function hasTipo($array, $tipo) { foreach ($array['campos'] as $campo => $configCampo) { if (is_array($tipo)) { foreach ($tipo as $miniTipo) { if (strtolower($configCampo['tipo']) == strtolower($miniTipo)) { return true; } } } elseif (strtolower($configCampo['tipo']) == strtolower($tipo)) { return true; } } return false; }
[ "public", "static", "function", "hasTipo", "(", "$", "array", ",", "$", "tipo", ")", "{", "foreach", "(", "$", "array", "[", "'campos'", "]", "as", "$", "campo", "=>", "$", "configCampo", ")", "{", "if", "(", "is_array", "(", "$", "tipo", ")", ")", "{", "foreach", "(", "$", "tipo", "as", "$", "miniTipo", ")", "{", "if", "(", "strtolower", "(", "$", "configCampo", "[", "'tipo'", "]", ")", "==", "strtolower", "(", "$", "miniTipo", ")", ")", "{", "return", "true", ";", "}", "}", "}", "elseif", "(", "strtolower", "(", "$", "configCampo", "[", "'tipo'", "]", ")", "==", "strtolower", "(", "$", "tipo", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Know if a config array has any field of certain type @param array $array Config array @param string|array $tipo Type of field @return boolean
[ "Know", "if", "a", "config", "array", "has", "any", "field", "of", "certain", "type" ]
4431e9991a705689be50c4367776dc611bffb863
https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/Traits/CrudConfig.php#L1030-L1043
10,279
WebCodr/Collection
src/Collection/Habit/AttributeTrait.php
AttributeTrait.get
public function get($attribute, $arrayAsMap = true) { if ($this->has($attribute)) { $value = $this->attributes[$attribute]; if ($arrayAsMap === true && is_array($value)) { $value = new self($value); } return $value; } throw new \OutOfBoundsException("Attribute '{$attribute}' does not exist"); }
php
public function get($attribute, $arrayAsMap = true) { if ($this->has($attribute)) { $value = $this->attributes[$attribute]; if ($arrayAsMap === true && is_array($value)) { $value = new self($value); } return $value; } throw new \OutOfBoundsException("Attribute '{$attribute}' does not exist"); }
[ "public", "function", "get", "(", "$", "attribute", ",", "$", "arrayAsMap", "=", "true", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "attribute", ")", ")", "{", "$", "value", "=", "$", "this", "->", "attributes", "[", "$", "attribute", "]", ";", "if", "(", "$", "arrayAsMap", "===", "true", "&&", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "new", "self", "(", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}", "throw", "new", "\\", "OutOfBoundsException", "(", "\"Attribute '{$attribute}' does not exist\"", ")", ";", "}" ]
Returns value of given attribute name or throws an exception if the attribute does not exist @param $attribute @param bool $arrayAsMap @return \Collection\MutableMap @throws \OutOfBoundsException
[ "Returns", "value", "of", "given", "attribute", "name", "or", "throws", "an", "exception", "if", "the", "attribute", "does", "not", "exist" ]
2c8e0dd2c1eb217cca318bc8c62ab86a9964f20f
https://github.com/WebCodr/Collection/blob/2c8e0dd2c1eb217cca318bc8c62ab86a9964f20f/src/Collection/Habit/AttributeTrait.php#L44-L57
10,280
WebCodr/Collection
src/Collection/Habit/AttributeTrait.php
AttributeTrait.delete
public function delete($value) { $index = $this->index($value); if ($index !== false) { $this->remove($index); } return $this; }
php
public function delete($value) { $index = $this->index($value); if ($index !== false) { $this->remove($index); } return $this; }
[ "public", "function", "delete", "(", "$", "value", ")", "{", "$", "index", "=", "$", "this", "->", "index", "(", "$", "value", ")", ";", "if", "(", "$", "index", "!==", "false", ")", "{", "$", "this", "->", "remove", "(", "$", "index", ")", ";", "}", "return", "$", "this", ";", "}" ]
Removes an attribute by value @param $value @return $this
[ "Removes", "an", "attribute", "by", "value" ]
2c8e0dd2c1eb217cca318bc8c62ab86a9964f20f
https://github.com/WebCodr/Collection/blob/2c8e0dd2c1eb217cca318bc8c62ab86a9964f20f/src/Collection/Habit/AttributeTrait.php#L124-L133
10,281
WebCodr/Collection
src/Collection/Habit/AttributeTrait.php
AttributeTrait.update
public function update($attributes) { if (!empty($attributes)) { foreach ($attributes as $attribute => $value) { $this->set($attribute, $value); } } return $this; }
php
public function update($attributes) { if (!empty($attributes)) { foreach ($attributes as $attribute => $value) { $this->set($attribute, $value); } } return $this; }
[ "public", "function", "update", "(", "$", "attributes", ")", "{", "if", "(", "!", "empty", "(", "$", "attributes", ")", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "attribute", "=>", "$", "value", ")", "{", "$", "this", "->", "set", "(", "$", "attribute", ",", "$", "value", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Update attributes with from given array @param array $attributes @return \Collection\MutableMap
[ "Update", "attributes", "with", "from", "given", "array" ]
2c8e0dd2c1eb217cca318bc8c62ab86a9964f20f
https://github.com/WebCodr/Collection/blob/2c8e0dd2c1eb217cca318bc8c62ab86a9964f20f/src/Collection/Habit/AttributeTrait.php#L156-L165
10,282
colorium/templating
src/Colorium/Templating/Sandbox.php
Sandbox.end
protected function end() { // stop recording block $content = ob_get_clean(); // read record list($name, $rewrite) = $this->record; // rewrite if($rewrite) { $this->blocks += [$name => $content]; } // render else { echo isset($this->blocks[$name]) ? $this->blocks[$name] : $content; } // reset record $this->record = null; }
php
protected function end() { // stop recording block $content = ob_get_clean(); // read record list($name, $rewrite) = $this->record; // rewrite if($rewrite) { $this->blocks += [$name => $content]; } // render else { echo isset($this->blocks[$name]) ? $this->blocks[$name] : $content; } // reset record $this->record = null; }
[ "protected", "function", "end", "(", ")", "{", "// stop recording block", "$", "content", "=", "ob_get_clean", "(", ")", ";", "// read record", "list", "(", "$", "name", ",", "$", "rewrite", ")", "=", "$", "this", "->", "record", ";", "// rewrite", "if", "(", "$", "rewrite", ")", "{", "$", "this", "->", "blocks", "+=", "[", "$", "name", "=>", "$", "content", "]", ";", "}", "// render", "else", "{", "echo", "isset", "(", "$", "this", "->", "blocks", "[", "$", "name", "]", ")", "?", "$", "this", "->", "blocks", "[", "$", "name", "]", ":", "$", "content", ";", "}", "// reset record", "$", "this", "->", "record", "=", "null", ";", "}" ]
Stop recording block
[ "Stop", "recording", "block" ]
d6c68954c6f8f776e3fcc887a4bc34d0f8d26219
https://github.com/colorium/templating/blob/d6c68954c6f8f776e3fcc887a4bc34d0f8d26219/src/Colorium/Templating/Sandbox.php#L98-L119
10,283
Archi-Strasbourg/archi-wiki
modules/opendata/lib/Convertor.php
Convertor.connect
public function connect($server,$user,$password,$database){ if(empty($this->database_info['server']) || $this->database_info['server']==''){ $this->database_info['server'] = $server; } if(empty($this->database_info['user']) || $this->database_info['user']==''){ $this->database_info['user'] = $user; } if(empty($this->database_info['pass']) || $this->database_info['pass']==''){ $this->database_info['pass'] = $password; } if(empty($this->database_info['database']) || $this->database_info['database']==''){ $this->database_info['database'] = $database; } mysql_connect( $this->database_info['server'], $this->database_info['user'], $this->database_info['pass'] ); @mysql_select_db($this->database_info['database']) or die("Unable to connect to ".$this->database_info['database']." database."); }
php
public function connect($server,$user,$password,$database){ if(empty($this->database_info['server']) || $this->database_info['server']==''){ $this->database_info['server'] = $server; } if(empty($this->database_info['user']) || $this->database_info['user']==''){ $this->database_info['user'] = $user; } if(empty($this->database_info['pass']) || $this->database_info['pass']==''){ $this->database_info['pass'] = $password; } if(empty($this->database_info['database']) || $this->database_info['database']==''){ $this->database_info['database'] = $database; } mysql_connect( $this->database_info['server'], $this->database_info['user'], $this->database_info['pass'] ); @mysql_select_db($this->database_info['database']) or die("Unable to connect to ".$this->database_info['database']." database."); }
[ "public", "function", "connect", "(", "$", "server", ",", "$", "user", ",", "$", "password", ",", "$", "database", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "database_info", "[", "'server'", "]", ")", "||", "$", "this", "->", "database_info", "[", "'server'", "]", "==", "''", ")", "{", "$", "this", "->", "database_info", "[", "'server'", "]", "=", "$", "server", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "database_info", "[", "'user'", "]", ")", "||", "$", "this", "->", "database_info", "[", "'user'", "]", "==", "''", ")", "{", "$", "this", "->", "database_info", "[", "'user'", "]", "=", "$", "user", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "database_info", "[", "'pass'", "]", ")", "||", "$", "this", "->", "database_info", "[", "'pass'", "]", "==", "''", ")", "{", "$", "this", "->", "database_info", "[", "'pass'", "]", "=", "$", "password", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "database_info", "[", "'database'", "]", ")", "||", "$", "this", "->", "database_info", "[", "'database'", "]", "==", "''", ")", "{", "$", "this", "->", "database_info", "[", "'database'", "]", "=", "$", "database", ";", "}", "mysql_connect", "(", "$", "this", "->", "database_info", "[", "'server'", "]", ",", "$", "this", "->", "database_info", "[", "'user'", "]", ",", "$", "this", "->", "database_info", "[", "'pass'", "]", ")", ";", "@", "mysql_select_db", "(", "$", "this", "->", "database_info", "[", "'database'", "]", ")", "or", "die", "(", "\"Unable to connect to \"", ".", "$", "this", "->", "database_info", "[", "'database'", "]", ".", "\" database.\"", ")", ";", "}" ]
Connect to the database, using credentials Credentiel input in constructor have priority @param unknown $server @param unknown $user @param unknown $password @param unknown $database
[ "Connect", "to", "the", "database", "using", "credentials", "Credentiel", "input", "in", "constructor", "have", "priority" ]
b9fb39f43a78409890a7de96426c1f6c49d5c323
https://github.com/Archi-Strasbourg/archi-wiki/blob/b9fb39f43a78409890a7de96426c1f6c49d5c323/modules/opendata/lib/Convertor.php#L33-L53
10,284
Archi-Strasbourg/archi-wiki
modules/opendata/lib/Convertor.php
Convertor.execute
function execute($request,$silencieux=false){ if ($silencieux==false) { $res = mysql_query($request) or die($request.' -- '.mysql_error().' -- <br/> Request in file : <b>'.debug_backtrace()[0]['file'].'</b><br/> on line <b>'.debug_backtrace()[0]['line']).'</b>'; } else { $res = mysql_query($request); } return $res; }
php
function execute($request,$silencieux=false){ if ($silencieux==false) { $res = mysql_query($request) or die($request.' -- '.mysql_error().' -- <br/> Request in file : <b>'.debug_backtrace()[0]['file'].'</b><br/> on line <b>'.debug_backtrace()[0]['line']).'</b>'; } else { $res = mysql_query($request); } return $res; }
[ "function", "execute", "(", "$", "request", ",", "$", "silencieux", "=", "false", ")", "{", "if", "(", "$", "silencieux", "==", "false", ")", "{", "$", "res", "=", "mysql_query", "(", "$", "request", ")", "or", "die", "(", "$", "request", ".", "' -- '", ".", "mysql_error", "(", ")", ".", "' -- <br/> Request in file : <b>'", ".", "debug_backtrace", "(", ")", "[", "0", "]", "[", "'file'", "]", ".", "'</b><br/> on line <b>'", ".", "debug_backtrace", "(", ")", "[", "0", "]", "[", "'line'", "]", ")", ".", "'</b>'", ";", "}", "else", "{", "$", "res", "=", "mysql_query", "(", "$", "request", ")", ";", "}", "return", "$", "res", ";", "}" ]
Executing the request in parameter @param unknown $request @param string $silencieux @return resource
[ "Executing", "the", "request", "in", "parameter" ]
b9fb39f43a78409890a7de96426c1f6c49d5c323
https://github.com/Archi-Strasbourg/archi-wiki/blob/b9fb39f43a78409890a7de96426c1f6c49d5c323/modules/opendata/lib/Convertor.php#L62-L72
10,285
Archi-Strasbourg/archi-wiki
modules/opendata/lib/Convertor.php
Convertor.processRequest
public function processRequest($request,$rowIndex ='row'){ $requestResult = array(); $result = $this->execute($request); $i=0; while($row = mysql_fetch_assoc($result)){ $index = $rowIndex.$i++; $requestResult[$index] = $row; } return $requestResult; }
php
public function processRequest($request,$rowIndex ='row'){ $requestResult = array(); $result = $this->execute($request); $i=0; while($row = mysql_fetch_assoc($result)){ $index = $rowIndex.$i++; $requestResult[$index] = $row; } return $requestResult; }
[ "public", "function", "processRequest", "(", "$", "request", ",", "$", "rowIndex", "=", "'row'", ")", "{", "$", "requestResult", "=", "array", "(", ")", ";", "$", "result", "=", "$", "this", "->", "execute", "(", "$", "request", ")", ";", "$", "i", "=", "0", ";", "while", "(", "$", "row", "=", "mysql_fetch_assoc", "(", "$", "result", ")", ")", "{", "$", "index", "=", "$", "rowIndex", ".", "$", "i", "++", ";", "$", "requestResult", "[", "$", "index", "]", "=", "$", "row", ";", "}", "return", "$", "requestResult", ";", "}" ]
Execute a request and return the result as an array @param unknown $request @return multitype:multitype:
[ "Execute", "a", "request", "and", "return", "the", "result", "as", "an", "array" ]
b9fb39f43a78409890a7de96426c1f6c49d5c323
https://github.com/Archi-Strasbourg/archi-wiki/blob/b9fb39f43a78409890a7de96426c1f6c49d5c323/modules/opendata/lib/Convertor.php#L80-L89
10,286
needle-project/common
src/ClassFinder.php
ClassFinder.findClasses
public function findClasses() { $files = $this->getFiles($this->searchPath); // if class are not loaded they will ne be caught by "declared_classes" $this->loadFiles($files); return $this->identifyClasses(); }
php
public function findClasses() { $files = $this->getFiles($this->searchPath); // if class are not loaded they will ne be caught by "declared_classes" $this->loadFiles($files); return $this->identifyClasses(); }
[ "public", "function", "findClasses", "(", ")", "{", "$", "files", "=", "$", "this", "->", "getFiles", "(", "$", "this", "->", "searchPath", ")", ";", "// if class are not loaded they will ne be caught by \"declared_classes\"", "$", "this", "->", "loadFiles", "(", "$", "files", ")", ";", "return", "$", "this", "->", "identifyClasses", "(", ")", ";", "}" ]
Start searching for files @return array
[ "Start", "searching", "for", "files" ]
07630d51a7d4ffe31e3d39e8fa3b106055290dad
https://github.com/needle-project/common/blob/07630d51a7d4ffe31e3d39e8fa3b106055290dad/src/ClassFinder.php#L61-L69
10,287
needle-project/common
src/ClassFinder.php
ClassFinder.getFiles
private function getFiles($directory) { $fileList = []; $files = scandir($directory); $this->log(sprintf("Scanning dir %s, found %d files", $directory, count($files))); foreach ($files as $index => $file) { // recursive retrieve files in subdirectories if (true === is_dir($directory . DIRECTORY_SEPARATOR . $file) && !in_array($file, [".", ".."])) { $fileList = array_merge( $fileList, $this->getFiles($directory . DIRECTORY_SEPARATOR . $file) ); continue; } // not the file we want if (false === $this->isRequiredFile($file)) { $this->log(sprintf("Files %s is not required", $directory . DIRECTORY_SEPARATOR . $file)); continue; } $this->log(sprintf("Collected %s", $directory . DIRECTORY_SEPARATOR . $file)); $fileList[] = $directory . DIRECTORY_SEPARATOR . $file; } return $fileList; }
php
private function getFiles($directory) { $fileList = []; $files = scandir($directory); $this->log(sprintf("Scanning dir %s, found %d files", $directory, count($files))); foreach ($files as $index => $file) { // recursive retrieve files in subdirectories if (true === is_dir($directory . DIRECTORY_SEPARATOR . $file) && !in_array($file, [".", ".."])) { $fileList = array_merge( $fileList, $this->getFiles($directory . DIRECTORY_SEPARATOR . $file) ); continue; } // not the file we want if (false === $this->isRequiredFile($file)) { $this->log(sprintf("Files %s is not required", $directory . DIRECTORY_SEPARATOR . $file)); continue; } $this->log(sprintf("Collected %s", $directory . DIRECTORY_SEPARATOR . $file)); $fileList[] = $directory . DIRECTORY_SEPARATOR . $file; } return $fileList; }
[ "private", "function", "getFiles", "(", "$", "directory", ")", "{", "$", "fileList", "=", "[", "]", ";", "$", "files", "=", "scandir", "(", "$", "directory", ")", ";", "$", "this", "->", "log", "(", "sprintf", "(", "\"Scanning dir %s, found %d files\"", ",", "$", "directory", ",", "count", "(", "$", "files", ")", ")", ")", ";", "foreach", "(", "$", "files", "as", "$", "index", "=>", "$", "file", ")", "{", "// recursive retrieve files in subdirectories", "if", "(", "true", "===", "is_dir", "(", "$", "directory", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ")", "&&", "!", "in_array", "(", "$", "file", ",", "[", "\".\"", ",", "\"..\"", "]", ")", ")", "{", "$", "fileList", "=", "array_merge", "(", "$", "fileList", ",", "$", "this", "->", "getFiles", "(", "$", "directory", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ")", ")", ";", "continue", ";", "}", "// not the file we want", "if", "(", "false", "===", "$", "this", "->", "isRequiredFile", "(", "$", "file", ")", ")", "{", "$", "this", "->", "log", "(", "sprintf", "(", "\"Files %s is not required\"", ",", "$", "directory", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ")", ")", ";", "continue", ";", "}", "$", "this", "->", "log", "(", "sprintf", "(", "\"Collected %s\"", ",", "$", "directory", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ")", ")", ";", "$", "fileList", "[", "]", "=", "$", "directory", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ";", "}", "return", "$", "fileList", ";", "}" ]
Scan a directory and list all files that correspond to given criteria @param string $directory @return array
[ "Scan", "a", "directory", "and", "list", "all", "files", "that", "correspond", "to", "given", "criteria" ]
07630d51a7d4ffe31e3d39e8fa3b106055290dad
https://github.com/needle-project/common/blob/07630d51a7d4ffe31e3d39e8fa3b106055290dad/src/ClassFinder.php#L90-L114
10,288
needle-project/common
src/ClassFinder.php
ClassFinder.isA
private function isA($className, $classType) { $types = array_merge( class_parents($className), class_implements($className) ); $this->log(sprintf("Class %s is a %s", $className, implode(', ', $types))); return in_array($classType, $types); }
php
private function isA($className, $classType) { $types = array_merge( class_parents($className), class_implements($className) ); $this->log(sprintf("Class %s is a %s", $className, implode(', ', $types))); return in_array($classType, $types); }
[ "private", "function", "isA", "(", "$", "className", ",", "$", "classType", ")", "{", "$", "types", "=", "array_merge", "(", "class_parents", "(", "$", "className", ")", ",", "class_implements", "(", "$", "className", ")", ")", ";", "$", "this", "->", "log", "(", "sprintf", "(", "\"Class %s is a %s\"", ",", "$", "className", ",", "implode", "(", "', '", ",", "$", "types", ")", ")", ")", ";", "return", "in_array", "(", "$", "classType", ",", "$", "types", ")", ";", "}" ]
Identify if a class-name extends a type or implements an interface @param string $className @param string $classType @return bool
[ "Identify", "if", "a", "class", "-", "name", "extends", "a", "type", "or", "implements", "an", "interface" ]
07630d51a7d4ffe31e3d39e8fa3b106055290dad
https://github.com/needle-project/common/blob/07630d51a7d4ffe31e3d39e8fa3b106055290dad/src/ClassFinder.php#L158-L166
10,289
popy-dev/popy-calendar
src/Factory/ConfigurableFactory.php
ConfigurableFactory.get
protected function get($service, array &$options) { if (isset($options[$service]) && is_object($options[$service])) { return $options[$service]; } $service = explode('_', $service); $service = array_map('ucfirst', $service); $service = 'get' . implode('', $service); return $options[$service] = $this->$service($options); }
php
protected function get($service, array &$options) { if (isset($options[$service]) && is_object($options[$service])) { return $options[$service]; } $service = explode('_', $service); $service = array_map('ucfirst', $service); $service = 'get' . implode('', $service); return $options[$service] = $this->$service($options); }
[ "protected", "function", "get", "(", "$", "service", ",", "array", "&", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "$", "service", "]", ")", "&&", "is_object", "(", "$", "options", "[", "$", "service", "]", ")", ")", "{", "return", "$", "options", "[", "$", "service", "]", ";", "}", "$", "service", "=", "explode", "(", "'_'", ",", "$", "service", ")", ";", "$", "service", "=", "array_map", "(", "'ucfirst'", ",", "$", "service", ")", ";", "$", "service", "=", "'get'", ".", "implode", "(", "''", ",", "$", "service", ")", ";", "return", "$", "options", "[", "$", "service", "]", "=", "$", "this", "->", "$", "service", "(", "$", "options", ")", ";", "}" ]
Generic service getter. @param string $service Service name. @param array $options Option array @return mixed
[ "Generic", "service", "getter", "." ]
989048be18451c813cfce926229c6aaddd1b0639
https://github.com/popy-dev/popy-calendar/blob/989048be18451c813cfce926229c6aaddd1b0639/src/Factory/ConfigurableFactory.php#L143-L154
10,290
MINISTRYGmbH/morrow-core
src/Core/Base.php
Base.arrayOrderBy
public function arrayOrderBy($data, $orderby) { // all the references are part of a workaround which only occurs with array_multisort and call_user_func_array in PHP >= 5.3 $asc = SORT_ASC; $desc = SORT_DESC; // the array we pass to array_multisort at the end $params = []; // explode the orderby to use it for array_multisort $orderbys = explode(',', $orderby); $orderbys = array_map('trim', $orderbys); foreach ($orderbys as &$orderby) { $parts = explode(" ", $orderby); if (!isset($parts[1])) $parts[1] = 'asc'; $parts[1] = strtolower($parts[1]); if (!in_array($parts[1], ['asc', 'desc'])) $parts[1] = 'asc'; // add field name $params[] = $parts[0]; // add sort flag if ($parts[1] == 'asc') $params[] =& $asc; else $params[] =& $desc; } // create temp arrays for multisort $temp = []; $count = count($params)-1; for ($i=0; $i<=$count; $i=$i+2) { $field = $params[$i]; $params[$i] = []; foreach ($data as $ii => $row) { $temp[$field][] = strtolower($row[$field]); } $params[$i] =& $temp[$field]; } //now sort $params[] =& $data; call_user_func_array('array_multisort', $params); return $data; }
php
public function arrayOrderBy($data, $orderby) { // all the references are part of a workaround which only occurs with array_multisort and call_user_func_array in PHP >= 5.3 $asc = SORT_ASC; $desc = SORT_DESC; // the array we pass to array_multisort at the end $params = []; // explode the orderby to use it for array_multisort $orderbys = explode(',', $orderby); $orderbys = array_map('trim', $orderbys); foreach ($orderbys as &$orderby) { $parts = explode(" ", $orderby); if (!isset($parts[1])) $parts[1] = 'asc'; $parts[1] = strtolower($parts[1]); if (!in_array($parts[1], ['asc', 'desc'])) $parts[1] = 'asc'; // add field name $params[] = $parts[0]; // add sort flag if ($parts[1] == 'asc') $params[] =& $asc; else $params[] =& $desc; } // create temp arrays for multisort $temp = []; $count = count($params)-1; for ($i=0; $i<=$count; $i=$i+2) { $field = $params[$i]; $params[$i] = []; foreach ($data as $ii => $row) { $temp[$field][] = strtolower($row[$field]); } $params[$i] =& $temp[$field]; } //now sort $params[] =& $data; call_user_func_array('array_multisort', $params); return $data; }
[ "public", "function", "arrayOrderBy", "(", "$", "data", ",", "$", "orderby", ")", "{", "// all the references are part of a workaround which only occurs with array_multisort and call_user_func_array in PHP >= 5.3", "$", "asc", "=", "SORT_ASC", ";", "$", "desc", "=", "SORT_DESC", ";", "// the array we pass to array_multisort at the end", "$", "params", "=", "[", "]", ";", "// explode the orderby to use it for array_multisort", "$", "orderbys", "=", "explode", "(", "','", ",", "$", "orderby", ")", ";", "$", "orderbys", "=", "array_map", "(", "'trim'", ",", "$", "orderbys", ")", ";", "foreach", "(", "$", "orderbys", "as", "&", "$", "orderby", ")", "{", "$", "parts", "=", "explode", "(", "\" \"", ",", "$", "orderby", ")", ";", "if", "(", "!", "isset", "(", "$", "parts", "[", "1", "]", ")", ")", "$", "parts", "[", "1", "]", "=", "'asc'", ";", "$", "parts", "[", "1", "]", "=", "strtolower", "(", "$", "parts", "[", "1", "]", ")", ";", "if", "(", "!", "in_array", "(", "$", "parts", "[", "1", "]", ",", "[", "'asc'", ",", "'desc'", "]", ")", ")", "$", "parts", "[", "1", "]", "=", "'asc'", ";", "// add field name", "$", "params", "[", "]", "=", "$", "parts", "[", "0", "]", ";", "// add sort flag", "if", "(", "$", "parts", "[", "1", "]", "==", "'asc'", ")", "$", "params", "[", "]", "=", "&", "$", "asc", ";", "else", "$", "params", "[", "]", "=", "&", "$", "desc", ";", "}", "// create temp arrays for multisort", "$", "temp", "=", "[", "]", ";", "$", "count", "=", "count", "(", "$", "params", ")", "-", "1", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<=", "$", "count", ";", "$", "i", "=", "$", "i", "+", "2", ")", "{", "$", "field", "=", "$", "params", "[", "$", "i", "]", ";", "$", "params", "[", "$", "i", "]", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "ii", "=>", "$", "row", ")", "{", "$", "temp", "[", "$", "field", "]", "[", "]", "=", "strtolower", "(", "$", "row", "[", "$", "field", "]", ")", ";", "}", "$", "params", "[", "$", "i", "]", "=", "&", "$", "temp", "[", "$", "field", "]", ";", "}", "//now sort", "$", "params", "[", "]", "=", "&", "$", "data", ";", "call_user_func_array", "(", "'array_multisort'", ",", "$", "params", ")", ";", "return", "$", "data", ";", "}" ]
Orders an array like in a SQL query. Usage example: ~~~{.php} class Dummy extends \Morrow\Core\Base { public function sort() { $data = [ 0 => [ 'title' => 'Foo', 'position' => 1, ], 1 => [ 'title' => 'Bar', 'position' => 0, ], ]; return $this->arrayOrderBy($data, 'position ASC, title ASC'); } } ~~~ @param array $data The multidimensional array that should get sorted. @param string $orderby An SQL like string to define the ordering. @return array Returns the sorted array.
[ "Orders", "an", "array", "like", "in", "a", "SQL", "query", "." ]
bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e
https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Core/Base.php#L59-L101
10,291
MINISTRYGmbH/morrow-core
src/Core/Base.php
Base.arrayGet
public function arrayGet(array &$array, $identifier = '', $fallback = null) { if (empty($identifier)) return $array; // create reference $parts = explode('.', $identifier); $returner =& $array; foreach ($parts as $part) { if (isset($returner[$part])) { // if the array key is set expand the reference $returner =& $returner[$part]; } else { // delete the reference unset($returner); break; } } if (isset($returner)) return $returner; else return $fallback; }
php
public function arrayGet(array &$array, $identifier = '', $fallback = null) { if (empty($identifier)) return $array; // create reference $parts = explode('.', $identifier); $returner =& $array; foreach ($parts as $part) { if (isset($returner[$part])) { // if the array key is set expand the reference $returner =& $returner[$part]; } else { // delete the reference unset($returner); break; } } if (isset($returner)) return $returner; else return $fallback; }
[ "public", "function", "arrayGet", "(", "array", "&", "$", "array", ",", "$", "identifier", "=", "''", ",", "$", "fallback", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "identifier", ")", ")", "return", "$", "array", ";", "// create reference", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "identifier", ")", ";", "$", "returner", "=", "&", "$", "array", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "if", "(", "isset", "(", "$", "returner", "[", "$", "part", "]", ")", ")", "{", "// if the array key is set expand the reference", "$", "returner", "=", "&", "$", "returner", "[", "$", "part", "]", ";", "}", "else", "{", "// delete the reference", "unset", "(", "$", "returner", ")", ";", "break", ";", "}", "}", "if", "(", "isset", "(", "$", "returner", ")", ")", "return", "$", "returner", ";", "else", "return", "$", "fallback", ";", "}" ]
Returns a branch or a value of a multidimensional array tree by use of the dot syntax to define subnodes. Usage example: ~~~{.php} class Dummy extends \Morrow\Core\Base { public function foo() { $data = [ 0 => [ 'title' => 'Foo', 'position' => 1, ], 1 => [ 'title' => 'Bar', 'position' => 0, ], ]; return $this->arrayGet($data, '1.title'); } } ~~~ @param array $array The input array which should be searched. @param string $identifier A string of array keys separated by dots. @param mixed $fallback Will be returned if the `$identifier` could not be found. @return array Returns the subnode.
[ "Returns", "a", "branch", "or", "a", "value", "of", "a", "multidimensional", "array", "tree", "by", "use", "of", "the", "dot", "syntax", "to", "define", "subnodes", "." ]
bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e
https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Core/Base.php#L132-L152
10,292
MINISTRYGmbH/morrow-core
src/Core/Base.php
Base.arraySet
public function arraySet(array &$array, $identifier, $value) { // create reference $returner =& $array; foreach (explode('.', $identifier) as $part) { if (!isset($returner[$part])) { $returner[$part] = ''; } $returner =& $returner[$part]; } $returner = $value; }
php
public function arraySet(array &$array, $identifier, $value) { // create reference $returner =& $array; foreach (explode('.', $identifier) as $part) { if (!isset($returner[$part])) { $returner[$part] = ''; } $returner =& $returner[$part]; } $returner = $value; }
[ "public", "function", "arraySet", "(", "array", "&", "$", "array", ",", "$", "identifier", ",", "$", "value", ")", "{", "// create reference", "$", "returner", "=", "&", "$", "array", ";", "foreach", "(", "explode", "(", "'.'", ",", "$", "identifier", ")", "as", "$", "part", ")", "{", "if", "(", "!", "isset", "(", "$", "returner", "[", "$", "part", "]", ")", ")", "{", "$", "returner", "[", "$", "part", "]", "=", "''", ";", "}", "$", "returner", "=", "&", "$", "returner", "[", "$", "part", "]", ";", "}", "$", "returner", "=", "$", "value", ";", "}" ]
Sets a branch or a value of a multidimensional array tree by use of the dot syntax to define subnodes. Usage example: ~~~{.php} class Dummy extends \Morrow\Core\Base { public function foo() { $data = [ 0 => [ 'title' => 'Foo', 'position' => 1, ], 1 => [ 'title' => 'Bar', 'position' => 0, ], ]; return $this->arraySet($data, '1.children', [0 => ['title' => 'FooBar', 'position' => 0]]); } } ~~~ @param array $array The input array which should be extended. @param string $identifier A string of array keys separated by dots. @param mixed $value The data to be set. @return null
[ "Sets", "a", "branch", "or", "a", "value", "of", "a", "multidimensional", "array", "tree", "by", "use", "of", "the", "dot", "syntax", "to", "define", "subnodes", "." ]
bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e
https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Core/Base.php#L183-L195
10,293
MINISTRYGmbH/morrow-core
src/Core/Base.php
Base.arrayDelete
public function arrayDelete(array &$array, $identifier) { // create reference $parts = explode('.', $identifier); $returner =& $array; $parent =& $array; foreach ($parts as $part) { // if the array key is set expand the reference if (isset($returner[$part]) && !empty($part)) { $parent =& $returner; $rkey = $part; $returner =& $returner[$part]; } else { // delete the reference unset($returner); break; } } if (isset($returner)) { unset($parent[$rkey]); } else { throw new \Exception(__CLASS__.': identifier "'.$identifier.'" does not exist.'); } }
php
public function arrayDelete(array &$array, $identifier) { // create reference $parts = explode('.', $identifier); $returner =& $array; $parent =& $array; foreach ($parts as $part) { // if the array key is set expand the reference if (isset($returner[$part]) && !empty($part)) { $parent =& $returner; $rkey = $part; $returner =& $returner[$part]; } else { // delete the reference unset($returner); break; } } if (isset($returner)) { unset($parent[$rkey]); } else { throw new \Exception(__CLASS__.': identifier "'.$identifier.'" does not exist.'); } }
[ "public", "function", "arrayDelete", "(", "array", "&", "$", "array", ",", "$", "identifier", ")", "{", "// create reference", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "identifier", ")", ";", "$", "returner", "=", "&", "$", "array", ";", "$", "parent", "=", "&", "$", "array", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "// if the array key is set expand the reference", "if", "(", "isset", "(", "$", "returner", "[", "$", "part", "]", ")", "&&", "!", "empty", "(", "$", "part", ")", ")", "{", "$", "parent", "=", "&", "$", "returner", ";", "$", "rkey", "=", "$", "part", ";", "$", "returner", "=", "&", "$", "returner", "[", "$", "part", "]", ";", "}", "else", "{", "// delete the reference", "unset", "(", "$", "returner", ")", ";", "break", ";", "}", "}", "if", "(", "isset", "(", "$", "returner", ")", ")", "{", "unset", "(", "$", "parent", "[", "$", "rkey", "]", ")", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", "__CLASS__", ".", "': identifier \"'", ".", "$", "identifier", ".", "'\" does not exist.'", ")", ";", "}", "}" ]
Deletes a branch or a key of a multidimensional array tree by use of the dot syntax to define subnodes. Usage example: ~~~{.php} class Dummy extends \Morrow\Core\Base { public function foo() { $data = [ 0 => [ 'title' => 'Foo', 'position' => 1, ], 1 => [ 'title' => 'Bar', 'position' => 0, ], ]; return $this->arrayDelete($data, '0.title'); } } ~~~ @param array $array The input array which should be extended. @param string $identifier A string of array keys separated by dots. @return null
[ "Deletes", "a", "branch", "or", "a", "key", "of", "a", "multidimensional", "array", "tree", "by", "use", "of", "the", "dot", "syntax", "to", "define", "subnodes", "." ]
bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e
https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Core/Base.php#L225-L249
10,294
MINISTRYGmbH/morrow-core
src/Core/Base.php
Base.arrayExplode
public function arrayExplode(array $array) { $data = []; // iterate keys foreach ($array as $rkey => $row) { $parent =& $data; $parts = explode('.', $rkey); // iterate key parts foreach ($parts as $part) { // build values if (!isset($parent[$part]) || !is_array($parent[$part])) { if ($part === end($parts)) { if (!is_array($row)) $parent[$part] = $row; else $parent[$part] = $this->arrayExplode($row); } else $parent[$part] = []; } $parent = &$parent[$part]; } } return $data; }
php
public function arrayExplode(array $array) { $data = []; // iterate keys foreach ($array as $rkey => $row) { $parent =& $data; $parts = explode('.', $rkey); // iterate key parts foreach ($parts as $part) { // build values if (!isset($parent[$part]) || !is_array($parent[$part])) { if ($part === end($parts)) { if (!is_array($row)) $parent[$part] = $row; else $parent[$part] = $this->arrayExplode($row); } else $parent[$part] = []; } $parent = &$parent[$part]; } } return $data; }
[ "public", "function", "arrayExplode", "(", "array", "$", "array", ")", "{", "$", "data", "=", "[", "]", ";", "// iterate keys", "foreach", "(", "$", "array", "as", "$", "rkey", "=>", "$", "row", ")", "{", "$", "parent", "=", "&", "$", "data", ";", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "rkey", ")", ";", "// iterate key parts", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "// build values", "if", "(", "!", "isset", "(", "$", "parent", "[", "$", "part", "]", ")", "||", "!", "is_array", "(", "$", "parent", "[", "$", "part", "]", ")", ")", "{", "if", "(", "$", "part", "===", "end", "(", "$", "parts", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "row", ")", ")", "$", "parent", "[", "$", "part", "]", "=", "$", "row", ";", "else", "$", "parent", "[", "$", "part", "]", "=", "$", "this", "->", "arrayExplode", "(", "$", "row", ")", ";", "}", "else", "$", "parent", "[", "$", "part", "]", "=", "[", "]", ";", "}", "$", "parent", "=", "&", "$", "parent", "[", "$", "part", "]", ";", "}", "}", "return", "$", "data", ";", "}" ]
Explodes an array with dotted keys to a normal array. Usage example: ~~~{.php} class Dummy extends \Morrow\Core\Base { public function foo() { $data = [ '0.title' => 'Foo', '0.position' => 1, '1.title' => 'Bar', '1.position' => 0, ]; return $this->arrayExplode($data); } } ~~~ @param array $array The input array that should be exploded. @return null
[ "Explodes", "an", "array", "with", "dotted", "keys", "to", "a", "normal", "array", "." ]
bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e
https://github.com/MINISTRYGmbH/morrow-core/blob/bdc916eedb14b65b06dbc88efbd2b7779f4a9a9e/src/Core/Base.php#L274-L296
10,295
keboola/php-oauth
src/Keboola/OAuth/OAuthController.php
OAuthController.initSessionBag
protected function initSessionBag($reset = false) { if ($reset || !$this->sessionBag) { $name = str_replace("-", "", $this->appName); /** @var Session $session */ $session = $this->container->get('session'); $bag = new AttributeBag('_' . str_replace("-", "_", $this->appName)); $bag->setName($name); $session->registerBag($bag); $this->sessionBag = $session->getBag($name); } return $this->sessionBag; }
php
protected function initSessionBag($reset = false) { if ($reset || !$this->sessionBag) { $name = str_replace("-", "", $this->appName); /** @var Session $session */ $session = $this->container->get('session'); $bag = new AttributeBag('_' . str_replace("-", "_", $this->appName)); $bag->setName($name); $session->registerBag($bag); $this->sessionBag = $session->getBag($name); } return $this->sessionBag; }
[ "protected", "function", "initSessionBag", "(", "$", "reset", "=", "false", ")", "{", "if", "(", "$", "reset", "||", "!", "$", "this", "->", "sessionBag", ")", "{", "$", "name", "=", "str_replace", "(", "\"-\"", ",", "\"\"", ",", "$", "this", "->", "appName", ")", ";", "/** @var Session $session */", "$", "session", "=", "$", "this", "->", "container", "->", "get", "(", "'session'", ")", ";", "$", "bag", "=", "new", "AttributeBag", "(", "'_'", ".", "str_replace", "(", "\"-\"", ",", "\"_\"", ",", "$", "this", "->", "appName", ")", ")", ";", "$", "bag", "->", "setName", "(", "$", "name", ")", ";", "$", "session", "->", "registerBag", "(", "$", "bag", ")", ";", "$", "this", "->", "sessionBag", "=", "$", "session", "->", "getBag", "(", "$", "name", ")", ";", "}", "return", "$", "this", "->", "sessionBag", ";", "}" ]
Init OAuth session bag @param bool $reset @return AttributeBag
[ "Init", "OAuth", "session", "bag" ]
6c62e85133adc0d8207aa79a36f281a78dbaa607
https://github.com/keboola/php-oauth/blob/6c62e85133adc0d8207aa79a36f281a78dbaa607/src/Keboola/OAuth/OAuthController.php#L148-L162
10,296
keboola/php-oauth
src/Keboola/OAuth/OAuthController.php
OAuthController.getCallbackUrl
protected function getCallbackUrl(Request $request) { $selfUrl = $this->getSelfUrl($request); if (substr($selfUrl, -9) == "-callback") { return $selfUrl; } else { return $selfUrl . "-callback"; } }
php
protected function getCallbackUrl(Request $request) { $selfUrl = $this->getSelfUrl($request); if (substr($selfUrl, -9) == "-callback") { return $selfUrl; } else { return $selfUrl . "-callback"; } }
[ "protected", "function", "getCallbackUrl", "(", "Request", "$", "request", ")", "{", "$", "selfUrl", "=", "$", "this", "->", "getSelfUrl", "(", "$", "request", ")", ";", "if", "(", "substr", "(", "$", "selfUrl", ",", "-", "9", ")", "==", "\"-callback\"", ")", "{", "return", "$", "selfUrl", ";", "}", "else", "{", "return", "$", "selfUrl", ".", "\"-callback\"", ";", "}", "}" ]
Get the callback URL @param Request $request @return string
[ "Get", "the", "callback", "URL" ]
6c62e85133adc0d8207aa79a36f281a78dbaa607
https://github.com/keboola/php-oauth/blob/6c62e85133adc0d8207aa79a36f281a78dbaa607/src/Keboola/OAuth/OAuthController.php#L202-L210
10,297
keboola/php-oauth
src/Keboola/OAuth/OAuthController.php
OAuthController.getParam
protected function getParam($name, $required = false) { if (!$this->container->hasParameter($name)) { if ($required) { throw new SyrupComponentException(500, "Parameter '{$name}' not set in parameters.yml"); } else { return null; } } else { return $this->container->getParameter($name); } }
php
protected function getParam($name, $required = false) { if (!$this->container->hasParameter($name)) { if ($required) { throw new SyrupComponentException(500, "Parameter '{$name}' not set in parameters.yml"); } else { return null; } } else { return $this->container->getParameter($name); } }
[ "protected", "function", "getParam", "(", "$", "name", ",", "$", "required", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "container", "->", "hasParameter", "(", "$", "name", ")", ")", "{", "if", "(", "$", "required", ")", "{", "throw", "new", "SyrupComponentException", "(", "500", ",", "\"Parameter '{$name}' not set in parameters.yml\"", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "else", "{", "return", "$", "this", "->", "container", "->", "getParameter", "(", "$", "name", ")", ";", "}", "}" ]
Get an attribute from parameters.yml @param $name Name of the attribute @param $required (bool) Whether the attribute is mandatory (false by default) @return mixed
[ "Get", "an", "attribute", "from", "parameters", ".", "yml" ]
6c62e85133adc0d8207aa79a36f281a78dbaa607
https://github.com/keboola/php-oauth/blob/6c62e85133adc0d8207aa79a36f281a78dbaa607/src/Keboola/OAuth/OAuthController.php#L219-L230
10,298
keboola/php-oauth
src/Keboola/OAuth/OAuthController.php
OAuthController.externalAuthAction
public function externalAuthAction(Request $request) { $this->checkParams($request->query); foreach($request->query->all() as $k => $v) { $request->request->set($k, $v); } return $this->getOAuthAction($request); }
php
public function externalAuthAction(Request $request) { $this->checkParams($request->query); foreach($request->query->all() as $k => $v) { $request->request->set($k, $v); } return $this->getOAuthAction($request); }
[ "public", "function", "externalAuthAction", "(", "Request", "$", "request", ")", "{", "$", "this", "->", "checkParams", "(", "$", "request", "->", "query", ")", ";", "foreach", "(", "$", "request", "->", "query", "->", "all", "(", ")", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "request", "->", "request", "->", "set", "(", "$", "k", ",", "$", "v", ")", ";", "}", "return", "$", "this", "->", "getOAuthAction", "(", "$", "request", ")", ";", "}" ]
Handle a GET request with token&config parameters in URL @param Request $request @return \Symfony\Component\HttpFoundation\Response
[ "Handle", "a", "GET", "request", "with", "token&config", "parameters", "in", "URL" ]
6c62e85133adc0d8207aa79a36f281a78dbaa607
https://github.com/keboola/php-oauth/blob/6c62e85133adc0d8207aa79a36f281a78dbaa607/src/Keboola/OAuth/OAuthController.php#L237-L246
10,299
keboola/php-oauth
src/Keboola/OAuth/OAuthController.php
OAuthController.returnResult
protected function returnResult($data, $status = "ok") { $referrer = $this->sessionBag->get("referrer"); if (!empty($referrer)) { return $this->redirect($referrer); } else { return new Response(jsonDecode(array_replace(array("status" => $status), (array) $data)), 200, $this->defaultResponseHeaders); } }
php
protected function returnResult($data, $status = "ok") { $referrer = $this->sessionBag->get("referrer"); if (!empty($referrer)) { return $this->redirect($referrer); } else { return new Response(jsonDecode(array_replace(array("status" => $status), (array) $data)), 200, $this->defaultResponseHeaders); } }
[ "protected", "function", "returnResult", "(", "$", "data", ",", "$", "status", "=", "\"ok\"", ")", "{", "$", "referrer", "=", "$", "this", "->", "sessionBag", "->", "get", "(", "\"referrer\"", ")", ";", "if", "(", "!", "empty", "(", "$", "referrer", ")", ")", "{", "return", "$", "this", "->", "redirect", "(", "$", "referrer", ")", ";", "}", "else", "{", "return", "new", "Response", "(", "jsonDecode", "(", "array_replace", "(", "array", "(", "\"status\"", "=>", "$", "status", ")", ",", "(", "array", ")", "$", "data", ")", ")", ",", "200", ",", "$", "this", "->", "defaultResponseHeaders", ")", ";", "}", "}" ]
Return Decide whether to return a redirect to "referrer" or a JSON encoded response @param array|stdClass $data Data to be returned in the JSON @param string $status A status to be included in the result. If the response contains a "status" key, it will replace the status @return \Symfony\Component\HttpFoundation\Response
[ "Return", "Decide", "whether", "to", "return", "a", "redirect", "to", "referrer", "or", "a", "JSON", "encoded", "response" ]
6c62e85133adc0d8207aa79a36f281a78dbaa607
https://github.com/keboola/php-oauth/blob/6c62e85133adc0d8207aa79a36f281a78dbaa607/src/Keboola/OAuth/OAuthController.php#L268-L276