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
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
18,500
slashworks/control-bundle
src/Slashworks/AppBundle/Controller/RemoteAppController.php
RemoteAppController.createAction
public function createAction(Request $request) { $oRemoteApp = new RemoteApp(); $form = $this->createCreateForm($oRemoteApp); $form->handleRequest($request); if ($form->isValid()) { $sDomain = $oRemoteApp->getDomain(); if(substr($sDomain,-1,1) !== "/"){ $sDomain .= "/"; $oRemoteApp->setDomain($sDomain); } $sModulePath = $oRemoteApp->getApiUrl(); if(substr($sModulePath,0,1) === "/"){ $sModulePath = substr($sModulePath,1); $oRemoteApp->setApiUrl($sModulePath); } $oRemoteApp->save(); return $this->redirect($this->generateUrl('remote_app')); } return $this->render('SlashworksAppBundle:RemoteApp:new.html.twig', array( 'entity' => $oRemoteApp, 'form' => $form->createView(), )); }
php
public function createAction(Request $request) { $oRemoteApp = new RemoteApp(); $form = $this->createCreateForm($oRemoteApp); $form->handleRequest($request); if ($form->isValid()) { $sDomain = $oRemoteApp->getDomain(); if(substr($sDomain,-1,1) !== "/"){ $sDomain .= "/"; $oRemoteApp->setDomain($sDomain); } $sModulePath = $oRemoteApp->getApiUrl(); if(substr($sModulePath,0,1) === "/"){ $sModulePath = substr($sModulePath,1); $oRemoteApp->setApiUrl($sModulePath); } $oRemoteApp->save(); return $this->redirect($this->generateUrl('remote_app')); } return $this->render('SlashworksAppBundle:RemoteApp:new.html.twig', array( 'entity' => $oRemoteApp, 'form' => $form->createView(), )); }
[ "public", "function", "createAction", "(", "Request", "$", "request", ")", "{", "$", "oRemoteApp", "=", "new", "RemoteApp", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createCreateForm", "(", "$", "oRemoteApp", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "$", "sDomain", "=", "$", "oRemoteApp", "->", "getDomain", "(", ")", ";", "if", "(", "substr", "(", "$", "sDomain", ",", "-", "1", ",", "1", ")", "!==", "\"/\"", ")", "{", "$", "sDomain", ".=", "\"/\"", ";", "$", "oRemoteApp", "->", "setDomain", "(", "$", "sDomain", ")", ";", "}", "$", "sModulePath", "=", "$", "oRemoteApp", "->", "getApiUrl", "(", ")", ";", "if", "(", "substr", "(", "$", "sModulePath", ",", "0", ",", "1", ")", "===", "\"/\"", ")", "{", "$", "sModulePath", "=", "substr", "(", "$", "sModulePath", ",", "1", ")", ";", "$", "oRemoteApp", "->", "setApiUrl", "(", "$", "sModulePath", ")", ";", "}", "$", "oRemoteApp", "->", "save", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'remote_app'", ")", ")", ";", "}", "return", "$", "this", "->", "render", "(", "'SlashworksAppBundle:RemoteApp:new.html.twig'", ",", "array", "(", "'entity'", "=>", "$", "oRemoteApp", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ")", ";", "}" ]
Create new remote app @param \Symfony\Component\HttpFoundation\Request $request @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response @throws \Exception @throws \PropelException
[ "Create", "new", "remote", "app" ]
2ba86d96f1f41f9424e2229c4e2b13017e973f89
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/RemoteAppController.php#L424-L454
18,501
slashworks/control-bundle
src/Slashworks/AppBundle/Controller/RemoteAppController.php
RemoteAppController.newAction
public function newAction() { $oRemoteApp = new RemoteApp(); $oRemoteApp->setApiUrl("swControl/"); $oRemoteApp->setActivated(true); $oRemoteApp->setIncludelog(true); $oRemoteApp->setNotificationRecipient($this->getUser()->getEmail()); $oRemoteApp->setNotificationSender($this->getUser()->getEmail()); $oRemoteApp->setNotificationChange(true); $oRemoteApp->setNotificationError(true); $form = $this->createCreateForm($oRemoteApp); return $this->render('SlashworksAppBundle:RemoteApp:new.html.twig', array( 'entity' => $oRemoteApp, 'form' => $form->createView(), )); }
php
public function newAction() { $oRemoteApp = new RemoteApp(); $oRemoteApp->setApiUrl("swControl/"); $oRemoteApp->setActivated(true); $oRemoteApp->setIncludelog(true); $oRemoteApp->setNotificationRecipient($this->getUser()->getEmail()); $oRemoteApp->setNotificationSender($this->getUser()->getEmail()); $oRemoteApp->setNotificationChange(true); $oRemoteApp->setNotificationError(true); $form = $this->createCreateForm($oRemoteApp); return $this->render('SlashworksAppBundle:RemoteApp:new.html.twig', array( 'entity' => $oRemoteApp, 'form' => $form->createView(), )); }
[ "public", "function", "newAction", "(", ")", "{", "$", "oRemoteApp", "=", "new", "RemoteApp", "(", ")", ";", "$", "oRemoteApp", "->", "setApiUrl", "(", "\"swControl/\"", ")", ";", "$", "oRemoteApp", "->", "setActivated", "(", "true", ")", ";", "$", "oRemoteApp", "->", "setIncludelog", "(", "true", ")", ";", "$", "oRemoteApp", "->", "setNotificationRecipient", "(", "$", "this", "->", "getUser", "(", ")", "->", "getEmail", "(", ")", ")", ";", "$", "oRemoteApp", "->", "setNotificationSender", "(", "$", "this", "->", "getUser", "(", ")", "->", "getEmail", "(", ")", ")", ";", "$", "oRemoteApp", "->", "setNotificationChange", "(", "true", ")", ";", "$", "oRemoteApp", "->", "setNotificationError", "(", "true", ")", ";", "$", "form", "=", "$", "this", "->", "createCreateForm", "(", "$", "oRemoteApp", ")", ";", "return", "$", "this", "->", "render", "(", "'SlashworksAppBundle:RemoteApp:new.html.twig'", ",", "array", "(", "'entity'", "=>", "$", "oRemoteApp", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ")", ";", "}" ]
Displays a form to create a new RemoteApp entity. @return \Symfony\Component\HttpFoundation\Response
[ "Displays", "a", "form", "to", "create", "a", "new", "RemoteApp", "entity", "." ]
2ba86d96f1f41f9424e2229c4e2b13017e973f89
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/RemoteAppController.php#L462-L479
18,502
slashworks/control-bundle
src/Slashworks/AppBundle/Controller/RemoteAppController.php
RemoteAppController.updateAction
public function updateAction(Request $request, $id) { /** @var RemoteApp $oRemoteApp */ $oRemoteApp = RemoteAppQuery::create()->findOneById($id); if (count($oRemoteApp) === 0) { throw $this->createNotFoundException('Unable to find RemoteApp entity.'); } $deleteForm = $this->createDeleteForm($id); $editForm = $this->createEditForm($oRemoteApp); $editForm->handleRequest($request); if ($editForm->isValid()) { $sDomain = $oRemoteApp->getDomain(); if(substr($sDomain,-1,1) !== "/"){ $sDomain .= "/"; $oRemoteApp->setDomain($sDomain); } $sModulePath = $oRemoteApp->getApiUrl(); if(substr($sModulePath,0,1) === "/"){ $sModulePath = substr($sModulePath,1); $oRemoteApp->setApiUrl($sModulePath); } $oRemoteApp->save(); return $this->redirect($this->generateUrl('remote_app')); } return $this->render('SlashworksAppBundle:RemoteApp:edit.html.twig', array( 'entity' => $oRemoteApp, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); }
php
public function updateAction(Request $request, $id) { /** @var RemoteApp $oRemoteApp */ $oRemoteApp = RemoteAppQuery::create()->findOneById($id); if (count($oRemoteApp) === 0) { throw $this->createNotFoundException('Unable to find RemoteApp entity.'); } $deleteForm = $this->createDeleteForm($id); $editForm = $this->createEditForm($oRemoteApp); $editForm->handleRequest($request); if ($editForm->isValid()) { $sDomain = $oRemoteApp->getDomain(); if(substr($sDomain,-1,1) !== "/"){ $sDomain .= "/"; $oRemoteApp->setDomain($sDomain); } $sModulePath = $oRemoteApp->getApiUrl(); if(substr($sModulePath,0,1) === "/"){ $sModulePath = substr($sModulePath,1); $oRemoteApp->setApiUrl($sModulePath); } $oRemoteApp->save(); return $this->redirect($this->generateUrl('remote_app')); } return $this->render('SlashworksAppBundle:RemoteApp:edit.html.twig', array( 'entity' => $oRemoteApp, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); }
[ "public", "function", "updateAction", "(", "Request", "$", "request", ",", "$", "id", ")", "{", "/** @var RemoteApp $oRemoteApp */", "$", "oRemoteApp", "=", "RemoteAppQuery", "::", "create", "(", ")", "->", "findOneById", "(", "$", "id", ")", ";", "if", "(", "count", "(", "$", "oRemoteApp", ")", "===", "0", ")", "{", "throw", "$", "this", "->", "createNotFoundException", "(", "'Unable to find RemoteApp entity.'", ")", ";", "}", "$", "deleteForm", "=", "$", "this", "->", "createDeleteForm", "(", "$", "id", ")", ";", "$", "editForm", "=", "$", "this", "->", "createEditForm", "(", "$", "oRemoteApp", ")", ";", "$", "editForm", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "editForm", "->", "isValid", "(", ")", ")", "{", "$", "sDomain", "=", "$", "oRemoteApp", "->", "getDomain", "(", ")", ";", "if", "(", "substr", "(", "$", "sDomain", ",", "-", "1", ",", "1", ")", "!==", "\"/\"", ")", "{", "$", "sDomain", ".=", "\"/\"", ";", "$", "oRemoteApp", "->", "setDomain", "(", "$", "sDomain", ")", ";", "}", "$", "sModulePath", "=", "$", "oRemoteApp", "->", "getApiUrl", "(", ")", ";", "if", "(", "substr", "(", "$", "sModulePath", ",", "0", ",", "1", ")", "===", "\"/\"", ")", "{", "$", "sModulePath", "=", "substr", "(", "$", "sModulePath", ",", "1", ")", ";", "$", "oRemoteApp", "->", "setApiUrl", "(", "$", "sModulePath", ")", ";", "}", "$", "oRemoteApp", "->", "save", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'remote_app'", ")", ")", ";", "}", "return", "$", "this", "->", "render", "(", "'SlashworksAppBundle:RemoteApp:edit.html.twig'", ",", "array", "(", "'entity'", "=>", "$", "oRemoteApp", ",", "'edit_form'", "=>", "$", "editForm", "->", "createView", "(", ")", ",", "'delete_form'", "=>", "$", "deleteForm", "->", "createView", "(", ")", ",", ")", ")", ";", "}" ]
Update existing remote app @param \Symfony\Component\HttpFoundation\Request $request @param $id @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response @throws \Exception @throws \PropelException
[ "Update", "existing", "remote", "app" ]
2ba86d96f1f41f9424e2229c4e2b13017e973f89
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/RemoteAppController.php#L520-L558
18,503
slashworks/control-bundle
src/Slashworks/AppBundle/Controller/RemoteAppController.php
RemoteAppController.deleteAction
public function deleteAction(Request $request, $id) { /** @var RemoteApp $oRemoteApp */ $oRemoteApp = RemoteAppQuery::create()->findOneById($id); if ($oRemoteApp === null) { throw $this->createNotFoundException('Unable to find RemoteApp entity.'); } // get history-entries for remoteapp to delete $aHistories = RemoteHistoryContaoQuery::create()->findByRemoteAppId($oRemoteApp->getId()); foreach ($aHistories as $oHistory) { $oHistory->delete(); } $oRemoteApp->delete(); return $this->redirect($this->generateUrl('remote_app')); }
php
public function deleteAction(Request $request, $id) { /** @var RemoteApp $oRemoteApp */ $oRemoteApp = RemoteAppQuery::create()->findOneById($id); if ($oRemoteApp === null) { throw $this->createNotFoundException('Unable to find RemoteApp entity.'); } // get history-entries for remoteapp to delete $aHistories = RemoteHistoryContaoQuery::create()->findByRemoteAppId($oRemoteApp->getId()); foreach ($aHistories as $oHistory) { $oHistory->delete(); } $oRemoteApp->delete(); return $this->redirect($this->generateUrl('remote_app')); }
[ "public", "function", "deleteAction", "(", "Request", "$", "request", ",", "$", "id", ")", "{", "/** @var RemoteApp $oRemoteApp */", "$", "oRemoteApp", "=", "RemoteAppQuery", "::", "create", "(", ")", "->", "findOneById", "(", "$", "id", ")", ";", "if", "(", "$", "oRemoteApp", "===", "null", ")", "{", "throw", "$", "this", "->", "createNotFoundException", "(", "'Unable to find RemoteApp entity.'", ")", ";", "}", "// get history-entries for remoteapp to delete", "$", "aHistories", "=", "RemoteHistoryContaoQuery", "::", "create", "(", ")", "->", "findByRemoteAppId", "(", "$", "oRemoteApp", "->", "getId", "(", ")", ")", ";", "foreach", "(", "$", "aHistories", "as", "$", "oHistory", ")", "{", "$", "oHistory", "->", "delete", "(", ")", ";", "}", "$", "oRemoteApp", "->", "delete", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'remote_app'", ")", ")", ";", "}" ]
Delete remote app @param \Symfony\Component\HttpFoundation\Request $request @param $id @return \Symfony\Component\HttpFoundation\RedirectResponse @throws \Exception @throws \PropelException
[ "Delete", "remote", "app" ]
2ba86d96f1f41f9424e2229c4e2b13017e973f89
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/RemoteAppController.php#L571-L590
18,504
slashworks/control-bundle
src/Slashworks/AppBundle/Controller/RemoteAppController.php
RemoteAppController.lastLogAction
public function lastLogAction($id) { $oLog = ApiLogQuery::create()->findOneByRemoteAppId($id); $oRemoteApp = RemoteAppQuery::create()->findOneById($id); return $this->render('SlashworksAppBundle:RemoteApp:log.html.twig', array( 'oLog' => $oLog, 'remote_app' => $oRemoteApp, )); }
php
public function lastLogAction($id) { $oLog = ApiLogQuery::create()->findOneByRemoteAppId($id); $oRemoteApp = RemoteAppQuery::create()->findOneById($id); return $this->render('SlashworksAppBundle:RemoteApp:log.html.twig', array( 'oLog' => $oLog, 'remote_app' => $oRemoteApp, )); }
[ "public", "function", "lastLogAction", "(", "$", "id", ")", "{", "$", "oLog", "=", "ApiLogQuery", "::", "create", "(", ")", "->", "findOneByRemoteAppId", "(", "$", "id", ")", ";", "$", "oRemoteApp", "=", "RemoteAppQuery", "::", "create", "(", ")", "->", "findOneById", "(", "$", "id", ")", ";", "return", "$", "this", "->", "render", "(", "'SlashworksAppBundle:RemoteApp:log.html.twig'", ",", "array", "(", "'oLog'", "=>", "$", "oLog", ",", "'remote_app'", "=>", "$", "oRemoteApp", ",", ")", ")", ";", "}" ]
Shows last api-log entry @param $id @return \Symfony\Component\HttpFoundation\Response
[ "Shows", "last", "api", "-", "log", "entry" ]
2ba86d96f1f41f9424e2229c4e2b13017e973f89
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/RemoteAppController.php#L600-L610
18,505
slashworks/control-bundle
src/Slashworks/AppBundle/Controller/RemoteAppController.php
RemoteAppController.createCreateForm
private function createCreateForm(RemoteApp $oRemoteApp) { $form = $this->createForm(new RemoteAppType(), $oRemoteApp, array( 'action' => $this->generateUrl('remote_app_create'), 'method' => 'POST', )); $form->add('submit', 'submit', array('label' => 'Create')); return $form; }
php
private function createCreateForm(RemoteApp $oRemoteApp) { $form = $this->createForm(new RemoteAppType(), $oRemoteApp, array( 'action' => $this->generateUrl('remote_app_create'), 'method' => 'POST', )); $form->add('submit', 'submit', array('label' => 'Create')); return $form; }
[ "private", "function", "createCreateForm", "(", "RemoteApp", "$", "oRemoteApp", ")", "{", "$", "form", "=", "$", "this", "->", "createForm", "(", "new", "RemoteAppType", "(", ")", ",", "$", "oRemoteApp", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'remote_app_create'", ")", ",", "'method'", "=>", "'POST'", ",", ")", ")", ";", "$", "form", "->", "add", "(", "'submit'", ",", "'submit'", ",", "array", "(", "'label'", "=>", "'Create'", ")", ")", ";", "return", "$", "form", ";", "}" ]
Creates a form to create a RemoteApp entity. @param RemoteApp $oRemoteApp The entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "create", "a", "RemoteApp", "entity", "." ]
2ba86d96f1f41f9424e2229c4e2b13017e973f89
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Controller/RemoteAppController.php#L620-L631
18,506
Chill-project/Main
DataFixtures/ORM/LoadLanguages.php
LoadLanguages.prepareName
private function prepareName($languageCode) { foreach ($this->container->getParameter('chill_main.available_languages') as $lang) { $names[$lang] = Intl::getLanguageBundle()->getLanguageName($languageCode); } return $names; }
php
private function prepareName($languageCode) { foreach ($this->container->getParameter('chill_main.available_languages') as $lang) { $names[$lang] = Intl::getLanguageBundle()->getLanguageName($languageCode); } return $names; }
[ "private", "function", "prepareName", "(", "$", "languageCode", ")", "{", "foreach", "(", "$", "this", "->", "container", "->", "getParameter", "(", "'chill_main.available_languages'", ")", "as", "$", "lang", ")", "{", "$", "names", "[", "$", "lang", "]", "=", "Intl", "::", "getLanguageBundle", "(", ")", "->", "getLanguageName", "(", "$", "languageCode", ")", ";", "}", "return", "$", "names", ";", "}" ]
prepare names for languages @param string $languageCode @return string[] languages name indexed by available language code
[ "prepare", "names", "for", "languages" ]
384cb6c793072a4f1047dc5cafc2157ee2419f60
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/DataFixtures/ORM/LoadLanguages.php#L71-L77
18,507
lode/fem
src/email.php
email.send
public static function send($recipient, $subject, $body, $options=[]) { if (empty(self::$mailer)) { self::login(); } if (ENVIRONMENT != 'production') { $recipient = self::protect_emailaddress($recipient); if (isset($options['cc'])) { $options['cc'] = self::protect_emailaddress($options['cc']); } if (isset($options['bcc'])) { $options['bcc'] = self::protect_emailaddress($options['bcc']); } if (isset($options['reply_to'])) { $options['reply_to'] = self::protect_emailaddress($options['reply_to']); } $subject = '['.ENVIRONMENT.'] '.$subject; } $sender = [self::$config['from'] => self::$config['name']]; $message = new \Swift_Message(); $message->setFrom($sender); $message->setTo($recipient); $message->setSubject($subject); $message->setBody($body); if (isset($options['cc'])) { $message->setCc($options['cc']); } if (isset($options['bcc'])) { $message->setBcc($options['bcc']); } if (isset($options['reply_to'])) { $message->setReplyTo($options['reply_to']); } if (isset($options['attachment'])) { $attachment = \Swift_Attachment::fromPath($options['attachment']['path'], $options['attachment']['mime']); $message->attach($attachment); } self::$mailer->send($message); }
php
public static function send($recipient, $subject, $body, $options=[]) { if (empty(self::$mailer)) { self::login(); } if (ENVIRONMENT != 'production') { $recipient = self::protect_emailaddress($recipient); if (isset($options['cc'])) { $options['cc'] = self::protect_emailaddress($options['cc']); } if (isset($options['bcc'])) { $options['bcc'] = self::protect_emailaddress($options['bcc']); } if (isset($options['reply_to'])) { $options['reply_to'] = self::protect_emailaddress($options['reply_to']); } $subject = '['.ENVIRONMENT.'] '.$subject; } $sender = [self::$config['from'] => self::$config['name']]; $message = new \Swift_Message(); $message->setFrom($sender); $message->setTo($recipient); $message->setSubject($subject); $message->setBody($body); if (isset($options['cc'])) { $message->setCc($options['cc']); } if (isset($options['bcc'])) { $message->setBcc($options['bcc']); } if (isset($options['reply_to'])) { $message->setReplyTo($options['reply_to']); } if (isset($options['attachment'])) { $attachment = \Swift_Attachment::fromPath($options['attachment']['path'], $options['attachment']['mime']); $message->attach($attachment); } self::$mailer->send($message); }
[ "public", "static", "function", "send", "(", "$", "recipient", ",", "$", "subject", ",", "$", "body", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "self", "::", "$", "mailer", ")", ")", "{", "self", "::", "login", "(", ")", ";", "}", "if", "(", "ENVIRONMENT", "!=", "'production'", ")", "{", "$", "recipient", "=", "self", "::", "protect_emailaddress", "(", "$", "recipient", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'cc'", "]", ")", ")", "{", "$", "options", "[", "'cc'", "]", "=", "self", "::", "protect_emailaddress", "(", "$", "options", "[", "'cc'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'bcc'", "]", ")", ")", "{", "$", "options", "[", "'bcc'", "]", "=", "self", "::", "protect_emailaddress", "(", "$", "options", "[", "'bcc'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'reply_to'", "]", ")", ")", "{", "$", "options", "[", "'reply_to'", "]", "=", "self", "::", "protect_emailaddress", "(", "$", "options", "[", "'reply_to'", "]", ")", ";", "}", "$", "subject", "=", "'['", ".", "ENVIRONMENT", ".", "'] '", ".", "$", "subject", ";", "}", "$", "sender", "=", "[", "self", "::", "$", "config", "[", "'from'", "]", "=>", "self", "::", "$", "config", "[", "'name'", "]", "]", ";", "$", "message", "=", "new", "\\", "Swift_Message", "(", ")", ";", "$", "message", "->", "setFrom", "(", "$", "sender", ")", ";", "$", "message", "->", "setTo", "(", "$", "recipient", ")", ";", "$", "message", "->", "setSubject", "(", "$", "subject", ")", ";", "$", "message", "->", "setBody", "(", "$", "body", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'cc'", "]", ")", ")", "{", "$", "message", "->", "setCc", "(", "$", "options", "[", "'cc'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'bcc'", "]", ")", ")", "{", "$", "message", "->", "setBcc", "(", "$", "options", "[", "'bcc'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'reply_to'", "]", ")", ")", "{", "$", "message", "->", "setReplyTo", "(", "$", "options", "[", "'reply_to'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'attachment'", "]", ")", ")", "{", "$", "attachment", "=", "\\", "Swift_Attachment", "::", "fromPath", "(", "$", "options", "[", "'attachment'", "]", "[", "'path'", "]", ",", "$", "options", "[", "'attachment'", "]", "[", "'mime'", "]", ")", ";", "$", "message", "->", "attach", "(", "$", "attachment", ")", ";", "}", "self", "::", "$", "mailer", "->", "send", "(", "$", "message", ")", ";", "}" ]
sends an email directly @todo allow for html emails as well @param mixed $recipient string or [email => name] @param string $subject @param string $message plain text only for now @param array $options array with optional 'cc', 'bcc', 'reply_to', 'attachment' options 'attachment' is expected to be an array with 'path' and 'mime' keys @return void
[ "sends", "an", "email", "directly" ]
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/email.php#L41-L84
18,508
lode/fem
src/email.php
email.validate
public static function validate($emailaddress) { try { $message = new \Swift_Message(); $message->setTo($emailaddress); } catch (\Swift_RfcComplianceException $e) { return false; } return true; }
php
public static function validate($emailaddress) { try { $message = new \Swift_Message(); $message->setTo($emailaddress); } catch (\Swift_RfcComplianceException $e) { return false; } return true; }
[ "public", "static", "function", "validate", "(", "$", "emailaddress", ")", "{", "try", "{", "$", "message", "=", "new", "\\", "Swift_Message", "(", ")", ";", "$", "message", "->", "setTo", "(", "$", "emailaddress", ")", ";", "}", "catch", "(", "\\", "Swift_RfcComplianceException", "$", "e", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
check email addresses validity @param string $emailaddress @return boolean
[ "check", "email", "addresses", "validity" ]
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/email.php#L92-L102
18,509
lode/fem
src/email.php
email.protect_emailaddress
public static function protect_emailaddress($emailaddress, $catchall_address=null) { if (empty($catchall_address)) { if (empty(self::$config)) { self::load_config(); } $catchall_address = self::$config['from']; } $recipient_name = null; if (is_array($emailaddress)) { $recipient_name = current($emailaddress); $emailaddress = key($emailaddress); } if (self::validate($emailaddress) == false) { $exception = bootstrap::get_library('exception'); throw new $exception('can not convert invalid email address'); } $emailaddress_key = preg_replace('{[^a-zA-Z0-9_]}', '_', $emailaddress); $emailaddress = str_replace('@', '+'.$emailaddress_key.'@', $catchall_address); if ($recipient_name) { $emailaddress = array($emailaddress => $recipient_name); } return $emailaddress; }
php
public static function protect_emailaddress($emailaddress, $catchall_address=null) { if (empty($catchall_address)) { if (empty(self::$config)) { self::load_config(); } $catchall_address = self::$config['from']; } $recipient_name = null; if (is_array($emailaddress)) { $recipient_name = current($emailaddress); $emailaddress = key($emailaddress); } if (self::validate($emailaddress) == false) { $exception = bootstrap::get_library('exception'); throw new $exception('can not convert invalid email address'); } $emailaddress_key = preg_replace('{[^a-zA-Z0-9_]}', '_', $emailaddress); $emailaddress = str_replace('@', '+'.$emailaddress_key.'@', $catchall_address); if ($recipient_name) { $emailaddress = array($emailaddress => $recipient_name); } return $emailaddress; }
[ "public", "static", "function", "protect_emailaddress", "(", "$", "emailaddress", ",", "$", "catchall_address", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "catchall_address", ")", ")", "{", "if", "(", "empty", "(", "self", "::", "$", "config", ")", ")", "{", "self", "::", "load_config", "(", ")", ";", "}", "$", "catchall_address", "=", "self", "::", "$", "config", "[", "'from'", "]", ";", "}", "$", "recipient_name", "=", "null", ";", "if", "(", "is_array", "(", "$", "emailaddress", ")", ")", "{", "$", "recipient_name", "=", "current", "(", "$", "emailaddress", ")", ";", "$", "emailaddress", "=", "key", "(", "$", "emailaddress", ")", ";", "}", "if", "(", "self", "::", "validate", "(", "$", "emailaddress", ")", "==", "false", ")", "{", "$", "exception", "=", "bootstrap", "::", "get_library", "(", "'exception'", ")", ";", "throw", "new", "$", "exception", "(", "'can not convert invalid email address'", ")", ";", "}", "$", "emailaddress_key", "=", "preg_replace", "(", "'{[^a-zA-Z0-9_]}'", ",", "'_'", ",", "$", "emailaddress", ")", ";", "$", "emailaddress", "=", "str_replace", "(", "'@'", ",", "'+'", ".", "$", "emailaddress_key", ".", "'@'", ",", "$", "catchall_address", ")", ";", "if", "(", "$", "recipient_name", ")", "{", "$", "emailaddress", "=", "array", "(", "$", "emailaddress", "=>", "$", "recipient_name", ")", ";", "}", "return", "$", "emailaddress", ";", "}" ]
protect email addresses from going to real people on non-production environments it returns the website's sender address with the original one as '+alias' @param string $emailaddress i.e. [email protected] @param string $catchall_address i.e. [email protected] @return string i.e. [email protected]
[ "protect", "email", "addresses", "from", "going", "to", "real", "people", "on", "non", "-", "production", "environments" ]
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/email.php#L113-L142
18,510
lode/fem
src/email.php
email.load_config
protected static function load_config($config=null) { if ($config) { self::$config = $config; return; } $config_file = ROOT_DIR.'config/email.ini'; if (file_exists($config_file) == false) { $exception = bootstrap::get_library('exception'); throw new $exception('no email config found'); } self::$config = parse_ini_file($config_file); // decode the password self::$config['pass'] = base64_decode(self::$config['pass']); }
php
protected static function load_config($config=null) { if ($config) { self::$config = $config; return; } $config_file = ROOT_DIR.'config/email.ini'; if (file_exists($config_file) == false) { $exception = bootstrap::get_library('exception'); throw new $exception('no email config found'); } self::$config = parse_ini_file($config_file); // decode the password self::$config['pass'] = base64_decode(self::$config['pass']); }
[ "protected", "static", "function", "load_config", "(", "$", "config", "=", "null", ")", "{", "if", "(", "$", "config", ")", "{", "self", "::", "$", "config", "=", "$", "config", ";", "return", ";", "}", "$", "config_file", "=", "ROOT_DIR", ".", "'config/email.ini'", ";", "if", "(", "file_exists", "(", "$", "config_file", ")", "==", "false", ")", "{", "$", "exception", "=", "bootstrap", "::", "get_library", "(", "'exception'", ")", ";", "throw", "new", "$", "exception", "(", "'no email config found'", ")", ";", "}", "self", "::", "$", "config", "=", "parse_ini_file", "(", "$", "config_file", ")", ";", "// decode the password", "self", "::", "$", "config", "[", "'pass'", "]", "=", "base64_decode", "(", "self", "::", "$", "config", "[", "'pass'", "]", ")", ";", "}" ]
collects the config for connecting from a ini file @note the password is expected to be in a base64 encoded format to help against shoulder surfing @note sets self::$config with 'host', 'port', 'ssl', 'user', 'pass', 'from', 'name' values
[ "collects", "the", "config", "for", "connecting", "from", "a", "ini", "file" ]
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/email.php#L152-L168
18,511
ClanCats/Core
src/classes/CCHTTP.php
CCHTTP.header
public function header( $key, $value = null ) { $key = explode( '-', $key ); foreach( $key as $k => $v ) { $key[$k] = ucfirst( strtolower($v)); } $key = implode( '-', $key ); if ( !is_null( $value ) ) { $this->_headers[$key] = $value; } return $this->_headers[$key]; }
php
public function header( $key, $value = null ) { $key = explode( '-', $key ); foreach( $key as $k => $v ) { $key[$k] = ucfirst( strtolower($v)); } $key = implode( '-', $key ); if ( !is_null( $value ) ) { $this->_headers[$key] = $value; } return $this->_headers[$key]; }
[ "public", "function", "header", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "$", "key", "=", "explode", "(", "'-'", ",", "$", "key", ")", ";", "foreach", "(", "$", "key", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "key", "[", "$", "k", "]", "=", "ucfirst", "(", "strtolower", "(", "$", "v", ")", ")", ";", "}", "$", "key", "=", "implode", "(", "'-'", ",", "$", "key", ")", ";", "if", "(", "!", "is_null", "(", "$", "value", ")", ")", "{", "$", "this", "->", "_headers", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "this", "->", "_headers", "[", "$", "key", "]", ";", "}" ]
header getter and setter @param string $key @param mixed $value
[ "header", "getter", "and", "setter" ]
9f6ec72c1a439de4b253d0223f1029f7f85b6ef8
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCHTTP.php#L134-L147
18,512
ClanCats/Core
src/classes/CCHTTP.php
CCHTTP.request
public function request( $what = 'both' ) { /* * prepare curl */ $ch = curl_init( $this->url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); //curl_setopt( $ch, CURLOPT_VERBOSE, 1 ); curl_setopt( $ch, CURLOPT_HEADER, 1 ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 ); /* * prepare the headers */ $headers = array(); foreach( $this->_headers as $key => $header ) { $headers[] = $key.': '.$header; } curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); /* * post data */ if ( $this->type == static::post || $this->type == static::put ) { curl_setopt( $ch, CURLOPT_POST, 1 ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data ); } /* * execute that request */ $response = curl_exec( $ch ); if( $response === false ) { //echo 'Curl error: ' . curl_error($ch); return false; } $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE ); $header = substr( $response, 0, $header_size ); $body = substr( $response, $header_size ); // close it curl_close($ch); // format the header $arr_header = array(); $header = explode( "\n", $header ); foreach( $header as $item ) { $head_part = explode( ":", $item ); if ( $this->_normalize_header_keys ) { $arr_header[strtolower( trim($head_part[0]) )] = trim($head_part[1]); } else { $arr_header[trim($head_part[0])] = trim($head_part[1]); } } /* * return it */ if ( $what == 'both' ) { $return = new \stdClass; $return->body = $body; $return->header = $arr_header; } elseif ( $what == 'body' ) { $return = $body; } elseif ( $what == 'header' ) { $return = $arr_header; } else { throw new CCException( 'CCHTTP - param 1 in request function is invalid! Allowed are: both, header, body' ); } return $return; }
php
public function request( $what = 'both' ) { /* * prepare curl */ $ch = curl_init( $this->url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); //curl_setopt( $ch, CURLOPT_VERBOSE, 1 ); curl_setopt( $ch, CURLOPT_HEADER, 1 ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 ); /* * prepare the headers */ $headers = array(); foreach( $this->_headers as $key => $header ) { $headers[] = $key.': '.$header; } curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); /* * post data */ if ( $this->type == static::post || $this->type == static::put ) { curl_setopt( $ch, CURLOPT_POST, 1 ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data ); } /* * execute that request */ $response = curl_exec( $ch ); if( $response === false ) { //echo 'Curl error: ' . curl_error($ch); return false; } $header_size = curl_getinfo( $ch, CURLINFO_HEADER_SIZE ); $header = substr( $response, 0, $header_size ); $body = substr( $response, $header_size ); // close it curl_close($ch); // format the header $arr_header = array(); $header = explode( "\n", $header ); foreach( $header as $item ) { $head_part = explode( ":", $item ); if ( $this->_normalize_header_keys ) { $arr_header[strtolower( trim($head_part[0]) )] = trim($head_part[1]); } else { $arr_header[trim($head_part[0])] = trim($head_part[1]); } } /* * return it */ if ( $what == 'both' ) { $return = new \stdClass; $return->body = $body; $return->header = $arr_header; } elseif ( $what == 'body' ) { $return = $body; } elseif ( $what == 'header' ) { $return = $arr_header; } else { throw new CCException( 'CCHTTP - param 1 in request function is invalid! Allowed are: both, header, body' ); } return $return; }
[ "public", "function", "request", "(", "$", "what", "=", "'both'", ")", "{", "/*\n\t\t * prepare curl\n\t\t */", "$", "ch", "=", "curl_init", "(", "$", "this", "->", "url", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "1", ")", ";", "//curl_setopt( $ch, CURLOPT_VERBOSE, 1 );", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HEADER", ",", "1", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_FOLLOWLOCATION", ",", "1", ")", ";", "/*\n\t\t * prepare the headers\n\t\t */", "$", "headers", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_headers", "as", "$", "key", "=>", "$", "header", ")", "{", "$", "headers", "[", "]", "=", "$", "key", ".", "': '", ".", "$", "header", ";", "}", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HTTPHEADER", ",", "$", "headers", ")", ";", "/*\n\t\t * post data\n\t\t */", "if", "(", "$", "this", "->", "type", "==", "static", "::", "post", "||", "$", "this", "->", "type", "==", "static", "::", "put", ")", "{", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POST", ",", "1", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "post_data", ")", ";", "}", "/*\n\t\t * execute that request\n\t\t */", "$", "response", "=", "curl_exec", "(", "$", "ch", ")", ";", "if", "(", "$", "response", "===", "false", ")", "{", "//echo 'Curl error: ' . curl_error($ch); ", "return", "false", ";", "}", "$", "header_size", "=", "curl_getinfo", "(", "$", "ch", ",", "CURLINFO_HEADER_SIZE", ")", ";", "$", "header", "=", "substr", "(", "$", "response", ",", "0", ",", "$", "header_size", ")", ";", "$", "body", "=", "substr", "(", "$", "response", ",", "$", "header_size", ")", ";", "// close it", "curl_close", "(", "$", "ch", ")", ";", "// format the header", "$", "arr_header", "=", "array", "(", ")", ";", "$", "header", "=", "explode", "(", "\"\\n\"", ",", "$", "header", ")", ";", "foreach", "(", "$", "header", "as", "$", "item", ")", "{", "$", "head_part", "=", "explode", "(", "\":\"", ",", "$", "item", ")", ";", "if", "(", "$", "this", "->", "_normalize_header_keys", ")", "{", "$", "arr_header", "[", "strtolower", "(", "trim", "(", "$", "head_part", "[", "0", "]", ")", ")", "]", "=", "trim", "(", "$", "head_part", "[", "1", "]", ")", ";", "}", "else", "{", "$", "arr_header", "[", "trim", "(", "$", "head_part", "[", "0", "]", ")", "]", "=", "trim", "(", "$", "head_part", "[", "1", "]", ")", ";", "}", "}", "/*\n\t\t * return it\n\t\t */", "if", "(", "$", "what", "==", "'both'", ")", "{", "$", "return", "=", "new", "\\", "stdClass", ";", "$", "return", "->", "body", "=", "$", "body", ";", "$", "return", "->", "header", "=", "$", "arr_header", ";", "}", "elseif", "(", "$", "what", "==", "'body'", ")", "{", "$", "return", "=", "$", "body", ";", "}", "elseif", "(", "$", "what", "==", "'header'", ")", "{", "$", "return", "=", "$", "arr_header", ";", "}", "else", "{", "throw", "new", "CCException", "(", "'CCHTTP - param 1 in request function is invalid! Allowed are: both, header, body'", ")", ";", "}", "return", "$", "return", ";", "}" ]
and finally execute the request returns false if the request fails @param string $what | both, header, body @return mixed
[ "and", "finally", "execute", "the", "request" ]
9f6ec72c1a439de4b253d0223f1029f7f85b6ef8
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCHTTP.php#L157-L231
18,513
vorbind/influx-analytics
src/Import/ImportAnalytics.php
ImportAnalytics.isUtcValid
protected function isUtcValid($utc, $now, $rp) { if( 'forever' == $rp) { $nowDate = date('Y-m-d', strtotime($now)); if(strtotime($utc) >= strtotime($nowDate)) { return false; } } if( 'years_5' == $rp) { $min = date('i', strtotime($now)); $minutes = $min > 45 ? 45 : ( $min > 30 ? 30 : ( $min > 15 ? 15 : '00') ); $nowLimit = date('Y-m-d', strtotime($now)) . "T" . date('H', strtotime($now)) . ":$minutes:00Z"; if(strtotime($utc) >= strtotime($nowLimit)) { return false; } } return true; }
php
protected function isUtcValid($utc, $now, $rp) { if( 'forever' == $rp) { $nowDate = date('Y-m-d', strtotime($now)); if(strtotime($utc) >= strtotime($nowDate)) { return false; } } if( 'years_5' == $rp) { $min = date('i', strtotime($now)); $minutes = $min > 45 ? 45 : ( $min > 30 ? 30 : ( $min > 15 ? 15 : '00') ); $nowLimit = date('Y-m-d', strtotime($now)) . "T" . date('H', strtotime($now)) . ":$minutes:00Z"; if(strtotime($utc) >= strtotime($nowLimit)) { return false; } } return true; }
[ "protected", "function", "isUtcValid", "(", "$", "utc", ",", "$", "now", ",", "$", "rp", ")", "{", "if", "(", "'forever'", "==", "$", "rp", ")", "{", "$", "nowDate", "=", "date", "(", "'Y-m-d'", ",", "strtotime", "(", "$", "now", ")", ")", ";", "if", "(", "strtotime", "(", "$", "utc", ")", ">=", "strtotime", "(", "$", "nowDate", ")", ")", "{", "return", "false", ";", "}", "}", "if", "(", "'years_5'", "==", "$", "rp", ")", "{", "$", "min", "=", "date", "(", "'i'", ",", "strtotime", "(", "$", "now", ")", ")", ";", "$", "minutes", "=", "$", "min", ">", "45", "?", "45", ":", "(", "$", "min", ">", "30", "?", "30", ":", "(", "$", "min", ">", "15", "?", "15", ":", "'00'", ")", ")", ";", "$", "nowLimit", "=", "date", "(", "'Y-m-d'", ",", "strtotime", "(", "$", "now", ")", ")", ".", "\"T\"", ".", "date", "(", "'H'", ",", "strtotime", "(", "$", "now", ")", ")", ".", "\":$minutes:00Z\"", ";", "if", "(", "strtotime", "(", "$", "utc", ")", ">=", "strtotime", "(", "$", "nowLimit", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Is valid utc @param string $utc @param string $now @param string $rp @return boolean
[ "Is", "valid", "utc" ]
8c0c150351f045ccd3d57063f2b3b50a2c926e3e
https://github.com/vorbind/influx-analytics/blob/8c0c150351f045ccd3d57063f2b3b50a2c926e3e/src/Import/ImportAnalytics.php#L124-L140
18,514
vorbind/influx-analytics
src/Import/ImportAnalytics.php
ImportAnalytics.isMetricValid
protected function isMetricValid($metric) { if (!isset($metric) || !is_array($metric) || !isset($metric["influx"]) || !isset($metric["influx"]["tags"]) || !isset($metric["mysql"]) || !isset($metric["mysql"]["query"])) { return false; } return true; }
php
protected function isMetricValid($metric) { if (!isset($metric) || !is_array($metric) || !isset($metric["influx"]) || !isset($metric["influx"]["tags"]) || !isset($metric["mysql"]) || !isset($metric["mysql"]["query"])) { return false; } return true; }
[ "protected", "function", "isMetricValid", "(", "$", "metric", ")", "{", "if", "(", "!", "isset", "(", "$", "metric", ")", "||", "!", "is_array", "(", "$", "metric", ")", "||", "!", "isset", "(", "$", "metric", "[", "\"influx\"", "]", ")", "||", "!", "isset", "(", "$", "metric", "[", "\"influx\"", "]", "[", "\"tags\"", "]", ")", "||", "!", "isset", "(", "$", "metric", "[", "\"mysql\"", "]", ")", "||", "!", "isset", "(", "$", "metric", "[", "\"mysql\"", "]", "[", "\"query\"", "]", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check if metric is valid @param array $metric @return boolean
[ "Check", "if", "metric", "is", "valid" ]
8c0c150351f045ccd3d57063f2b3b50a2c926e3e
https://github.com/vorbind/influx-analytics/blob/8c0c150351f045ccd3d57063f2b3b50a2c926e3e/src/Import/ImportAnalytics.php#L148-L155
18,515
maximebf/events
src/Events/EventDispatcher.php
EventDispatcher.addListener
public function addListener(EventListener $listener, $priority = 0, $important = false) { if ($listener === $this) { throw new EventException("Adding self as listener in 'Events\EventDispatcher' would cause an infinite loop"); } $priority = -$priority; while (isset($this->listeners[$priority])) { $priority += $important ? -1 : 1; } $this->listeners[$priority] = $listener; ksort($this->listeners); $this->processStackedEvents(); return $this; }
php
public function addListener(EventListener $listener, $priority = 0, $important = false) { if ($listener === $this) { throw new EventException("Adding self as listener in 'Events\EventDispatcher' would cause an infinite loop"); } $priority = -$priority; while (isset($this->listeners[$priority])) { $priority += $important ? -1 : 1; } $this->listeners[$priority] = $listener; ksort($this->listeners); $this->processStackedEvents(); return $this; }
[ "public", "function", "addListener", "(", "EventListener", "$", "listener", ",", "$", "priority", "=", "0", ",", "$", "important", "=", "false", ")", "{", "if", "(", "$", "listener", "===", "$", "this", ")", "{", "throw", "new", "EventException", "(", "\"Adding self as listener in 'Events\\EventDispatcher' would cause an infinite loop\"", ")", ";", "}", "$", "priority", "=", "-", "$", "priority", ";", "while", "(", "isset", "(", "$", "this", "->", "listeners", "[", "$", "priority", "]", ")", ")", "{", "$", "priority", "+=", "$", "important", "?", "-", "1", ":", "1", ";", "}", "$", "this", "->", "listeners", "[", "$", "priority", "]", "=", "$", "listener", ";", "ksort", "(", "$", "this", "->", "listeners", ")", ";", "$", "this", "->", "processStackedEvents", "(", ")", ";", "return", "$", "this", ";", "}" ]
Adds a new listener @param EventListener $listener @param integer $priority Listener's priority, higher is more important @param boolean $important Whether this listener is more important than other ones of the same priority
[ "Adds", "a", "new", "listener" ]
b9861c260ee9eaabb9aa986bab76a2e039eb871f
https://github.com/maximebf/events/blob/b9861c260ee9eaabb9aa986bab76a2e039eb871f/src/Events/EventDispatcher.php#L76-L89
18,516
maximebf/events
src/Events/EventDispatcher.php
EventDispatcher.removeListener
public function removeListener(EventListener $listener) { if (($i = array_search($listener, $this->listeners)) !== false) { unset($this->listeners[$i]); } return $this; }
php
public function removeListener(EventListener $listener) { if (($i = array_search($listener, $this->listeners)) !== false) { unset($this->listeners[$i]); } return $this; }
[ "public", "function", "removeListener", "(", "EventListener", "$", "listener", ")", "{", "if", "(", "(", "$", "i", "=", "array_search", "(", "$", "listener", ",", "$", "this", "->", "listeners", ")", ")", "!==", "false", ")", "{", "unset", "(", "$", "this", "->", "listeners", "[", "$", "i", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Removes a listener @param EventListener $listener @return EventDispatcher
[ "Removes", "a", "listener" ]
b9861c260ee9eaabb9aa986bab76a2e039eb871f
https://github.com/maximebf/events/blob/b9861c260ee9eaabb9aa986bab76a2e039eb871f/src/Events/EventDispatcher.php#L109-L115
18,517
maximebf/events
src/Events/EventDispatcher.php
EventDispatcher.notify
public function notify(Event $event) { $processed = false; foreach ($this->listeners as $listener) { if ($listener->match($event)) { $listener->handle($event); $processed = true; if ($event->isPropagationStopped()) { break; } } } return $processed; }
php
public function notify(Event $event) { $processed = false; foreach ($this->listeners as $listener) { if ($listener->match($event)) { $listener->handle($event); $processed = true; if ($event->isPropagationStopped()) { break; } } } return $processed; }
[ "public", "function", "notify", "(", "Event", "$", "event", ")", "{", "$", "processed", "=", "false", ";", "foreach", "(", "$", "this", "->", "listeners", "as", "$", "listener", ")", "{", "if", "(", "$", "listener", "->", "match", "(", "$", "event", ")", ")", "{", "$", "listener", "->", "handle", "(", "$", "event", ")", ";", "$", "processed", "=", "true", ";", "if", "(", "$", "event", "->", "isPropagationStopped", "(", ")", ")", "{", "break", ";", "}", "}", "}", "return", "$", "processed", ";", "}" ]
Notifies the listeners of an event @param Event $event @return boolean Whether a listener handled the event
[ "Notifies", "the", "listeners", "of", "an", "event" ]
b9861c260ee9eaabb9aa986bab76a2e039eb871f
https://github.com/maximebf/events/blob/b9861c260ee9eaabb9aa986bab76a2e039eb871f/src/Events/EventDispatcher.php#L160-L173
18,518
maximebf/events
src/Events/EventDispatcher.php
EventDispatcher.notifyUntil
public function notifyUntil(Event $event, $callback = null) { if ($this->notify($event)) { if ($callback) { $callback(); } return true; } $this->stackedEvents[] = array($event, $callback); return false; }
php
public function notifyUntil(Event $event, $callback = null) { if ($this->notify($event)) { if ($callback) { $callback(); } return true; } $this->stackedEvents[] = array($event, $callback); return false; }
[ "public", "function", "notifyUntil", "(", "Event", "$", "event", ",", "$", "callback", "=", "null", ")", "{", "if", "(", "$", "this", "->", "notify", "(", "$", "event", ")", ")", "{", "if", "(", "$", "callback", ")", "{", "$", "callback", "(", ")", ";", "}", "return", "true", ";", "}", "$", "this", "->", "stackedEvents", "[", "]", "=", "array", "(", "$", "event", ",", "$", "callback", ")", ";", "return", "false", ";", "}" ]
Notifies the listeners of an event. Won't stop until the event has been handled by a listener. @param Event $event @param callback $callback Will be called once the event has been processed @return bool
[ "Notifies", "the", "listeners", "of", "an", "event", ".", "Won", "t", "stop", "until", "the", "event", "has", "been", "handled", "by", "a", "listener", "." ]
b9861c260ee9eaabb9aa986bab76a2e039eb871f
https://github.com/maximebf/events/blob/b9861c260ee9eaabb9aa986bab76a2e039eb871f/src/Events/EventDispatcher.php#L182-L192
18,519
simple-php-mvc/simple-php-mvc
src/MVC/Module/Module.php
Module.getModuleExtension
public function getModuleExtension() { if (null === $this->extension) { $class = $this->getModuleExtensionClass(); if (class_exists($class)) { $extension = new $class(); // check naming convention $basename = preg_replace('/Module$/', '', $this->getName()); $expectedAlias = Container::underscore($basename); if ($expectedAlias != $extension->getAlias()) { throw new \LogicException(sprintf( 'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', $expectedAlias, $extension->getAlias() )); } $this->extension = $extension; } else { $this->extension = false; } } if ($this->extension) { return $this->extension; } }
php
public function getModuleExtension() { if (null === $this->extension) { $class = $this->getModuleExtensionClass(); if (class_exists($class)) { $extension = new $class(); // check naming convention $basename = preg_replace('/Module$/', '', $this->getName()); $expectedAlias = Container::underscore($basename); if ($expectedAlias != $extension->getAlias()) { throw new \LogicException(sprintf( 'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.', $expectedAlias, $extension->getAlias() )); } $this->extension = $extension; } else { $this->extension = false; } } if ($this->extension) { return $this->extension; } }
[ "public", "function", "getModuleExtension", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "extension", ")", "{", "$", "class", "=", "$", "this", "->", "getModuleExtensionClass", "(", ")", ";", "if", "(", "class_exists", "(", "$", "class", ")", ")", "{", "$", "extension", "=", "new", "$", "class", "(", ")", ";", "// check naming convention", "$", "basename", "=", "preg_replace", "(", "'/Module$/'", ",", "''", ",", "$", "this", "->", "getName", "(", ")", ")", ";", "$", "expectedAlias", "=", "Container", "::", "underscore", "(", "$", "basename", ")", ";", "if", "(", "$", "expectedAlias", "!=", "$", "extension", "->", "getAlias", "(", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "sprintf", "(", "'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name (\"%s\"). You can override \"Bundle::getContainerExtension()\" if you want to use \"%s\" or another alias.'", ",", "$", "expectedAlias", ",", "$", "extension", "->", "getAlias", "(", ")", ")", ")", ";", "}", "$", "this", "->", "extension", "=", "$", "extension", ";", "}", "else", "{", "$", "this", "->", "extension", "=", "false", ";", "}", "}", "if", "(", "$", "this", "->", "extension", ")", "{", "return", "$", "this", "->", "extension", ";", "}", "}" ]
Returns the module's extension. @return ExtensionInterface|null The container extension @throws \LogicException
[ "Returns", "the", "module", "s", "extension", "." ]
e319eb09d29afad6993acb4a7e35f32a87dd0841
https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Module/Module.php#L34-L60
18,520
simple-php-mvc/simple-php-mvc
src/MVC/Module/Module.php
Module.registerTemplatesPathTwig
public function registerTemplatesPathTwig(MVC $mvc) { $viewsPath = $this->getPath() . '/Resources/views'; if (file_exists(dirname($viewsPath)) && file_exists($viewsPath)) { $mvc->getCvpp('twig.loader.filesystem')->addPath($viewsPath); } }
php
public function registerTemplatesPathTwig(MVC $mvc) { $viewsPath = $this->getPath() . '/Resources/views'; if (file_exists(dirname($viewsPath)) && file_exists($viewsPath)) { $mvc->getCvpp('twig.loader.filesystem')->addPath($viewsPath); } }
[ "public", "function", "registerTemplatesPathTwig", "(", "MVC", "$", "mvc", ")", "{", "$", "viewsPath", "=", "$", "this", "->", "getPath", "(", ")", ".", "'/Resources/views'", ";", "if", "(", "file_exists", "(", "dirname", "(", "$", "viewsPath", ")", ")", "&&", "file_exists", "(", "$", "viewsPath", ")", ")", "{", "$", "mvc", "->", "getCvpp", "(", "'twig.loader.filesystem'", ")", "->", "addPath", "(", "$", "viewsPath", ")", ";", "}", "}" ]
Register Templates Path Twig @param MVC $mvc
[ "Register", "Templates", "Path", "Twig" ]
e319eb09d29afad6993acb4a7e35f32a87dd0841
https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Module/Module.php#L161-L167
18,521
qcubed/orm
src/Query/Node/NodeBase.php
NodeBase._MergeExpansionNode
public function _MergeExpansionNode(NodeBase $objNewNode) { if (!$objNewNode || empty($objNewNode->objChildNodeArray)) { return; } if ($objNewNode->strName != $this->strName) { throw new Caller('Expansion node tables must match.'); } if (!$this->objChildNodeArray) { $this->objChildNodeArray = $objNewNode->objChildNodeArray; } else { $objChildNode = reset($objNewNode->objChildNodeArray); if (isset ($this->objChildNodeArray[$objChildNode->strAlias])) { if ($objChildNode->blnExpandAsArray) { $this->objChildNodeArray[$objChildNode->strAlias]->blnExpandAsArray = true; // assume this is a leaf node, so don't follow any more. } else { $this->objChildNodeArray[$objChildNode->strAlias]->_MergeExpansionNode($objChildNode); } } else { $this->objChildNodeArray[$objChildNode->strAlias] = $objChildNode; } } }
php
public function _MergeExpansionNode(NodeBase $objNewNode) { if (!$objNewNode || empty($objNewNode->objChildNodeArray)) { return; } if ($objNewNode->strName != $this->strName) { throw new Caller('Expansion node tables must match.'); } if (!$this->objChildNodeArray) { $this->objChildNodeArray = $objNewNode->objChildNodeArray; } else { $objChildNode = reset($objNewNode->objChildNodeArray); if (isset ($this->objChildNodeArray[$objChildNode->strAlias])) { if ($objChildNode->blnExpandAsArray) { $this->objChildNodeArray[$objChildNode->strAlias]->blnExpandAsArray = true; // assume this is a leaf node, so don't follow any more. } else { $this->objChildNodeArray[$objChildNode->strAlias]->_MergeExpansionNode($objChildNode); } } else { $this->objChildNodeArray[$objChildNode->strAlias] = $objChildNode; } } }
[ "public", "function", "_MergeExpansionNode", "(", "NodeBase", "$", "objNewNode", ")", "{", "if", "(", "!", "$", "objNewNode", "||", "empty", "(", "$", "objNewNode", "->", "objChildNodeArray", ")", ")", "{", "return", ";", "}", "if", "(", "$", "objNewNode", "->", "strName", "!=", "$", "this", "->", "strName", ")", "{", "throw", "new", "Caller", "(", "'Expansion node tables must match.'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "objChildNodeArray", ")", "{", "$", "this", "->", "objChildNodeArray", "=", "$", "objNewNode", "->", "objChildNodeArray", ";", "}", "else", "{", "$", "objChildNode", "=", "reset", "(", "$", "objNewNode", "->", "objChildNodeArray", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "objChildNodeArray", "[", "$", "objChildNode", "->", "strAlias", "]", ")", ")", "{", "if", "(", "$", "objChildNode", "->", "blnExpandAsArray", ")", "{", "$", "this", "->", "objChildNodeArray", "[", "$", "objChildNode", "->", "strAlias", "]", "->", "blnExpandAsArray", "=", "true", ";", "// assume this is a leaf node, so don't follow any more.", "}", "else", "{", "$", "this", "->", "objChildNodeArray", "[", "$", "objChildNode", "->", "strAlias", "]", "->", "_MergeExpansionNode", "(", "$", "objChildNode", ")", ";", "}", "}", "else", "{", "$", "this", "->", "objChildNodeArray", "[", "$", "objChildNode", "->", "strAlias", "]", "=", "$", "objChildNode", ";", "}", "}", "}" ]
Merges a node tree into this node, building the child nodes. The node being received is assumed to be specially built node such that only one child node exists, if any, and the last node in the chain is designated as array expansion. The goal of all of this is to set up a node chain where intermediate nodes can be designated as being array expansion nodes, as well as the leaf nodes. @param NodeBase $objNewNode @throws Caller
[ "Merges", "a", "node", "tree", "into", "this", "node", "building", "the", "child", "nodes", ".", "The", "node", "being", "received", "is", "assumed", "to", "be", "specially", "built", "node", "such", "that", "only", "one", "child", "node", "exists", "if", "any", "and", "the", "last", "node", "in", "the", "chain", "is", "designated", "as", "array", "expansion", ".", "The", "goal", "of", "all", "of", "this", "is", "to", "set", "up", "a", "node", "chain", "where", "intermediate", "nodes", "can", "be", "designated", "as", "being", "array", "expansion", "nodes", "as", "well", "as", "the", "leaf", "nodes", "." ]
f320eba671f20874b1f3809c5293f8c02d5b1204
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/Node/NodeBase.php#L163-L187
18,522
qcubed/orm
src/Query/Node/NodeBase.php
NodeBase.putSelectFields
public function putSelectFields($objBuilder, $strPrefix = null, $objSelect = null) { if ($strPrefix) { $strTableName = $strPrefix; $strAliasPrefix = $strPrefix . '__'; } else { $strTableName = $this->strTableName; $strAliasPrefix = ''; } if ($objSelect) { if (!$objSelect->skipPrimaryKey() && !$objBuilder->Distinct) { $strFields = $this->primaryKeyFields(); foreach ($strFields as $strField) { $objBuilder->addSelectItem($strTableName, $strField, $strAliasPrefix . $strField); } } $objSelect->addSelectItems($objBuilder, $strTableName, $strAliasPrefix); } else { $strFields = $this->fields(); foreach ($strFields as $strField) { $objBuilder->addSelectItem($strTableName, $strField, $strAliasPrefix . $strField); } } }
php
public function putSelectFields($objBuilder, $strPrefix = null, $objSelect = null) { if ($strPrefix) { $strTableName = $strPrefix; $strAliasPrefix = $strPrefix . '__'; } else { $strTableName = $this->strTableName; $strAliasPrefix = ''; } if ($objSelect) { if (!$objSelect->skipPrimaryKey() && !$objBuilder->Distinct) { $strFields = $this->primaryKeyFields(); foreach ($strFields as $strField) { $objBuilder->addSelectItem($strTableName, $strField, $strAliasPrefix . $strField); } } $objSelect->addSelectItems($objBuilder, $strTableName, $strAliasPrefix); } else { $strFields = $this->fields(); foreach ($strFields as $strField) { $objBuilder->addSelectItem($strTableName, $strField, $strAliasPrefix . $strField); } } }
[ "public", "function", "putSelectFields", "(", "$", "objBuilder", ",", "$", "strPrefix", "=", "null", ",", "$", "objSelect", "=", "null", ")", "{", "if", "(", "$", "strPrefix", ")", "{", "$", "strTableName", "=", "$", "strPrefix", ";", "$", "strAliasPrefix", "=", "$", "strPrefix", ".", "'__'", ";", "}", "else", "{", "$", "strTableName", "=", "$", "this", "->", "strTableName", ";", "$", "strAliasPrefix", "=", "''", ";", "}", "if", "(", "$", "objSelect", ")", "{", "if", "(", "!", "$", "objSelect", "->", "skipPrimaryKey", "(", ")", "&&", "!", "$", "objBuilder", "->", "Distinct", ")", "{", "$", "strFields", "=", "$", "this", "->", "primaryKeyFields", "(", ")", ";", "foreach", "(", "$", "strFields", "as", "$", "strField", ")", "{", "$", "objBuilder", "->", "addSelectItem", "(", "$", "strTableName", ",", "$", "strField", ",", "$", "strAliasPrefix", ".", "$", "strField", ")", ";", "}", "}", "$", "objSelect", "->", "addSelectItems", "(", "$", "objBuilder", ",", "$", "strTableName", ",", "$", "strAliasPrefix", ")", ";", "}", "else", "{", "$", "strFields", "=", "$", "this", "->", "fields", "(", ")", ";", "foreach", "(", "$", "strFields", "as", "$", "strField", ")", "{", "$", "objBuilder", "->", "addSelectItem", "(", "$", "strTableName", ",", "$", "strField", ",", "$", "strAliasPrefix", ".", "$", "strField", ")", ";", "}", "}", "}" ]
Puts the "Select" clause fields for this node into builder. @param Builder $objBuilder @param null|string $strPrefix @param null|Select $objSelect
[ "Puts", "the", "Select", "clause", "fields", "for", "this", "node", "into", "builder", "." ]
f320eba671f20874b1f3809c5293f8c02d5b1204
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/Node/NodeBase.php#L196-L220
18,523
phore/phore-micro-app
src/Type/Request.php
Request.getJsonBody
public function getJsonBody($json_options=null) : array { try { return phore_json_decode($bodyRaw = $this->getBody()); } catch (\InvalidArgumentException $e) { throw new \InvalidArgumentException("Cannot json-decode body: '$bodyRaw'", 0, $e); } }
php
public function getJsonBody($json_options=null) : array { try { return phore_json_decode($bodyRaw = $this->getBody()); } catch (\InvalidArgumentException $e) { throw new \InvalidArgumentException("Cannot json-decode body: '$bodyRaw'", 0, $e); } }
[ "public", "function", "getJsonBody", "(", "$", "json_options", "=", "null", ")", ":", "array", "{", "try", "{", "return", "phore_json_decode", "(", "$", "bodyRaw", "=", "$", "this", "->", "getBody", "(", ")", ")", ";", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "e", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Cannot json-decode body: '$bodyRaw'\"", ",", "0", ",", "$", "e", ")", ";", "}", "}" ]
json-decode the body @return array
[ "json", "-", "decode", "the", "body" ]
6cf87a647b8b0be05afbfe6bd020650e98558c23
https://github.com/phore/phore-micro-app/blob/6cf87a647b8b0be05afbfe6bd020650e98558c23/src/Type/Request.php#L74-L81
18,524
maniaplanet/maniaplanet-ws-sdk
libraries/Maniaplanet/WebServices/ManiaHome.php
ManiaHome.postNotification
function postNotification(Notification $n) { if($n->receiverName) { if($n->isPrivate) { return $this->manialinkPublisher->postPrivateNotification($n->message, $n->receiverName); } return $this->manialinkPublisher->postPersonalNotification($n->message, $n->link, $n->iconStyle, $n->iconSubStyle); } return $this->manialinkPublisher->postPublicNotification($n->message, $n->link, $n->iconStyle, $n->iconSubStyle); }
php
function postNotification(Notification $n) { if($n->receiverName) { if($n->isPrivate) { return $this->manialinkPublisher->postPrivateNotification($n->message, $n->receiverName); } return $this->manialinkPublisher->postPersonalNotification($n->message, $n->link, $n->iconStyle, $n->iconSubStyle); } return $this->manialinkPublisher->postPublicNotification($n->message, $n->link, $n->iconStyle, $n->iconSubStyle); }
[ "function", "postNotification", "(", "Notification", "$", "n", ")", "{", "if", "(", "$", "n", "->", "receiverName", ")", "{", "if", "(", "$", "n", "->", "isPrivate", ")", "{", "return", "$", "this", "->", "manialinkPublisher", "->", "postPrivateNotification", "(", "$", "n", "->", "message", ",", "$", "n", "->", "receiverName", ")", ";", "}", "return", "$", "this", "->", "manialinkPublisher", "->", "postPersonalNotification", "(", "$", "n", "->", "message", ",", "$", "n", "->", "link", ",", "$", "n", "->", "iconStyle", ",", "$", "n", "->", "iconSubStyle", ")", ";", "}", "return", "$", "this", "->", "manialinkPublisher", "->", "postPublicNotification", "(", "$", "n", "->", "message", ",", "$", "n", "->", "link", ",", "$", "n", "->", "iconStyle", ",", "$", "n", "->", "iconSubStyle", ")", ";", "}" ]
Please use the other methods which are more robust @deprecated since version 3.1.0
[ "Please", "use", "the", "other", "methods", "which", "are", "more", "robust" ]
027a458388035fe66f2f56ff3ea1f85eff2a5a4e
https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome.php#L47-L58
18,525
maniaplanet/maniaplanet-ws-sdk
libraries/Maniaplanet/WebServices/ManiaHome.php
ManiaHome.postPublicNotification
function postPublicNotification(Notification $n) { return $this->manialinkPublisher->postPublicNotification($n->message, $n->link, $n->iconStyle, $n->iconSubStyle); }
php
function postPublicNotification(Notification $n) { return $this->manialinkPublisher->postPublicNotification($n->message, $n->link, $n->iconStyle, $n->iconSubStyle); }
[ "function", "postPublicNotification", "(", "Notification", "$", "n", ")", "{", "return", "$", "this", "->", "manialinkPublisher", "->", "postPublicNotification", "(", "$", "n", "->", "message", ",", "$", "n", "->", "link", ",", "$", "n", "->", "iconStyle", ",", "$", "n", "->", "iconSubStyle", ")", ";", "}" ]
Send a public notification to every player that bookmarked your Manialink. @param Notification $n @deprecated since version 3.1.0
[ "Send", "a", "public", "notification", "to", "every", "player", "that", "bookmarked", "your", "Manialink", "." ]
027a458388035fe66f2f56ff3ea1f85eff2a5a4e
https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome.php#L65-L68
18,526
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.getLobby
function getLobby($lobbyLogin) { return $this->db->execute( 'SELECT * FROM LobbyServers '. 'WHERE login = %s', $this->db->quote($lobbyLogin) )->fetchObject(__NAMESPACE__.'\Lobby'); }
php
function getLobby($lobbyLogin) { return $this->db->execute( 'SELECT * FROM LobbyServers '. 'WHERE login = %s', $this->db->quote($lobbyLogin) )->fetchObject(__NAMESPACE__.'\Lobby'); }
[ "function", "getLobby", "(", "$", "lobbyLogin", ")", "{", "return", "$", "this", "->", "db", "->", "execute", "(", "'SELECT * FROM LobbyServers '", ".", "'WHERE login = %s'", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "lobbyLogin", ")", ")", "->", "fetchObject", "(", "__NAMESPACE__", ".", "'\\Lobby'", ")", ";", "}" ]
Get lobby information @param string $lobbyLogin @return Lobby
[ "Get", "lobby", "information" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L40-L46
18,527
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.getMatch
function getMatch($matchId) { $match = $this->db->execute( 'SELECT id, matchServerLogin, scriptName, titleIdString, state, matchPointsTeam1, matchPointsTeam2, mapPointsTeam1, mapPointsTeam2 '. 'FROM Matches '. 'WHERE id = %d ', $matchId )->fetchObject(__NAMESPACE__.'\\Match'); if(!$match) return false; $results = $this->db->execute( 'SELECT P.login, P.teamId, P.rank, P.state '. 'FROM Players P '. 'WHERE P.matchId = %d ', $match->id )->fetchArrayOfAssoc(); foreach($results as $row) { $match->players[] = $row['login']; $match->playersState[$row['login']] = $row['state']; if($row['rank'] !== null) { $match->ranking[$row['rank']][] = $row['login']; } if($row['teamId'] === null) { continue; } elseif((int)$row['teamId'] === 0) { $match->team1[] = $row['login']; } elseif((int)$row['teamId'] === 1) { $match->team2[] = $row['login']; } } uksort($match->ranking, function ($k1, $k2) { if($k1 == 0) { return 1; } if($k1 > $k2) { return 1; } else { return $k1 == $k2 ? 0: -1; } }); return $match; }
php
function getMatch($matchId) { $match = $this->db->execute( 'SELECT id, matchServerLogin, scriptName, titleIdString, state, matchPointsTeam1, matchPointsTeam2, mapPointsTeam1, mapPointsTeam2 '. 'FROM Matches '. 'WHERE id = %d ', $matchId )->fetchObject(__NAMESPACE__.'\\Match'); if(!$match) return false; $results = $this->db->execute( 'SELECT P.login, P.teamId, P.rank, P.state '. 'FROM Players P '. 'WHERE P.matchId = %d ', $match->id )->fetchArrayOfAssoc(); foreach($results as $row) { $match->players[] = $row['login']; $match->playersState[$row['login']] = $row['state']; if($row['rank'] !== null) { $match->ranking[$row['rank']][] = $row['login']; } if($row['teamId'] === null) { continue; } elseif((int)$row['teamId'] === 0) { $match->team1[] = $row['login']; } elseif((int)$row['teamId'] === 1) { $match->team2[] = $row['login']; } } uksort($match->ranking, function ($k1, $k2) { if($k1 == 0) { return 1; } if($k1 > $k2) { return 1; } else { return $k1 == $k2 ? 0: -1; } }); return $match; }
[ "function", "getMatch", "(", "$", "matchId", ")", "{", "$", "match", "=", "$", "this", "->", "db", "->", "execute", "(", "'SELECT id, matchServerLogin, scriptName, titleIdString, state, matchPointsTeam1, matchPointsTeam2, mapPointsTeam1, mapPointsTeam2 '", ".", "'FROM Matches '", ".", "'WHERE id = %d '", ",", "$", "matchId", ")", "->", "fetchObject", "(", "__NAMESPACE__", ".", "'\\\\Match'", ")", ";", "if", "(", "!", "$", "match", ")", "return", "false", ";", "$", "results", "=", "$", "this", "->", "db", "->", "execute", "(", "'SELECT P.login, P.teamId, P.rank, P.state '", ".", "'FROM Players P '", ".", "'WHERE P.matchId = %d '", ",", "$", "match", "->", "id", ")", "->", "fetchArrayOfAssoc", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "row", ")", "{", "$", "match", "->", "players", "[", "]", "=", "$", "row", "[", "'login'", "]", ";", "$", "match", "->", "playersState", "[", "$", "row", "[", "'login'", "]", "]", "=", "$", "row", "[", "'state'", "]", ";", "if", "(", "$", "row", "[", "'rank'", "]", "!==", "null", ")", "{", "$", "match", "->", "ranking", "[", "$", "row", "[", "'rank'", "]", "]", "[", "]", "=", "$", "row", "[", "'login'", "]", ";", "}", "if", "(", "$", "row", "[", "'teamId'", "]", "===", "null", ")", "{", "continue", ";", "}", "elseif", "(", "(", "int", ")", "$", "row", "[", "'teamId'", "]", "===", "0", ")", "{", "$", "match", "->", "team1", "[", "]", "=", "$", "row", "[", "'login'", "]", ";", "}", "elseif", "(", "(", "int", ")", "$", "row", "[", "'teamId'", "]", "===", "1", ")", "{", "$", "match", "->", "team2", "[", "]", "=", "$", "row", "[", "'login'", "]", ";", "}", "}", "uksort", "(", "$", "match", "->", "ranking", ",", "function", "(", "$", "k1", ",", "$", "k2", ")", "{", "if", "(", "$", "k1", "==", "0", ")", "{", "return", "1", ";", "}", "if", "(", "$", "k1", ">", "$", "k2", ")", "{", "return", "1", ";", "}", "else", "{", "return", "$", "k1", "==", "$", "k2", "?", "0", ":", "-", "1", ";", "}", "}", ")", ";", "return", "$", "match", ";", "}" ]
Get matchServer information @param string $serverLogin @param string $scriptName @param string $titleIdString @return Match
[ "Get", "matchServer", "information" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L55-L111
18,528
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.getPlayersPlayingCount
function getPlayersPlayingCount($lobbyLogin) { return $this->db->execute( 'SELECT COUNT(*) '. 'FROM Players P '. 'INNER JOIN Matches M ON P.matchId = M.id '. 'INNER JOIN MatchServers MS ON MS.matchId = M.id '. 'WHERE M.`state` >= %d AND P.state >= %d '. 'AND MS.lobbyLogin = %s', Match::PREPARED, PlayerInfo::PLAYER_STATE_CONNECTED, $this->db->quote($lobbyLogin) )->fetchSingleValue(0); }
php
function getPlayersPlayingCount($lobbyLogin) { return $this->db->execute( 'SELECT COUNT(*) '. 'FROM Players P '. 'INNER JOIN Matches M ON P.matchId = M.id '. 'INNER JOIN MatchServers MS ON MS.matchId = M.id '. 'WHERE M.`state` >= %d AND P.state >= %d '. 'AND MS.lobbyLogin = %s', Match::PREPARED, PlayerInfo::PLAYER_STATE_CONNECTED, $this->db->quote($lobbyLogin) )->fetchSingleValue(0); }
[ "function", "getPlayersPlayingCount", "(", "$", "lobbyLogin", ")", "{", "return", "$", "this", "->", "db", "->", "execute", "(", "'SELECT COUNT(*) '", ".", "'FROM Players P '", ".", "'INNER JOIN Matches M ON P.matchId = M.id '", ".", "'INNER JOIN MatchServers MS ON MS.matchId = M.id '", ".", "'WHERE M.`state` >= %d AND P.state >= %d '", ".", "'AND MS.lobbyLogin = %s'", ",", "Match", "::", "PREPARED", ",", "PlayerInfo", "::", "PLAYER_STATE_CONNECTED", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "lobbyLogin", ")", ")", "->", "fetchSingleValue", "(", "0", ")", ";", "}" ]
Return the number of match currently played for the lobby @param string $lobbyLogin @return int
[ "Return", "the", "number", "of", "match", "currently", "played", "for", "the", "lobby" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L254-L266
18,529
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.getLiveMatchServersCount
function getLiveMatchServersCount($lobbyLogin, $scriptName, $titleIdString) { return $this->db->execute( 'SELECT COUNT(*) FROM MatchServers '. 'WHERE DATE_ADD(lastLive, INTERVAL 15 MINUTE) > NOW() '. 'AND lobbyLogin = %s AND scriptName = %s AND titleIdString = %s', $this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString) )->fetchSingleValue(0); }
php
function getLiveMatchServersCount($lobbyLogin, $scriptName, $titleIdString) { return $this->db->execute( 'SELECT COUNT(*) FROM MatchServers '. 'WHERE DATE_ADD(lastLive, INTERVAL 15 MINUTE) > NOW() '. 'AND lobbyLogin = %s AND scriptName = %s AND titleIdString = %s', $this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString) )->fetchSingleValue(0); }
[ "function", "getLiveMatchServersCount", "(", "$", "lobbyLogin", ",", "$", "scriptName", ",", "$", "titleIdString", ")", "{", "return", "$", "this", "->", "db", "->", "execute", "(", "'SELECT COUNT(*) FROM MatchServers '", ".", "'WHERE DATE_ADD(lastLive, INTERVAL 15 MINUTE) > NOW() '", ".", "'AND lobbyLogin = %s AND scriptName = %s AND titleIdString = %s'", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "lobbyLogin", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "scriptName", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "titleIdString", ")", ")", "->", "fetchSingleValue", "(", "0", ")", ";", "}" ]
Get the number of server the lobby can use @param string $lobbyLogin @param string $scriptName @param string $titleIdString @return int
[ "Get", "the", "number", "of", "server", "the", "lobby", "can", "use" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L289-L297
18,530
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.getLeaveCount
function getLeaveCount($playerLogin, $lobbyLogin) { return $this->db->query( 'SELECT count(*) FROM Players P '. 'INNER JOIN Matches M ON P.matchId = M.id '. 'WHERE P.login = %s AND P.`state` IN (%s) AND M.lobbyLogin = %s '. 'AND M.state NOT IN (%s) '. 'AND DATE_ADD(M.creationDate, INTERVAL 1 HOUR) > NOW()', $this->db->quote($playerLogin), implode(',', array(PlayerInfo::PLAYER_STATE_NOT_CONNECTED, PlayerInfo::PLAYER_STATE_QUITTER, PlayerInfo::PLAYER_STATE_GIVE_UP, PlayerInfo::PLAYER_STATE_REPLACED)), $this->db->quote($lobbyLogin), implode(',', array(Match::PLAYER_CANCEL)) )->fetchSingleValue(0); }
php
function getLeaveCount($playerLogin, $lobbyLogin) { return $this->db->query( 'SELECT count(*) FROM Players P '. 'INNER JOIN Matches M ON P.matchId = M.id '. 'WHERE P.login = %s AND P.`state` IN (%s) AND M.lobbyLogin = %s '. 'AND M.state NOT IN (%s) '. 'AND DATE_ADD(M.creationDate, INTERVAL 1 HOUR) > NOW()', $this->db->quote($playerLogin), implode(',', array(PlayerInfo::PLAYER_STATE_NOT_CONNECTED, PlayerInfo::PLAYER_STATE_QUITTER, PlayerInfo::PLAYER_STATE_GIVE_UP, PlayerInfo::PLAYER_STATE_REPLACED)), $this->db->quote($lobbyLogin), implode(',', array(Match::PLAYER_CANCEL)) )->fetchSingleValue(0); }
[ "function", "getLeaveCount", "(", "$", "playerLogin", ",", "$", "lobbyLogin", ")", "{", "return", "$", "this", "->", "db", "->", "query", "(", "'SELECT count(*) FROM Players P '", ".", "'INNER JOIN Matches M ON P.matchId = M.id '", ".", "'WHERE P.login = %s AND P.`state` IN (%s) AND M.lobbyLogin = %s '", ".", "'AND M.state NOT IN (%s) '", ".", "'AND DATE_ADD(M.creationDate, INTERVAL 1 HOUR) > NOW()'", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "playerLogin", ")", ",", "implode", "(", "','", ",", "array", "(", "PlayerInfo", "::", "PLAYER_STATE_NOT_CONNECTED", ",", "PlayerInfo", "::", "PLAYER_STATE_QUITTER", ",", "PlayerInfo", "::", "PLAYER_STATE_GIVE_UP", ",", "PlayerInfo", "::", "PLAYER_STATE_REPLACED", ")", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "lobbyLogin", ")", ",", "implode", "(", "','", ",", "array", "(", "Match", "::", "PLAYER_CANCEL", ")", ")", ")", "->", "fetchSingleValue", "(", "0", ")", ";", "}" ]
Get the number of time the player quit a match for this lobby @param string $playerLogin @return int
[ "Get", "the", "number", "of", "time", "the", "player", "quit", "a", "match", "for", "this", "lobby" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L304-L317
18,531
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.countAvailableServer
function countAvailableServer($lobbyLogin, $scriptName, $titleIdString) { return $this->db->execute( 'SELECT count(MS.login) FROM MatchServers MS '. 'WHERE MS.lobbyLogin = %s AND MS.scriptName = %s AND MS.titleIdString = %s '. 'AND MS.`state` = %d AND matchId IS NULL '. 'AND DATE_ADD(MS.lastLive, INTERVAL 20 SECOND) > NOW() ', $this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString), \ManiaLivePlugins\MatchMakingLobby\Match\Plugin::SLEEPING )->fetchSingleValue(null); }
php
function countAvailableServer($lobbyLogin, $scriptName, $titleIdString) { return $this->db->execute( 'SELECT count(MS.login) FROM MatchServers MS '. 'WHERE MS.lobbyLogin = %s AND MS.scriptName = %s AND MS.titleIdString = %s '. 'AND MS.`state` = %d AND matchId IS NULL '. 'AND DATE_ADD(MS.lastLive, INTERVAL 20 SECOND) > NOW() ', $this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString), \ManiaLivePlugins\MatchMakingLobby\Match\Plugin::SLEEPING )->fetchSingleValue(null); }
[ "function", "countAvailableServer", "(", "$", "lobbyLogin", ",", "$", "scriptName", ",", "$", "titleIdString", ")", "{", "return", "$", "this", "->", "db", "->", "execute", "(", "'SELECT count(MS.login) FROM MatchServers MS '", ".", "'WHERE MS.lobbyLogin = %s AND MS.scriptName = %s AND MS.titleIdString = %s '", ".", "'AND MS.`state` = %d AND matchId IS NULL '", ".", "'AND DATE_ADD(MS.lastLive, INTERVAL 20 SECOND) > NOW() '", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "lobbyLogin", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "scriptName", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "titleIdString", ")", ",", "\\", "ManiaLivePlugins", "\\", "MatchMakingLobby", "\\", "Match", "\\", "Plugin", "::", "SLEEPING", ")", "->", "fetchSingleValue", "(", "null", ")", ";", "}" ]
Get number of server available to host a match for the lobby @param string $lobbyLogin @param string $scriptName @param string $titleIdString @return string the match server login
[ "Get", "number", "of", "server", "available", "to", "host", "a", "match", "for", "the", "lobby" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L335-L345
18,532
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.getAverageTimeBetweenMatches
function getAverageTimeBetweenMatches($lobbyLogin, $scriptName, $titleIdString) { $creationTimestamps = $this->db->execute( 'SELECT UNIX_TIMESTAMP(creationDate) '. 'FROM Matches m '. 'WHERE m.lobbyLogin = %s '. 'AND m.scriptName = %s '. 'AND m.titleIdString = %s '. 'AND m.state NOT IN (%s) AND m.creationDate > DATE_SUB(NOW(), INTERVAL 1 HOUR) '. 'ORDER BY creationDate ASC LIMIT 10', $this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString), implode(',',array(Match::PLAYER_CANCEL)) )->fetchArrayOfSingleValues(); if(count($creationTimestamps) < 2) { return -1; } $sum = 0; for($i = 1; $i < count($creationTimestamps); $i++) { $sum += $creationTimestamps[$i] - $creationTimestamps[$i - 1]; } return $sum / (count($creationTimestamps) - 1); }
php
function getAverageTimeBetweenMatches($lobbyLogin, $scriptName, $titleIdString) { $creationTimestamps = $this->db->execute( 'SELECT UNIX_TIMESTAMP(creationDate) '. 'FROM Matches m '. 'WHERE m.lobbyLogin = %s '. 'AND m.scriptName = %s '. 'AND m.titleIdString = %s '. 'AND m.state NOT IN (%s) AND m.creationDate > DATE_SUB(NOW(), INTERVAL 1 HOUR) '. 'ORDER BY creationDate ASC LIMIT 10', $this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString), implode(',',array(Match::PLAYER_CANCEL)) )->fetchArrayOfSingleValues(); if(count($creationTimestamps) < 2) { return -1; } $sum = 0; for($i = 1; $i < count($creationTimestamps); $i++) { $sum += $creationTimestamps[$i] - $creationTimestamps[$i - 1]; } return $sum / (count($creationTimestamps) - 1); }
[ "function", "getAverageTimeBetweenMatches", "(", "$", "lobbyLogin", ",", "$", "scriptName", ",", "$", "titleIdString", ")", "{", "$", "creationTimestamps", "=", "$", "this", "->", "db", "->", "execute", "(", "'SELECT UNIX_TIMESTAMP(creationDate) '", ".", "'FROM Matches m '", ".", "'WHERE m.lobbyLogin = %s '", ".", "'AND m.scriptName = %s '", ".", "'AND m.titleIdString = %s '", ".", "'AND m.state NOT IN (%s) AND m.creationDate > DATE_SUB(NOW(), INTERVAL 1 HOUR) '", ".", "'ORDER BY creationDate ASC LIMIT 10'", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "lobbyLogin", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "scriptName", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "titleIdString", ")", ",", "implode", "(", "','", ",", "array", "(", "Match", "::", "PLAYER_CANCEL", ")", ")", ")", "->", "fetchArrayOfSingleValues", "(", ")", ";", "if", "(", "count", "(", "$", "creationTimestamps", ")", "<", "2", ")", "{", "return", "-", "1", ";", "}", "$", "sum", "=", "0", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "count", "(", "$", "creationTimestamps", ")", ";", "$", "i", "++", ")", "{", "$", "sum", "+=", "$", "creationTimestamps", "[", "$", "i", "]", "-", "$", "creationTimestamps", "[", "$", "i", "-", "1", "]", ";", "}", "return", "$", "sum", "/", "(", "count", "(", "$", "creationTimestamps", ")", "-", "1", ")", ";", "}" ]
Get average time between two match. This time is compute with matches over the last hour If there is not anough matches in database, it returns -1 @param string $lobbyLogin @param string $scriptName @param string $titleIdString @return float Number of seconds
[ "Get", "average", "time", "between", "two", "match", ".", "This", "time", "is", "compute", "with", "matches", "over", "the", "last", "hour", "If", "there", "is", "not", "anough", "matches", "in", "database", "it", "returns", "-", "1" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L477-L501
18,533
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.registerMatch
function registerMatch($serverLogin, Match $match, $scriptName, $titleIdString, $lobbyLogin) { $this->db->execute('BEGIN'); try { $this->db->execute( 'INSERT INTO Matches (creationDate, state, matchServerLogin, scriptName, titleIdString, lobbyLogin) '. 'VALUES (NOW(), -1, %s, %s, %s, %s)', $this->db->quote($serverLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString), $this->db->quote($lobbyLogin) ); $matchId = $this->db->insertID(); $this->updateServerCurrentMatchId($matchId, $serverLogin, $scriptName, $titleIdString); foreach($match->players as $player) { $this->addMatchPlayer($matchId, $player, $match->getTeam($player)); } $this->db->execute('COMMIT'); } catch(\Exception $e) { $this->db->execute('ROLLBACK'); throw $e; } return $matchId; }
php
function registerMatch($serverLogin, Match $match, $scriptName, $titleIdString, $lobbyLogin) { $this->db->execute('BEGIN'); try { $this->db->execute( 'INSERT INTO Matches (creationDate, state, matchServerLogin, scriptName, titleIdString, lobbyLogin) '. 'VALUES (NOW(), -1, %s, %s, %s, %s)', $this->db->quote($serverLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString), $this->db->quote($lobbyLogin) ); $matchId = $this->db->insertID(); $this->updateServerCurrentMatchId($matchId, $serverLogin, $scriptName, $titleIdString); foreach($match->players as $player) { $this->addMatchPlayer($matchId, $player, $match->getTeam($player)); } $this->db->execute('COMMIT'); } catch(\Exception $e) { $this->db->execute('ROLLBACK'); throw $e; } return $matchId; }
[ "function", "registerMatch", "(", "$", "serverLogin", ",", "Match", "$", "match", ",", "$", "scriptName", ",", "$", "titleIdString", ",", "$", "lobbyLogin", ")", "{", "$", "this", "->", "db", "->", "execute", "(", "'BEGIN'", ")", ";", "try", "{", "$", "this", "->", "db", "->", "execute", "(", "'INSERT INTO Matches (creationDate, state, matchServerLogin, scriptName, titleIdString, lobbyLogin) '", ".", "'VALUES (NOW(), -1, %s, %s, %s, %s)'", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "serverLogin", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "scriptName", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "titleIdString", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "lobbyLogin", ")", ")", ";", "$", "matchId", "=", "$", "this", "->", "db", "->", "insertID", "(", ")", ";", "$", "this", "->", "updateServerCurrentMatchId", "(", "$", "matchId", ",", "$", "serverLogin", ",", "$", "scriptName", ",", "$", "titleIdString", ")", ";", "foreach", "(", "$", "match", "->", "players", "as", "$", "player", ")", "{", "$", "this", "->", "addMatchPlayer", "(", "$", "matchId", ",", "$", "player", ",", "$", "match", "->", "getTeam", "(", "$", "player", ")", ")", ";", "}", "$", "this", "->", "db", "->", "execute", "(", "'COMMIT'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "db", "->", "execute", "(", "'ROLLBACK'", ")", ";", "throw", "$", "e", ";", "}", "return", "$", "matchId", ";", "}" ]
Register a match in database, the match Server will use this to ready up @param string $serverLogin @param \ManiaLivePlugins\MatchMakingLobby\Services\Match $match @param string $scriptName @param string $titleIdString @return int $matchId
[ "Register", "a", "match", "in", "database", "the", "match", "Server", "will", "use", "this", "to", "ready", "up" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L523-L553
18,534
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.updatePlayerState
function updatePlayerState($playerLogin, $matchId, $state) { $this->db->execute( 'UPDATE Players SET state = %d WHERE login = %s AND matchId = %d', $state, $this->db->quote($playerLogin), $matchId ); }
php
function updatePlayerState($playerLogin, $matchId, $state) { $this->db->execute( 'UPDATE Players SET state = %d WHERE login = %s AND matchId = %d', $state, $this->db->quote($playerLogin), $matchId ); }
[ "function", "updatePlayerState", "(", "$", "playerLogin", ",", "$", "matchId", ",", "$", "state", ")", "{", "$", "this", "->", "db", "->", "execute", "(", "'UPDATE Players SET state = %d WHERE login = %s AND matchId = %d'", ",", "$", "state", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "playerLogin", ")", ",", "$", "matchId", ")", ";", "}" ]
Set the new player state @param string $playerLogin @param int $matchId @param int $state
[ "Set", "the", "new", "player", "state" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L594-L602
18,535
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.updatePlayerRank
function updatePlayerRank($playerLogin, $matchId, $rank) { $this->db->execute( 'UPDATE Players SET rank = %d WHERE login = %s AND matchId = %d', $rank, $this->db->quote($playerLogin), $matchId ); }
php
function updatePlayerRank($playerLogin, $matchId, $rank) { $this->db->execute( 'UPDATE Players SET rank = %d WHERE login = %s AND matchId = %d', $rank, $this->db->quote($playerLogin), $matchId ); }
[ "function", "updatePlayerRank", "(", "$", "playerLogin", ",", "$", "matchId", ",", "$", "rank", ")", "{", "$", "this", "->", "db", "->", "execute", "(", "'UPDATE Players SET rank = %d WHERE login = %s AND matchId = %d'", ",", "$", "rank", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "playerLogin", ")", ",", "$", "matchId", ")", ";", "}" ]
Register the player rank on his match @param string $playerLogin @param int $matchId @param int $rank
[ "Register", "the", "player", "rank", "on", "his", "match" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L610-L618
18,536
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.registerMatchServer
function registerMatchServer($serverLogin, $lobbyLogin, $state, $scriptName, $titleIdString, $currentMap) { $this->db->execute( 'INSERT INTO MatchServers (login, lobbyLogin, state, lastLive, scriptName, titleIdString, currentMap) '. 'VALUES(%s, %s, %d, NOW(), %s, %s, %s) '. 'ON DUPLICATE KEY UPDATE state=VALUES(state), lobbyLogin=VALUES(lobbyLogin), lastLive=VALUES(lastLive), currentMap=VALUES(currentMap)', $this->db->quote($serverLogin), $this->db->quote($lobbyLogin), $state, $this->db->quote($scriptName), $this->db->quote($titleIdString), $this->db->quote($currentMap) ); }
php
function registerMatchServer($serverLogin, $lobbyLogin, $state, $scriptName, $titleIdString, $currentMap) { $this->db->execute( 'INSERT INTO MatchServers (login, lobbyLogin, state, lastLive, scriptName, titleIdString, currentMap) '. 'VALUES(%s, %s, %d, NOW(), %s, %s, %s) '. 'ON DUPLICATE KEY UPDATE state=VALUES(state), lobbyLogin=VALUES(lobbyLogin), lastLive=VALUES(lastLive), currentMap=VALUES(currentMap)', $this->db->quote($serverLogin), $this->db->quote($lobbyLogin), $state, $this->db->quote($scriptName), $this->db->quote($titleIdString), $this->db->quote($currentMap) ); }
[ "function", "registerMatchServer", "(", "$", "serverLogin", ",", "$", "lobbyLogin", ",", "$", "state", ",", "$", "scriptName", ",", "$", "titleIdString", ",", "$", "currentMap", ")", "{", "$", "this", "->", "db", "->", "execute", "(", "'INSERT INTO MatchServers (login, lobbyLogin, state, lastLive, scriptName, titleIdString, currentMap) '", ".", "'VALUES(%s, %s, %d, NOW(), %s, %s, %s) '", ".", "'ON DUPLICATE KEY UPDATE state=VALUES(state), lobbyLogin=VALUES(lobbyLogin), lastLive=VALUES(lastLive), currentMap=VALUES(currentMap)'", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "serverLogin", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "lobbyLogin", ")", ",", "$", "state", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "scriptName", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "titleIdString", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "currentMap", ")", ")", ";", "}" ]
Register a server as match server @param string $serverLogin @param string $lobbyLogin @param string $state
[ "Register", "a", "server", "as", "match", "server" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L626-L639
18,537
maniaplanet/matchmaking-lobby
MatchMakingLobby/Services/MatchMakingService.php
MatchMakingService.registerLobby
function registerLobby($lobbyLogin, $readyPlayersCount, $connectedPlayersCount, $serverName, $backLink) { $this->db->execute( 'INSERT INTO LobbyServers VALUES (%s, %s, %s, %d, %d) '. 'ON DUPLICATE KEY UPDATE '. 'name = VALUES(name), '. 'backLink = VALUES(backLink), '. 'readyPlayers = VALUES(readyPlayers), '. 'connectedPlayers = VALUES(connectedPlayers) ', $this->db->quote($lobbyLogin), $this->db->quote($serverName), $this->db->quote($backLink), $readyPlayersCount, $connectedPlayersCount ); }
php
function registerLobby($lobbyLogin, $readyPlayersCount, $connectedPlayersCount, $serverName, $backLink) { $this->db->execute( 'INSERT INTO LobbyServers VALUES (%s, %s, %s, %d, %d) '. 'ON DUPLICATE KEY UPDATE '. 'name = VALUES(name), '. 'backLink = VALUES(backLink), '. 'readyPlayers = VALUES(readyPlayers), '. 'connectedPlayers = VALUES(connectedPlayers) ', $this->db->quote($lobbyLogin), $this->db->quote($serverName), $this->db->quote($backLink), $readyPlayersCount, $connectedPlayersCount ); }
[ "function", "registerLobby", "(", "$", "lobbyLogin", ",", "$", "readyPlayersCount", ",", "$", "connectedPlayersCount", ",", "$", "serverName", ",", "$", "backLink", ")", "{", "$", "this", "->", "db", "->", "execute", "(", "'INSERT INTO LobbyServers VALUES (%s, %s, %s, %d, %d) '", ".", "'ON DUPLICATE KEY UPDATE '", ".", "'name = VALUES(name), '", ".", "'backLink = VALUES(backLink), '", ".", "'readyPlayers = VALUES(readyPlayers), '", ".", "'connectedPlayers = VALUES(connectedPlayers) '", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "lobbyLogin", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "serverName", ")", ",", "$", "this", "->", "db", "->", "quote", "(", "$", "backLink", ")", ",", "$", "readyPlayersCount", ",", "$", "connectedPlayersCount", ")", ";", "}" ]
Register a lobby server in the system @param string $lobbyLogin @param int $readyPlayersCount @param int $connectedPlayersCount @param string $serverName @param string $backLink
[ "Register", "a", "lobby", "server", "in", "the", "system" ]
384f22cdd2cfb0204a071810549eaf1eb01d8b7f
https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L663-L675
18,538
yuncms/framework
src/web/UploadedFile.php
UploadedFile.saveAsTempFile
public function saveAsTempFile(bool $deleteTempFile = true) { if ($this->error != UPLOAD_ERR_OK) { return false; } $tempPath = FileHelper::getTempFilePath($this->name); if (!$this->saveAs($tempPath, $deleteTempFile)) { return false; } return $tempPath; }
php
public function saveAsTempFile(bool $deleteTempFile = true) { if ($this->error != UPLOAD_ERR_OK) { return false; } $tempPath = FileHelper::getTempFilePath($this->name); if (!$this->saveAs($tempPath, $deleteTempFile)) { return false; } return $tempPath; }
[ "public", "function", "saveAsTempFile", "(", "bool", "$", "deleteTempFile", "=", "true", ")", "{", "if", "(", "$", "this", "->", "error", "!=", "UPLOAD_ERR_OK", ")", "{", "return", "false", ";", "}", "$", "tempPath", "=", "FileHelper", "::", "getTempFilePath", "(", "$", "this", "->", "name", ")", ";", "if", "(", "!", "$", "this", "->", "saveAs", "(", "$", "tempPath", ",", "$", "deleteTempFile", ")", ")", "{", "return", "false", ";", "}", "return", "$", "tempPath", ";", "}" ]
Saves the uploaded file to a temp location. @param bool $deleteTempFile whether to delete the temporary file after saving. If true, you will not be able to save the uploaded file again in the current request. @return string|false the path to the temp file, or false if the file wasn't saved successfully @see error @throws \yii\base\Exception
[ "Saves", "the", "uploaded", "file", "to", "a", "temp", "location", "." ]
af42e28ea4ae15ab8eead3f6d119f93863b94154
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/UploadedFile.php#L193-L203
18,539
TypistTech/wp-kses-view
src/ViewAwareTrait.php
ViewAwareTrait.getView
public function getView(): ViewInterface { if (null === $this->view) { $this->setView( $this->getDefaultView() ); } return $this->view; }
php
public function getView(): ViewInterface { if (null === $this->view) { $this->setView( $this->getDefaultView() ); } return $this->view; }
[ "public", "function", "getView", "(", ")", ":", "ViewInterface", "{", "if", "(", "null", "===", "$", "this", "->", "view", ")", "{", "$", "this", "->", "setView", "(", "$", "this", "->", "getDefaultView", "(", ")", ")", ";", "}", "return", "$", "this", "->", "view", ";", "}" ]
View getter. @throws UnexpectedValueException If view is null. @throws UnexpectedValueException If view is not an instance of ViewInterface. @return ViewInterface
[ "View", "getter", "." ]
6a5e5a34b81c6387d1c5356c9e42166daec9225f
https://github.com/TypistTech/wp-kses-view/blob/6a5e5a34b81c6387d1c5356c9e42166daec9225f/src/ViewAwareTrait.php#L51-L60
18,540
Craftsware/scissor
src/Module.php
Module.model
public function model($name, $inject = null) { // Model instance $instance = function($path) use ($inject) { if(class_exists($namespace = 'App\\Modules\\' . str_replace('/', '\\', $path))) { return new $namespace($inject); } }; // Split module and model name if(strstr($name, '/')) { $name = explode('/', $name); return $instance($name[0] . '/Models/' . $name[1]); } if(isset($this->module['name'])) { if($model = $instance($this->module['name'] . '/Models/'. $name)) { return $model; } } // Use module name if model name is not defined return $instance($name . '/Models/' . $name); }
php
public function model($name, $inject = null) { // Model instance $instance = function($path) use ($inject) { if(class_exists($namespace = 'App\\Modules\\' . str_replace('/', '\\', $path))) { return new $namespace($inject); } }; // Split module and model name if(strstr($name, '/')) { $name = explode('/', $name); return $instance($name[0] . '/Models/' . $name[1]); } if(isset($this->module['name'])) { if($model = $instance($this->module['name'] . '/Models/'. $name)) { return $model; } } // Use module name if model name is not defined return $instance($name . '/Models/' . $name); }
[ "public", "function", "model", "(", "$", "name", ",", "$", "inject", "=", "null", ")", "{", "// Model instance", "$", "instance", "=", "function", "(", "$", "path", ")", "use", "(", "$", "inject", ")", "{", "if", "(", "class_exists", "(", "$", "namespace", "=", "'App\\\\Modules\\\\'", ".", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "$", "path", ")", ")", ")", "{", "return", "new", "$", "namespace", "(", "$", "inject", ")", ";", "}", "}", ";", "// Split module and model name", "if", "(", "strstr", "(", "$", "name", ",", "'/'", ")", ")", "{", "$", "name", "=", "explode", "(", "'/'", ",", "$", "name", ")", ";", "return", "$", "instance", "(", "$", "name", "[", "0", "]", ".", "'/Models/'", ".", "$", "name", "[", "1", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "module", "[", "'name'", "]", ")", ")", "{", "if", "(", "$", "model", "=", "$", "instance", "(", "$", "this", "->", "module", "[", "'name'", "]", ".", "'/Models/'", ".", "$", "name", ")", ")", "{", "return", "$", "model", ";", "}", "}", "// Use module name if model name is not defined", "return", "$", "instance", "(", "$", "name", ".", "'/Models/'", ".", "$", "name", ")", ";", "}" ]
Get model from it's module and other modules @param string $name
[ "Get", "model", "from", "it", "s", "module", "and", "other", "modules" ]
644e4a8ea9859fc30fee36705e54784acd8d43e2
https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Module.php#L181-L212
18,541
LUSHDigital/microservice-model-utils
src/Traits/MicroServiceCacheTrait.php
MicroServiceCacheTrait.getModelCacheKeys
public function getModelCacheKeys(Cacheable $model) { // Build list of cache keys we need to clear. $cacheKeys = [ implode(':', [$model->getTable(), 'index']), ]; // If the model has an primary key add the cache key. if (!empty($model->getPrimaryKeyValue())) { $cacheKeys[] = implode(':', [$model->getTable(), $model->getPrimaryKeyValue()]); } // Add the cache keys for the model attributes. $this->addAttributeCacheKeys($cacheKeys, $model); return $cacheKeys; }
php
public function getModelCacheKeys(Cacheable $model) { // Build list of cache keys we need to clear. $cacheKeys = [ implode(':', [$model->getTable(), 'index']), ]; // If the model has an primary key add the cache key. if (!empty($model->getPrimaryKeyValue())) { $cacheKeys[] = implode(':', [$model->getTable(), $model->getPrimaryKeyValue()]); } // Add the cache keys for the model attributes. $this->addAttributeCacheKeys($cacheKeys, $model); return $cacheKeys; }
[ "public", "function", "getModelCacheKeys", "(", "Cacheable", "$", "model", ")", "{", "// Build list of cache keys we need to clear.", "$", "cacheKeys", "=", "[", "implode", "(", "':'", ",", "[", "$", "model", "->", "getTable", "(", ")", ",", "'index'", "]", ")", ",", "]", ";", "// If the model has an primary key add the cache key.", "if", "(", "!", "empty", "(", "$", "model", "->", "getPrimaryKeyValue", "(", ")", ")", ")", "{", "$", "cacheKeys", "[", "]", "=", "implode", "(", "':'", ",", "[", "$", "model", "->", "getTable", "(", ")", ",", "$", "model", "->", "getPrimaryKeyValue", "(", ")", "]", ")", ";", "}", "// Add the cache keys for the model attributes.", "$", "this", "->", "addAttributeCacheKeys", "(", "$", "cacheKeys", ",", "$", "model", ")", ";", "return", "$", "cacheKeys", ";", "}" ]
Get an array of possible cache keys for the given model. @param Cacheable $model @return array|bool
[ "Get", "an", "array", "of", "possible", "cache", "keys", "for", "the", "given", "model", "." ]
37a6e3b5f326ab120bb31262fa596e6e3cc20832
https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L27-L43
18,542
LUSHDigital/microservice-model-utils
src/Traits/MicroServiceCacheTrait.php
MicroServiceCacheTrait.cacheForget
public function cacheForget(Cacheable $model) { // Clear the cache for each key. foreach ($this->getModelCacheKeys($model) as $cacheKey) { Cache::forget($cacheKey); } return true; }
php
public function cacheForget(Cacheable $model) { // Clear the cache for each key. foreach ($this->getModelCacheKeys($model) as $cacheKey) { Cache::forget($cacheKey); } return true; }
[ "public", "function", "cacheForget", "(", "Cacheable", "$", "model", ")", "{", "// Clear the cache for each key.", "foreach", "(", "$", "this", "->", "getModelCacheKeys", "(", "$", "model", ")", "as", "$", "cacheKey", ")", "{", "Cache", "::", "forget", "(", "$", "cacheKey", ")", ";", "}", "return", "true", ";", "}" ]
Attempt to forget items from the cache for a given model. @param Cacheable $model @return bool
[ "Attempt", "to", "forget", "items", "from", "the", "cache", "for", "a", "given", "model", "." ]
37a6e3b5f326ab120bb31262fa596e6e3cc20832
https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L51-L59
18,543
LUSHDigital/microservice-model-utils
src/Traits/MicroServiceCacheTrait.php
MicroServiceCacheTrait.addAttributeCacheKeys
protected function addAttributeCacheKeys(array &$cacheKeys, Cacheable $model) { // Add a cache key for each attribute marked as a cache key. foreach ($model->getAttributeCacheKeys() as $attributeCacheKey) { $origAttributeValue = $this->getOriginalCacheKeyValue($model, $attributeCacheKey); $attributesValues = []; if ($origAttributeValue != null) { array_push($attributesValues, $origAttributeValue); } array_push($attributesValues, $model->{$attributeCacheKey}); foreach ($attributesValues as $attributeValue) { // If the attribute is a collection check each item value. if ($attributeValue instanceof Collection) { $this->getCollectionAttributeCacheKeys($cacheKeys, $model, $attributeCacheKey, $attributeValue); } elseif (is_scalar($attributeValue)) { // Otherwise just get the value. $cacheKeys[] = implode(':', [$model->getTable(), $attributeCacheKey, $attributeValue]); } } } }
php
protected function addAttributeCacheKeys(array &$cacheKeys, Cacheable $model) { // Add a cache key for each attribute marked as a cache key. foreach ($model->getAttributeCacheKeys() as $attributeCacheKey) { $origAttributeValue = $this->getOriginalCacheKeyValue($model, $attributeCacheKey); $attributesValues = []; if ($origAttributeValue != null) { array_push($attributesValues, $origAttributeValue); } array_push($attributesValues, $model->{$attributeCacheKey}); foreach ($attributesValues as $attributeValue) { // If the attribute is a collection check each item value. if ($attributeValue instanceof Collection) { $this->getCollectionAttributeCacheKeys($cacheKeys, $model, $attributeCacheKey, $attributeValue); } elseif (is_scalar($attributeValue)) { // Otherwise just get the value. $cacheKeys[] = implode(':', [$model->getTable(), $attributeCacheKey, $attributeValue]); } } } }
[ "protected", "function", "addAttributeCacheKeys", "(", "array", "&", "$", "cacheKeys", ",", "Cacheable", "$", "model", ")", "{", "// Add a cache key for each attribute marked as a cache key.", "foreach", "(", "$", "model", "->", "getAttributeCacheKeys", "(", ")", "as", "$", "attributeCacheKey", ")", "{", "$", "origAttributeValue", "=", "$", "this", "->", "getOriginalCacheKeyValue", "(", "$", "model", ",", "$", "attributeCacheKey", ")", ";", "$", "attributesValues", "=", "[", "]", ";", "if", "(", "$", "origAttributeValue", "!=", "null", ")", "{", "array_push", "(", "$", "attributesValues", ",", "$", "origAttributeValue", ")", ";", "}", "array_push", "(", "$", "attributesValues", ",", "$", "model", "->", "{", "$", "attributeCacheKey", "}", ")", ";", "foreach", "(", "$", "attributesValues", "as", "$", "attributeValue", ")", "{", "// If the attribute is a collection check each item value.", "if", "(", "$", "attributeValue", "instanceof", "Collection", ")", "{", "$", "this", "->", "getCollectionAttributeCacheKeys", "(", "$", "cacheKeys", ",", "$", "model", ",", "$", "attributeCacheKey", ",", "$", "attributeValue", ")", ";", "}", "elseif", "(", "is_scalar", "(", "$", "attributeValue", ")", ")", "{", "// Otherwise just get the value.", "$", "cacheKeys", "[", "]", "=", "implode", "(", "':'", ",", "[", "$", "model", "->", "getTable", "(", ")", ",", "$", "attributeCacheKey", ",", "$", "attributeValue", "]", ")", ";", "}", "}", "}", "}" ]
Add cache keys for each attribute of a given model. @param array $cacheKeys @param Cacheable $model
[ "Add", "cache", "keys", "for", "each", "attribute", "of", "a", "given", "model", "." ]
37a6e3b5f326ab120bb31262fa596e6e3cc20832
https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L67-L90
18,544
LUSHDigital/microservice-model-utils
src/Traits/MicroServiceCacheTrait.php
MicroServiceCacheTrait.getCollectionAttributeCacheKeys
protected function getCollectionAttributeCacheKeys(array &$cacheKeys, Cacheable $model, $attribute, $collection) { foreach ($collection as $item) { if (isset($item->id)) { $cacheKeys[] = implode(':', [$model->getTable(), $attribute, $item->id]); } } }
php
protected function getCollectionAttributeCacheKeys(array &$cacheKeys, Cacheable $model, $attribute, $collection) { foreach ($collection as $item) { if (isset($item->id)) { $cacheKeys[] = implode(':', [$model->getTable(), $attribute, $item->id]); } } }
[ "protected", "function", "getCollectionAttributeCacheKeys", "(", "array", "&", "$", "cacheKeys", ",", "Cacheable", "$", "model", ",", "$", "attribute", ",", "$", "collection", ")", "{", "foreach", "(", "$", "collection", "as", "$", "item", ")", "{", "if", "(", "isset", "(", "$", "item", "->", "id", ")", ")", "{", "$", "cacheKeys", "[", "]", "=", "implode", "(", "':'", ",", "[", "$", "model", "->", "getTable", "(", ")", ",", "$", "attribute", ",", "$", "item", "->", "id", "]", ")", ";", "}", "}", "}" ]
Get the attribute cache keys from a collection attribute. @param array $cacheKeys @param Cacheable $model @param $attribute @param $collection
[ "Get", "the", "attribute", "cache", "keys", "from", "a", "collection", "attribute", "." ]
37a6e3b5f326ab120bb31262fa596e6e3cc20832
https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L100-L107
18,545
LUSHDigital/microservice-model-utils
src/Traits/MicroServiceCacheTrait.php
MicroServiceCacheTrait.getOriginalCacheKeyValue
protected function getOriginalCacheKeyValue(Cacheable $model, $attributeCacheKey) { // Bail out if the model is not an eloquent model. if (!$model instanceof Model) { return null; } return empty($model->getOriginal($attributeCacheKey)) ? null : $model->getOriginal($attributeCacheKey); }
php
protected function getOriginalCacheKeyValue(Cacheable $model, $attributeCacheKey) { // Bail out if the model is not an eloquent model. if (!$model instanceof Model) { return null; } return empty($model->getOriginal($attributeCacheKey)) ? null : $model->getOriginal($attributeCacheKey); }
[ "protected", "function", "getOriginalCacheKeyValue", "(", "Cacheable", "$", "model", ",", "$", "attributeCacheKey", ")", "{", "// Bail out if the model is not an eloquent model.", "if", "(", "!", "$", "model", "instanceof", "Model", ")", "{", "return", "null", ";", "}", "return", "empty", "(", "$", "model", "->", "getOriginal", "(", "$", "attributeCacheKey", ")", ")", "?", "null", ":", "$", "model", "->", "getOriginal", "(", "$", "attributeCacheKey", ")", ";", "}" ]
Get original cache key value. @param Cacheable $model @param $attributeCacheKey @return mixed|null
[ "Get", "original", "cache", "key", "value", "." ]
37a6e3b5f326ab120bb31262fa596e6e3cc20832
https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L116-L124
18,546
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.getName
public function getName() { $fqdnClassName = get_class($this); $className = substr($fqdnClassName, strrpos($fqdnClassName, '\\') + 1); return str_replace("Service", "", $className); }
php
public function getName() { $fqdnClassName = get_class($this); $className = substr($fqdnClassName, strrpos($fqdnClassName, '\\') + 1); return str_replace("Service", "", $className); }
[ "public", "function", "getName", "(", ")", "{", "$", "fqdnClassName", "=", "get_class", "(", "$", "this", ")", ";", "$", "className", "=", "substr", "(", "$", "fqdnClassName", ",", "strrpos", "(", "$", "fqdnClassName", ",", "'\\\\'", ")", "+", "1", ")", ";", "return", "str_replace", "(", "\"Service\"", ",", "\"\"", ",", "$", "className", ")", ";", "}" ]
Returns base entity name @return string
[ "Returns", "base", "entity", "name" ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L58-L63
18,547
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.findEntities
public function findEntities(Request $request, $filters = array(), $addPagination = false) { $options = $this->getOptions($request, $filters, $addPagination); if (!$addPagination) { return array( 'entities' => $this->getRepository()->getEntities($options), 'options' => $options ); } $entities = $this->getRepository()->getPaginatedEntities($options); $options['elements'] = $entities->count(); $options['pages'] = (int)ceil($options['elements'] / $options['elementsPerPage']); return array( 'entities' => $entities, 'options' => $options ); }
php
public function findEntities(Request $request, $filters = array(), $addPagination = false) { $options = $this->getOptions($request, $filters, $addPagination); if (!$addPagination) { return array( 'entities' => $this->getRepository()->getEntities($options), 'options' => $options ); } $entities = $this->getRepository()->getPaginatedEntities($options); $options['elements'] = $entities->count(); $options['pages'] = (int)ceil($options['elements'] / $options['elementsPerPage']); return array( 'entities' => $entities, 'options' => $options ); }
[ "public", "function", "findEntities", "(", "Request", "$", "request", ",", "$", "filters", "=", "array", "(", ")", ",", "$", "addPagination", "=", "false", ")", "{", "$", "options", "=", "$", "this", "->", "getOptions", "(", "$", "request", ",", "$", "filters", ",", "$", "addPagination", ")", ";", "if", "(", "!", "$", "addPagination", ")", "{", "return", "array", "(", "'entities'", "=>", "$", "this", "->", "getRepository", "(", ")", "->", "getEntities", "(", "$", "options", ")", ",", "'options'", "=>", "$", "options", ")", ";", "}", "$", "entities", "=", "$", "this", "->", "getRepository", "(", ")", "->", "getPaginatedEntities", "(", "$", "options", ")", ";", "$", "options", "[", "'elements'", "]", "=", "$", "entities", "->", "count", "(", ")", ";", "$", "options", "[", "'pages'", "]", "=", "(", "int", ")", "ceil", "(", "$", "options", "[", "'elements'", "]", "/", "$", "options", "[", "'elementsPerPage'", "]", ")", ";", "return", "array", "(", "'entities'", "=>", "$", "entities", ",", "'options'", "=>", "$", "options", ")", ";", "}" ]
Returns a list of entities. @param \Symfony\Component\HttpFoundation\Request $request @param array $filters @param bool $addPagination @return array
[ "Returns", "a", "list", "of", "entities", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L115-L133
18,548
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.saveEntity
public function saveEntity($entity) { if (!$this->entityManager->contains($entity)) { $this->entityManager->persist($entity); } $this->entityManager->flush(); return true; }
php
public function saveEntity($entity) { if (!$this->entityManager->contains($entity)) { $this->entityManager->persist($entity); } $this->entityManager->flush(); return true; }
[ "public", "function", "saveEntity", "(", "$", "entity", ")", "{", "if", "(", "!", "$", "this", "->", "entityManager", "->", "contains", "(", "$", "entity", ")", ")", "{", "$", "this", "->", "entityManager", "->", "persist", "(", "$", "entity", ")", ";", "}", "$", "this", "->", "entityManager", "->", "flush", "(", ")", ";", "return", "true", ";", "}" ]
Saves the entity. @param object $entity @return bool
[ "Saves", "the", "entity", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L169-L177
18,549
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.removeEntity
public function removeEntity($entity) { $this->entityManager->remove($entity); $this->entityManager->flush(); return true; }
php
public function removeEntity($entity) { $this->entityManager->remove($entity); $this->entityManager->flush(); return true; }
[ "public", "function", "removeEntity", "(", "$", "entity", ")", "{", "$", "this", "->", "entityManager", "->", "remove", "(", "$", "entity", ")", ";", "$", "this", "->", "entityManager", "->", "flush", "(", ")", ";", "return", "true", ";", "}" ]
Removes the entity. @param object $entity @return bool
[ "Removes", "the", "entity", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L185-L190
18,550
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.removeEntities
public function removeEntities(array $ids) { foreach ($this->getRepository()->getEntitiesById($ids) as $entity) { $this->entityManager->remove($entity); } $this->entityManager->flush(); return true; }
php
public function removeEntities(array $ids) { foreach ($this->getRepository()->getEntitiesById($ids) as $entity) { $this->entityManager->remove($entity); } $this->entityManager->flush(); return true; }
[ "public", "function", "removeEntities", "(", "array", "$", "ids", ")", "{", "foreach", "(", "$", "this", "->", "getRepository", "(", ")", "->", "getEntitiesById", "(", "$", "ids", ")", "as", "$", "entity", ")", "{", "$", "this", "->", "entityManager", "->", "remove", "(", "$", "entity", ")", ";", "}", "$", "this", "->", "entityManager", "->", "flush", "(", ")", ";", "return", "true", ";", "}" ]
Removes a list of entities. @param array $ids @return bool
[ "Removes", "a", "list", "of", "entities", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L198-L207
18,551
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.getFilters
public function getFilters(Request $request, $overrideFilters = array(), $ignoreSession = false) { if ($ignoreSession) { return array_replace( $this->getFiltersFromRequest($request), $overrideFilters ); } $filters = array_replace( $this->getFiltersFromSession($request->getSession()), $this->getFiltersFromRequest($request), $overrideFilters ); $this->saveFilters($request->getSession(), $filters); return $filters; }
php
public function getFilters(Request $request, $overrideFilters = array(), $ignoreSession = false) { if ($ignoreSession) { return array_replace( $this->getFiltersFromRequest($request), $overrideFilters ); } $filters = array_replace( $this->getFiltersFromSession($request->getSession()), $this->getFiltersFromRequest($request), $overrideFilters ); $this->saveFilters($request->getSession(), $filters); return $filters; }
[ "public", "function", "getFilters", "(", "Request", "$", "request", ",", "$", "overrideFilters", "=", "array", "(", ")", ",", "$", "ignoreSession", "=", "false", ")", "{", "if", "(", "$", "ignoreSession", ")", "{", "return", "array_replace", "(", "$", "this", "->", "getFiltersFromRequest", "(", "$", "request", ")", ",", "$", "overrideFilters", ")", ";", "}", "$", "filters", "=", "array_replace", "(", "$", "this", "->", "getFiltersFromSession", "(", "$", "request", "->", "getSession", "(", ")", ")", ",", "$", "this", "->", "getFiltersFromRequest", "(", "$", "request", ")", ",", "$", "overrideFilters", ")", ";", "$", "this", "->", "saveFilters", "(", "$", "request", "->", "getSession", "(", ")", ",", "$", "filters", ")", ";", "return", "$", "filters", ";", "}" ]
Returns the current filters for the entity, if any. @param \Symfony\Component\HttpFoundation\Request $request @param array $overrideFilters @param bool $ignoreSession @return array
[ "Returns", "the", "current", "filters", "for", "the", "entity", "if", "any", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L217-L234
18,552
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.getSorting
public function getSorting(Request $request, $ignoreSession = false) { if ($ignoreSession) { return $this->getSortingFromRequest($request); } $sorting = array_replace( $this->getSortingFromSession($request->getSession()), $this->getSortingFromRequest($request) ); $this->saveSorting($request->getSession(), $sorting); return $sorting; }
php
public function getSorting(Request $request, $ignoreSession = false) { if ($ignoreSession) { return $this->getSortingFromRequest($request); } $sorting = array_replace( $this->getSortingFromSession($request->getSession()), $this->getSortingFromRequest($request) ); $this->saveSorting($request->getSession(), $sorting); return $sorting; }
[ "public", "function", "getSorting", "(", "Request", "$", "request", ",", "$", "ignoreSession", "=", "false", ")", "{", "if", "(", "$", "ignoreSession", ")", "{", "return", "$", "this", "->", "getSortingFromRequest", "(", "$", "request", ")", ";", "}", "$", "sorting", "=", "array_replace", "(", "$", "this", "->", "getSortingFromSession", "(", "$", "request", "->", "getSession", "(", ")", ")", ",", "$", "this", "->", "getSortingFromRequest", "(", "$", "request", ")", ")", ";", "$", "this", "->", "saveSorting", "(", "$", "request", "->", "getSession", "(", ")", ",", "$", "sorting", ")", ";", "return", "$", "sorting", ";", "}" ]
Returns the current sorting options for the entity. @param \Symfony\Component\HttpFoundation\Request $request @param bool $ignoreSession @return array
[ "Returns", "the", "current", "sorting", "options", "for", "the", "entity", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L243-L256
18,553
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.addFilter
public function addFilter(SessionInterface $session, $filterName, $filterValue, $overwrite = true) { if (!$overwrite && $this->hasFilter($session, $filterName)) { return; } $session->set($this->getFilterPrefix() . $filterName, $filterValue); }
php
public function addFilter(SessionInterface $session, $filterName, $filterValue, $overwrite = true) { if (!$overwrite && $this->hasFilter($session, $filterName)) { return; } $session->set($this->getFilterPrefix() . $filterName, $filterValue); }
[ "public", "function", "addFilter", "(", "SessionInterface", "$", "session", ",", "$", "filterName", ",", "$", "filterValue", ",", "$", "overwrite", "=", "true", ")", "{", "if", "(", "!", "$", "overwrite", "&&", "$", "this", "->", "hasFilter", "(", "$", "session", ",", "$", "filterName", ")", ")", "{", "return", ";", "}", "$", "session", "->", "set", "(", "$", "this", "->", "getFilterPrefix", "(", ")", ".", "$", "filterName", ",", "$", "filterValue", ")", ";", "}" ]
Adds a single filter to the session; set the `overwrite` flag to `false` if you want to preserve an already existing value. @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session @param string $filterName @param mixed $filterValue @param boolean $overwrite
[ "Adds", "a", "single", "filter", "to", "the", "session", ";", "set", "the", "overwrite", "flag", "to", "false", "if", "you", "want", "to", "preserve", "an", "already", "existing", "value", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L279-L286
18,554
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.saveFilters
protected function saveFilters(SessionInterface $session, array $filters) { $this->saveValues($filters, $this->getFilterPrefix(), $session); }
php
protected function saveFilters(SessionInterface $session, array $filters) { $this->saveValues($filters, $this->getFilterPrefix(), $session); }
[ "protected", "function", "saveFilters", "(", "SessionInterface", "$", "session", ",", "array", "$", "filters", ")", "{", "$", "this", "->", "saveValues", "(", "$", "filters", ",", "$", "this", "->", "getFilterPrefix", "(", ")", ",", "$", "session", ")", ";", "}" ]
Saves the filters inside the session. @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session @param array $filters
[ "Saves", "the", "filters", "inside", "the", "session", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L305-L308
18,555
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.getFiltersFromRequest
protected function getFiltersFromRequest(Request $request) { return $this->extractValues($this->getValuesFromRequest($request), $this->getFilterPrefix()); }
php
protected function getFiltersFromRequest(Request $request) { return $this->extractValues($this->getValuesFromRequest($request), $this->getFilterPrefix()); }
[ "protected", "function", "getFiltersFromRequest", "(", "Request", "$", "request", ")", "{", "return", "$", "this", "->", "extractValues", "(", "$", "this", "->", "getValuesFromRequest", "(", "$", "request", ")", ",", "$", "this", "->", "getFilterPrefix", "(", ")", ")", ";", "}" ]
Returns the filters from the request. @param \Symfony\Component\HttpFoundation\Request $request @return array
[ "Returns", "the", "filters", "from", "the", "request", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L347-L350
18,556
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.getSortingFromRequest
protected function getSortingFromRequest(Request $request) { return $this->extractValues($this->getValuesFromRequest($request), $this->getSortingPrefix()); }
php
protected function getSortingFromRequest(Request $request) { return $this->extractValues($this->getValuesFromRequest($request), $this->getSortingPrefix()); }
[ "protected", "function", "getSortingFromRequest", "(", "Request", "$", "request", ")", "{", "return", "$", "this", "->", "extractValues", "(", "$", "this", "->", "getValuesFromRequest", "(", "$", "request", ")", ",", "$", "this", "->", "getSortingPrefix", "(", ")", ")", ";", "}" ]
Returns the sorting options from the request. @param \Symfony\Component\HttpFoundation\Request $request @return array
[ "Returns", "the", "sorting", "options", "from", "the", "request", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L369-L372
18,557
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.getValuesFromRequest
private function getValuesFromRequest(Request $request) { $values = array_merge($request->query->all(), $request->request->all()); $contentValues = json_decode($request->getContent(), true); if (is_array($contentValues)) { $values = array_merge($values, $contentValues); } return $values; }
php
private function getValuesFromRequest(Request $request) { $values = array_merge($request->query->all(), $request->request->all()); $contentValues = json_decode($request->getContent(), true); if (is_array($contentValues)) { $values = array_merge($values, $contentValues); } return $values; }
[ "private", "function", "getValuesFromRequest", "(", "Request", "$", "request", ")", "{", "$", "values", "=", "array_merge", "(", "$", "request", "->", "query", "->", "all", "(", ")", ",", "$", "request", "->", "request", "->", "all", "(", ")", ")", ";", "$", "contentValues", "=", "json_decode", "(", "$", "request", "->", "getContent", "(", ")", ",", "true", ")", ";", "if", "(", "is_array", "(", "$", "contentValues", ")", ")", "{", "$", "values", "=", "array_merge", "(", "$", "values", ",", "$", "contentValues", ")", ";", "}", "return", "$", "values", ";", "}" ]
Returns the values of the options from the request. @param \Symfony\Component\HttpFoundation\Request $request @return array
[ "Returns", "the", "values", "of", "the", "options", "from", "the", "request", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L423-L432
18,558
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.extractValues
private function extractValues(array $values, $prefix, $removePrefixFromKeys = true) { if (empty($values)) { return array(); } $validKeys = array_filter(array_keys($values), function($name) use ($prefix) { return (0 === strpos($name, $prefix)); }); $results = array_intersect_key($values, array_flip($validKeys)); if (!$removePrefixFromKeys) { return $results; } return array_combine( array_map(function($key) use ($prefix) { return str_replace($prefix, '', $key); }, array_keys($results)), $results ); }
php
private function extractValues(array $values, $prefix, $removePrefixFromKeys = true) { if (empty($values)) { return array(); } $validKeys = array_filter(array_keys($values), function($name) use ($prefix) { return (0 === strpos($name, $prefix)); }); $results = array_intersect_key($values, array_flip($validKeys)); if (!$removePrefixFromKeys) { return $results; } return array_combine( array_map(function($key) use ($prefix) { return str_replace($prefix, '', $key); }, array_keys($results)), $results ); }
[ "private", "function", "extractValues", "(", "array", "$", "values", ",", "$", "prefix", ",", "$", "removePrefixFromKeys", "=", "true", ")", "{", "if", "(", "empty", "(", "$", "values", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "validKeys", "=", "array_filter", "(", "array_keys", "(", "$", "values", ")", ",", "function", "(", "$", "name", ")", "use", "(", "$", "prefix", ")", "{", "return", "(", "0", "===", "strpos", "(", "$", "name", ",", "$", "prefix", ")", ")", ";", "}", ")", ";", "$", "results", "=", "array_intersect_key", "(", "$", "values", ",", "array_flip", "(", "$", "validKeys", ")", ")", ";", "if", "(", "!", "$", "removePrefixFromKeys", ")", "{", "return", "$", "results", ";", "}", "return", "array_combine", "(", "array_map", "(", "function", "(", "$", "key", ")", "use", "(", "$", "prefix", ")", "{", "return", "str_replace", "(", "$", "prefix", ",", "''", ",", "$", "key", ")", ";", "}", ",", "array_keys", "(", "$", "results", ")", ")", ",", "$", "results", ")", ";", "}" ]
Returns all the key-value pairs from the array whose key has the specified prefix. @param array $values @param string $prefix @param bool $removePrefixFromKeys @return array
[ "Returns", "all", "the", "key", "-", "value", "pairs", "from", "the", "array", "whose", "key", "has", "the", "specified", "prefix", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L442-L462
18,559
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.saveValues
private function saveValues(array $values, $prefix, SessionInterface $session) { foreach ($values as $name => $value) { $session->set($prefix . $name, $value); } }
php
private function saveValues(array $values, $prefix, SessionInterface $session) { foreach ($values as $name => $value) { $session->set($prefix . $name, $value); } }
[ "private", "function", "saveValues", "(", "array", "$", "values", ",", "$", "prefix", ",", "SessionInterface", "$", "session", ")", "{", "foreach", "(", "$", "values", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "session", "->", "set", "(", "$", "prefix", ".", "$", "name", ",", "$", "value", ")", ";", "}", "}" ]
Saves into the session all the key-value pairs from the array, adding to their keys the specified prefix. @param array $values @param string $prefix @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
[ "Saves", "into", "the", "session", "all", "the", "key", "-", "value", "pairs", "from", "the", "array", "adding", "to", "their", "keys", "the", "specified", "prefix", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L471-L476
18,560
gibilogic/crud-bundle
Entity/EntityService.php
EntityService.removeValues
private function removeValues($prefix, SessionInterface $session) { foreach ($session->all() as $key => $value) { if (0 === strpos($key, $prefix)) { $session->remove($key); } } }
php
private function removeValues($prefix, SessionInterface $session) { foreach ($session->all() as $key => $value) { if (0 === strpos($key, $prefix)) { $session->remove($key); } } }
[ "private", "function", "removeValues", "(", "$", "prefix", ",", "SessionInterface", "$", "session", ")", "{", "foreach", "(", "$", "session", "->", "all", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "0", "===", "strpos", "(", "$", "key", ",", "$", "prefix", ")", ")", "{", "$", "session", "->", "remove", "(", "$", "key", ")", ";", "}", "}", "}" ]
Removes from the session all the key-value pairs whose key has the specified prefix. @param string $prefix @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
[ "Removes", "from", "the", "session", "all", "the", "key", "-", "value", "pairs", "whose", "key", "has", "the", "specified", "prefix", "." ]
847e7c7bee4016026411eb230154f24986335633
https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L484-L491
18,561
trafficgate/shell-command
src/ShellCommand.php
ShellCommand.setCommandTimeout
public function setCommandTimeout($commandTimeout) { if ($commandTimeout !== null && ! is_numeric($commandTimeout)) { throw new InvalidArgumentException('Timeout must be an integer.'); } if (is_string($commandTimeout)) { $commandTimeout = (int) $commandTimeout; } $this->commandTimeout = $commandTimeout; return $this; }
php
public function setCommandTimeout($commandTimeout) { if ($commandTimeout !== null && ! is_numeric($commandTimeout)) { throw new InvalidArgumentException('Timeout must be an integer.'); } if (is_string($commandTimeout)) { $commandTimeout = (int) $commandTimeout; } $this->commandTimeout = $commandTimeout; return $this; }
[ "public", "function", "setCommandTimeout", "(", "$", "commandTimeout", ")", "{", "if", "(", "$", "commandTimeout", "!==", "null", "&&", "!", "is_numeric", "(", "$", "commandTimeout", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Timeout must be an integer.'", ")", ";", "}", "if", "(", "is_string", "(", "$", "commandTimeout", ")", ")", "{", "$", "commandTimeout", "=", "(", "int", ")", "$", "commandTimeout", ";", "}", "$", "this", "->", "commandTimeout", "=", "$", "commandTimeout", ";", "return", "$", "this", ";", "}" ]
Set the command timeout. @param int $commandTimeout @return $this
[ "Set", "the", "command", "timeout", "." ]
1a5f3fcf689f33098b192c34839effe309202c0e
https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L165-L178
18,562
trafficgate/shell-command
src/ShellCommand.php
ShellCommand.setRetryLimit
public function setRetryLimit($retryLimit = null) { if (! is_numeric($retryLimit) && ! is_null($retryLimit)) { throw new InvalidArgumentException('Retry limit must be a number or null.'); } if (is_string($retryLimit)) { $retryLimit = (int) $retryLimit; } $this->retryLimit = $retryLimit; return $this; }
php
public function setRetryLimit($retryLimit = null) { if (! is_numeric($retryLimit) && ! is_null($retryLimit)) { throw new InvalidArgumentException('Retry limit must be a number or null.'); } if (is_string($retryLimit)) { $retryLimit = (int) $retryLimit; } $this->retryLimit = $retryLimit; return $this; }
[ "public", "function", "setRetryLimit", "(", "$", "retryLimit", "=", "null", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "retryLimit", ")", "&&", "!", "is_null", "(", "$", "retryLimit", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Retry limit must be a number or null.'", ")", ";", "}", "if", "(", "is_string", "(", "$", "retryLimit", ")", ")", "{", "$", "retryLimit", "=", "(", "int", ")", "$", "retryLimit", ";", "}", "$", "this", "->", "retryLimit", "=", "$", "retryLimit", ";", "return", "$", "this", ";", "}" ]
Set the number of times to retry a command if it fails. Set the limit to null to retry forever. @param int|null $retryLimit @return $this
[ "Set", "the", "number", "of", "times", "to", "retry", "a", "command", "if", "it", "fails", "." ]
1a5f3fcf689f33098b192c34839effe309202c0e
https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L199-L212
18,563
trafficgate/shell-command
src/ShellCommand.php
ShellCommand.argument
final public function argument($key) { $result = null; foreach ($this->shellArguments as $shellArgument) { if ($shellArgument['key'] === $key) { $result = $shellArgument; break; } } return $result; }
php
final public function argument($key) { $result = null; foreach ($this->shellArguments as $shellArgument) { if ($shellArgument['key'] === $key) { $result = $shellArgument; break; } } return $result; }
[ "final", "public", "function", "argument", "(", "$", "key", ")", "{", "$", "result", "=", "null", ";", "foreach", "(", "$", "this", "->", "shellArguments", "as", "$", "shellArgument", ")", "{", "if", "(", "$", "shellArgument", "[", "'key'", "]", "===", "$", "key", ")", "{", "$", "result", "=", "$", "shellArgument", ";", "break", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get a specific argument. Return null if the argument isn't found. @param $key @return mixed
[ "Get", "a", "specific", "argument", "." ]
1a5f3fcf689f33098b192c34839effe309202c0e
https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L264-L277
18,564
trafficgate/shell-command
src/ShellCommand.php
ShellCommand.updateArgument
final protected function updateArgument($key, $value) { foreach ($this->shellArguments as &$shellArgument) { if ($shellArgument['key'] === $key) { $shellArgument['value'] = $value; break; } } unset($shellArgument); return $this; }
php
final protected function updateArgument($key, $value) { foreach ($this->shellArguments as &$shellArgument) { if ($shellArgument['key'] === $key) { $shellArgument['value'] = $value; break; } } unset($shellArgument); return $this; }
[ "final", "protected", "function", "updateArgument", "(", "$", "key", ",", "$", "value", ")", "{", "foreach", "(", "$", "this", "->", "shellArguments", "as", "&", "$", "shellArgument", ")", "{", "if", "(", "$", "shellArgument", "[", "'key'", "]", "===", "$", "key", ")", "{", "$", "shellArgument", "[", "'value'", "]", "=", "$", "value", ";", "break", ";", "}", "}", "unset", "(", "$", "shellArgument", ")", ";", "return", "$", "this", ";", "}" ]
Update the specific argument. @param string $key @param bool $value @return $this
[ "Update", "the", "specific", "argument", "." ]
1a5f3fcf689f33098b192c34839effe309202c0e
https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L426-L438
18,565
trafficgate/shell-command
src/ShellCommand.php
ShellCommand.updateOption
final protected function updateOption($flag, $enabled, $value = null, $remove = false) { $shellOption = $this->option($flag); $shellOption->enable($enabled); if ($shellOption->canHaveValue()) { $this->updateOptionValue($shellOption, $value, $remove); } return $this; }
php
final protected function updateOption($flag, $enabled, $value = null, $remove = false) { $shellOption = $this->option($flag); $shellOption->enable($enabled); if ($shellOption->canHaveValue()) { $this->updateOptionValue($shellOption, $value, $remove); } return $this; }
[ "final", "protected", "function", "updateOption", "(", "$", "flag", ",", "$", "enabled", ",", "$", "value", "=", "null", ",", "$", "remove", "=", "false", ")", "{", "$", "shellOption", "=", "$", "this", "->", "option", "(", "$", "flag", ")", ";", "$", "shellOption", "->", "enable", "(", "$", "enabled", ")", ";", "if", "(", "$", "shellOption", "->", "canHaveValue", "(", ")", ")", "{", "$", "this", "->", "updateOptionValue", "(", "$", "shellOption", ",", "$", "value", ",", "$", "remove", ")", ";", "}", "return", "$", "this", ";", "}" ]
Update an option. @param string $flag @param bool $enabled @param bool $value @param bool $remove @return $this
[ "Update", "an", "option", "." ]
1a5f3fcf689f33098b192c34839effe309202c0e
https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L450-L460
18,566
trafficgate/shell-command
src/ShellCommand.php
ShellCommand.setShellCommand
private function setShellCommand($command) { if (! isset($command)) { throw new InvalidArgumentException('Must define a command.'); } if (isset($this->shellCommand) && $this->shellCommand !== $command) { throw new LogicException('Cannot redefine command once set!'); } $this->shellCommand = $command; return $this; }
php
private function setShellCommand($command) { if (! isset($command)) { throw new InvalidArgumentException('Must define a command.'); } if (isset($this->shellCommand) && $this->shellCommand !== $command) { throw new LogicException('Cannot redefine command once set!'); } $this->shellCommand = $command; return $this; }
[ "private", "function", "setShellCommand", "(", "$", "command", ")", "{", "if", "(", "!", "isset", "(", "$", "command", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Must define a command.'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "shellCommand", ")", "&&", "$", "this", "->", "shellCommand", "!==", "$", "command", ")", "{", "throw", "new", "LogicException", "(", "'Cannot redefine command once set!'", ")", ";", "}", "$", "this", "->", "shellCommand", "=", "$", "command", ";", "return", "$", "this", ";", "}" ]
Set the command to execute. The command can only be set once. @param $command @return $this
[ "Set", "the", "command", "to", "execute", "." ]
1a5f3fcf689f33098b192c34839effe309202c0e
https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L481-L494
18,567
trafficgate/shell-command
src/ShellCommand.php
ShellCommand.defineArgument
private function defineArgument($key) { $shellArgumentFound = false; foreach ($this->shellArguments as $shellArgument) { if ($shellArgument['key'] === $key) { $shellArgumentFound = true; } } if (! $shellArgumentFound) { array_push($this->shellArguments, ['key' => $key, 'value' => '']); } return $this; }
php
private function defineArgument($key) { $shellArgumentFound = false; foreach ($this->shellArguments as $shellArgument) { if ($shellArgument['key'] === $key) { $shellArgumentFound = true; } } if (! $shellArgumentFound) { array_push($this->shellArguments, ['key' => $key, 'value' => '']); } return $this; }
[ "private", "function", "defineArgument", "(", "$", "key", ")", "{", "$", "shellArgumentFound", "=", "false", ";", "foreach", "(", "$", "this", "->", "shellArguments", "as", "$", "shellArgument", ")", "{", "if", "(", "$", "shellArgument", "[", "'key'", "]", "===", "$", "key", ")", "{", "$", "shellArgumentFound", "=", "true", ";", "}", "}", "if", "(", "!", "$", "shellArgumentFound", ")", "{", "array_push", "(", "$", "this", "->", "shellArguments", ",", "[", "'key'", "=>", "$", "key", ",", "'value'", "=>", "''", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set an argument for the command. @param string $key @return $this
[ "Set", "an", "argument", "for", "the", "command", "." ]
1a5f3fcf689f33098b192c34839effe309202c0e
https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L527-L541
18,568
trafficgate/shell-command
src/ShellCommand.php
ShellCommand.updateOptionValue
private function updateOptionValue(ShellOption $shellOption, $value = null, $remove = false) { if ($remove) { $shellOption->removeValue($value); } else { $shellOption->addValue($value); } }
php
private function updateOptionValue(ShellOption $shellOption, $value = null, $remove = false) { if ($remove) { $shellOption->removeValue($value); } else { $shellOption->addValue($value); } }
[ "private", "function", "updateOptionValue", "(", "ShellOption", "$", "shellOption", ",", "$", "value", "=", "null", ",", "$", "remove", "=", "false", ")", "{", "if", "(", "$", "remove", ")", "{", "$", "shellOption", "->", "removeValue", "(", "$", "value", ")", ";", "}", "else", "{", "$", "shellOption", "->", "addValue", "(", "$", "value", ")", ";", "}", "}" ]
Update the value for an option. @param ShellOption $shellOption @param mixed|null $value @param bool|false $remove
[ "Update", "the", "value", "for", "an", "option", "." ]
1a5f3fcf689f33098b192c34839effe309202c0e
https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L564-L571
18,569
trafficgate/shell-command
src/ShellCommand.php
ShellCommand.compile
private function compile() { $shellOptions = []; /** @var ShellOption $shellOption */ foreach ($this->shellOptions as $shellOption) { $shellOptions = array_merge($shellOptions, $shellOption->getArray()); } $shellArguments = []; foreach ($this->shellArguments as $shellArgument) { $shellArguments[] = $shellArgument['value']; } $command = array_merge([$this->shellCommand], $shellOptions, $shellArguments); $builder = new Process($command); $builder->setTimeout($this->getCommandTimeout()); $this->builder = $builder; return $this->builder; }
php
private function compile() { $shellOptions = []; /** @var ShellOption $shellOption */ foreach ($this->shellOptions as $shellOption) { $shellOptions = array_merge($shellOptions, $shellOption->getArray()); } $shellArguments = []; foreach ($this->shellArguments as $shellArgument) { $shellArguments[] = $shellArgument['value']; } $command = array_merge([$this->shellCommand], $shellOptions, $shellArguments); $builder = new Process($command); $builder->setTimeout($this->getCommandTimeout()); $this->builder = $builder; return $this->builder; }
[ "private", "function", "compile", "(", ")", "{", "$", "shellOptions", "=", "[", "]", ";", "/** @var ShellOption $shellOption */", "foreach", "(", "$", "this", "->", "shellOptions", "as", "$", "shellOption", ")", "{", "$", "shellOptions", "=", "array_merge", "(", "$", "shellOptions", ",", "$", "shellOption", "->", "getArray", "(", ")", ")", ";", "}", "$", "shellArguments", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "shellArguments", "as", "$", "shellArgument", ")", "{", "$", "shellArguments", "[", "]", "=", "$", "shellArgument", "[", "'value'", "]", ";", "}", "$", "command", "=", "array_merge", "(", "[", "$", "this", "->", "shellCommand", "]", ",", "$", "shellOptions", ",", "$", "shellArguments", ")", ";", "$", "builder", "=", "new", "Process", "(", "$", "command", ")", ";", "$", "builder", "->", "setTimeout", "(", "$", "this", "->", "getCommandTimeout", "(", ")", ")", ";", "$", "this", "->", "builder", "=", "$", "builder", ";", "return", "$", "this", "->", "builder", ";", "}" ]
Compile the parts of the command. @return Process
[ "Compile", "the", "parts", "of", "the", "command", "." ]
1a5f3fcf689f33098b192c34839effe309202c0e
https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L578-L600
18,570
forxer/tao
src/Tao/Templating/Helpers/Modifier.php
Modifier.nlToP
public function nlToP($string) { $string = trim($string); $string = Modifiers::linebreaks($string); $string = str_replace("\n", "</p>\n<p>", $string); $string = str_replace('<p></p>', '', $string); return '<p>' . $string . '</p>' . PHP_EOL; }
php
public function nlToP($string) { $string = trim($string); $string = Modifiers::linebreaks($string); $string = str_replace("\n", "</p>\n<p>", $string); $string = str_replace('<p></p>', '', $string); return '<p>' . $string . '</p>' . PHP_EOL; }
[ "public", "function", "nlToP", "(", "$", "string", ")", "{", "$", "string", "=", "trim", "(", "$", "string", ")", ";", "$", "string", "=", "Modifiers", "::", "linebreaks", "(", "$", "string", ")", ";", "$", "string", "=", "str_replace", "(", "\"\\n\"", ",", "\"</p>\\n<p>\"", ",", "$", "string", ")", ";", "$", "string", "=", "str_replace", "(", "'<p></p>'", ",", "''", ",", "$", "string", ")", ";", "return", "'<p>'", ".", "$", "string", ".", "'</p>'", ".", "PHP_EOL", ";", "}" ]
Converts text line breaks into HTML paragraphs. @param string $string String to transform @return string
[ "Converts", "text", "line", "breaks", "into", "HTML", "paragraphs", "." ]
b5e9109c244a29a72403ae6a58633ab96a67c660
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Templating/Helpers/Modifier.php#L29-L36
18,571
forxer/tao
src/Tao/Templating/Helpers/Modifier.php
Modifier.nlToPbr
public function nlToPbr($string) { $string = trim($string); $string = Modifiers::linebreaks($string); $string = str_replace("\n", '<br />', $string); $string = str_replace('<br /><br />', "</p>\n<p>", $string); $string = str_replace('<p></p>', '', $string); return '<p>' . $string . '</p>' . PHP_EOL; }
php
public function nlToPbr($string) { $string = trim($string); $string = Modifiers::linebreaks($string); $string = str_replace("\n", '<br />', $string); $string = str_replace('<br /><br />', "</p>\n<p>", $string); $string = str_replace('<p></p>', '', $string); return '<p>' . $string . '</p>' . PHP_EOL; }
[ "public", "function", "nlToPbr", "(", "$", "string", ")", "{", "$", "string", "=", "trim", "(", "$", "string", ")", ";", "$", "string", "=", "Modifiers", "::", "linebreaks", "(", "$", "string", ")", ";", "$", "string", "=", "str_replace", "(", "\"\\n\"", ",", "'<br />'", ",", "$", "string", ")", ";", "$", "string", "=", "str_replace", "(", "'<br /><br />'", ",", "\"</p>\\n<p>\"", ",", "$", "string", ")", ";", "$", "string", "=", "str_replace", "(", "'<p></p>'", ",", "''", ",", "$", "string", ")", ";", "return", "'<p>'", ".", "$", "string", ".", "'</p>'", ".", "PHP_EOL", ";", "}" ]
Converts text line breaks into HTML paragraphs and HTML line breaks. @param string $string String to transform @return string
[ "Converts", "text", "line", "breaks", "into", "HTML", "paragraphs", "and", "HTML", "line", "breaks", "." ]
b5e9109c244a29a72403ae6a58633ab96a67c660
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Templating/Helpers/Modifier.php#L44-L52
18,572
forxer/tao
src/Tao/Templating/Helpers/Modifier.php
Modifier.emailEncode
public static function emailEncode($sEmail) { $sEmail = bin2hex($sEmail); $sEmail = chunk_split($sEmail, 2, '%'); $sEmail = '%' . substr($sEmail, 0, strlen($sEmail) - 1); return $sEmail; }
php
public static function emailEncode($sEmail) { $sEmail = bin2hex($sEmail); $sEmail = chunk_split($sEmail, 2, '%'); $sEmail = '%' . substr($sEmail, 0, strlen($sEmail) - 1); return $sEmail; }
[ "public", "static", "function", "emailEncode", "(", "$", "sEmail", ")", "{", "$", "sEmail", "=", "bin2hex", "(", "$", "sEmail", ")", ";", "$", "sEmail", "=", "chunk_split", "(", "$", "sEmail", ",", "2", ",", "'%'", ")", ";", "$", "sEmail", "=", "'%'", ".", "substr", "(", "$", "sEmail", ",", "0", ",", "strlen", "(", "$", "sEmail", ")", "-", "1", ")", ";", "return", "$", "sEmail", ";", "}" ]
Encode an email address for HTML. @param string $sEmail @return string encoded email
[ "Encode", "an", "email", "address", "for", "HTML", "." ]
b5e9109c244a29a72403ae6a58633ab96a67c660
https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Templating/Helpers/Modifier.php#L60-L66
18,573
jenwachter/html-form
src/Abstracts/Addable.php
Addable.findClass
protected function findClass($method) { if (!preg_match("/^add([a-zA-Z]+)/", $method, $matches)) { return false; } $className = "\\HtmlForm\\Elements\\{$matches[1]}"; if (!class_exists($className)) { return false; } return $className; }
php
protected function findClass($method) { if (!preg_match("/^add([a-zA-Z]+)/", $method, $matches)) { return false; } $className = "\\HtmlForm\\Elements\\{$matches[1]}"; if (!class_exists($className)) { return false; } return $className; }
[ "protected", "function", "findClass", "(", "$", "method", ")", "{", "if", "(", "!", "preg_match", "(", "\"/^add([a-zA-Z]+)/\"", ",", "$", "method", ",", "$", "matches", ")", ")", "{", "return", "false", ";", "}", "$", "className", "=", "\"\\\\HtmlForm\\\\Elements\\\\{$matches[1]}\"", ";", "if", "(", "!", "class_exists", "(", "$", "className", ")", ")", "{", "return", "false", ";", "}", "return", "$", "className", ";", "}" ]
Based on a passed method name, figure out if there is a cooresponding HtmlForm element. @param string $method Called method @return string Class name (if there is one)
[ "Based", "on", "a", "passed", "method", "name", "figure", "out", "if", "there", "is", "a", "cooresponding", "HtmlForm", "element", "." ]
eaece87d474f7da5c25679548fb8f1608a94303c
https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Abstracts/Addable.php#L40-L53
18,574
atkrad/data-tables
src/Table.php
Table.setDataSource
public function setDataSource(DataSourceInterface $dataSource) { $this->dataSource = $dataSource; $this->dataSource->initialize($this); }
php
public function setDataSource(DataSourceInterface $dataSource) { $this->dataSource = $dataSource; $this->dataSource->initialize($this); }
[ "public", "function", "setDataSource", "(", "DataSourceInterface", "$", "dataSource", ")", "{", "$", "this", "->", "dataSource", "=", "$", "dataSource", ";", "$", "this", "->", "dataSource", "->", "initialize", "(", "$", "this", ")", ";", "}" ]
Set Table data source @param DataSourceInterface $dataSource DataSource object
[ "Set", "Table", "data", "source" ]
5afcc337ab624ca626e29d9674459c5105982b16
https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Table.php#L101-L105
18,575
atkrad/data-tables
src/Table.php
Table.addColumn
public function addColumn(Column $column) { $this->columns[] = $column; if ($column instanceof ColumnInterface) { $column->initialize($this); } return $this; }
php
public function addColumn(Column $column) { $this->columns[] = $column; if ($column instanceof ColumnInterface) { $column->initialize($this); } return $this; }
[ "public", "function", "addColumn", "(", "Column", "$", "column", ")", "{", "$", "this", "->", "columns", "[", "]", "=", "$", "column", ";", "if", "(", "$", "column", "instanceof", "ColumnInterface", ")", "{", "$", "column", "->", "initialize", "(", "$", "this", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add column to table @param \DataTable\Column $column Column object @return Table
[ "Add", "column", "to", "table" ]
5afcc337ab624ca626e29d9674459c5105982b16
https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Table.php#L161-L170
18,576
atkrad/data-tables
src/Table.php
Table.setAjax
public function setAjax($ajax) { if (is_string($ajax)) { $pattern = '/^(\s+)*(function)(\s+)*\(/i'; if (preg_match($pattern, $ajax, $matches) && strtolower($matches[2]) == 'function') { $hash = sha1($ajax); $this->properties['ajax'] = $hash; $this->callbacks[$hash] = $ajax; return $this; } $this->properties['ajax'] = $ajax; return $this; } else { $this->properties['ajax'] = $ajax; return $this; } }
php
public function setAjax($ajax) { if (is_string($ajax)) { $pattern = '/^(\s+)*(function)(\s+)*\(/i'; if (preg_match($pattern, $ajax, $matches) && strtolower($matches[2]) == 'function') { $hash = sha1($ajax); $this->properties['ajax'] = $hash; $this->callbacks[$hash] = $ajax; return $this; } $this->properties['ajax'] = $ajax; return $this; } else { $this->properties['ajax'] = $ajax; return $this; } }
[ "public", "function", "setAjax", "(", "$", "ajax", ")", "{", "if", "(", "is_string", "(", "$", "ajax", ")", ")", "{", "$", "pattern", "=", "'/^(\\s+)*(function)(\\s+)*\\(/i'", ";", "if", "(", "preg_match", "(", "$", "pattern", ",", "$", "ajax", ",", "$", "matches", ")", "&&", "strtolower", "(", "$", "matches", "[", "2", "]", ")", "==", "'function'", ")", "{", "$", "hash", "=", "sha1", "(", "$", "ajax", ")", ";", "$", "this", "->", "properties", "[", "'ajax'", "]", "=", "$", "hash", ";", "$", "this", "->", "callbacks", "[", "$", "hash", "]", "=", "$", "ajax", ";", "return", "$", "this", ";", "}", "$", "this", "->", "properties", "[", "'ajax'", "]", "=", "$", "ajax", ";", "return", "$", "this", ";", "}", "else", "{", "$", "this", "->", "properties", "[", "'ajax'", "]", "=", "$", "ajax", ";", "return", "$", "this", ";", "}", "}" ]
DataTables can obtain the data it is to display in the table table's body from a number of sources, including from an Ajax data source, using this initialisation parameter. As with other dynamic data sources, arrays or objects can be used for the data source for each row, with columns.dataDT employed to read from specific object properties. @param string|object|callback $ajax Load data for the table's content from an Ajax source. @return Table @see http://datatables.net/reference/option/ajax
[ "DataTables", "can", "obtain", "the", "data", "it", "is", "to", "display", "in", "the", "table", "table", "s", "body", "from", "a", "number", "of", "sources", "including", "from", "an", "Ajax", "data", "source", "using", "this", "initialisation", "parameter", ".", "As", "with", "other", "dynamic", "data", "sources", "arrays", "or", "objects", "can", "be", "used", "for", "the", "data", "source", "for", "each", "row", "with", "columns", ".", "dataDT", "employed", "to", "read", "from", "specific", "object", "properties", "." ]
5afcc337ab624ca626e29d9674459c5105982b16
https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Table.php#L513-L530
18,577
freyo/flysystem-qcloud-cos-v3
src/Client/Http.php
Http.send
public static function send($rq) { if (self::$_curlHandler) { if (function_exists('curl_reset')) { curl_reset(self::$_curlHandler); } else { my_curl_reset(self::$_curlHandler); } } else { self::$_curlHandler = curl_init(); } curl_setopt(self::$_curlHandler, CURLOPT_URL, $rq['url']); switch (true) { case isset($rq['method']) && in_array(strtolower($rq['method']), ['get', 'post', 'put', 'delete', 'head']): $method = strtoupper($rq['method']); break; case isset($rq['data']): $method = 'POST'; break; default: $method = 'GET'; } $header = isset($rq['header']) ? $rq['header'] : []; $header[] = 'Method:'.$method; $header[] = 'User-Agent:'.Conf::getUA(); $header[] = 'Connection: keep-alive'; if ('POST' == $method) { $header[] = 'Expect: '; } isset($rq['host']) && $header[] = 'Host:'.$rq['host']; curl_setopt(self::$_curlHandler, CURLOPT_HTTPHEADER, $header); curl_setopt(self::$_curlHandler, CURLOPT_RETURNTRANSFER, 1); curl_setopt(self::$_curlHandler, CURLOPT_CUSTOMREQUEST, $method); isset($rq['timeout']) && curl_setopt(self::$_curlHandler, CURLOPT_TIMEOUT, $rq['timeout']); isset($rq['data']) && in_array($method, ['POST', 'PUT']) && curl_setopt(self::$_curlHandler, CURLOPT_POSTFIELDS, $rq['data']); $ssl = substr($rq['url'], 0, 8) == 'https://' ? true : false; if (isset($rq['cert'])) { curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, true); curl_setopt(self::$_curlHandler, CURLOPT_CAINFO, $rq['cert']); curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 2); self::setCurlSSLVersion($rq); } elseif ($ssl) { curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, false); //true any ca curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 0); //not check the names self::setCurlSSLVersion($rq); } $ret = curl_exec(self::$_curlHandler); self::$_httpInfo = curl_getinfo(self::$_curlHandler); return $ret; }
php
public static function send($rq) { if (self::$_curlHandler) { if (function_exists('curl_reset')) { curl_reset(self::$_curlHandler); } else { my_curl_reset(self::$_curlHandler); } } else { self::$_curlHandler = curl_init(); } curl_setopt(self::$_curlHandler, CURLOPT_URL, $rq['url']); switch (true) { case isset($rq['method']) && in_array(strtolower($rq['method']), ['get', 'post', 'put', 'delete', 'head']): $method = strtoupper($rq['method']); break; case isset($rq['data']): $method = 'POST'; break; default: $method = 'GET'; } $header = isset($rq['header']) ? $rq['header'] : []; $header[] = 'Method:'.$method; $header[] = 'User-Agent:'.Conf::getUA(); $header[] = 'Connection: keep-alive'; if ('POST' == $method) { $header[] = 'Expect: '; } isset($rq['host']) && $header[] = 'Host:'.$rq['host']; curl_setopt(self::$_curlHandler, CURLOPT_HTTPHEADER, $header); curl_setopt(self::$_curlHandler, CURLOPT_RETURNTRANSFER, 1); curl_setopt(self::$_curlHandler, CURLOPT_CUSTOMREQUEST, $method); isset($rq['timeout']) && curl_setopt(self::$_curlHandler, CURLOPT_TIMEOUT, $rq['timeout']); isset($rq['data']) && in_array($method, ['POST', 'PUT']) && curl_setopt(self::$_curlHandler, CURLOPT_POSTFIELDS, $rq['data']); $ssl = substr($rq['url'], 0, 8) == 'https://' ? true : false; if (isset($rq['cert'])) { curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, true); curl_setopt(self::$_curlHandler, CURLOPT_CAINFO, $rq['cert']); curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 2); self::setCurlSSLVersion($rq); } elseif ($ssl) { curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, false); //true any ca curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 0); //not check the names self::setCurlSSLVersion($rq); } $ret = curl_exec(self::$_curlHandler); self::$_httpInfo = curl_getinfo(self::$_curlHandler); return $ret; }
[ "public", "static", "function", "send", "(", "$", "rq", ")", "{", "if", "(", "self", "::", "$", "_curlHandler", ")", "{", "if", "(", "function_exists", "(", "'curl_reset'", ")", ")", "{", "curl_reset", "(", "self", "::", "$", "_curlHandler", ")", ";", "}", "else", "{", "my_curl_reset", "(", "self", "::", "$", "_curlHandler", ")", ";", "}", "}", "else", "{", "self", "::", "$", "_curlHandler", "=", "curl_init", "(", ")", ";", "}", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_URL", ",", "$", "rq", "[", "'url'", "]", ")", ";", "switch", "(", "true", ")", "{", "case", "isset", "(", "$", "rq", "[", "'method'", "]", ")", "&&", "in_array", "(", "strtolower", "(", "$", "rq", "[", "'method'", "]", ")", ",", "[", "'get'", ",", "'post'", ",", "'put'", ",", "'delete'", ",", "'head'", "]", ")", ":", "$", "method", "=", "strtoupper", "(", "$", "rq", "[", "'method'", "]", ")", ";", "break", ";", "case", "isset", "(", "$", "rq", "[", "'data'", "]", ")", ":", "$", "method", "=", "'POST'", ";", "break", ";", "default", ":", "$", "method", "=", "'GET'", ";", "}", "$", "header", "=", "isset", "(", "$", "rq", "[", "'header'", "]", ")", "?", "$", "rq", "[", "'header'", "]", ":", "[", "]", ";", "$", "header", "[", "]", "=", "'Method:'", ".", "$", "method", ";", "$", "header", "[", "]", "=", "'User-Agent:'", ".", "Conf", "::", "getUA", "(", ")", ";", "$", "header", "[", "]", "=", "'Connection: keep-alive'", ";", "if", "(", "'POST'", "==", "$", "method", ")", "{", "$", "header", "[", "]", "=", "'Expect: '", ";", "}", "isset", "(", "$", "rq", "[", "'host'", "]", ")", "&&", "$", "header", "[", "]", "=", "'Host:'", ".", "$", "rq", "[", "'host'", "]", ";", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_HTTPHEADER", ",", "$", "header", ")", ";", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_RETURNTRANSFER", ",", "1", ")", ";", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_CUSTOMREQUEST", ",", "$", "method", ")", ";", "isset", "(", "$", "rq", "[", "'timeout'", "]", ")", "&&", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_TIMEOUT", ",", "$", "rq", "[", "'timeout'", "]", ")", ";", "isset", "(", "$", "rq", "[", "'data'", "]", ")", "&&", "in_array", "(", "$", "method", ",", "[", "'POST'", ",", "'PUT'", "]", ")", "&&", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_POSTFIELDS", ",", "$", "rq", "[", "'data'", "]", ")", ";", "$", "ssl", "=", "substr", "(", "$", "rq", "[", "'url'", "]", ",", "0", ",", "8", ")", "==", "'https://'", "?", "true", ":", "false", ";", "if", "(", "isset", "(", "$", "rq", "[", "'cert'", "]", ")", ")", "{", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_SSL_VERIFYPEER", ",", "true", ")", ";", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_CAINFO", ",", "$", "rq", "[", "'cert'", "]", ")", ";", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_SSL_VERIFYHOST", ",", "2", ")", ";", "self", "::", "setCurlSSLVersion", "(", "$", "rq", ")", ";", "}", "elseif", "(", "$", "ssl", ")", "{", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_SSL_VERIFYPEER", ",", "false", ")", ";", "//true any ca", "curl_setopt", "(", "self", "::", "$", "_curlHandler", ",", "CURLOPT_SSL_VERIFYHOST", ",", "0", ")", ";", "//not check the names", "self", "::", "setCurlSSLVersion", "(", "$", "rq", ")", ";", "}", "$", "ret", "=", "curl_exec", "(", "self", "::", "$", "_curlHandler", ")", ";", "self", "::", "$", "_httpInfo", "=", "curl_getinfo", "(", "self", "::", "$", "_curlHandler", ")", ";", "return", "$", "ret", ";", "}" ]
send http request. @param array $rq http请求信息 url : 请求的url地址 method : 请求方法,'get', 'post', 'put', 'delete', 'head' data : 请求数据,如有设置,则method为post header : 需要设置的http头部 host : 请求头部host timeout : 请求超时时间 cert : ca文件路径 ssl_version: SSL版本号 @return string http请求响应
[ "send", "http", "request", "." ]
6bddbc22396aa1228942ec4c0ce46935d415f3b4
https://github.com/freyo/flysystem-qcloud-cos-v3/blob/6bddbc22396aa1228942ec4c0ce46935d415f3b4/src/Client/Http.php#L34-L85
18,578
praxisnetau/silverware-spam-guard
src/Extensions/UserFormExtension.php
UserFormExtension.updateForm
public function updateForm() { if ($userDefinedForm = $this->owner->getController()->data()) { if ($userDefinedForm->EnableSpamGuard) { $this->owner->enableSpamProtection(); } } }
php
public function updateForm() { if ($userDefinedForm = $this->owner->getController()->data()) { if ($userDefinedForm->EnableSpamGuard) { $this->owner->enableSpamProtection(); } } }
[ "public", "function", "updateForm", "(", ")", "{", "if", "(", "$", "userDefinedForm", "=", "$", "this", "->", "owner", "->", "getController", "(", ")", "->", "data", "(", ")", ")", "{", "if", "(", "$", "userDefinedForm", "->", "EnableSpamGuard", ")", "{", "$", "this", "->", "owner", "->", "enableSpamProtection", "(", ")", ";", "}", "}", "}" ]
Updates the extended user form instance. @return void
[ "Updates", "the", "extended", "user", "form", "instance", "." ]
c5f8836a09141bd675173892a1e3d8c8cc8c1886
https://github.com/praxisnetau/silverware-spam-guard/blob/c5f8836a09141bd675173892a1e3d8c8cc8c1886/src/Extensions/UserFormExtension.php#L38-L47
18,579
narrowspark/http-status
src/HttpStatus.php
HttpStatus.getReasonMessage
public static function getReasonMessage(int $code): string { $code = static::filterStatusCode($code); if (! isset(self::$errorPhrases[$code])) { throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code)); } return self::$errorPhrases[$code]; }
php
public static function getReasonMessage(int $code): string { $code = static::filterStatusCode($code); if (! isset(self::$errorPhrases[$code])) { throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code)); } return self::$errorPhrases[$code]; }
[ "public", "static", "function", "getReasonMessage", "(", "int", "$", "code", ")", ":", "string", "{", "$", "code", "=", "static", "::", "filterStatusCode", "(", "$", "code", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "errorPhrases", "[", "$", "code", "]", ")", ")", "{", "throw", "new", "OutOfBoundsException", "(", "\\", "sprintf", "(", "'Unknown http status code: `%s`.'", ",", "$", "code", ")", ")", ";", "}", "return", "self", "::", "$", "errorPhrases", "[", "$", "code", "]", ";", "}" ]
Get the message for a given status code. @param int $code http status code @throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException If the requested $code is not valid @throws \Narrowspark\HttpStatus\Exception\OutOfBoundsException If the requested $code is not found @return string Returns message for the given status code
[ "Get", "the", "message", "for", "a", "given", "status", "code", "." ]
127dcbf1fd02ca9c2a7451da7e3c4dd98c508cde
https://github.com/narrowspark/http-status/blob/127dcbf1fd02ca9c2a7451da7e3c4dd98c508cde/src/HttpStatus.php#L271-L280
18,580
narrowspark/http-status
src/HttpStatus.php
HttpStatus.getReasonPhrase
public static function getReasonPhrase(int $code): string { $code = static::filterStatusCode($code); if (! isset(self::$statusNames[$code])) { throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code)); } return self::$statusNames[$code]; }
php
public static function getReasonPhrase(int $code): string { $code = static::filterStatusCode($code); if (! isset(self::$statusNames[$code])) { throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code)); } return self::$statusNames[$code]; }
[ "public", "static", "function", "getReasonPhrase", "(", "int", "$", "code", ")", ":", "string", "{", "$", "code", "=", "static", "::", "filterStatusCode", "(", "$", "code", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "statusNames", "[", "$", "code", "]", ")", ")", "{", "throw", "new", "OutOfBoundsException", "(", "\\", "sprintf", "(", "'Unknown http status code: `%s`.'", ",", "$", "code", ")", ")", ";", "}", "return", "self", "::", "$", "statusNames", "[", "$", "code", "]", ";", "}" ]
Get the name for a given status code. @param int $code http status code @throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException If the requested $code is not valid @throws \Narrowspark\HttpStatus\Exception\OutOfBoundsException If the requested $code is not found @return string Returns name for the given status code
[ "Get", "the", "name", "for", "a", "given", "status", "code", "." ]
127dcbf1fd02ca9c2a7451da7e3c4dd98c508cde
https://github.com/narrowspark/http-status/blob/127dcbf1fd02ca9c2a7451da7e3c4dd98c508cde/src/HttpStatus.php#L292-L301
18,581
GrafiteInc/Mission-Control-Package
src/Analyzers/TrafficAnalyzer.php
TrafficAnalyzer.getLogCollection
public function getLogCollection($now, $then) { if (!file_exists($this->fileName)) { throw new Exception("Access log file is not present - no traffic to report.", 1); } $collection = []; $lines = file($this->fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($lines as $line) { $collection[] = $this->parser->parse($line); } $logs = collect($collection); return $logs->where('stamp', '<=', $now) ->where('stamp', '>=', $then); }
php
public function getLogCollection($now, $then) { if (!file_exists($this->fileName)) { throw new Exception("Access log file is not present - no traffic to report.", 1); } $collection = []; $lines = file($this->fileName, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach ($lines as $line) { $collection[] = $this->parser->parse($line); } $logs = collect($collection); return $logs->where('stamp', '<=', $now) ->where('stamp', '>=', $then); }
[ "public", "function", "getLogCollection", "(", "$", "now", ",", "$", "then", ")", "{", "if", "(", "!", "file_exists", "(", "$", "this", "->", "fileName", ")", ")", "{", "throw", "new", "Exception", "(", "\"Access log file is not present - no traffic to report.\"", ",", "1", ")", ";", "}", "$", "collection", "=", "[", "]", ";", "$", "lines", "=", "file", "(", "$", "this", "->", "fileName", ",", "FILE_IGNORE_NEW_LINES", "|", "FILE_SKIP_EMPTY_LINES", ")", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "collection", "[", "]", "=", "$", "this", "->", "parser", "->", "parse", "(", "$", "line", ")", ";", "}", "$", "logs", "=", "collect", "(", "$", "collection", ")", ";", "return", "$", "logs", "->", "where", "(", "'stamp'", ",", "'<='", ",", "$", "now", ")", "->", "where", "(", "'stamp'", ",", "'>='", ",", "$", "then", ")", ";", "}" ]
Get the log collection based on time @param int $now @param int $then @return Illuminate\Support\Collection
[ "Get", "the", "log", "collection", "based", "on", "time" ]
4e85f0b729329783b34e35d90abba2807899ff58
https://github.com/GrafiteInc/Mission-Control-Package/blob/4e85f0b729329783b34e35d90abba2807899ff58/src/Analyzers/TrafficAnalyzer.php#L42-L59
18,582
GrafiteInc/Mission-Control-Package
src/Analyzers/TrafficAnalyzer.php
TrafficAnalyzer.processLogStats
public function processLogStats($collection) { $validLogs = $collection->filter(function ($line) { return $this->validateLine($line); }); $sentBytes = $validLogs->pluck('sentBytes'); $stats = [ 'hits' => $validLogs->count(), 'total_data_sent' => $sentBytes->sum(), 'most_common_method' => $this->sortByField('requestMethod', $validLogs), 'most_common_url' => $this->sortByField('URL', $validLogs), 'most_common_user_agent' => $this->sortByField('HeaderUserAgent', $validLogs), ]; return $stats; }
php
public function processLogStats($collection) { $validLogs = $collection->filter(function ($line) { return $this->validateLine($line); }); $sentBytes = $validLogs->pluck('sentBytes'); $stats = [ 'hits' => $validLogs->count(), 'total_data_sent' => $sentBytes->sum(), 'most_common_method' => $this->sortByField('requestMethod', $validLogs), 'most_common_url' => $this->sortByField('URL', $validLogs), 'most_common_user_agent' => $this->sortByField('HeaderUserAgent', $validLogs), ]; return $stats; }
[ "public", "function", "processLogStats", "(", "$", "collection", ")", "{", "$", "validLogs", "=", "$", "collection", "->", "filter", "(", "function", "(", "$", "line", ")", "{", "return", "$", "this", "->", "validateLine", "(", "$", "line", ")", ";", "}", ")", ";", "$", "sentBytes", "=", "$", "validLogs", "->", "pluck", "(", "'sentBytes'", ")", ";", "$", "stats", "=", "[", "'hits'", "=>", "$", "validLogs", "->", "count", "(", ")", ",", "'total_data_sent'", "=>", "$", "sentBytes", "->", "sum", "(", ")", ",", "'most_common_method'", "=>", "$", "this", "->", "sortByField", "(", "'requestMethod'", ",", "$", "validLogs", ")", ",", "'most_common_url'", "=>", "$", "this", "->", "sortByField", "(", "'URL'", ",", "$", "validLogs", ")", ",", "'most_common_user_agent'", "=>", "$", "this", "->", "sortByField", "(", "'HeaderUserAgent'", ",", "$", "validLogs", ")", ",", "]", ";", "return", "$", "stats", ";", "}" ]
Process the log stats @param Collection $collection @return array
[ "Process", "the", "log", "stats" ]
4e85f0b729329783b34e35d90abba2807899ff58
https://github.com/GrafiteInc/Mission-Control-Package/blob/4e85f0b729329783b34e35d90abba2807899ff58/src/Analyzers/TrafficAnalyzer.php#L68-L85
18,583
GrafiteInc/Mission-Control-Package
src/Analyzers/TrafficAnalyzer.php
TrafficAnalyzer.sortByField
public function sortByField($field, $collection) { if ($collection->isEmpty()) { return 'N/A'; } return $collection->groupBy($field)->sortByDesc(function ($logs) { return count($logs); })->first()->pluck($field)->first(); }
php
public function sortByField($field, $collection) { if ($collection->isEmpty()) { return 'N/A'; } return $collection->groupBy($field)->sortByDesc(function ($logs) { return count($logs); })->first()->pluck($field)->first(); }
[ "public", "function", "sortByField", "(", "$", "field", ",", "$", "collection", ")", "{", "if", "(", "$", "collection", "->", "isEmpty", "(", ")", ")", "{", "return", "'N/A'", ";", "}", "return", "$", "collection", "->", "groupBy", "(", "$", "field", ")", "->", "sortByDesc", "(", "function", "(", "$", "logs", ")", "{", "return", "count", "(", "$", "logs", ")", ";", "}", ")", "->", "first", "(", ")", "->", "pluck", "(", "$", "field", ")", "->", "first", "(", ")", ";", "}" ]
Sort data by field @param string $field @param Collection $collection @return Collection
[ "Sort", "data", "by", "field" ]
4e85f0b729329783b34e35d90abba2807899ff58
https://github.com/GrafiteInc/Mission-Control-Package/blob/4e85f0b729329783b34e35d90abba2807899ff58/src/Analyzers/TrafficAnalyzer.php#L95-L104
18,584
GrafiteInc/Mission-Control-Package
src/Analyzers/TrafficAnalyzer.php
TrafficAnalyzer.validateLine
public function validateLine($line) { $invalidExtensions = [ '.jpg', '.js', '.css', '.sass', '.scss', '.png', '.svg', '.ico', '.jpeg', '.gif', '.mp4', ]; foreach ($invalidExtensions as $needle) { if (stristr($line->URL, $needle)) { return false; } } if ($line->HeaderUserAgent === 'MissionControlAgent') { return false; } return true; }
php
public function validateLine($line) { $invalidExtensions = [ '.jpg', '.js', '.css', '.sass', '.scss', '.png', '.svg', '.ico', '.jpeg', '.gif', '.mp4', ]; foreach ($invalidExtensions as $needle) { if (stristr($line->URL, $needle)) { return false; } } if ($line->HeaderUserAgent === 'MissionControlAgent') { return false; } return true; }
[ "public", "function", "validateLine", "(", "$", "line", ")", "{", "$", "invalidExtensions", "=", "[", "'.jpg'", ",", "'.js'", ",", "'.css'", ",", "'.sass'", ",", "'.scss'", ",", "'.png'", ",", "'.svg'", ",", "'.ico'", ",", "'.jpeg'", ",", "'.gif'", ",", "'.mp4'", ",", "]", ";", "foreach", "(", "$", "invalidExtensions", "as", "$", "needle", ")", "{", "if", "(", "stristr", "(", "$", "line", "->", "URL", ",", "$", "needle", ")", ")", "{", "return", "false", ";", "}", "}", "if", "(", "$", "line", "->", "HeaderUserAgent", "===", "'MissionControlAgent'", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Line object from logs @param object $line @return bool
[ "Line", "object", "from", "logs" ]
4e85f0b729329783b34e35d90abba2807899ff58
https://github.com/GrafiteInc/Mission-Control-Package/blob/4e85f0b729329783b34e35d90abba2807899ff58/src/Analyzers/TrafficAnalyzer.php#L113-L140
18,585
lode/fem
src/response.php
response.send_status
public static function send_status($code) { if (!isset(static::$status_messages[$code])) { $code = self::STATUS_INTERNAL_SERVER_ERROR; } http_response_code($code); }
php
public static function send_status($code) { if (!isset(static::$status_messages[$code])) { $code = self::STATUS_INTERNAL_SERVER_ERROR; } http_response_code($code); }
[ "public", "static", "function", "send_status", "(", "$", "code", ")", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "status_messages", "[", "$", "code", "]", ")", ")", "{", "$", "code", "=", "self", "::", "STATUS_INTERNAL_SERVER_ERROR", ";", "}", "http_response_code", "(", "$", "code", ")", ";", "}" ]
send a status code to the browser @param int $code @return void
[ "send", "a", "status", "code", "to", "the", "browser" ]
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/response.php#L48-L54
18,586
lode/fem
src/response.php
response.get_status_message
public static function get_status_message($code) { if (!isset(static::$status_messages[$code])) { $code = self::STATUS_INTERNAL_SERVER_ERROR; } $message = static::$status_messages[$code]; return $message; }
php
public static function get_status_message($code) { if (!isset(static::$status_messages[$code])) { $code = self::STATUS_INTERNAL_SERVER_ERROR; } $message = static::$status_messages[$code]; return $message; }
[ "public", "static", "function", "get_status_message", "(", "$", "code", ")", "{", "if", "(", "!", "isset", "(", "static", "::", "$", "status_messages", "[", "$", "code", "]", ")", ")", "{", "$", "code", "=", "self", "::", "STATUS_INTERNAL_SERVER_ERROR", ";", "}", "$", "message", "=", "static", "::", "$", "status_messages", "[", "$", "code", "]", ";", "return", "$", "message", ";", "}" ]
get the describing message of the status code @param int $code i.e. 404 @return string i.e. 'Not found'
[ "get", "the", "describing", "message", "of", "the", "status", "code" ]
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/response.php#L62-L69
18,587
lode/fem
src/response.php
response.download
public static function download($output, $content_type='text/plain', $filename=null) { $filename_postfix = ($filename) ? '; filename="'.$filename.'"' : ''; // force download header('Content-Type: '.$content_type.'; charset=utf-8'); header('Content-Disposition: attachment'.$filename_postfix); // write to browser echo $output; }
php
public static function download($output, $content_type='text/plain', $filename=null) { $filename_postfix = ($filename) ? '; filename="'.$filename.'"' : ''; // force download header('Content-Type: '.$content_type.'; charset=utf-8'); header('Content-Disposition: attachment'.$filename_postfix); // write to browser echo $output; }
[ "public", "static", "function", "download", "(", "$", "output", ",", "$", "content_type", "=", "'text/plain'", ",", "$", "filename", "=", "null", ")", "{", "$", "filename_postfix", "=", "(", "$", "filename", ")", "?", "'; filename=\"'", ".", "$", "filename", ".", "'\"'", ":", "''", ";", "// force download", "header", "(", "'Content-Type: '", ".", "$", "content_type", ".", "'; charset=utf-8'", ")", ";", "header", "(", "'Content-Disposition: attachment'", ".", "$", "filename_postfix", ")", ";", "// write to browser", "echo", "$", "output", ";", "}" ]
force the user to download certain output @param string $output @param string $content_type optional, defaults to 'text/plain' @param string $filename optional, suggested filename when saving downloaded content @return void
[ "force", "the", "user", "to", "download", "certain", "output" ]
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/response.php#L79-L88
18,588
praxisnetau/silverware-spam-guard
src/Extensions/FormExtension.php
FormExtension.enableSpamProtection
public function enableSpamProtection($args = []) { // Obtain Spam Guard Instance: if ($guard = $this->getSpamGuardInstance($args)) { // Define Field Name and Title: $name = isset($args['name']) ? $args['name'] : $guard->getDefaultName(); $title = isset($args['title']) ? $args['title'] : $guard->getDefaultTitle(); // Obtain Spam Guard Form Field: if ($field = $guard->getFormField($name, $title)) { // Link Field with Form: $field->setForm($this->owner); // Add Field to Form: if (isset($args['insertBefore'])) { // Insert Before Specified Field: $this->owner->Fields()->insertBefore($field, $args['insertBefore']); } elseif (isset($args['insertAfter'])) { // Insert After Specified Field: $this->owner->Fields()->insertAfter($field, $args['insertAfter']); } else { // Push Field to End of List: $this->owner->Fields()->push($field); } } } // Answer Extended Form: return $this->owner; }
php
public function enableSpamProtection($args = []) { // Obtain Spam Guard Instance: if ($guard = $this->getSpamGuardInstance($args)) { // Define Field Name and Title: $name = isset($args['name']) ? $args['name'] : $guard->getDefaultName(); $title = isset($args['title']) ? $args['title'] : $guard->getDefaultTitle(); // Obtain Spam Guard Form Field: if ($field = $guard->getFormField($name, $title)) { // Link Field with Form: $field->setForm($this->owner); // Add Field to Form: if (isset($args['insertBefore'])) { // Insert Before Specified Field: $this->owner->Fields()->insertBefore($field, $args['insertBefore']); } elseif (isset($args['insertAfter'])) { // Insert After Specified Field: $this->owner->Fields()->insertAfter($field, $args['insertAfter']); } else { // Push Field to End of List: $this->owner->Fields()->push($field); } } } // Answer Extended Form: return $this->owner; }
[ "public", "function", "enableSpamProtection", "(", "$", "args", "=", "[", "]", ")", "{", "// Obtain Spam Guard Instance:", "if", "(", "$", "guard", "=", "$", "this", "->", "getSpamGuardInstance", "(", "$", "args", ")", ")", "{", "// Define Field Name and Title:", "$", "name", "=", "isset", "(", "$", "args", "[", "'name'", "]", ")", "?", "$", "args", "[", "'name'", "]", ":", "$", "guard", "->", "getDefaultName", "(", ")", ";", "$", "title", "=", "isset", "(", "$", "args", "[", "'title'", "]", ")", "?", "$", "args", "[", "'title'", "]", ":", "$", "guard", "->", "getDefaultTitle", "(", ")", ";", "// Obtain Spam Guard Form Field:", "if", "(", "$", "field", "=", "$", "guard", "->", "getFormField", "(", "$", "name", ",", "$", "title", ")", ")", "{", "// Link Field with Form:", "$", "field", "->", "setForm", "(", "$", "this", "->", "owner", ")", ";", "// Add Field to Form:", "if", "(", "isset", "(", "$", "args", "[", "'insertBefore'", "]", ")", ")", "{", "// Insert Before Specified Field:", "$", "this", "->", "owner", "->", "Fields", "(", ")", "->", "insertBefore", "(", "$", "field", ",", "$", "args", "[", "'insertBefore'", "]", ")", ";", "}", "elseif", "(", "isset", "(", "$", "args", "[", "'insertAfter'", "]", ")", ")", "{", "// Insert After Specified Field:", "$", "this", "->", "owner", "->", "Fields", "(", ")", "->", "insertAfter", "(", "$", "field", ",", "$", "args", "[", "'insertAfter'", "]", ")", ";", "}", "else", "{", "// Push Field to End of List:", "$", "this", "->", "owner", "->", "Fields", "(", ")", "->", "push", "(", "$", "field", ")", ";", "}", "}", "}", "// Answer Extended Form:", "return", "$", "this", "->", "owner", ";", "}" ]
Enables spam guard protection for the extended form. @param array $args @return Form
[ "Enables", "spam", "guard", "protection", "for", "the", "extended", "form", "." ]
c5f8836a09141bd675173892a1e3d8c8cc8c1886
https://github.com/praxisnetau/silverware-spam-guard/blob/c5f8836a09141bd675173892a1e3d8c8cc8c1886/src/Extensions/FormExtension.php#L41-L89
18,589
ClanCats/Core
src/bundles/Database/Query/Select.php
Query_Select.fields
public function fields( $fields ) { if ( !is_array( $fields ) && !is_null( $fields ) ) { $fields = array( $fields ); } // do nothing if we get nothing if ( empty( $fields ) || $fields == array( '*' ) ) { $this->fields = array(); return $this; } $this->fields = $fields; // return self so we can continue running the next function return $this; }
php
public function fields( $fields ) { if ( !is_array( $fields ) && !is_null( $fields ) ) { $fields = array( $fields ); } // do nothing if we get nothing if ( empty( $fields ) || $fields == array( '*' ) ) { $this->fields = array(); return $this; } $this->fields = $fields; // return self so we can continue running the next function return $this; }
[ "public", "function", "fields", "(", "$", "fields", ")", "{", "if", "(", "!", "is_array", "(", "$", "fields", ")", "&&", "!", "is_null", "(", "$", "fields", ")", ")", "{", "$", "fields", "=", "array", "(", "$", "fields", ")", ";", "}", "// do nothing if we get nothing", "if", "(", "empty", "(", "$", "fields", ")", "||", "$", "fields", "==", "array", "(", "'*'", ")", ")", "{", "$", "this", "->", "fields", "=", "array", "(", ")", ";", "return", "$", "this", ";", "}", "$", "this", "->", "fields", "=", "$", "fields", ";", "// return self so we can continue running the next function", "return", "$", "this", ";", "}" ]
Set the select fields @param array $values @return self
[ "Set", "the", "select", "fields" ]
9f6ec72c1a439de4b253d0223f1029f7f85b6ef8
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query/Select.php#L87-L104
18,590
ClanCats/Core
src/bundles/Database/Query/Select.php
Query_Select.add_fields
public function add_fields( $fields ) { if ( !is_array( $fields ) ) { $fields = array( $fields ); } // merge the new values with the existing ones. $this->fields = array_merge( $this->fields, $fields ); // return self so we can continue running the next function return $this; }
php
public function add_fields( $fields ) { if ( !is_array( $fields ) ) { $fields = array( $fields ); } // merge the new values with the existing ones. $this->fields = array_merge( $this->fields, $fields ); // return self so we can continue running the next function return $this; }
[ "public", "function", "add_fields", "(", "$", "fields", ")", "{", "if", "(", "!", "is_array", "(", "$", "fields", ")", ")", "{", "$", "fields", "=", "array", "(", "$", "fields", ")", ";", "}", "// merge the new values with the existing ones.", "$", "this", "->", "fields", "=", "array_merge", "(", "$", "this", "->", "fields", ",", "$", "fields", ")", ";", "// return self so we can continue running the next function", "return", "$", "this", ";", "}" ]
Add select fields @param array $values @return self
[ "Add", "select", "fields" ]
9f6ec72c1a439de4b253d0223f1029f7f85b6ef8
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query/Select.php#L112-L124
18,591
ClanCats/Core
src/bundles/Database/Query/Select.php
Query_Select.order_by
public function order_by( $cols, $order = 'asc' ) { if ( !is_array( $cols ) ) { $this->orders[] = array( $cols, $order ); return $this; } else { foreach( $cols as $key => $col ) { if ( is_numeric( $key ) ) { $this->orders[] = array( $col, $order ); } else { $this->orders[] = array( $key, $col ); } } } return $this; }
php
public function order_by( $cols, $order = 'asc' ) { if ( !is_array( $cols ) ) { $this->orders[] = array( $cols, $order ); return $this; } else { foreach( $cols as $key => $col ) { if ( is_numeric( $key ) ) { $this->orders[] = array( $col, $order ); } else { $this->orders[] = array( $key, $col ); } } } return $this; }
[ "public", "function", "order_by", "(", "$", "cols", ",", "$", "order", "=", "'asc'", ")", "{", "if", "(", "!", "is_array", "(", "$", "cols", ")", ")", "{", "$", "this", "->", "orders", "[", "]", "=", "array", "(", "$", "cols", ",", "$", "order", ")", ";", "return", "$", "this", ";", "}", "else", "{", "foreach", "(", "$", "cols", "as", "$", "key", "=>", "$", "col", ")", "{", "if", "(", "is_numeric", "(", "$", "key", ")", ")", "{", "$", "this", "->", "orders", "[", "]", "=", "array", "(", "$", "col", ",", "$", "order", ")", ";", "}", "else", "{", "$", "this", "->", "orders", "[", "]", "=", "array", "(", "$", "key", ",", "$", "col", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Set the order parameters @param mixed $cols @param string $order @return self
[ "Set", "the", "order", "parameters" ]
9f6ec72c1a439de4b253d0223f1029f7f85b6ef8
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query/Select.php#L133-L155
18,592
ClanCats/Core
src/bundles/Database/Query/Select.php
Query_Select.group_by
public function group_by( $key ) { if ( !is_array( $key ) ) { $key = array( $key ); } foreach( $key as $group_key ) { $this->groups[] = $group_key; } return $this; }
php
public function group_by( $key ) { if ( !is_array( $key ) ) { $key = array( $key ); } foreach( $key as $group_key ) { $this->groups[] = $group_key; } return $this; }
[ "public", "function", "group_by", "(", "$", "key", ")", "{", "if", "(", "!", "is_array", "(", "$", "key", ")", ")", "{", "$", "key", "=", "array", "(", "$", "key", ")", ";", "}", "foreach", "(", "$", "key", "as", "$", "group_key", ")", "{", "$", "this", "->", "groups", "[", "]", "=", "$", "group_key", ";", "}", "return", "$", "this", ";", "}" ]
Add group by stuff @param mixed $key By passing an array you can add multiple groups @return self
[ "Add", "group", "by", "stuff" ]
9f6ec72c1a439de4b253d0223f1029f7f85b6ef8
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query/Select.php#L163-L176
18,593
ClanCats/Core
src/bundles/Database/Query/Select.php
Query_Select.column
public function column( $column, $name = null ) { return $this->fields( $column )->one( $name )->$column; }
php
public function column( $column, $name = null ) { return $this->fields( $column )->one( $name )->$column; }
[ "public", "function", "column", "(", "$", "column", ",", "$", "name", "=", "null", ")", "{", "return", "$", "this", "->", "fields", "(", "$", "column", ")", "->", "one", "(", "$", "name", ")", "->", "$", "column", ";", "}" ]
Just get a single value from the db @param string $column @param string $name @return mixed
[ "Just", "get", "a", "single", "value", "from", "the", "db" ]
9f6ec72c1a439de4b253d0223f1029f7f85b6ef8
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Database/Query/Select.php#L421-L424
18,594
bosha/PTel
src/PTel.php
PTel.login
public function login($user, $pass, $maxtimeout = 10) { try { $this->expect('((U|u)ser|(L|l)ogin)((N|n)ame|)(:|)', $user); $this->expect('(P|p)ass((W|w)ord|)(:|)', $pass); } catch (TelnetException $e) { throw new TelnetException('Could not find password request. Login failed.'); } $timestart = time(); $buff = ''; while (true) { $buff = $this->recvLine(); $timerun = time() - $timestart; if (preg_match("/(fail|wrong|incorrect|failed)/i", $buff)) { throw new TelnetException("Username or password wrong! Login failed"); } if (preg_match("/(#|>|\$)/", $buff)) { break; } if ($timerun >= $maxtimeout) { throw new TelnetException("Could not get reply from device. Login failed."); } } $this->recvAll(); $lines = explode("\n", $this->getBuffer()); $prompt = array_slice($lines, -1); $this->prompt = $prompt[0]; return $this; }
php
public function login($user, $pass, $maxtimeout = 10) { try { $this->expect('((U|u)ser|(L|l)ogin)((N|n)ame|)(:|)', $user); $this->expect('(P|p)ass((W|w)ord|)(:|)', $pass); } catch (TelnetException $e) { throw new TelnetException('Could not find password request. Login failed.'); } $timestart = time(); $buff = ''; while (true) { $buff = $this->recvLine(); $timerun = time() - $timestart; if (preg_match("/(fail|wrong|incorrect|failed)/i", $buff)) { throw new TelnetException("Username or password wrong! Login failed"); } if (preg_match("/(#|>|\$)/", $buff)) { break; } if ($timerun >= $maxtimeout) { throw new TelnetException("Could not get reply from device. Login failed."); } } $this->recvAll(); $lines = explode("\n", $this->getBuffer()); $prompt = array_slice($lines, -1); $this->prompt = $prompt[0]; return $this; }
[ "public", "function", "login", "(", "$", "user", ",", "$", "pass", ",", "$", "maxtimeout", "=", "10", ")", "{", "try", "{", "$", "this", "->", "expect", "(", "'((U|u)ser|(L|l)ogin)((N|n)ame|)(:|)'", ",", "$", "user", ")", ";", "$", "this", "->", "expect", "(", "'(P|p)ass((W|w)ord|)(:|)'", ",", "$", "pass", ")", ";", "}", "catch", "(", "TelnetException", "$", "e", ")", "{", "throw", "new", "TelnetException", "(", "'Could not find password request. Login failed.'", ")", ";", "}", "$", "timestart", "=", "time", "(", ")", ";", "$", "buff", "=", "''", ";", "while", "(", "true", ")", "{", "$", "buff", "=", "$", "this", "->", "recvLine", "(", ")", ";", "$", "timerun", "=", "time", "(", ")", "-", "$", "timestart", ";", "if", "(", "preg_match", "(", "\"/(fail|wrong|incorrect|failed)/i\"", ",", "$", "buff", ")", ")", "{", "throw", "new", "TelnetException", "(", "\"Username or password wrong! Login failed\"", ")", ";", "}", "if", "(", "preg_match", "(", "\"/(#|>|\\$)/\"", ",", "$", "buff", ")", ")", "{", "break", ";", "}", "if", "(", "$", "timerun", ">=", "$", "maxtimeout", ")", "{", "throw", "new", "TelnetException", "(", "\"Could not get reply from device. Login failed.\"", ")", ";", "}", "}", "$", "this", "->", "recvAll", "(", ")", ";", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "this", "->", "getBuffer", "(", ")", ")", ";", "$", "prompt", "=", "array_slice", "(", "$", "lines", ",", "-", "1", ")", ";", "$", "this", "->", "prompt", "=", "$", "prompt", "[", "0", "]", ";", "return", "$", "this", ";", "}" ]
Login to device. @param string $user Username @param string $pass Password @throws TelnetException On wrong username/password @throws SocketClientException On socket communication error @return $this Current instance on success
[ "Login", "to", "device", "." ]
049d72f8faaf6c2548353e715e06ad1f28c756b5
https://github.com/bosha/PTel/blob/049d72f8faaf6c2548353e715e06ad1f28c756b5/src/PTel.php#L180-L212
18,595
bosha/PTel
src/PTel.php
PTel.send
public function send($data, $newline = true) { if (!$this->_sock) { throw new SocketClientException("Connection unexpectedly closed!"); } if ($newline) { $data = $data.$this->retcarriage; } if (! $wr = fwrite($this->_sock, $data)) { throw new SocketClientException('Error while sending data!'); } return $wr; }
php
public function send($data, $newline = true) { if (!$this->_sock) { throw new SocketClientException("Connection unexpectedly closed!"); } if ($newline) { $data = $data.$this->retcarriage; } if (! $wr = fwrite($this->_sock, $data)) { throw new SocketClientException('Error while sending data!'); } return $wr; }
[ "public", "function", "send", "(", "$", "data", ",", "$", "newline", "=", "true", ")", "{", "if", "(", "!", "$", "this", "->", "_sock", ")", "{", "throw", "new", "SocketClientException", "(", "\"Connection unexpectedly closed!\"", ")", ";", "}", "if", "(", "$", "newline", ")", "{", "$", "data", "=", "$", "data", ".", "$", "this", "->", "retcarriage", ";", "}", "if", "(", "!", "$", "wr", "=", "fwrite", "(", "$", "this", "->", "_sock", ",", "$", "data", ")", ")", "{", "throw", "new", "SocketClientException", "(", "'Error while sending data!'", ")", ";", "}", "return", "$", "wr", ";", "}" ]
Send data to socket @param $data mixed Can be anything: string, int, hex, binary @param $newline bool Determines send or not carriage return @throws SocketClientException On socket communication error @return int Bytes written
[ "Send", "data", "to", "socket" ]
049d72f8faaf6c2548353e715e06ad1f28c756b5
https://github.com/bosha/PTel/blob/049d72f8faaf6c2548353e715e06ad1f28c756b5/src/PTel.php#L224-L231
18,596
bosha/PTel
src/PTel.php
PTel.recvChr
public function recvChr() { if (!$this->_sock) { throw new SocketClientException("Connection gone!"); } $char = fgetc($this->_sock); if ($this->stream_eof()) { return false; } if ($char === TEL_IAC && $this->negotiation_enabled) { $this->_negotiate(fgetc($this->_sock)); return ""; } $this->_buff .= $char; return $char; }
php
public function recvChr() { if (!$this->_sock) { throw new SocketClientException("Connection gone!"); } $char = fgetc($this->_sock); if ($this->stream_eof()) { return false; } if ($char === TEL_IAC && $this->negotiation_enabled) { $this->_negotiate(fgetc($this->_sock)); return ""; } $this->_buff .= $char; return $char; }
[ "public", "function", "recvChr", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_sock", ")", "{", "throw", "new", "SocketClientException", "(", "\"Connection gone!\"", ")", ";", "}", "$", "char", "=", "fgetc", "(", "$", "this", "->", "_sock", ")", ";", "if", "(", "$", "this", "->", "stream_eof", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "char", "===", "TEL_IAC", "&&", "$", "this", "->", "negotiation_enabled", ")", "{", "$", "this", "->", "_negotiate", "(", "fgetc", "(", "$", "this", "->", "_sock", ")", ")", ";", "return", "\"\"", ";", "}", "$", "this", "->", "_buff", ".=", "$", "char", ";", "return", "$", "char", ";", "}" ]
Get char from socket or call negotiation method if found telnet negotiaton command. @throws SocketClientException On socket communication error @return char Char from socket connection
[ "Get", "char", "from", "socket", "or", "call", "negotiation", "method", "if", "found", "telnet", "negotiaton", "command", "." ]
049d72f8faaf6c2548353e715e06ad1f28c756b5
https://github.com/bosha/PTel/blob/049d72f8faaf6c2548353e715e06ad1f28c756b5/src/PTel.php#L240-L250
18,597
bosha/PTel
src/PTel.php
PTel.recvLine
public function recvLine($delimiter = "\n") { $str = ''; while (!$this->stream_eof()) { $char = $this->recvChr(); $str .= $char; if ($char === false) { return $str; } if (strpos($str, $delimiter) !== false) { return $str; } } return $str; }
php
public function recvLine($delimiter = "\n") { $str = ''; while (!$this->stream_eof()) { $char = $this->recvChr(); $str .= $char; if ($char === false) { return $str; } if (strpos($str, $delimiter) !== false) { return $str; } } return $str; }
[ "public", "function", "recvLine", "(", "$", "delimiter", "=", "\"\\n\"", ")", "{", "$", "str", "=", "''", ";", "while", "(", "!", "$", "this", "->", "stream_eof", "(", ")", ")", "{", "$", "char", "=", "$", "this", "->", "recvChr", "(", ")", ";", "$", "str", ".=", "$", "char", ";", "if", "(", "$", "char", "===", "false", ")", "{", "return", "$", "str", ";", "}", "if", "(", "strpos", "(", "$", "str", ",", "$", "delimiter", ")", "!==", "false", ")", "{", "return", "$", "str", ";", "}", "}", "return", "$", "str", ";", "}" ]
Receive line from connection @param string $delimiter Line delimiter @throws SocketClientException On socket communication error @return string String from socket connection
[ "Receive", "line", "from", "connection" ]
049d72f8faaf6c2548353e715e06ad1f28c756b5
https://github.com/bosha/PTel/blob/049d72f8faaf6c2548353e715e06ad1f28c756b5/src/PTel.php#L260-L269
18,598
bosha/PTel
src/PTel.php
PTel.findAll
public function findAll($str) { $this->recvAll(); $output_as_array = explode($this->retcarriage, $this->getBuffer()); foreach ($output_as_array as $line) { if (preg_match("/{$str}/", $line, $matches)) { return $matches[0]; } } return false; }
php
public function findAll($str) { $this->recvAll(); $output_as_array = explode($this->retcarriage, $this->getBuffer()); foreach ($output_as_array as $line) { if (preg_match("/{$str}/", $line, $matches)) { return $matches[0]; } } return false; }
[ "public", "function", "findAll", "(", "$", "str", ")", "{", "$", "this", "->", "recvAll", "(", ")", ";", "$", "output_as_array", "=", "explode", "(", "$", "this", "->", "retcarriage", ",", "$", "this", "->", "getBuffer", "(", ")", ")", ";", "foreach", "(", "$", "output_as_array", "as", "$", "line", ")", "{", "if", "(", "preg_match", "(", "\"/{$str}/\"", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "return", "$", "matches", "[", "0", "]", ";", "}", "}", "return", "false", ";", "}" ]
Receive all data, and search through global buffer @param string $str String to search (regex supported) @return bool|string False if not found, string contains search
[ "Receive", "all", "data", "and", "search", "through", "global", "buffer" ]
049d72f8faaf6c2548353e715e06ad1f28c756b5
https://github.com/bosha/PTel/blob/049d72f8faaf6c2548353e715e06ad1f28c756b5/src/PTel.php#L309-L318
18,599
bosha/PTel
src/PTel.php
PTel.expect
public function expect($str, $cmd, $newline = true, $maxtimeout = 10) { if ($this->waitFor($str, $maxtimeout)) { $this->send($cmd, $newline); return true; } }
php
public function expect($str, $cmd, $newline = true, $maxtimeout = 10) { if ($this->waitFor($str, $maxtimeout)) { $this->send($cmd, $newline); return true; } }
[ "public", "function", "expect", "(", "$", "str", ",", "$", "cmd", ",", "$", "newline", "=", "true", ",", "$", "maxtimeout", "=", "10", ")", "{", "if", "(", "$", "this", "->", "waitFor", "(", "$", "str", ",", "$", "maxtimeout", ")", ")", "{", "$", "this", "->", "send", "(", "$", "cmd", ",", "$", "newline", ")", ";", "return", "true", ";", "}", "}" ]
Search for given occurance and send given command if found @param string $str String/regexp for search @param string $cmd Command to send @param bool $newline Send new line character @param int $maxtimeout Maximum timeout for waiting sought string @throws SocketClientException On socket communication error @throws TelnetException If wait timeout is reached @return bool True on search and send success, false otherwise
[ "Search", "for", "given", "occurance", "and", "send", "given", "command", "if", "found" ]
049d72f8faaf6c2548353e715e06ad1f28c756b5
https://github.com/bosha/PTel/blob/049d72f8faaf6c2548353e715e06ad1f28c756b5/src/PTel.php#L332-L337