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 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
mirko-pagliai/me-cms | src/Plugin.php | Plugin.setWritableDirs | protected function setWritableDirs()
{
$dirs = array_unique(array_filter(array_merge(Configure::read('WRITABLE_DIRS', []), [
getConfig('Assets.target'),
getConfigOrFail('DatabaseBackup.target'),
getConfigOrFail('Thumber.target'),
BANNERS,
LOGIN_RECORDS,
PHOTOS,
USER_PICTURES,
])));
return Configure::write('WRITABLE_DIRS', $dirs) ? $dirs : false;
} | php | protected function setWritableDirs()
{
$dirs = array_unique(array_filter(array_merge(Configure::read('WRITABLE_DIRS', []), [
getConfig('Assets.target'),
getConfigOrFail('DatabaseBackup.target'),
getConfigOrFail('Thumber.target'),
BANNERS,
LOGIN_RECORDS,
PHOTOS,
USER_PICTURES,
])));
return Configure::write('WRITABLE_DIRS', $dirs) ? $dirs : false;
} | [
"protected",
"function",
"setWritableDirs",
"(",
")",
"{",
"$",
"dirs",
"=",
"array_unique",
"(",
"array_filter",
"(",
"array_merge",
"(",
"Configure",
"::",
"read",
"(",
"'WRITABLE_DIRS'",
",",
"[",
"]",
")",
",",
"[",
"getConfig",
"(",
"'Assets.target'",
"... | Sets directories to be created and must be writable
@return array | [
"Sets",
"directories",
"to",
"be",
"created",
"and",
"must",
"be",
"writable"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Plugin.php#L160-L173 | train |
mirko-pagliai/me-cms | src/Controller/Admin/UsersController.php | UsersController.changePassword | public function changePassword()
{
$user = $this->Users->get($this->Auth->user('id'));
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
//Sends email
$this->getMailer('MeCms.User')->send('changePassword', [$user]);
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['_name' => 'dashboard']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('user'));
} | php | public function changePassword()
{
$user = $this->Users->get($this->Auth->user('id'));
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->request->getData());
if ($this->Users->save($user)) {
//Sends email
$this->getMailer('MeCms.User')->send('changePassword', [$user]);
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['_name' => 'dashboard']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('user'));
} | [
"public",
"function",
"changePassword",
"(",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"Users",
"->",
"get",
"(",
"$",
"this",
"->",
"Auth",
"->",
"user",
"(",
"'id'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"is",
"(",
... | Changes the user's password
@return \Cake\Network\Response|null|void
@uses MeCms\Mailer\UserMailer::changePassword() | [
"Changes",
"the",
"user",
"s",
"password"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/Admin/UsersController.php#L224-L243 | train |
mirko-pagliai/me-cms | src/Controller/Admin/UsersController.php | UsersController.changePicture | public function changePicture()
{
$id = $this->Auth->user('id');
if ($this->request->getData('file')) {
//Deletes any picture that already exists
foreach (((new Folder(USER_PICTURES))->find($id . '\..+')) as $filename) {
@unlink(USER_PICTURES . $filename);
}
$filename = sprintf('%s.%s', $id, pathinfo($this->request->getData('file')['tmp_name'], PATHINFO_EXTENSION));
$uploaded = $this->Uploader->set($this->request->getData('file'))
->mimetype('image')
->save(USER_PICTURES, $filename);
if (!$uploaded) {
return $this->setUploadError($this->Uploader->getError());
}
//Updates the authentication data and clears similar thumbnails
$this->Auth->setUser(array_merge($this->Auth->user(), ['picture' => $uploaded]));
(new ThumbManager)->clear($uploaded);
}
} | php | public function changePicture()
{
$id = $this->Auth->user('id');
if ($this->request->getData('file')) {
//Deletes any picture that already exists
foreach (((new Folder(USER_PICTURES))->find($id . '\..+')) as $filename) {
@unlink(USER_PICTURES . $filename);
}
$filename = sprintf('%s.%s', $id, pathinfo($this->request->getData('file')['tmp_name'], PATHINFO_EXTENSION));
$uploaded = $this->Uploader->set($this->request->getData('file'))
->mimetype('image')
->save(USER_PICTURES, $filename);
if (!$uploaded) {
return $this->setUploadError($this->Uploader->getError());
}
//Updates the authentication data and clears similar thumbnails
$this->Auth->setUser(array_merge($this->Auth->user(), ['picture' => $uploaded]));
(new ThumbManager)->clear($uploaded);
}
} | [
"public",
"function",
"changePicture",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"Auth",
"->",
"user",
"(",
"'id'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"getData",
"(",
"'file'",
")",
")",
"{",
"//Deletes any picture that al... | Changes the user's picture
@return \Cake\Network\Response|null|void
@uses MeCms\Controller\AppController::setUploadError()
@uses MeTools\Controller\Component\UploaderComponent | [
"Changes",
"the",
"user",
"s",
"picture"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/Admin/UsersController.php#L251-L275 | train |
mirko-pagliai/me-cms | src/Controller/Admin/UsersController.php | UsersController.lastLogin | public function lastLogin()
{
//Checks if login logs are enabled
if (!getConfig('users.login_log')) {
$this->Flash->error(I18N_DISABLED);
return $this->redirect(['_name' => 'dashboard']);
}
$this->set('loginLog', $this->LoginRecorder->setConfig('user', $this->Auth->user('id'))->read());
} | php | public function lastLogin()
{
//Checks if login logs are enabled
if (!getConfig('users.login_log')) {
$this->Flash->error(I18N_DISABLED);
return $this->redirect(['_name' => 'dashboard']);
}
$this->set('loginLog', $this->LoginRecorder->setConfig('user', $this->Auth->user('id'))->read());
} | [
"public",
"function",
"lastLogin",
"(",
")",
"{",
"//Checks if login logs are enabled",
"if",
"(",
"!",
"getConfig",
"(",
"'users.login_log'",
")",
")",
"{",
"$",
"this",
"->",
"Flash",
"->",
"error",
"(",
"I18N_DISABLED",
")",
";",
"return",
"$",
"this",
"-... | Displays the login log
@return \Cake\Network\Response|null|void
@uses MeCms\Controller\Component\LoginRecorderComponent::read() | [
"Displays",
"the",
"login",
"log"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/Admin/UsersController.php#L282-L292 | train |
nails/module-console | src/Command/Base.php | Base.setStyles | public function setStyles(OutputInterface $oOutput): void
{
$oWarningStyle = new OutputFormatterStyle('white', 'yellow');
$oOutput->getFormatter()->setStyle('warning', $oWarningStyle);
} | php | public function setStyles(OutputInterface $oOutput): void
{
$oWarningStyle = new OutputFormatterStyle('white', 'yellow');
$oOutput->getFormatter()->setStyle('warning', $oWarningStyle);
} | [
"public",
"function",
"setStyles",
"(",
"OutputInterface",
"$",
"oOutput",
")",
":",
"void",
"{",
"$",
"oWarningStyle",
"=",
"new",
"OutputFormatterStyle",
"(",
"'white'",
",",
"'yellow'",
")",
";",
"$",
"oOutput",
"->",
"getFormatter",
"(",
")",
"->",
"setS... | Adds additional styles to the output
@param OutputInterface $oOutput The output interface | [
"Adds",
"additional",
"styles",
"to",
"the",
"output"
] | bef013213c914af33172293a386e2738ceedc12d | https://github.com/nails/module-console/blob/bef013213c914af33172293a386e2738ceedc12d/src/Command/Base.php#L56-L60 | train |
nails/module-console | src/Command/Base.php | Base.confirm | protected function confirm($sQuestion, $bDefault)
{
$sQuestion = is_array($sQuestion) ? implode("\n", $sQuestion) : $sQuestion;
$oHelper = $this->getHelper('question');
$sDefault = (bool) $bDefault ? 'Y' : 'N';
$oQuestion = new ConfirmationQuestion($sQuestion . ' [' . $sDefault . ']: ', $bDefault);
return $oHelper->ask($this->oInput, $this->oOutput, $oQuestion);
} | php | protected function confirm($sQuestion, $bDefault)
{
$sQuestion = is_array($sQuestion) ? implode("\n", $sQuestion) : $sQuestion;
$oHelper = $this->getHelper('question');
$sDefault = (bool) $bDefault ? 'Y' : 'N';
$oQuestion = new ConfirmationQuestion($sQuestion . ' [' . $sDefault . ']: ', $bDefault);
return $oHelper->ask($this->oInput, $this->oOutput, $oQuestion);
} | [
"protected",
"function",
"confirm",
"(",
"$",
"sQuestion",
",",
"$",
"bDefault",
")",
"{",
"$",
"sQuestion",
"=",
"is_array",
"(",
"$",
"sQuestion",
")",
"?",
"implode",
"(",
"\"\\n\"",
",",
"$",
"sQuestion",
")",
":",
"$",
"sQuestion",
";",
"$",
"oHel... | Confirms something with the user
@param string $sQuestion The question to confirm
@param boolean $bDefault The default answer
@return string | [
"Confirms",
"something",
"with",
"the",
"user"
] | bef013213c914af33172293a386e2738ceedc12d | https://github.com/nails/module-console/blob/bef013213c914af33172293a386e2738ceedc12d/src/Command/Base.php#L72-L80 | train |
nails/module-console | src/Command/Base.php | Base.ask | protected function ask($mQuestion, $sDefault)
{
$mQuestion = is_array($mQuestion) ? implode("\n", $mQuestion) : $mQuestion;
$oHelper = $this->getHelper('question');
$oQuestion = new Question($mQuestion . ' [' . $sDefault . ']: ', $sDefault);
return $oHelper->ask($this->oInput, $this->oOutput, $oQuestion);
} | php | protected function ask($mQuestion, $sDefault)
{
$mQuestion = is_array($mQuestion) ? implode("\n", $mQuestion) : $mQuestion;
$oHelper = $this->getHelper('question');
$oQuestion = new Question($mQuestion . ' [' . $sDefault . ']: ', $sDefault);
return $oHelper->ask($this->oInput, $this->oOutput, $oQuestion);
} | [
"protected",
"function",
"ask",
"(",
"$",
"mQuestion",
",",
"$",
"sDefault",
")",
"{",
"$",
"mQuestion",
"=",
"is_array",
"(",
"$",
"mQuestion",
")",
"?",
"implode",
"(",
"\"\\n\"",
",",
"$",
"mQuestion",
")",
":",
"$",
"mQuestion",
";",
"$",
"oHelper"... | Asks the user for some input
@param string $mQuestion The question to ask
@param mixed $sDefault The default answer
@return string | [
"Asks",
"the",
"user",
"for",
"some",
"input"
] | bef013213c914af33172293a386e2738ceedc12d | https://github.com/nails/module-console/blob/bef013213c914af33172293a386e2738ceedc12d/src/Command/Base.php#L92-L99 | train |
nails/module-console | src/Command/Base.php | Base.outputBlock | protected function outputBlock(array $aLines, string $sType): void
{
$aLengths = array_map('strlen', $aLines);
$iMaxLength = max($aLengths);
$this->oOutput->writeln('<' . $sType . '> ' . str_pad('', $iMaxLength, ' ') . ' </' . $sType . '>');
foreach ($aLines as $sLine) {
$this->oOutput->writeln('<' . $sType . '> ' . str_pad($sLine, $iMaxLength, ' ') . ' </' . $sType . '>');
}
$this->oOutput->writeln('<' . $sType . '> ' . str_pad('', $iMaxLength, ' ') . ' </' . $sType . '>');
} | php | protected function outputBlock(array $aLines, string $sType): void
{
$aLengths = array_map('strlen', $aLines);
$iMaxLength = max($aLengths);
$this->oOutput->writeln('<' . $sType . '> ' . str_pad('', $iMaxLength, ' ') . ' </' . $sType . '>');
foreach ($aLines as $sLine) {
$this->oOutput->writeln('<' . $sType . '> ' . str_pad($sLine, $iMaxLength, ' ') . ' </' . $sType . '>');
}
$this->oOutput->writeln('<' . $sType . '> ' . str_pad('', $iMaxLength, ' ') . ' </' . $sType . '>');
} | [
"protected",
"function",
"outputBlock",
"(",
"array",
"$",
"aLines",
",",
"string",
"$",
"sType",
")",
":",
"void",
"{",
"$",
"aLengths",
"=",
"array_map",
"(",
"'strlen'",
",",
"$",
"aLines",
")",
";",
"$",
"iMaxLength",
"=",
"max",
"(",
"$",
"aLength... | Renders an coloured block
@param array $aLines The lines to render
@param string $sType The type of block to render | [
"Renders",
"an",
"coloured",
"block"
] | bef013213c914af33172293a386e2738ceedc12d | https://github.com/nails/module-console/blob/bef013213c914af33172293a386e2738ceedc12d/src/Command/Base.php#L174-L184 | train |
nails/module-console | src/Command/Base.php | Base.callCommand | protected function callCommand($sCommand, array $aArguments = [], $bInteractive = true, $bSilent = false)
{
$oCmd = $this->getApplication()->find($sCommand);
$aArguments = array_merge(['command' => $sCommand], $aArguments);
$oCmdInput = new ArrayInput($aArguments);
$oCmdInput->setInteractive($bInteractive);
if ($bSilent) {
$oCmdOutput = new NullOutput();
} else {
$oCmdOutput = $this->oOutput;
}
return $oCmd->run($oCmdInput, $oCmdOutput);
} | php | protected function callCommand($sCommand, array $aArguments = [], $bInteractive = true, $bSilent = false)
{
$oCmd = $this->getApplication()->find($sCommand);
$aArguments = array_merge(['command' => $sCommand], $aArguments);
$oCmdInput = new ArrayInput($aArguments);
$oCmdInput->setInteractive($bInteractive);
if ($bSilent) {
$oCmdOutput = new NullOutput();
} else {
$oCmdOutput = $this->oOutput;
}
return $oCmd->run($oCmdInput, $oCmdOutput);
} | [
"protected",
"function",
"callCommand",
"(",
"$",
"sCommand",
",",
"array",
"$",
"aArguments",
"=",
"[",
"]",
",",
"$",
"bInteractive",
"=",
"true",
",",
"$",
"bSilent",
"=",
"false",
")",
"{",
"$",
"oCmd",
"=",
"$",
"this",
"->",
"getApplication",
"("... | Call another command within the app
@param string $sCommand The command to execute
@param array $aArguments Any arguments to pass to the command
@param bool $bInteractive Whether the command should be executed interactively
@param bool $bSilent Whether the command should be executed silently
@return int
@throws \Exception | [
"Call",
"another",
"command",
"within",
"the",
"app"
] | bef013213c914af33172293a386e2738ceedc12d | https://github.com/nails/module-console/blob/bef013213c914af33172293a386e2738ceedc12d/src/Command/Base.php#L199-L214 | train |
nails/module-auth | src/Service/SocialSignOn.php | SocialSignOn.getProviders | public function getProviders($status = null)
{
if ($status == 'ENABLED') {
return $this->aProviders['enabled'];
} elseif ($status == 'DISABLED') {
return $this->aProviders['disabled'];
} else {
return $this->aProviders['all'];
}
} | php | public function getProviders($status = null)
{
if ($status == 'ENABLED') {
return $this->aProviders['enabled'];
} elseif ($status == 'DISABLED') {
return $this->aProviders['disabled'];
} else {
return $this->aProviders['all'];
}
} | [
"public",
"function",
"getProviders",
"(",
"$",
"status",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"status",
"==",
"'ENABLED'",
")",
"{",
"return",
"$",
"this",
"->",
"aProviders",
"[",
"'enabled'",
"]",
";",
"}",
"elseif",
"(",
"$",
"status",
"==",
"'... | Returns a list of providers, optionally filtered by availability
@param string $status The filter to apply
@return array | [
"Returns",
"a",
"list",
"of",
"providers",
"optionally",
"filtered",
"by",
"availability"
] | f9b0b554c1e06399fa8042dd94c5acf86bac5548 | https://github.com/nails/module-auth/blob/f9b0b554c1e06399fa8042dd94c5acf86bac5548/src/Service/SocialSignOn.php#L163-L172 | train |
nails/module-auth | src/Service/SocialSignOn.php | SocialSignOn.getProvider | public function getProvider($provider)
{
if (isset($this->aProviders['all'][strtolower($provider)])) {
return $this->aProviders['all'][strtolower($provider)];
} else {
return false;
}
} | php | public function getProvider($provider)
{
if (isset($this->aProviders['all'][strtolower($provider)])) {
return $this->aProviders['all'][strtolower($provider)];
} else {
return false;
}
} | [
"public",
"function",
"getProvider",
"(",
"$",
"provider",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aProviders",
"[",
"'all'",
"]",
"[",
"strtolower",
"(",
"$",
"provider",
")",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aProvide... | Returns the details of a particular provider
@param string $provider The provider to return
@return mixed Array on success, false on failure | [
"Returns",
"the",
"details",
"of",
"a",
"particular",
"provider"
] | f9b0b554c1e06399fa8042dd94c5acf86bac5548 | https://github.com/nails/module-auth/blob/f9b0b554c1e06399fa8042dd94c5acf86bac5548/src/Service/SocialSignOn.php#L183-L190 | train |
nails/module-auth | src/Service/SocialSignOn.php | SocialSignOn.getProviderClass | protected function getProviderClass($sProvider)
{
$aProviders = $this->getProviders();
return isset($aProviders[strtolower($sProvider)]['class']) ? $aProviders[strtolower($sProvider)]['class'] : null;
} | php | protected function getProviderClass($sProvider)
{
$aProviders = $this->getProviders();
return isset($aProviders[strtolower($sProvider)]['class']) ? $aProviders[strtolower($sProvider)]['class'] : null;
} | [
"protected",
"function",
"getProviderClass",
"(",
"$",
"sProvider",
")",
"{",
"$",
"aProviders",
"=",
"$",
"this",
"->",
"getProviders",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"aProviders",
"[",
"strtolower",
"(",
"$",
"sProvider",
")",
"]",
"[",
"'... | Returns the correct casing for a provider
@param string $sProvider The provider to return
@return mixed String on success, null on failure | [
"Returns",
"the",
"correct",
"casing",
"for",
"a",
"provider"
] | f9b0b554c1e06399fa8042dd94c5acf86bac5548 | https://github.com/nails/module-auth/blob/f9b0b554c1e06399fa8042dd94c5acf86bac5548/src/Service/SocialSignOn.php#L201-L205 | train |
nails/module-auth | src/Service/SocialSignOn.php | SocialSignOn.authenticate | public function authenticate($sProvider, $mParams = null)
{
try {
$sProvider = $this->getProviderClass($sProvider);
return $this->oHybridAuth->authenticate($sProvider, $mParams);
} catch (\Exception $e) {
$this->setError('Provider Error: ' . $e->getMessage());
return false;
}
} | php | public function authenticate($sProvider, $mParams = null)
{
try {
$sProvider = $this->getProviderClass($sProvider);
return $this->oHybridAuth->authenticate($sProvider, $mParams);
} catch (\Exception $e) {
$this->setError('Provider Error: ' . $e->getMessage());
return false;
}
} | [
"public",
"function",
"authenticate",
"(",
"$",
"sProvider",
",",
"$",
"mParams",
"=",
"null",
")",
"{",
"try",
"{",
"$",
"sProvider",
"=",
"$",
"this",
"->",
"getProviderClass",
"(",
"$",
"sProvider",
")",
";",
"return",
"$",
"this",
"->",
"oHybridAuth"... | Authenticates a user using Hybrid Auth's authenticate method
@param string $sProvider The provider to authenticate against
@param mixed $mParams Additional parameters to pass to the Provider
@return Hybrid_Provider_Adapter|false | [
"Authenticates",
"a",
"user",
"using",
"Hybrid",
"Auth",
"s",
"authenticate",
"method"
] | f9b0b554c1e06399fa8042dd94c5acf86bac5548 | https://github.com/nails/module-auth/blob/f9b0b554c1e06399fa8042dd94c5acf86bac5548/src/Service/SocialSignOn.php#L231-L240 | train |
nails/module-auth | src/Service/SocialSignOn.php | SocialSignOn.getUserProfile | public function getUserProfile($provider)
{
$oAdapter = $this->authenticate($provider);
try {
return $oAdapter->getUserProfile();
} catch (\Exception $e) {
$this->setError('Provider Error: ' . $e->getMessage());
return false;
}
} | php | public function getUserProfile($provider)
{
$oAdapter = $this->authenticate($provider);
try {
return $oAdapter->getUserProfile();
} catch (\Exception $e) {
$this->setError('Provider Error: ' . $e->getMessage());
return false;
}
} | [
"public",
"function",
"getUserProfile",
"(",
"$",
"provider",
")",
"{",
"$",
"oAdapter",
"=",
"$",
"this",
"->",
"authenticate",
"(",
"$",
"provider",
")",
";",
"try",
"{",
"return",
"$",
"oAdapter",
"->",
"getUserProfile",
"(",
")",
";",
"}",
"catch",
... | Returns the user's profile for a particular provider.
@param string $provider The name of the provider.
@return mixed Hybrid_User_Profile on success, false on failure | [
"Returns",
"the",
"user",
"s",
"profile",
"for",
"a",
"particular",
"provider",
"."
] | f9b0b554c1e06399fa8042dd94c5acf86bac5548 | https://github.com/nails/module-auth/blob/f9b0b554c1e06399fa8042dd94c5acf86bac5548/src/Service/SocialSignOn.php#L251-L261 | train |
nails/module-auth | src/Service/SocialSignOn.php | SocialSignOn.getUserByProviderId | public function getUserByProviderId($provider, $identifier)
{
$this->oDb->select('user_id');
$this->oDb->where('provider', $provider);
$this->oDb->where('identifier', $identifier);
$oUser = $this->oDb->get(NAILS_DB_PREFIX . 'user_social')->row();
if (empty($oUser)) {
return false;
}
return $this->oUserModel->getById($oUser->user_id);
} | php | public function getUserByProviderId($provider, $identifier)
{
$this->oDb->select('user_id');
$this->oDb->where('provider', $provider);
$this->oDb->where('identifier', $identifier);
$oUser = $this->oDb->get(NAILS_DB_PREFIX . 'user_social')->row();
if (empty($oUser)) {
return false;
}
return $this->oUserModel->getById($oUser->user_id);
} | [
"public",
"function",
"getUserByProviderId",
"(",
"$",
"provider",
",",
"$",
"identifier",
")",
"{",
"$",
"this",
"->",
"oDb",
"->",
"select",
"(",
"'user_id'",
")",
";",
"$",
"this",
"->",
"oDb",
"->",
"where",
"(",
"'provider'",
",",
"$",
"provider",
... | Fetches a local user profile via a provider and provider ID
@param string $provider The provider to use
@param string $identifier The provider's user ID
@return mixed stdClass on success, false on failure | [
"Fetches",
"a",
"local",
"user",
"profile",
"via",
"a",
"provider",
"and",
"provider",
"ID"
] | f9b0b554c1e06399fa8042dd94c5acf86bac5548 | https://github.com/nails/module-auth/blob/f9b0b554c1e06399fa8042dd94c5acf86bac5548/src/Service/SocialSignOn.php#L284-L297 | train |
nails/module-auth | src/Service/SocialSignOn.php | SocialSignOn.restoreSession | public function restoreSession($user_id = null)
{
if (empty($user_id)) {
$user_id = activeUser('id');
}
if (empty($user_id)) {
$this->setError('Must specify which user ID\'s session to restore.');
return false;
}
$oUser = $this->oUserModel->getById($user_id);
if (!$oUser) {
$this->setError('Invalid User ID');
return false;
}
// --------------------------------------------------------------------------
// Clean slate
$this->oHybridAuth->logoutAllProviders();
// --------------------------------------------------------------------------
$this->oDb->where('user_id', $oUser->id);
$aSessions = $this->oDb->get(NAILS_DB_PREFIX . 'user_social')->result();
$aRestore = [];
foreach ($aSessions as $oSession) {
$oSession->session_data = unserialize($oSession->session_data);
$aRestore = array_merge($aRestore, $oSession->session_data);
}
return $this->oHybridAuth->restoreSessionData(serialize($aRestore));
} | php | public function restoreSession($user_id = null)
{
if (empty($user_id)) {
$user_id = activeUser('id');
}
if (empty($user_id)) {
$this->setError('Must specify which user ID\'s session to restore.');
return false;
}
$oUser = $this->oUserModel->getById($user_id);
if (!$oUser) {
$this->setError('Invalid User ID');
return false;
}
// --------------------------------------------------------------------------
// Clean slate
$this->oHybridAuth->logoutAllProviders();
// --------------------------------------------------------------------------
$this->oDb->where('user_id', $oUser->id);
$aSessions = $this->oDb->get(NAILS_DB_PREFIX . 'user_social')->result();
$aRestore = [];
foreach ($aSessions as $oSession) {
$oSession->session_data = unserialize($oSession->session_data);
$aRestore = array_merge($aRestore, $oSession->session_data);
}
return $this->oHybridAuth->restoreSessionData(serialize($aRestore));
} | [
"public",
"function",
"restoreSession",
"(",
"$",
"user_id",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"user_id",
")",
")",
"{",
"$",
"user_id",
"=",
"activeUser",
"(",
"'id'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"user_id",
")",... | Restores a user's social session
@param mixed $user_id The User's ID (if null, then the active user ID is used)
@return boolean | [
"Restores",
"a",
"user",
"s",
"social",
"session"
] | f9b0b554c1e06399fa8042dd94c5acf86bac5548 | https://github.com/nails/module-auth/blob/f9b0b554c1e06399fa8042dd94c5acf86bac5548/src/Service/SocialSignOn.php#L470-L505 | train |
nails/module-auth | src/Service/SocialSignOn.php | SocialSignOn.api | public function api($sProvider, $call = '')
{
if (!$this->isConnectedWith($sProvider)) {
$this->setError('Not connected with provider "' . $sProvider . '"');
return false;
}
try {
$sProvider = $this->getProviderClass($sProvider);
$oProvider = $this->oHybridAuth->getAdapter($sProvider);
return $oProvider->api()->api($call);
} catch (\Exception $e) {
$this->setError('Provider Error: ' . $e->getMessage());
return false;
}
} | php | public function api($sProvider, $call = '')
{
if (!$this->isConnectedWith($sProvider)) {
$this->setError('Not connected with provider "' . $sProvider . '"');
return false;
}
try {
$sProvider = $this->getProviderClass($sProvider);
$oProvider = $this->oHybridAuth->getAdapter($sProvider);
return $oProvider->api()->api($call);
} catch (\Exception $e) {
$this->setError('Provider Error: ' . $e->getMessage());
return false;
}
} | [
"public",
"function",
"api",
"(",
"$",
"sProvider",
",",
"$",
"call",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isConnectedWith",
"(",
"$",
"sProvider",
")",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"'Not connected with provider \"'",... | Abstraction to a provider's API
@param string $sProvider The provider whose API you wish to call
@param string $call The API call
@return mixed | [
"Abstraction",
"to",
"a",
"provider",
"s",
"API"
] | f9b0b554c1e06399fa8042dd94c5acf86bac5548 | https://github.com/nails/module-auth/blob/f9b0b554c1e06399fa8042dd94c5acf86bac5548/src/Service/SocialSignOn.php#L543-L560 | train |
ommu/mod-core | ommu/ModuleHandle.php | ModuleHandle.cacheModuleConfig | public function cacheModuleConfig($return=false)
{
$modules = $this->getModulesFromDb();
$arrayModule = array();
foreach($modules as $module) {
if(!in_array($module->folder, $arrayModule))
$arrayModule[] = $module->folder;
}
if($return == false) {
$filePath = Yii::getPathOfAlias('application.config');
$fileHandle = fopen($filePath.'/cache_module.php', 'w');
fwrite($fileHandle, implode("\n", $arrayModule));
fclose($fileHandle);
} else
return $arrayModule;
} | php | public function cacheModuleConfig($return=false)
{
$modules = $this->getModulesFromDb();
$arrayModule = array();
foreach($modules as $module) {
if(!in_array($module->folder, $arrayModule))
$arrayModule[] = $module->folder;
}
if($return == false) {
$filePath = Yii::getPathOfAlias('application.config');
$fileHandle = fopen($filePath.'/cache_module.php', 'w');
fwrite($fileHandle, implode("\n", $arrayModule));
fclose($fileHandle);
} else
return $arrayModule;
} | [
"public",
"function",
"cacheModuleConfig",
"(",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"modules",
"=",
"$",
"this",
"->",
"getModulesFromDb",
"(",
")",
";",
"$",
"arrayModule",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"modules",
"as",
"$"... | Cache modul dari database ke bentuk file.
Untuk mengurangi query pada saat install ke database. | [
"Cache",
"modul",
"dari",
"database",
"ke",
"bentuk",
"file",
".",
"Untuk",
"mengurangi",
"query",
"pada",
"saat",
"install",
"ke",
"database",
"."
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/ommu/ModuleHandle.php#L131-L148 | train |
ommu/mod-core | ommu/ModuleHandle.php | ModuleHandle.getModuleConfig | public function getModuleConfig($module)
{
Yii::import('mustangostang.spyc.Spyc');
define('DS', DIRECTORY_SEPARATOR);
$configPath = Yii::getPathOfAlias('application.vendor.ommu.'.$module).DS.$module.'.yaml';
if(file_exists($configPath))
return Spyc::YAMLLoad($configPath);
else
return null;
} | php | public function getModuleConfig($module)
{
Yii::import('mustangostang.spyc.Spyc');
define('DS', DIRECTORY_SEPARATOR);
$configPath = Yii::getPathOfAlias('application.vendor.ommu.'.$module).DS.$module.'.yaml';
if(file_exists($configPath))
return Spyc::YAMLLoad($configPath);
else
return null;
} | [
"public",
"function",
"getModuleConfig",
"(",
"$",
"module",
")",
"{",
"Yii",
"::",
"import",
"(",
"'mustangostang.spyc.Spyc'",
")",
";",
"define",
"(",
"'DS'",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"$",
"configPath",
"=",
"Yii",
"::",
"getPathOfAlias",
"(",
... | Get module config from yaml file
@param string $module
@return array | [
"Get",
"module",
"config",
"from",
"yaml",
"file"
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/ommu/ModuleHandle.php#L156-L167 | train |
ommu/mod-core | ommu/ModuleHandle.php | ModuleHandle.deleteModuleDatabase | public function deleteModuleDatabase($module)
{
$config = $this->getModuleConfig($module);
$tableName = $config['db_table_name'];
if($config && $tableName) {
foreach($tableName as $val){
Yii::app()->db->createCommand("DROP TABLE {$val}")->execute();
}
} else
return false;
} | php | public function deleteModuleDatabase($module)
{
$config = $this->getModuleConfig($module);
$tableName = $config['db_table_name'];
if($config && $tableName) {
foreach($tableName as $val){
Yii::app()->db->createCommand("DROP TABLE {$val}")->execute();
}
} else
return false;
} | [
"public",
"function",
"deleteModuleDatabase",
"(",
"$",
"module",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getModuleConfig",
"(",
"$",
"module",
")",
";",
"$",
"tableName",
"=",
"$",
"config",
"[",
"'db_table_name'",
"]",
";",
"if",
"(",
"$",
... | Delete Module Database | [
"Delete",
"Module",
"Database"
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/ommu/ModuleHandle.php#L180-L192 | train |
ommu/mod-core | ommu/ModuleHandle.php | ModuleHandle.deleteModuleDb | public function deleteModuleDb($module)
{
if($module != null) {
$model = OmmuPlugins::model()->findByAttributes(array('folder'=>$module));
if($model != null)
$model->delete();
else
return true;
} else
return true;
} | php | public function deleteModuleDb($module)
{
if($module != null) {
$model = OmmuPlugins::model()->findByAttributes(array('folder'=>$module));
if($model != null)
$model->delete();
else
return true;
} else
return true;
} | [
"public",
"function",
"deleteModuleDb",
"(",
"$",
"module",
")",
"{",
"if",
"(",
"$",
"module",
"!=",
"null",
")",
"{",
"$",
"model",
"=",
"OmmuPlugins",
"::",
"model",
"(",
")",
"->",
"findByAttributes",
"(",
"array",
"(",
"'folder'",
"=>",
"$",
"modu... | Delete Module from Plugin Database | [
"Delete",
"Module",
"from",
"Plugin",
"Database"
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/ommu/ModuleHandle.php#L197-L210 | train |
ommu/mod-core | ommu/ModuleHandle.php | ModuleHandle.setModules | public function setModules()
{
$moduleVendorPath = Yii::getPathOfAlias('application.vendor.ommu');
$installedModule = $this->getModulesFromDir();
$cacheModule = file(Yii::getPathOfAlias('application.config').'/cache_module.php');
$toBeInstalled = array();
$caches = array();
foreach($cacheModule as $val) {
$caches[] = trim($val);
}
if(!$installedModule)
$installedModule = array();
foreach($caches as $cache) {
if(!in_array($cache, array_map("trim", $installedModule)))
$this->deleteModuleDb($cache);
}
$moduleDb = $this->cacheModuleConfig(true);
foreach($installedModule as $module) {
$module = trim($module);
if(!in_array($module, array_map("trim", $moduleDb))) {
$config = $this->getModuleConfig($module);
$moduleFile = join('/', array($moduleVendorPath, $module, ucfirst($module).'Module.php'));
if($config && file_exists($moduleFile) && $module == $config['folder_name']) {
$model=new OmmuPlugins;
$model->folder = $module;
$model->name = $config['name'];
$model->desc = $config['description'];
if($config['model'])
$model->model = $config['model'];
$model->save();
}
}
}
$this->generateModules();
} | php | public function setModules()
{
$moduleVendorPath = Yii::getPathOfAlias('application.vendor.ommu');
$installedModule = $this->getModulesFromDir();
$cacheModule = file(Yii::getPathOfAlias('application.config').'/cache_module.php');
$toBeInstalled = array();
$caches = array();
foreach($cacheModule as $val) {
$caches[] = trim($val);
}
if(!$installedModule)
$installedModule = array();
foreach($caches as $cache) {
if(!in_array($cache, array_map("trim", $installedModule)))
$this->deleteModuleDb($cache);
}
$moduleDb = $this->cacheModuleConfig(true);
foreach($installedModule as $module) {
$module = trim($module);
if(!in_array($module, array_map("trim", $moduleDb))) {
$config = $this->getModuleConfig($module);
$moduleFile = join('/', array($moduleVendorPath, $module, ucfirst($module).'Module.php'));
if($config && file_exists($moduleFile) && $module == $config['folder_name']) {
$model=new OmmuPlugins;
$model->folder = $module;
$model->name = $config['name'];
$model->desc = $config['description'];
if($config['model'])
$model->model = $config['model'];
$model->save();
}
}
}
$this->generateModules();
} | [
"public",
"function",
"setModules",
"(",
")",
"{",
"$",
"moduleVendorPath",
"=",
"Yii",
"::",
"getPathOfAlias",
"(",
"'application.vendor.ommu'",
")",
";",
"$",
"installedModule",
"=",
"$",
"this",
"->",
"getModulesFromDir",
"(",
")",
";",
"$",
"cacheModule",
... | Install modul ke database | [
"Install",
"modul",
"ke",
"database"
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/ommu/ModuleHandle.php#L259-L299 | train |
au-research/ANDS-DOI-Service | src/Formatter/Formatter.php | Formatter.fill | public function fill($payload)
{
$payload = $this->determineTypeAndMessage($payload);
$payload = $this->fillBlanks($payload);
return $payload;
} | php | public function fill($payload)
{
$payload = $this->determineTypeAndMessage($payload);
$payload = $this->fillBlanks($payload);
return $payload;
} | [
"public",
"function",
"fill",
"(",
"$",
"payload",
")",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"determineTypeAndMessage",
"(",
"$",
"payload",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"fillBlanks",
"(",
"$",
"payload",
")",
";",
"return"... | Helper method to assist with filling out the values in the payload
@param $payload
@return mixed | [
"Helper",
"method",
"to",
"assist",
"with",
"filling",
"out",
"the",
"values",
"in",
"the",
"payload"
] | c8e2cc98eca23a0c550af9a45b5c5dee230da1c9 | https://github.com/au-research/ANDS-DOI-Service/blob/c8e2cc98eca23a0c550af9a45b5c5dee230da1c9/src/Formatter/Formatter.php#L13-L18 | train |
au-research/ANDS-DOI-Service | src/Formatter/Formatter.php | Formatter.fillBlanks | public function fillBlanks($payload)
{
$fields = ['doi', 'url', 'message', 'verbosemessage', 'responsecode', 'app_id'];
foreach ($fields as $field) {
if (!array_key_exists($field, $payload)) {
$payload[$field] = "";
}
}
return $payload;
} | php | public function fillBlanks($payload)
{
$fields = ['doi', 'url', 'message', 'verbosemessage', 'responsecode', 'app_id'];
foreach ($fields as $field) {
if (!array_key_exists($field, $payload)) {
$payload[$field] = "";
}
}
return $payload;
} | [
"public",
"function",
"fillBlanks",
"(",
"$",
"payload",
")",
"{",
"$",
"fields",
"=",
"[",
"'doi'",
",",
"'url'",
",",
"'message'",
",",
"'verbosemessage'",
",",
"'responsecode'",
",",
"'app_id'",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fie... | Make sure that all fields are filled out
@param $payload
@return mixed | [
"Make",
"sure",
"that",
"all",
"fields",
"are",
"filled",
"out"
] | c8e2cc98eca23a0c550af9a45b5c5dee230da1c9 | https://github.com/au-research/ANDS-DOI-Service/blob/c8e2cc98eca23a0c550af9a45b5c5dee230da1c9/src/Formatter/Formatter.php#L163-L172 | train |
locomotivemtl/charcoal-attachment | src/Charcoal/Attachment/AttachmentsConfig.php | AttachmentsConfig.setData | public function setData(array $data)
{
if (isset($data['attachables'])) {
$this->setAttachables($data['attachables']);
}
if (isset($data['groups'])) {
$this->setGroups($data['groups']);
}
if (isset($data['widgets'])) {
$this->setWidgets($data['widgets']);
}
unset($data['attachables'], $data['groups'], $data['widgets']);
return parent::setData($data);
} | php | public function setData(array $data)
{
if (isset($data['attachables'])) {
$this->setAttachables($data['attachables']);
}
if (isset($data['groups'])) {
$this->setGroups($data['groups']);
}
if (isset($data['widgets'])) {
$this->setWidgets($data['widgets']);
}
unset($data['attachables'], $data['groups'], $data['widgets']);
return parent::setData($data);
} | [
"public",
"function",
"setData",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'attachables'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setAttachables",
"(",
"$",
"data",
"[",
"'attachables'",
"]",
")",
";",
"}",
"... | Set attachments settings in a specific order.
@param array $data New config values.
@return AttachmentsConfig Chainable | [
"Set",
"attachments",
"settings",
"in",
"a",
"specific",
"order",
"."
] | 82963e414483e7a0fc75e30894db0bba376dbd2d | https://github.com/locomotivemtl/charcoal-attachment/blob/82963e414483e7a0fc75e30894db0bba376dbd2d/src/Charcoal/Attachment/AttachmentsConfig.php#L42-L59 | train |
locomotivemtl/charcoal-attachment | src/Charcoal/Attachment/AttachmentsConfig.php | AttachmentsConfig.setAttachables | public function setAttachables(array $attachables)
{
foreach ($attachables as $attType => $attStruct) {
if (!is_array($attStruct)) {
throw new InvalidArgumentException(sprintf(
'The attachment structure for "%s" must be an array',
$attType
));
}
if (isset($attStruct['attachment_type'])) {
$attType = $attStruct['attachment_type'];
} else {
$attStruct['attachment_type'] = $attType;
}
if (!is_string($attType)) {
throw new InvalidArgumentException(
'The attachment type must be a string'
);
}
$this->attachables[$attType] = $attStruct;
}
return $this;
} | php | public function setAttachables(array $attachables)
{
foreach ($attachables as $attType => $attStruct) {
if (!is_array($attStruct)) {
throw new InvalidArgumentException(sprintf(
'The attachment structure for "%s" must be an array',
$attType
));
}
if (isset($attStruct['attachment_type'])) {
$attType = $attStruct['attachment_type'];
} else {
$attStruct['attachment_type'] = $attType;
}
if (!is_string($attType)) {
throw new InvalidArgumentException(
'The attachment type must be a string'
);
}
$this->attachables[$attType] = $attStruct;
}
return $this;
} | [
"public",
"function",
"setAttachables",
"(",
"array",
"$",
"attachables",
")",
"{",
"foreach",
"(",
"$",
"attachables",
"as",
"$",
"attType",
"=>",
"$",
"attStruct",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"attStruct",
")",
")",
"{",
"throw",
"... | Set attachment types.
@param array $attachables One or more attachment types.
@throws InvalidArgumentException If the attachment type or structure is invalid.
@return AttachmentsConfig Chainable | [
"Set",
"attachment",
"types",
"."
] | 82963e414483e7a0fc75e30894db0bba376dbd2d | https://github.com/locomotivemtl/charcoal-attachment/blob/82963e414483e7a0fc75e30894db0bba376dbd2d/src/Charcoal/Attachment/AttachmentsConfig.php#L68-L94 | train |
locomotivemtl/charcoal-attachment | src/Charcoal/Attachment/AttachmentsConfig.php | AttachmentsConfig.setGroups | public function setGroups(array $groups)
{
foreach ($groups as $groupIdent => $groupStruct) {
if (!is_array($groupStruct)) {
throw new InvalidArgumentException(sprintf(
'The attachment group "%s" must be an array of attachable objects',
$groupIdent
));
}
if (isset($groupStruct['ident'])) {
$groupIdent = $groupStruct['ident'];
unset($groupStruct['ident']);
}
if (!is_string($groupIdent)) {
throw new InvalidArgumentException(
'The attachment group identifier must be a string'
);
}
if (isset($groupStruct['attachable_objects'])) {
$groupStruct = $groupStruct['attachable_objects'];
} elseif (isset($groupStruct['attachables'])) {
$groupStruct = $groupStruct['attachables'];
}
$this->groups[$groupIdent] = $groupStruct;
}
return $this;
} | php | public function setGroups(array $groups)
{
foreach ($groups as $groupIdent => $groupStruct) {
if (!is_array($groupStruct)) {
throw new InvalidArgumentException(sprintf(
'The attachment group "%s" must be an array of attachable objects',
$groupIdent
));
}
if (isset($groupStruct['ident'])) {
$groupIdent = $groupStruct['ident'];
unset($groupStruct['ident']);
}
if (!is_string($groupIdent)) {
throw new InvalidArgumentException(
'The attachment group identifier must be a string'
);
}
if (isset($groupStruct['attachable_objects'])) {
$groupStruct = $groupStruct['attachable_objects'];
} elseif (isset($groupStruct['attachables'])) {
$groupStruct = $groupStruct['attachables'];
}
$this->groups[$groupIdent] = $groupStruct;
}
return $this;
} | [
"public",
"function",
"setGroups",
"(",
"array",
"$",
"groups",
")",
"{",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"groupIdent",
"=>",
"$",
"groupStruct",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"groupStruct",
")",
")",
"{",
"throw",
"new",
... | Set attachment type groups.
@param array $groups One or more groupings.
@throws InvalidArgumentException If the group identifier or structure is invalid.
@return AttachmentsConfig Chainable | [
"Set",
"attachment",
"type",
"groups",
"."
] | 82963e414483e7a0fc75e30894db0bba376dbd2d | https://github.com/locomotivemtl/charcoal-attachment/blob/82963e414483e7a0fc75e30894db0bba376dbd2d/src/Charcoal/Attachment/AttachmentsConfig.php#L113-L144 | train |
locomotivemtl/charcoal-attachment | src/Charcoal/Attachment/AttachmentsConfig.php | AttachmentsConfig.setWidgets | public function setWidgets(array $widgets)
{
foreach ($widgets as $widgetIdent => $widgetStruct) {
if (!is_array($widgetStruct)) {
throw new InvalidArgumentException(sprintf(
'The attachment widget "%s" must be an array of widget settings',
$widgetIdent
));
}
if (isset($widgetStruct['ident'])) {
$widgetIdent = $widgetStruct['ident'];
unset($widgetStruct['ident']);
}
if (!is_string($widgetIdent)) {
throw new InvalidArgumentException(
'The attachment widget identifier must be a string'
);
}
$this->widgets[$widgetIdent] = $widgetStruct;
}
return $this;
} | php | public function setWidgets(array $widgets)
{
foreach ($widgets as $widgetIdent => $widgetStruct) {
if (!is_array($widgetStruct)) {
throw new InvalidArgumentException(sprintf(
'The attachment widget "%s" must be an array of widget settings',
$widgetIdent
));
}
if (isset($widgetStruct['ident'])) {
$widgetIdent = $widgetStruct['ident'];
unset($widgetStruct['ident']);
}
if (!is_string($widgetIdent)) {
throw new InvalidArgumentException(
'The attachment widget identifier must be a string'
);
}
$this->widgets[$widgetIdent] = $widgetStruct;
}
return $this;
} | [
"public",
"function",
"setWidgets",
"(",
"array",
"$",
"widgets",
")",
"{",
"foreach",
"(",
"$",
"widgets",
"as",
"$",
"widgetIdent",
"=>",
"$",
"widgetStruct",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"widgetStruct",
")",
")",
"{",
"throw",
"ne... | Set attachment widget structures.
@param array $widgets One or more widget structures.
@throws InvalidArgumentException If the widget identifier or structure is invalid.
@return AttachmentsConfig Chainable | [
"Set",
"attachment",
"widget",
"structures",
"."
] | 82963e414483e7a0fc75e30894db0bba376dbd2d | https://github.com/locomotivemtl/charcoal-attachment/blob/82963e414483e7a0fc75e30894db0bba376dbd2d/src/Charcoal/Attachment/AttachmentsConfig.php#L163-L188 | train |
s9e/RegexpBuilder | src/Passes/MergePrefix.php | MergePrefix.getPrefixLength | protected function getPrefixLength(array $strings)
{
$len = 1;
$cnt = count($strings[0]);
while ($len < $cnt && $this->stringsMatch($strings, $len))
{
++$len;
}
return $len;
} | php | protected function getPrefixLength(array $strings)
{
$len = 1;
$cnt = count($strings[0]);
while ($len < $cnt && $this->stringsMatch($strings, $len))
{
++$len;
}
return $len;
} | [
"protected",
"function",
"getPrefixLength",
"(",
"array",
"$",
"strings",
")",
"{",
"$",
"len",
"=",
"1",
";",
"$",
"cnt",
"=",
"count",
"(",
"$",
"strings",
"[",
"0",
"]",
")",
";",
"while",
"(",
"$",
"len",
"<",
"$",
"cnt",
"&&",
"$",
"this",
... | Get the number of leading elements common to all given strings
@param array[] $strings
@return integer | [
"Get",
"the",
"number",
"of",
"leading",
"elements",
"common",
"to",
"all",
"given",
"strings"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Passes/MergePrefix.php#L35-L45 | train |
s9e/RegexpBuilder | src/Passes/MergePrefix.php | MergePrefix.getStringsByPrefix | protected function getStringsByPrefix(array $strings)
{
$byPrefix = [];
foreach ($strings as $string)
{
$byPrefix[$string[0]][] = $string;
}
return $byPrefix;
} | php | protected function getStringsByPrefix(array $strings)
{
$byPrefix = [];
foreach ($strings as $string)
{
$byPrefix[$string[0]][] = $string;
}
return $byPrefix;
} | [
"protected",
"function",
"getStringsByPrefix",
"(",
"array",
"$",
"strings",
")",
"{",
"$",
"byPrefix",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"strings",
"as",
"$",
"string",
")",
"{",
"$",
"byPrefix",
"[",
"$",
"string",
"[",
"0",
"]",
"]",
"[",
... | Return given strings grouped by their first element
NOTE: assumes that this pass is run before the first element of any string could be replaced
@param array[] $strings
@return array[] | [
"Return",
"given",
"strings",
"grouped",
"by",
"their",
"first",
"element"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Passes/MergePrefix.php#L55-L64 | train |
s9e/RegexpBuilder | src/Passes/MergePrefix.php | MergePrefix.mergeStrings | protected function mergeStrings(array $strings)
{
$len = $this->getPrefixLength($strings);
$newString = array_slice($strings[0], 0, $len);
foreach ($strings as $string)
{
$newString[$len][] = array_slice($string, $len);
}
return $newString;
} | php | protected function mergeStrings(array $strings)
{
$len = $this->getPrefixLength($strings);
$newString = array_slice($strings[0], 0, $len);
foreach ($strings as $string)
{
$newString[$len][] = array_slice($string, $len);
}
return $newString;
} | [
"protected",
"function",
"mergeStrings",
"(",
"array",
"$",
"strings",
")",
"{",
"$",
"len",
"=",
"$",
"this",
"->",
"getPrefixLength",
"(",
"$",
"strings",
")",
";",
"$",
"newString",
"=",
"array_slice",
"(",
"$",
"strings",
"[",
"0",
"]",
",",
"0",
... | Merge given strings into a new single string
@param array[] $strings
@return array | [
"Merge",
"given",
"strings",
"into",
"a",
"new",
"single",
"string"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Passes/MergePrefix.php#L72-L82 | train |
s9e/RegexpBuilder | src/Passes/MergePrefix.php | MergePrefix.stringsMatch | protected function stringsMatch(array $strings, $pos)
{
$value = $strings[0][$pos];
foreach ($strings as $string)
{
if (!isset($string[$pos]) || $string[$pos] !== $value)
{
return false;
}
}
return true;
} | php | protected function stringsMatch(array $strings, $pos)
{
$value = $strings[0][$pos];
foreach ($strings as $string)
{
if (!isset($string[$pos]) || $string[$pos] !== $value)
{
return false;
}
}
return true;
} | [
"protected",
"function",
"stringsMatch",
"(",
"array",
"$",
"strings",
",",
"$",
"pos",
")",
"{",
"$",
"value",
"=",
"$",
"strings",
"[",
"0",
"]",
"[",
"$",
"pos",
"]",
";",
"foreach",
"(",
"$",
"strings",
"as",
"$",
"string",
")",
"{",
"if",
"(... | Test whether all given strings' elements match at given position
@param array[] $strings
@param integer $pos
@return bool | [
"Test",
"whether",
"all",
"given",
"strings",
"elements",
"match",
"at",
"given",
"position"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Passes/MergePrefix.php#L91-L103 | train |
mirko-pagliai/me-cms | src/Model/Table/PostsAndPagesTables.php | PostsAndPagesTables.find | public function find($type = 'all', $options = [])
{
//Gets from cache the timestamp of the next record to be published
$next = $this->getNextToBePublished();
//If the cache is invalid, it clears the cache and sets the next record
// to be published
if ($next && time() >= $next) {
Cache::clear(false, $this->getCacheName());
//Sets the next record to be published
$this->setNextToBePublished();
}
return parent::find($type, $options);
} | php | public function find($type = 'all', $options = [])
{
//Gets from cache the timestamp of the next record to be published
$next = $this->getNextToBePublished();
//If the cache is invalid, it clears the cache and sets the next record
// to be published
if ($next && time() >= $next) {
Cache::clear(false, $this->getCacheName());
//Sets the next record to be published
$this->setNextToBePublished();
}
return parent::find($type, $options);
} | [
"public",
"function",
"find",
"(",
"$",
"type",
"=",
"'all'",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"//Gets from cache the timestamp of the next record to be published",
"$",
"next",
"=",
"$",
"this",
"->",
"getNextToBePublished",
"(",
")",
";",
"//If th... | Creates a new Query for this repository and applies some defaults based
on the type of search that was selected
@param string $type The type of query to perform
@param array|ArrayAccess $options An array that will be passed to
Query::applyOptions()
@return \Cake\ORM\Query The query builder
@uses getCacheName()
@uses MeCms\Model\Table\Traits\NextToBePublishedTrait::getNextToBePublished()
@uses MeCms\Model\Table\Traits\NextToBePublishedTrait::setNextToBePublished() | [
"Creates",
"a",
"new",
"Query",
"for",
"this",
"repository",
"and",
"applies",
"some",
"defaults",
"based",
"on",
"the",
"type",
"of",
"search",
"that",
"was",
"selected"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Model/Table/PostsAndPagesTables.php#L110-L125 | train |
mirko-pagliai/me-cms | src/Model/Table/Traits/NextToBePublishedTrait.php | NextToBePublishedTrait.setNextToBePublished | public function setNextToBePublished()
{
$next = $this->find()
->where([
sprintf('%s.active', $this->getAlias()) => true,
sprintf('%s.created >', $this->getAlias()) => new Time,
])
->order([sprintf('%s.created', $this->getAlias()) => 'ASC'])
->extract('created')
->first();
$next = empty($next) ? false : $next->toUnixString();
Cache::write('next_to_be_published', $next, $this->getCacheName());
return $next;
} | php | public function setNextToBePublished()
{
$next = $this->find()
->where([
sprintf('%s.active', $this->getAlias()) => true,
sprintf('%s.created >', $this->getAlias()) => new Time,
])
->order([sprintf('%s.created', $this->getAlias()) => 'ASC'])
->extract('created')
->first();
$next = empty($next) ? false : $next->toUnixString();
Cache::write('next_to_be_published', $next, $this->getCacheName());
return $next;
} | [
"public",
"function",
"setNextToBePublished",
"(",
")",
"{",
"$",
"next",
"=",
"$",
"this",
"->",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"sprintf",
"(",
"'%s.active'",
",",
"$",
"this",
"->",
"getAlias",
"(",
")",
")",
"=>",
"true",
",",
"sprintf... | Sets to cache the timestamp of the next record to be published.
This value can be used to check if the cache is valid
@return string|bool Timestamp or `false`
@uses $cache | [
"Sets",
"to",
"cache",
"the",
"timestamp",
"of",
"the",
"next",
"record",
"to",
"be",
"published",
".",
"This",
"value",
"can",
"be",
"used",
"to",
"check",
"if",
"the",
"cache",
"is",
"valid"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Model/Table/Traits/NextToBePublishedTrait.php#L39-L55 | train |
php-api-clients/resource-test-utilities | src/Types.php | Types.ensureTypes | protected static function ensureTypes()
{
if (self::$doneScanning && count(self::$types) > 0) {
return;
}
foreach (self::types() as $t) {
}
} | php | protected static function ensureTypes()
{
if (self::$doneScanning && count(self::$types) > 0) {
return;
}
foreach (self::types() as $t) {
}
} | [
"protected",
"static",
"function",
"ensureTypes",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"doneScanning",
"&&",
"count",
"(",
"self",
"::",
"$",
"types",
")",
">",
"0",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"self",
"::",
"types",
"(",
... | A wee bit hacky, but this ensures that when ever `has` or `get` is called before `types`
all types are detected and available for `has` and `get`. | [
"A",
"wee",
"bit",
"hacky",
"but",
"this",
"ensures",
"that",
"when",
"ever",
"has",
"or",
"get",
"is",
"called",
"before",
"types",
"all",
"types",
"are",
"detected",
"and",
"available",
"for",
"has",
"and",
"get",
"."
] | a11098dad51f28ce2c2dc4e6f954257c6679b810 | https://github.com/php-api-clients/resource-test-utilities/blob/a11098dad51f28ce2c2dc4e6f954257c6679b810/src/Types.php#L92-L100 | train |
mirko-pagliai/me-cms | src/Controller/Admin/UsersGroupsController.php | UsersGroupsController.add | public function add()
{
$group = $this->UsersGroups->newEntity();
if ($this->request->is('post')) {
$group = $this->UsersGroups->patchEntity($group, $this->request->getData());
if ($this->UsersGroups->save($group)) {
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('group'));
} | php | public function add()
{
$group = $this->UsersGroups->newEntity();
if ($this->request->is('post')) {
$group = $this->UsersGroups->patchEntity($group, $this->request->getData());
if ($this->UsersGroups->save($group)) {
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('group'));
} | [
"public",
"function",
"add",
"(",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"UsersGroups",
"->",
"newEntity",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"is",
"(",
"'post'",
")",
")",
"{",
"$",
"group",
"=",
"$",
"this",
... | Adds users group
@return \Cake\Network\Response|null|void | [
"Adds",
"users",
"group"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/Admin/UsersGroupsController.php#L53-L70 | train |
mirko-pagliai/me-cms | src/Controller/Admin/UsersGroupsController.php | UsersGroupsController.edit | public function edit($id = null)
{
$group = $this->UsersGroups->get($id);
if ($this->request->is(['patch', 'post', 'put'])) {
$group = $this->UsersGroups->patchEntity($group, $this->request->getData());
if ($this->UsersGroups->save($group)) {
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('group'));
} | php | public function edit($id = null)
{
$group = $this->UsersGroups->get($id);
if ($this->request->is(['patch', 'post', 'put'])) {
$group = $this->UsersGroups->patchEntity($group, $this->request->getData());
if ($this->UsersGroups->save($group)) {
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('group'));
} | [
"public",
"function",
"edit",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"UsersGroups",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"is",
"(",
"[",
"'patch'",
",",
"'po... | Edits users group
@param string $id Users Group ID
@return \Cake\Network\Response|null|void | [
"Edits",
"users",
"group"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/Admin/UsersGroupsController.php#L77-L94 | train |
mirko-pagliai/me-cms | src/Controller/Admin/UsersGroupsController.php | UsersGroupsController.delete | public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$group = $this->UsersGroups->get($id);
//Before deleting, checks if the group is a necessary group or if the group has some users
if ($id > 3 && !$group->user_count) {
$this->UsersGroups->deleteOrFail($group);
$this->Flash->success(I18N_OPERATION_OK);
} else {
$this->Flash->alert($id <= 3 ? __d('me_cms', 'You cannot delete this users group') : I18N_BEFORE_DELETE);
}
return $this->redirect(['action' => 'index']);
} | php | public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$group = $this->UsersGroups->get($id);
//Before deleting, checks if the group is a necessary group or if the group has some users
if ($id > 3 && !$group->user_count) {
$this->UsersGroups->deleteOrFail($group);
$this->Flash->success(I18N_OPERATION_OK);
} else {
$this->Flash->alert($id <= 3 ? __d('me_cms', 'You cannot delete this users group') : I18N_BEFORE_DELETE);
}
return $this->redirect(['action' => 'index']);
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"request",
"->",
"allowMethod",
"(",
"[",
"'post'",
",",
"'delete'",
"]",
")",
";",
"$",
"group",
"=",
"$",
"this",
"->",
"UsersGroups",
"->",
"get",
"(",
"$"... | Deletes users group
@param string $id Users Group ID
@return \Cake\Network\Response|null | [
"Deletes",
"users",
"group"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/Admin/UsersGroupsController.php#L100-L116 | train |
hiqdev/hipanel-module-ticket | src/models/TicketSettings.php | TicketSettings.getFormData | public function getFormData()
{
$data = Client::perform('get-class-values', ['class' => 'client,ticket_settings']);
$this->ticket_emails = $data['ticket_emails'];
$this->send_message_text = $data['send_message_text'];
$this->new_messages_first = $data['new_messages_first'];
} | php | public function getFormData()
{
$data = Client::perform('get-class-values', ['class' => 'client,ticket_settings']);
$this->ticket_emails = $data['ticket_emails'];
$this->send_message_text = $data['send_message_text'];
$this->new_messages_first = $data['new_messages_first'];
} | [
"public",
"function",
"getFormData",
"(",
")",
"{",
"$",
"data",
"=",
"Client",
"::",
"perform",
"(",
"'get-class-values'",
",",
"[",
"'class'",
"=>",
"'client,ticket_settings'",
"]",
")",
";",
"$",
"this",
"->",
"ticket_emails",
"=",
"$",
"data",
"[",
"'t... | Get form data from API. | [
"Get",
"form",
"data",
"from",
"API",
"."
] | 749e22a96c186c3313f78398b09a549d332d1814 | https://github.com/hiqdev/hipanel-module-ticket/blob/749e22a96c186c3313f78398b09a549d332d1814/src/models/TicketSettings.php#L64-L70 | train |
ommu/mod-core | models/OmmuPages.php | OmmuPages.getPages | public static function getPages($publish=null, $array=true)
{
$criteria=new CDbCriteria;
if($publish != null)
$criteria->compare('t.publish', $publish);
$model = self::model()->findAll($criteria);
if($array == true) {
$items = array();
if($model != null) {
foreach($model as $key => $val) {
$items[$val->page_id] = $val->name;
}
return $items;
} else
return false;
} else
return $model;
} | php | public static function getPages($publish=null, $array=true)
{
$criteria=new CDbCriteria;
if($publish != null)
$criteria->compare('t.publish', $publish);
$model = self::model()->findAll($criteria);
if($array == true) {
$items = array();
if($model != null) {
foreach($model as $key => $val) {
$items[$val->page_id] = $val->name;
}
return $items;
} else
return false;
} else
return $model;
} | [
"public",
"static",
"function",
"getPages",
"(",
"$",
"publish",
"=",
"null",
",",
"$",
"array",
"=",
"true",
")",
"{",
"$",
"criteria",
"=",
"new",
"CDbCriteria",
";",
"if",
"(",
"$",
"publish",
"!=",
"null",
")",
"$",
"criteria",
"->",
"compare",
"... | getPages
0 = unpublish
1 = publish | [
"getPages",
"0",
"=",
"unpublish",
"1",
"=",
"publish"
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/models/OmmuPages.php#L390-L409 | train |
ommu/mod-core | models/OmmuMenus.php | OmmuMenus.getParentMenu | public static function getParentMenu($publish=null, $parent=null, $type=null)
{
$criteria=new CDbCriteria;
if($publish != null)
$criteria->compare('t.publish',$publish);
if($parent != null)
$criteria->compare('t.parent_id',$parent);
$model = self::model()->findAll($criteria);
if($type == null) {
$items = array();
if($model != null) {
foreach($model as $key => $val) {
$items[$val->id] = $val->title->message;
}
return $items;
} else {
return false;
}
} else
return $model;
} | php | public static function getParentMenu($publish=null, $parent=null, $type=null)
{
$criteria=new CDbCriteria;
if($publish != null)
$criteria->compare('t.publish',$publish);
if($parent != null)
$criteria->compare('t.parent_id',$parent);
$model = self::model()->findAll($criteria);
if($type == null) {
$items = array();
if($model != null) {
foreach($model as $key => $val) {
$items[$val->id] = $val->title->message;
}
return $items;
} else {
return false;
}
} else
return $model;
} | [
"public",
"static",
"function",
"getParentMenu",
"(",
"$",
"publish",
"=",
"null",
",",
"$",
"parent",
"=",
"null",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"criteria",
"=",
"new",
"CDbCriteria",
";",
"if",
"(",
"$",
"publish",
"!=",
"null",
")"... | getParentMenu
0 = unpublish
1 = publish | [
"getParentMenu",
"0",
"=",
"unpublish",
"1",
"=",
"publish"
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/models/OmmuMenus.php#L374-L396 | train |
ekowabaka/clearice | src/io/Io.php | Io.getResponse | public function getResponse($question, $params = array())
{
$params = $this->cleanParamsAndPrintPrompt($question, $params);
$response = str_replace(array("\n", "\r"), array("", ""), $this->input());
return $this->validateResponse($response, $question, $params);
} | php | public function getResponse($question, $params = array())
{
$params = $this->cleanParamsAndPrintPrompt($question, $params);
$response = str_replace(array("\n", "\r"), array("", ""), $this->input());
return $this->validateResponse($response, $question, $params);
} | [
"public",
"function",
"getResponse",
"(",
"$",
"question",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"cleanParamsAndPrintPrompt",
"(",
"$",
"question",
",",
"$",
"params",
")",
";",
"$",
"response",
"=... | A function for getting answers to questions from users interractively.
This function takes the question and an optional array of parameters.
The question is a regular string and the array provides extra information
about the question being asked.
The array takes the following parameters
**answers**
An array of posible answers to the question. Once this array is available
the user would be expected to provide an answer which is specifically in
the list. Any other answer would be rejected. The library would print
out all the possible answers so the user is aware of which answers
are valid.
**default**
A default answer which should be used in case the user does not supply an
answer. The library would make the user aware of this default by placing
it in square brackets after the question.
**required**
If this flag is set, the user would be required to provide an answer. A
blank answer would be rejected.
@param string $question The question you want to ask
@param array $params An array of options that this function takes.
@return string The response provided by the user to the prompt. | [
"A",
"function",
"for",
"getting",
"answers",
"to",
"questions",
"from",
"users",
"interractively",
".",
"This",
"function",
"takes",
"the",
"question",
"and",
"an",
"optional",
"array",
"of",
"parameters",
".",
"The",
"question",
"is",
"a",
"regular",
"string... | 8762c8a75e62df5c1a5505f2c78d6809ab5b3658 | https://github.com/ekowabaka/clearice/blob/8762c8a75e62df5c1a5505f2c78d6809ab5b3658/src/io/Io.php#L168-L173 | train |
ekowabaka/clearice | src/io/Io.php | Io.resetOutputLevel | public function resetOutputLevel()
{
if (count($this->outputLevelStack) > 0) {
$this->setOutputLevel(reset($this->outputLevelStack));
$this->outputLevelStack = array();
}
} | php | public function resetOutputLevel()
{
if (count($this->outputLevelStack) > 0) {
$this->setOutputLevel(reset($this->outputLevelStack));
$this->outputLevelStack = array();
}
} | [
"public",
"function",
"resetOutputLevel",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"outputLevelStack",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"setOutputLevel",
"(",
"reset",
"(",
"$",
"this",
"->",
"outputLevelStack",
")",
")",
"... | Resets the output level stack.
This method clears all items off the output level stack leaving only the
current output level. | [
"Resets",
"the",
"output",
"level",
"stack",
".",
"This",
"method",
"clears",
"all",
"items",
"off",
"the",
"output",
"level",
"stack",
"leaving",
"only",
"the",
"current",
"output",
"level",
"."
] | 8762c8a75e62df5c1a5505f2c78d6809ab5b3658 | https://github.com/ekowabaka/clearice/blob/8762c8a75e62df5c1a5505f2c78d6809ab5b3658/src/io/Io.php#L289-L295 | train |
ekowabaka/clearice | src/io/Io.php | Io.getStream | private function getStream($type)
{
if (!isset($this->streams[$type])) {
$this->streams[$type] = fopen($this->streamUrls[$type], $type == 'input' ? 'r' : 'w');
}
return $this->streams[$type];
} | php | private function getStream($type)
{
if (!isset($this->streams[$type])) {
$this->streams[$type] = fopen($this->streamUrls[$type], $type == 'input' ? 'r' : 'w');
}
return $this->streams[$type];
} | [
"private",
"function",
"getStream",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"streams",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"this",
"->",
"streams",
"[",
"$",
"type",
"]",
"=",
"fopen",
"(",
"$",
"this... | Returns a stream resource for a given stream type.
If the stream has not been opened this method opens the stream before
returning the asociated resource. This ensures that there is only one
resource handle to any stream at any given time.
@param string $type
@return resource | [
"Returns",
"a",
"stream",
"resource",
"for",
"a",
"given",
"stream",
"type",
".",
"If",
"the",
"stream",
"has",
"not",
"been",
"opened",
"this",
"method",
"opens",
"the",
"stream",
"before",
"returning",
"the",
"asociated",
"resource",
".",
"This",
"ensures"... | 8762c8a75e62df5c1a5505f2c78d6809ab5b3658 | https://github.com/ekowabaka/clearice/blob/8762c8a75e62df5c1a5505f2c78d6809ab5b3658/src/io/Io.php#L319-L325 | train |
gregorybesson/PlaygroundUser | src/Controller/Frontend/UserController.php | UserController.ajaxauthenticateAction | public function ajaxauthenticateAction()
{
// $this->getServiceLocator()->get('Zend\Log')->info('ajaxloginAction -
// AUTHENT : ');
if ($this->zfcUserAuthentication()
->getAuthService()
->hasIdentity()) {
return true;
}
$adapter = $this->zfcUserAuthentication()->getAuthAdapter();
$adapter->prepareForAuthentication($this->getRequest());
$auth = $this->zfcUserAuthentication()->getAuthService()->authenticate($adapter);
if (! $auth->isValid()) {
$adapter->resetAdapters();
return false;
}
$user = $this->zfcUserAuthentication()->getIdentity();
if ($user->getState() && $user->getState() === 2) {
$this->getUserService()->getUserMapper()->activate($user);
}
$this->getEventManager()->trigger('login.post', $this, array('user' => $user));
return true;
} | php | public function ajaxauthenticateAction()
{
// $this->getServiceLocator()->get('Zend\Log')->info('ajaxloginAction -
// AUTHENT : ');
if ($this->zfcUserAuthentication()
->getAuthService()
->hasIdentity()) {
return true;
}
$adapter = $this->zfcUserAuthentication()->getAuthAdapter();
$adapter->prepareForAuthentication($this->getRequest());
$auth = $this->zfcUserAuthentication()->getAuthService()->authenticate($adapter);
if (! $auth->isValid()) {
$adapter->resetAdapters();
return false;
}
$user = $this->zfcUserAuthentication()->getIdentity();
if ($user->getState() && $user->getState() === 2) {
$this->getUserService()->getUserMapper()->activate($user);
}
$this->getEventManager()->trigger('login.post', $this, array('user' => $user));
return true;
} | [
"public",
"function",
"ajaxauthenticateAction",
"(",
")",
"{",
"// $this->getServiceLocator()->get('Zend\\Log')->info('ajaxloginAction -",
"// AUTHENT : ');",
"if",
"(",
"$",
"this",
"->",
"zfcUserAuthentication",
"(",
")",
"->",
"getAuthService",
"(",
")",
"->",
"hasIdenti... | Ajax authentication action | [
"Ajax",
"authentication",
"action"
] | b07c9969b5da1c173001fbba343f0a006d87eb8e | https://github.com/gregorybesson/PlaygroundUser/blob/b07c9969b5da1c173001fbba343f0a006d87eb8e/src/Controller/Frontend/UserController.php#L330-L356 | train |
gregorybesson/PlaygroundUser | src/Controller/Frontend/UserController.php | UserController.emailExistsAction | public function emailExistsAction()
{
$email = $this->getEvent()->getRouteMatch()->getParam('email');
$request = $this->getRequest();
$response = $this->getResponse();
$user = $this->getUserService()->getUserMapper()->findByEmail($email);
if (empty($user)) {
$result = ['result' => false];
} else {
$result = ['result' => true];
}
$response->setContent(\Zend\Json\Json::encode($result));
return $response;
} | php | public function emailExistsAction()
{
$email = $this->getEvent()->getRouteMatch()->getParam('email');
$request = $this->getRequest();
$response = $this->getResponse();
$user = $this->getUserService()->getUserMapper()->findByEmail($email);
if (empty($user)) {
$result = ['result' => false];
} else {
$result = ['result' => true];
}
$response->setContent(\Zend\Json\Json::encode($result));
return $response;
} | [
"public",
"function",
"emailExistsAction",
"(",
")",
"{",
"$",
"email",
"=",
"$",
"this",
"->",
"getEvent",
"(",
")",
"->",
"getRouteMatch",
"(",
")",
"->",
"getParam",
"(",
"'email'",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"("... | You can search for a user based on the email | [
"You",
"can",
"search",
"for",
"a",
"user",
"based",
"on",
"the",
"email"
] | b07c9969b5da1c173001fbba343f0a006d87eb8e | https://github.com/gregorybesson/PlaygroundUser/blob/b07c9969b5da1c173001fbba343f0a006d87eb8e/src/Controller/Frontend/UserController.php#L951-L966 | train |
gregorybesson/PlaygroundUser | src/Controller/Frontend/UserController.php | UserController.autoCompleteUserAction | public function autoCompleteUserAction()
{
$field = $this->getEvent()->getRouteMatch()->getParam('field');
$value = $this->getEvent()->getRouteMatch()->getParam('value');
$request = $this->getRequest();
$response = $this->getResponse();
$result = $this->getUserService()->autoCompleteUser($field, $value);
$response->setContent(\Zend\Json\Json::encode($result));
return $response;
} | php | public function autoCompleteUserAction()
{
$field = $this->getEvent()->getRouteMatch()->getParam('field');
$value = $this->getEvent()->getRouteMatch()->getParam('value');
$request = $this->getRequest();
$response = $this->getResponse();
$result = $this->getUserService()->autoCompleteUser($field, $value);
$response->setContent(\Zend\Json\Json::encode($result));
return $response;
} | [
"public",
"function",
"autoCompleteUserAction",
"(",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"getEvent",
"(",
")",
"->",
"getRouteMatch",
"(",
")",
"->",
"getParam",
"(",
"'field'",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getEvent",
"(... | You can search for a user based on any user field | [
"You",
"can",
"search",
"for",
"a",
"user",
"based",
"on",
"any",
"user",
"field"
] | b07c9969b5da1c173001fbba343f0a006d87eb8e | https://github.com/gregorybesson/PlaygroundUser/blob/b07c9969b5da1c173001fbba343f0a006d87eb8e/src/Controller/Frontend/UserController.php#L972-L983 | train |
gregorybesson/PlaygroundUser | src/Controller/Frontend/UserController.php | UserController.getPrizeCategoryForm | public function getPrizeCategoryForm()
{
if (! $this->prizeCategoryForm) {
$this->setPrizeCategoryForm(
$this->getServiceLocator()->get('playgroundgame_prizecategoryuser_form')
);
}
return $this->prizeCategoryForm;
} | php | public function getPrizeCategoryForm()
{
if (! $this->prizeCategoryForm) {
$this->setPrizeCategoryForm(
$this->getServiceLocator()->get('playgroundgame_prizecategoryuser_form')
);
}
return $this->prizeCategoryForm;
} | [
"public",
"function",
"getPrizeCategoryForm",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"prizeCategoryForm",
")",
"{",
"$",
"this",
"->",
"setPrizeCategoryForm",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'playgroundgam... | Get prizeCategoryForm.
@return prizeCategoryForm. | [
"Get",
"prizeCategoryForm",
"."
] | b07c9969b5da1c173001fbba343f0a006d87eb8e | https://github.com/gregorybesson/PlaygroundUser/blob/b07c9969b5da1c173001fbba343f0a006d87eb8e/src/Controller/Frontend/UserController.php#L1056-L1065 | train |
gregorybesson/PlaygroundUser | src/Controller/Frontend/UserController.php | UserController.getBlockAccountForm | public function getBlockAccountForm()
{
if (! $this->blockAccountForm) {
$this->setBlockAccountForm(
$this->getServiceLocator()->get('playgrounduser_blockaccount_form')
);
}
return $this->blockAccountForm;
} | php | public function getBlockAccountForm()
{
if (! $this->blockAccountForm) {
$this->setBlockAccountForm(
$this->getServiceLocator()->get('playgrounduser_blockaccount_form')
);
}
return $this->blockAccountForm;
} | [
"public",
"function",
"getBlockAccountForm",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"blockAccountForm",
")",
"{",
"$",
"this",
"->",
"setBlockAccountForm",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'playgrounduser_b... | Get blockAccountForm.
@return blockAccountForm. | [
"Get",
"blockAccountForm",
"."
] | b07c9969b5da1c173001fbba343f0a006d87eb8e | https://github.com/gregorybesson/PlaygroundUser/blob/b07c9969b5da1c173001fbba343f0a006d87eb8e/src/Controller/Frontend/UserController.php#L1085-L1094 | train |
gregorybesson/PlaygroundUser | src/Controller/Frontend/UserController.php | UserController.getNewsletterForm | public function getNewsletterForm()
{
if (! $this->newsletterForm) {
$this->setNewsletterForm(
$this->getServiceLocator()->get('playgrounduser_newsletter_form')
);
}
return $this->newsletterForm;
} | php | public function getNewsletterForm()
{
if (! $this->newsletterForm) {
$this->setNewsletterForm(
$this->getServiceLocator()->get('playgrounduser_newsletter_form')
);
}
return $this->newsletterForm;
} | [
"public",
"function",
"getNewsletterForm",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"newsletterForm",
")",
"{",
"$",
"this",
"->",
"setNewsletterForm",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'playgrounduser_newslet... | Get newsletterForm.
@return newsletterForm. | [
"Get",
"newsletterForm",
"."
] | b07c9969b5da1c173001fbba343f0a006d87eb8e | https://github.com/gregorybesson/PlaygroundUser/blob/b07c9969b5da1c173001fbba343f0a006d87eb8e/src/Controller/Frontend/UserController.php#L1113-L1122 | train |
gregorybesson/PlaygroundUser | src/Controller/Frontend/UserController.php | UserController.getAddressForm | public function getAddressForm()
{
if (! $this->addressForm) {
$this->setAddressForm(
$this->getServiceLocator()->get('playgrounduser_address_form')
);
}
return $this->addressForm;
} | php | public function getAddressForm()
{
if (! $this->addressForm) {
$this->setAddressForm(
$this->getServiceLocator()->get('playgrounduser_address_form')
);
}
return $this->addressForm;
} | [
"public",
"function",
"getAddressForm",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"addressForm",
")",
"{",
"$",
"this",
"->",
"setAddressForm",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'playgrounduser_address_form'",
... | Get addressForm.
@return addressForm. | [
"Get",
"addressForm",
"."
] | b07c9969b5da1c173001fbba343f0a006d87eb8e | https://github.com/gregorybesson/PlaygroundUser/blob/b07c9969b5da1c173001fbba343f0a006d87eb8e/src/Controller/Frontend/UserController.php#L1141-L1150 | train |
gregorybesson/PlaygroundUser | src/Controller/Frontend/UserController.php | UserController.getProviderService | public function getProviderService()
{
if ($this->providerService == null) {
$this->setProviderService($this->getServiceLocator()->get('playgrounduser_provider_service'));
}
return $this->providerService;
} | php | public function getProviderService()
{
if ($this->providerService == null) {
$this->setProviderService($this->getServiceLocator()->get('playgrounduser_provider_service'));
}
return $this->providerService;
} | [
"public",
"function",
"getProviderService",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"providerService",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"setProviderService",
"(",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'playgrou... | retourne le service social
@return | [
"retourne",
"le",
"service",
"social"
] | b07c9969b5da1c173001fbba343f0a006d87eb8e | https://github.com/gregorybesson/PlaygroundUser/blob/b07c9969b5da1c173001fbba343f0a006d87eb8e/src/Controller/Frontend/UserController.php#L1183-L1190 | train |
gregorybesson/PlaygroundUser | src/Controller/Frontend/UserController.php | UserController.getHybridAuth | public function getHybridAuth()
{
if (!$this->hybridAuth) {
$this->hybridAuth = $this->getServiceLocator()->get('HybridAuth');
}
return $this->hybridAuth;
} | php | public function getHybridAuth()
{
if (!$this->hybridAuth) {
$this->hybridAuth = $this->getServiceLocator()->get('HybridAuth');
}
return $this->hybridAuth;
} | [
"public",
"function",
"getHybridAuth",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hybridAuth",
")",
"{",
"$",
"this",
"->",
"hybridAuth",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'HybridAuth'",
")",
";",
"}",
... | Get the Hybrid_Auth object
@return Hybrid_Auth | [
"Get",
"the",
"Hybrid_Auth",
"object"
] | b07c9969b5da1c173001fbba343f0a006d87eb8e | https://github.com/gregorybesson/PlaygroundUser/blob/b07c9969b5da1c173001fbba343f0a006d87eb8e/src/Controller/Frontend/UserController.php#L1197-L1204 | train |
ommu/mod-core | ommu/Ommu.php | Ommu.getDefaultTheme | public function getDefaultTheme($type='public')
{
$theme = OmmuThemes::model()->find(array(
'select' => 'folder',
'condition' => 'group_page = :group AND default_theme = :default',
'params' => array(
':group' => $type,
':default' => '1',
),
));
if($theme !== null)
return $theme->folder;
else
return null;
} | php | public function getDefaultTheme($type='public')
{
$theme = OmmuThemes::model()->find(array(
'select' => 'folder',
'condition' => 'group_page = :group AND default_theme = :default',
'params' => array(
':group' => $type,
':default' => '1',
),
));
if($theme !== null)
return $theme->folder;
else
return null;
} | [
"public",
"function",
"getDefaultTheme",
"(",
"$",
"type",
"=",
"'public'",
")",
"{",
"$",
"theme",
"=",
"OmmuThemes",
"::",
"model",
"(",
")",
"->",
"find",
"(",
"array",
"(",
"'select'",
"=>",
"'folder'",
",",
"'condition'",
"=>",
"'group_page = :group AND... | Get default theme from database
@return string theme name | [
"Get",
"default",
"theme",
"from",
"database"
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/ommu/Ommu.php#L302-L317 | train |
ommu/mod-core | ommu/Ommu.php | Ommu.getRulePos | public static function getRulePos($rules) {
$result = 1;
$before = array();
$after = array();
foreach($rules as $key => $val) {
if($key == '<module:\w+>/<controller:\w+>/<action:\w+>')
break;
$result++;
}
$i = 1;
foreach($rules as $key => $val) {
if($i < $result)
$before[$key] = $val;
elseif($i >= $pos)
$after[$key] = $val;
$i++;
}
return array('after' => $after, 'before' => $before);
} | php | public static function getRulePos($rules) {
$result = 1;
$before = array();
$after = array();
foreach($rules as $key => $val) {
if($key == '<module:\w+>/<controller:\w+>/<action:\w+>')
break;
$result++;
}
$i = 1;
foreach($rules as $key => $val) {
if($i < $result)
$before[$key] = $val;
elseif($i >= $pos)
$after[$key] = $val;
$i++;
}
return array('after' => $after, 'before' => $before);
} | [
"public",
"static",
"function",
"getRulePos",
"(",
"$",
"rules",
")",
"{",
"$",
"result",
"=",
"1",
";",
"$",
"before",
"=",
"array",
"(",
")",
";",
"$",
"after",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"key",
"=>",
... | Split rules into two part
@param array $rules
@return array | [
"Split",
"rules",
"into",
"two",
"part"
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/ommu/Ommu.php#L325-L346 | train |
s9e/RegexpBuilder | src/Serializer.php | Serializer.serializeStrings | public function serializeStrings(array $strings)
{
$info = $this->analyzeStrings($strings);
$alternations = array_map([$this, 'serializeString'], $info['strings']);
if (!empty($info['chars']))
{
// Prepend the character class to the list of alternations
array_unshift($alternations, $this->serializeCharacterClass($info['chars']));
}
$expr = implode('|', $alternations);
if ($this->needsParentheses($info))
{
$expr = '(?:' . $expr . ')';
}
return $expr . $info['quantifier'];
} | php | public function serializeStrings(array $strings)
{
$info = $this->analyzeStrings($strings);
$alternations = array_map([$this, 'serializeString'], $info['strings']);
if (!empty($info['chars']))
{
// Prepend the character class to the list of alternations
array_unshift($alternations, $this->serializeCharacterClass($info['chars']));
}
$expr = implode('|', $alternations);
if ($this->needsParentheses($info))
{
$expr = '(?:' . $expr . ')';
}
return $expr . $info['quantifier'];
} | [
"public",
"function",
"serializeStrings",
"(",
"array",
"$",
"strings",
")",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"analyzeStrings",
"(",
"$",
"strings",
")",
";",
"$",
"alternations",
"=",
"array_map",
"(",
"[",
"$",
"this",
",",
"'serializeString'",
... | Serialize given strings into a regular expression
@param array[] $strings
@return string | [
"Serialize",
"given",
"strings",
"into",
"a",
"regular",
"expression"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Serializer.php#L48-L65 | train |
s9e/RegexpBuilder | src/Serializer.php | Serializer.analyzeStrings | protected function analyzeStrings(array $strings)
{
$info = ['alternationsCount' => 0, 'quantifier' => ''];
if ($strings[0] === [])
{
$info['quantifier'] = '?';
unset($strings[0]);
}
$chars = $this->getChars($strings);
if (count($chars) > 1)
{
++$info['alternationsCount'];
$info['chars'] = array_values($chars);
$strings = array_diff_key($strings, $chars);
}
$info['strings'] = array_values($strings);
$info['alternationsCount'] += count($strings);
return $info;
} | php | protected function analyzeStrings(array $strings)
{
$info = ['alternationsCount' => 0, 'quantifier' => ''];
if ($strings[0] === [])
{
$info['quantifier'] = '?';
unset($strings[0]);
}
$chars = $this->getChars($strings);
if (count($chars) > 1)
{
++$info['alternationsCount'];
$info['chars'] = array_values($chars);
$strings = array_diff_key($strings, $chars);
}
$info['strings'] = array_values($strings);
$info['alternationsCount'] += count($strings);
return $info;
} | [
"protected",
"function",
"analyzeStrings",
"(",
"array",
"$",
"strings",
")",
"{",
"$",
"info",
"=",
"[",
"'alternationsCount'",
"=>",
"0",
",",
"'quantifier'",
"=>",
"''",
"]",
";",
"if",
"(",
"$",
"strings",
"[",
"0",
"]",
"===",
"[",
"]",
")",
"{"... | Analyze given strings to determine how to serialize them
The returned array may contains any of the following elements:
- (string) quantifier Either '' or '?'
- (array) chars List of values from single-char strings
- (array) strings List of multi-char strings
@param array[] $strings
@return array | [
"Analyze",
"given",
"strings",
"to",
"determine",
"how",
"to",
"serialize",
"them"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Serializer.php#L79-L100 | train |
s9e/RegexpBuilder | src/Serializer.php | Serializer.getChars | protected function getChars(array $strings)
{
$chars = [];
foreach ($strings as $k => $string)
{
if ($this->isChar($string))
{
$chars[$k] = $string[0];
}
}
return $chars;
} | php | protected function getChars(array $strings)
{
$chars = [];
foreach ($strings as $k => $string)
{
if ($this->isChar($string))
{
$chars[$k] = $string[0];
}
}
return $chars;
} | [
"protected",
"function",
"getChars",
"(",
"array",
"$",
"strings",
")",
"{",
"$",
"chars",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"strings",
"as",
"$",
"k",
"=>",
"$",
"string",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isChar",
"(",
"$",
"strin... | Return the portion of strings that are composed of a single character
@param array[]
@return array String key => value | [
"Return",
"the",
"portion",
"of",
"strings",
"that",
"are",
"composed",
"of",
"a",
"single",
"character"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Serializer.php#L108-L120 | train |
s9e/RegexpBuilder | src/Serializer.php | Serializer.getRanges | protected function getRanges(array $values)
{
$i = 0;
$cnt = count($values);
$start = $values[0];
$end = $start;
$ranges = [];
while (++$i < $cnt)
{
if ($values[$i] === $end + 1)
{
++$end;
}
else
{
$ranges[] = [$start, $end];
$start = $end = $values[$i];
}
}
$ranges[] = [$start, $end];
return $ranges;
} | php | protected function getRanges(array $values)
{
$i = 0;
$cnt = count($values);
$start = $values[0];
$end = $start;
$ranges = [];
while (++$i < $cnt)
{
if ($values[$i] === $end + 1)
{
++$end;
}
else
{
$ranges[] = [$start, $end];
$start = $end = $values[$i];
}
}
$ranges[] = [$start, $end];
return $ranges;
} | [
"protected",
"function",
"getRanges",
"(",
"array",
"$",
"values",
")",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"cnt",
"=",
"count",
"(",
"$",
"values",
")",
";",
"$",
"start",
"=",
"$",
"values",
"[",
"0",
"]",
";",
"$",
"end",
"=",
"$",
"start",
... | Get the list of ranges that cover all given values
@param integer[] $values Ordered list of values
@return array[] List of ranges in the form [start, end] | [
"Get",
"the",
"list",
"of",
"ranges",
"that",
"cover",
"all",
"given",
"values"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Serializer.php#L128-L150 | train |
s9e/RegexpBuilder | src/Serializer.php | Serializer.serializeCharacterClass | protected function serializeCharacterClass(array $values)
{
$expr = '[';
foreach ($this->getRanges($values) as list($start, $end))
{
$expr .= $this->serializeCharacterClassUnit($start);
if ($end > $start)
{
if ($end > $start + 1)
{
$expr .= '-';
}
$expr .= $this->serializeCharacterClassUnit($end);
}
}
$expr .= ']';
return $expr;
} | php | protected function serializeCharacterClass(array $values)
{
$expr = '[';
foreach ($this->getRanges($values) as list($start, $end))
{
$expr .= $this->serializeCharacterClassUnit($start);
if ($end > $start)
{
if ($end > $start + 1)
{
$expr .= '-';
}
$expr .= $this->serializeCharacterClassUnit($end);
}
}
$expr .= ']';
return $expr;
} | [
"protected",
"function",
"serializeCharacterClass",
"(",
"array",
"$",
"values",
")",
"{",
"$",
"expr",
"=",
"'['",
";",
"foreach",
"(",
"$",
"this",
"->",
"getRanges",
"(",
"$",
"values",
")",
"as",
"list",
"(",
"$",
"start",
",",
"$",
"end",
")",
"... | Serialize a given list of values into a character class
@param integer[] $values
@return string | [
"Serialize",
"a",
"given",
"list",
"of",
"values",
"into",
"a",
"character",
"class"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Serializer.php#L204-L222 | train |
s9e/RegexpBuilder | src/Serializer.php | Serializer.serializeElement | protected function serializeElement($element)
{
return (is_array($element)) ? $this->serializeStrings($element) : $this->serializeLiteral($element);
} | php | protected function serializeElement($element)
{
return (is_array($element)) ? $this->serializeStrings($element) : $this->serializeLiteral($element);
} | [
"protected",
"function",
"serializeElement",
"(",
"$",
"element",
")",
"{",
"return",
"(",
"is_array",
"(",
"$",
"element",
")",
")",
"?",
"$",
"this",
"->",
"serializeStrings",
"(",
"$",
"element",
")",
":",
"$",
"this",
"->",
"serializeLiteral",
"(",
"... | Serialize an element from a string
@param array|integer $element
@return string | [
"Serialize",
"an",
"element",
"from",
"a",
"string"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Serializer.php#L241-L244 | train |
s9e/RegexpBuilder | src/Serializer.php | Serializer.serializeValue | protected function serializeValue($value, $escapeMethod)
{
return ($value < 0) ? $this->meta->getExpression($value) : $this->escaper->$escapeMethod($this->output->output($value));
} | php | protected function serializeValue($value, $escapeMethod)
{
return ($value < 0) ? $this->meta->getExpression($value) : $this->escaper->$escapeMethod($this->output->output($value));
} | [
"protected",
"function",
"serializeValue",
"(",
"$",
"value",
",",
"$",
"escapeMethod",
")",
"{",
"return",
"(",
"$",
"value",
"<",
"0",
")",
"?",
"$",
"this",
"->",
"meta",
"->",
"getExpression",
"(",
"$",
"value",
")",
":",
"$",
"this",
"->",
"esca... | Serialize a given value
@param integer $value
@param string $escapeMethod
@return string | [
"Serialize",
"a",
"given",
"value"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Serializer.php#L275-L278 | train |
Nekland/Tools | src/Tools/StringTools.php | StringTools.mb_ucfirst | public static function mb_ucfirst($str, $encoding = 'UTF-8')
{
$length = mb_strlen($str, $encoding);
$firstChar = mb_substr($str, 0, 1, $encoding);
$then = mb_substr($str, 1, $length - 1, $encoding);
return mb_strtoupper($firstChar, $encoding) . $then;
} | php | public static function mb_ucfirst($str, $encoding = 'UTF-8')
{
$length = mb_strlen($str, $encoding);
$firstChar = mb_substr($str, 0, 1, $encoding);
$then = mb_substr($str, 1, $length - 1, $encoding);
return mb_strtoupper($firstChar, $encoding) . $then;
} | [
"public",
"static",
"function",
"mb_ucfirst",
"(",
"$",
"str",
",",
"$",
"encoding",
"=",
"'UTF-8'",
")",
"{",
"$",
"length",
"=",
"mb_strlen",
"(",
"$",
"str",
",",
"$",
"encoding",
")",
";",
"$",
"firstChar",
"=",
"mb_substr",
"(",
"$",
"str",
",",... | This function is missing in PHP for now.
@param string $str
@param string $encoding
@return string | [
"This",
"function",
"is",
"missing",
"in",
"PHP",
"for",
"now",
"."
] | b3f05e5cf2291271e21397060069221a2b65d201 | https://github.com/Nekland/Tools/blob/b3f05e5cf2291271e21397060069221a2b65d201/src/Tools/StringTools.php#L112-L119 | train |
ommu/mod-core | models/OmmuPlugins.php | OmmuPlugins.getPlugin | public static function getPlugin($actived=null, $keypath=null, $array=true)
{
$criteria=new CDbCriteria;
if($actived != null)
$criteria->compare('actived', $actived);
$criteria->addNotInCondition('orders', array(0));
if($actived == null || $actived == 0)
$criteria->order = 'folder ASC';
else
$criteria->order = 'orders ASC';
$model = self::model()->findAll($criteria);
if($array == true) {
$items = array();
if($model != null) {
foreach($model as $key => $val) {
if($keypath == null || $keypath == 'id')
$items[$val->plugin_id] = $val->name;
else
$items[$val->folder] = $val->name;
}
return $items;
} else
return false;
} else
return $model;
} | php | public static function getPlugin($actived=null, $keypath=null, $array=true)
{
$criteria=new CDbCriteria;
if($actived != null)
$criteria->compare('actived', $actived);
$criteria->addNotInCondition('orders', array(0));
if($actived == null || $actived == 0)
$criteria->order = 'folder ASC';
else
$criteria->order = 'orders ASC';
$model = self::model()->findAll($criteria);
if($array == true) {
$items = array();
if($model != null) {
foreach($model as $key => $val) {
if($keypath == null || $keypath == 'id')
$items[$val->plugin_id] = $val->name;
else
$items[$val->folder] = $val->name;
}
return $items;
} else
return false;
} else
return $model;
} | [
"public",
"static",
"function",
"getPlugin",
"(",
"$",
"actived",
"=",
"null",
",",
"$",
"keypath",
"=",
"null",
",",
"$",
"array",
"=",
"true",
")",
"{",
"$",
"criteria",
"=",
"new",
"CDbCriteria",
";",
"if",
"(",
"$",
"actived",
"!=",
"null",
")",
... | getPlugin
0 = unpublish
1 = publish | [
"getPlugin",
"0",
"=",
"unpublish",
"1",
"=",
"publish"
] | 68c90e76440e74ee93bcf82905a54d86c941b771 | https://github.com/ommu/mod-core/blob/68c90e76440e74ee93bcf82905a54d86c941b771/models/OmmuPlugins.php#L329-L356 | train |
merk/Dough | lib/Dough/Money/MultiCurrencySum.php | MultiCurrencySum.times | public function times($multiplier)
{
return new self($this->getAugend()->times($multiplier), $this->getAddend()->times($multiplier));
} | php | public function times($multiplier)
{
return new self($this->getAugend()->times($multiplier), $this->getAddend()->times($multiplier));
} | [
"public",
"function",
"times",
"(",
"$",
"multiplier",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"this",
"->",
"getAugend",
"(",
")",
"->",
"times",
"(",
"$",
"multiplier",
")",
",",
"$",
"this",
"->",
"getAddend",
"(",
")",
"->",
"times",
"(",
... | Multiplies all items of this sum by the multiplier.
@param int|float $multiplier
@return MultiCurrencyMoneyInterface | [
"Multiplies",
"all",
"items",
"of",
"this",
"sum",
"by",
"the",
"multiplier",
"."
] | af36775564fbaf46a8018acc4f1fd993530c1a96 | https://github.com/merk/Dough/blob/af36775564fbaf46a8018acc4f1fd993530c1a96/lib/Dough/Money/MultiCurrencySum.php#L30-L33 | train |
unikent/lib-php-readinglists | src/Parser.php | Parser.get_dataset | private function get_dataset($index, $apiindex) {
if (isset($this->data[$index])) {
return $this->data[$index];
}
$data = array();
foreach ($this->raw as $k => $v) {
$pos = strpos($k, $apiindex);
if ($pos !== 0) {
continue;
}
$data[] = substr($k, strlen($apiindex));
}
$this->data[$index] = $data;
return $data;
} | php | private function get_dataset($index, $apiindex) {
if (isset($this->data[$index])) {
return $this->data[$index];
}
$data = array();
foreach ($this->raw as $k => $v) {
$pos = strpos($k, $apiindex);
if ($pos !== 0) {
continue;
}
$data[] = substr($k, strlen($apiindex));
}
$this->data[$index] = $data;
return $data;
} | [
"private",
"function",
"get_dataset",
"(",
"$",
"index",
",",
"$",
"apiindex",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"index",
"]",
";",
... | Shorthand method.
@param string $index The index to find.
@param string $apiindex The index of the API. | [
"Shorthand",
"method",
"."
] | e14bfaee0ec52319c3f95a0599d01222948b6d76 | https://github.com/unikent/lib-php-readinglists/blob/e14bfaee0ec52319c3f95a0599d01222948b6d76/src/Parser.php#L93-L111 | train |
unikent/lib-php-readinglists | src/Parser.php | Parser.get_lists | public function get_lists($timeperiod) {
$lists = array();
foreach ($this->get_all_lists() as $list) {
$object = $this->get_list($list);
if ($object->get_time_period() == $timeperiod) {
$lists[] = $list;
}
}
return $lists;
} | php | public function get_lists($timeperiod) {
$lists = array();
foreach ($this->get_all_lists() as $list) {
$object = $this->get_list($list);
if ($object->get_time_period() == $timeperiod) {
$lists[] = $list;
}
}
return $lists;
} | [
"public",
"function",
"get_lists",
"(",
"$",
"timeperiod",
")",
"{",
"$",
"lists",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_all_lists",
"(",
")",
"as",
"$",
"list",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"get_l... | Grabs lists for a specific time period.
@param string $timeperiod Get all lists within a timeperiod. | [
"Grabs",
"lists",
"for",
"a",
"specific",
"time",
"period",
"."
] | e14bfaee0ec52319c3f95a0599d01222948b6d76 | https://github.com/unikent/lib-php-readinglists/blob/e14bfaee0ec52319c3f95a0599d01222948b6d76/src/Parser.php#L132-L142 | train |
unikent/lib-php-readinglists | src/Parser.php | Parser.get_list | public function get_list($id) {
foreach (array(self::INDEX_LISTS, self::INDEX_LIST) as $k) {
$key = $this->baseurl . '/' . $k . $id;
if (isset($this->raw[$key])) {
return new ReadingList($this->api, $this->baseurl, $id, $this->raw[$key]);
}
}
return null;
} | php | public function get_list($id) {
foreach (array(self::INDEX_LISTS, self::INDEX_LIST) as $k) {
$key = $this->baseurl . '/' . $k . $id;
if (isset($this->raw[$key])) {
return new ReadingList($this->api, $this->baseurl, $id, $this->raw[$key]);
}
}
return null;
} | [
"public",
"function",
"get_list",
"(",
"$",
"id",
")",
"{",
"foreach",
"(",
"array",
"(",
"self",
"::",
"INDEX_LISTS",
",",
"self",
"::",
"INDEX_LIST",
")",
"as",
"$",
"k",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"baseurl",
".",
"'/'",
".",
... | Returns a list object for a specific list.
@param string $id Returns a list with a specified ID. | [
"Returns",
"a",
"list",
"object",
"for",
"a",
"specific",
"list",
"."
] | e14bfaee0ec52319c3f95a0599d01222948b6d76 | https://github.com/unikent/lib-php-readinglists/blob/e14bfaee0ec52319c3f95a0599d01222948b6d76/src/Parser.php#L149-L158 | train |
unikent/lib-php-readinglists | src/Parser.php | Parser.get_category | public function get_category($url) {
if (isset($this->raw[$url])) {
return new Category($this->api, $this->baseurl, $url, $this->raw[$url]);
}
return null;
} | php | public function get_category($url) {
if (isset($this->raw[$url])) {
return new Category($this->api, $this->baseurl, $url, $this->raw[$url]);
}
return null;
} | [
"public",
"function",
"get_category",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"raw",
"[",
"$",
"url",
"]",
")",
")",
"{",
"return",
"new",
"Category",
"(",
"$",
"this",
"->",
"api",
",",
"$",
"this",
"->",
"baseurl"... | So, this is a category.
Return a sensible object.
@param string $url The category URL. | [
"So",
"this",
"is",
"a",
"category",
".",
"Return",
"a",
"sensible",
"object",
"."
] | e14bfaee0ec52319c3f95a0599d01222948b6d76 | https://github.com/unikent/lib-php-readinglists/blob/e14bfaee0ec52319c3f95a0599d01222948b6d76/src/Parser.php#L166-L172 | train |
php-toolkit/php-utils | src/PhpDoc.php | PhpDoc.firstLine | public static function firstLine(string $comment): string
{
$docLines = \preg_split('~\R~u', $comment);
if (isset($docLines[1])) {
return \trim($docLines[1], "/\t *");
}
return '';
} | php | public static function firstLine(string $comment): string
{
$docLines = \preg_split('~\R~u', $comment);
if (isset($docLines[1])) {
return \trim($docLines[1], "/\t *");
}
return '';
} | [
"public",
"static",
"function",
"firstLine",
"(",
"string",
"$",
"comment",
")",
":",
"string",
"{",
"$",
"docLines",
"=",
"\\",
"preg_split",
"(",
"'~\\R~u'",
",",
"$",
"comment",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"docLines",
"[",
"1",
"]",
")... | Returns the first line of docBlock.
@param string $comment
@return string | [
"Returns",
"the",
"first",
"line",
"of",
"docBlock",
"."
] | 6e4b249b1c3cae36e19db466ddf5c7dd2c985904 | https://github.com/php-toolkit/php-utils/blob/6e4b249b1c3cae36e19db466ddf5c7dd2c985904/src/PhpDoc.php#L85-L94 | train |
php-toolkit/php-utils | src/PhpDoc.php | PhpDoc.description | public static function description(string $comment): string
{
$comment = \str_replace("\r", '', \trim(\preg_replace('/^\s*\**( |\t)?/m', '', trim($comment, '/'))));
if (\preg_match('/^\s*@\w+/m', $comment, $matches, \PREG_OFFSET_CAPTURE)) {
$comment = \trim(\substr($comment, 0, $matches[0][1]));
}
return $comment;
} | php | public static function description(string $comment): string
{
$comment = \str_replace("\r", '', \trim(\preg_replace('/^\s*\**( |\t)?/m', '', trim($comment, '/'))));
if (\preg_match('/^\s*@\w+/m', $comment, $matches, \PREG_OFFSET_CAPTURE)) {
$comment = \trim(\substr($comment, 0, $matches[0][1]));
}
return $comment;
} | [
"public",
"static",
"function",
"description",
"(",
"string",
"$",
"comment",
")",
":",
"string",
"{",
"$",
"comment",
"=",
"\\",
"str_replace",
"(",
"\"\\r\"",
",",
"''",
",",
"\\",
"trim",
"(",
"\\",
"preg_replace",
"(",
"'/^\\s*\\**( |\\t)?/m'",
",",
"'... | Returns full description from the doc-block.
If have multi line text, will return multi line.
@param string $comment
@return string | [
"Returns",
"full",
"description",
"from",
"the",
"doc",
"-",
"block",
".",
"If",
"have",
"multi",
"line",
"text",
"will",
"return",
"multi",
"line",
"."
] | 6e4b249b1c3cae36e19db466ddf5c7dd2c985904 | https://github.com/php-toolkit/php-utils/blob/6e4b249b1c3cae36e19db466ddf5c7dd2c985904/src/PhpDoc.php#L102-L111 | train |
froq/froq-http | src/Response.php | Response.sendHeader | public function sendHeader(string $name, ?string $value): void
{
if (headers_sent($file, $line)) {
throw new HttpException(sprintf("Cannot use '%s()', headers already sent in %s:%s",
__method__, $file, $line));
}
// null means remove
if ($value === null) {
$this->removeHeader($name);
header_remove($name);
} else {
$this->setHeader($name, $value);
header(sprintf('%s: %s', $name, $value));
}
} | php | public function sendHeader(string $name, ?string $value): void
{
if (headers_sent($file, $line)) {
throw new HttpException(sprintf("Cannot use '%s()', headers already sent in %s:%s",
__method__, $file, $line));
}
// null means remove
if ($value === null) {
$this->removeHeader($name);
header_remove($name);
} else {
$this->setHeader($name, $value);
header(sprintf('%s: %s', $name, $value));
}
} | [
"public",
"function",
"sendHeader",
"(",
"string",
"$",
"name",
",",
"?",
"string",
"$",
"value",
")",
":",
"void",
"{",
"if",
"(",
"headers_sent",
"(",
"$",
"file",
",",
"$",
"line",
")",
")",
"{",
"throw",
"new",
"HttpException",
"(",
"sprintf",
"(... | Send header.
@param string $name
@param ?string $value
@return void
@throws froq\http\HttpException | [
"Send",
"header",
"."
] | 067207669b5054b867b7df2b5557acf1d43f572a | https://github.com/froq/froq-http/blob/067207669b5054b867b7df2b5557acf1d43f572a/src/Response.php#L127-L142 | train |
froq/froq-http | src/Response.php | Response.sendCookie | public function sendCookie(string $name, ?string $value, int $expire = 0,
string $path = '/', string $domain = '', bool $secure = false, bool $httpOnly = false): void
{
// check name
if (!preg_match('~^[a-z0-9_\-\.]+$~i', $name)) {
throw new HttpException("Invalid cookie name '{$name}' given");
}
$value = (string) $value;
if ($expire < 0) {
$value = '';
}
setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
} | php | public function sendCookie(string $name, ?string $value, int $expire = 0,
string $path = '/', string $domain = '', bool $secure = false, bool $httpOnly = false): void
{
// check name
if (!preg_match('~^[a-z0-9_\-\.]+$~i', $name)) {
throw new HttpException("Invalid cookie name '{$name}' given");
}
$value = (string) $value;
if ($expire < 0) {
$value = '';
}
setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
} | [
"public",
"function",
"sendCookie",
"(",
"string",
"$",
"name",
",",
"?",
"string",
"$",
"value",
",",
"int",
"$",
"expire",
"=",
"0",
",",
"string",
"$",
"path",
"=",
"'/'",
",",
"string",
"$",
"domain",
"=",
"''",
",",
"bool",
"$",
"secure",
"=",... | Send cookie.
@param string $name
@param ?string $value
@param int $expire
@param string $path
@param string $domain
@param bool $secure
@param bool $httpOnly
@return void
@throws froq\http\HttpException | [
"Send",
"cookie",
"."
] | 067207669b5054b867b7df2b5557acf1d43f572a | https://github.com/froq/froq-http/blob/067207669b5054b867b7df2b5557acf1d43f572a/src/Response.php#L167-L181 | train |
froq/froq-http | src/Response.php | Response.sendCookies | public function sendCookies(): void
{
foreach ((array) $this->cookies as $cookie) {
$this->sendCookie($cookie['name'], $cookie['value'], $cookie['expire'],
$cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httpOnly']);
}
} | php | public function sendCookies(): void
{
foreach ((array) $this->cookies as $cookie) {
$this->sendCookie($cookie['name'], $cookie['value'], $cookie['expire'],
$cookie['path'], $cookie['domain'], $cookie['secure'], $cookie['httpOnly']);
}
} | [
"public",
"function",
"sendCookies",
"(",
")",
":",
"void",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"cookies",
"as",
"$",
"cookie",
")",
"{",
"$",
"this",
"->",
"sendCookie",
"(",
"$",
"cookie",
"[",
"'name'",
"]",
",",
"$",
"coo... | Send cookies.
@return void | [
"Send",
"cookies",
"."
] | 067207669b5054b867b7df2b5557acf1d43f572a | https://github.com/froq/froq-http/blob/067207669b5054b867b7df2b5557acf1d43f572a/src/Response.php#L187-L193 | train |
vanilla/garden-db | src/Drivers/SqliteDb.php | SqliteDb.alterTableMigrate | private function alterTableMigrate(array $alterDef, array $options = []) {
$table = $alterDef['name'];
$currentDef = $this->fetchTableDef($table);
// Merge the table definitions if we aren't dropping stuff.
if (!self::val(Db::OPTION_DROP, $options)) {
$tableDef = $this->mergeTableDefs($currentDef, $alterDef);
} else {
$tableDef = $alterDef['def'];
}
// Drop all of the indexes on the current table.
foreach (self::val('indexes', $currentDef, []) as $indexDef) {
if (self::val('type', $indexDef, Db::INDEX_IX) === Db::INDEX_IX) {
$this->dropIndex($indexDef['name']);
}
}
$tmpTable = $table.'_'.time();
// Rename the current table.
$this->renameTable($table, $tmpTable);
// Create the new table.
$this->createTableDb($tableDef, $options);
// Figure out the columns that we can insert.
$columns = array_keys(array_intersect_key($tableDef['columns'], $currentDef['columns']));
// Build the insert/select statement.
$sql = 'insert into '.$this->prefixTable($table)."\n".
$this->bracketList($columns, '`')."\n".
$this->buildSelect($tmpTable, [], ['columns' => $columns]);
$this->queryDefine($sql);
// Drop the temp table.
$this->dropTable($tmpTable);
} | php | private function alterTableMigrate(array $alterDef, array $options = []) {
$table = $alterDef['name'];
$currentDef = $this->fetchTableDef($table);
// Merge the table definitions if we aren't dropping stuff.
if (!self::val(Db::OPTION_DROP, $options)) {
$tableDef = $this->mergeTableDefs($currentDef, $alterDef);
} else {
$tableDef = $alterDef['def'];
}
// Drop all of the indexes on the current table.
foreach (self::val('indexes', $currentDef, []) as $indexDef) {
if (self::val('type', $indexDef, Db::INDEX_IX) === Db::INDEX_IX) {
$this->dropIndex($indexDef['name']);
}
}
$tmpTable = $table.'_'.time();
// Rename the current table.
$this->renameTable($table, $tmpTable);
// Create the new table.
$this->createTableDb($tableDef, $options);
// Figure out the columns that we can insert.
$columns = array_keys(array_intersect_key($tableDef['columns'], $currentDef['columns']));
// Build the insert/select statement.
$sql = 'insert into '.$this->prefixTable($table)."\n".
$this->bracketList($columns, '`')."\n".
$this->buildSelect($tmpTable, [], ['columns' => $columns]);
$this->queryDefine($sql);
// Drop the temp table.
$this->dropTable($tmpTable);
} | [
"private",
"function",
"alterTableMigrate",
"(",
"array",
"$",
"alterDef",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"table",
"=",
"$",
"alterDef",
"[",
"'name'",
"]",
";",
"$",
"currentDef",
"=",
"$",
"this",
"->",
"fetchTableDef",
"... | Alter a table by creating a new table and copying the old table's data to it.
@param array $alterDef The new definition.
@param array $options An array of options for the migration. | [
"Alter",
"a",
"table",
"by",
"creating",
"a",
"new",
"table",
"and",
"copying",
"the",
"old",
"table",
"s",
"data",
"to",
"it",
"."
] | 2634229fb7a161f649ad371e59a973ccbbe72247 | https://github.com/vanilla/garden-db/blob/2634229fb7a161f649ad371e59a973ccbbe72247/src/Drivers/SqliteDb.php#L32-L70 | train |
vanilla/garden-db | src/Drivers/SqliteDb.php | SqliteDb.fetchColumnDefsDb | protected function fetchColumnDefsDb(string $table) {
$cdefs = $this->query('pragma table_info('.$this->prefixTable($table, false).')')->fetchAll(PDO::FETCH_ASSOC);
if (empty($cdefs)) {
return null;
}
$columns = [];
$pk = [];
foreach ($cdefs as $cdef) {
$column = Db::typeDef($cdef['type']);
if ($column === null) {
throw new \Exception("Unknown type '$columnType'.", 500);
}
$column['allowNull'] = !filter_var($cdef['notnull'], FILTER_VALIDATE_BOOLEAN);
if ($cdef['pk']) {
$pk[] = $cdef['name'];
if (strcasecmp($cdef['type'], 'integer') === 0) {
$column['autoIncrement'] = true;
} else {
$column['primary'] = true;
}
}
if ($cdef['dflt_value'] !== null) {
$column['default'] = $this->forceType($cdef['dflt_value'], $column['type']);
}
$columns[$cdef['name']] = $column;
}
// $tdef = ['columns' => $columns];
// if (!empty($pk)) {
// $tdef['indexes'][Db::INDEX_PK] = [
// 'columns' => $pk,
// 'type' => Db::INDEX_PK
// ];
// }
// $this->tables[$table] = $tdef;
return $columns;
} | php | protected function fetchColumnDefsDb(string $table) {
$cdefs = $this->query('pragma table_info('.$this->prefixTable($table, false).')')->fetchAll(PDO::FETCH_ASSOC);
if (empty($cdefs)) {
return null;
}
$columns = [];
$pk = [];
foreach ($cdefs as $cdef) {
$column = Db::typeDef($cdef['type']);
if ($column === null) {
throw new \Exception("Unknown type '$columnType'.", 500);
}
$column['allowNull'] = !filter_var($cdef['notnull'], FILTER_VALIDATE_BOOLEAN);
if ($cdef['pk']) {
$pk[] = $cdef['name'];
if (strcasecmp($cdef['type'], 'integer') === 0) {
$column['autoIncrement'] = true;
} else {
$column['primary'] = true;
}
}
if ($cdef['dflt_value'] !== null) {
$column['default'] = $this->forceType($cdef['dflt_value'], $column['type']);
}
$columns[$cdef['name']] = $column;
}
// $tdef = ['columns' => $columns];
// if (!empty($pk)) {
// $tdef['indexes'][Db::INDEX_PK] = [
// 'columns' => $pk,
// 'type' => Db::INDEX_PK
// ];
// }
// $this->tables[$table] = $tdef;
return $columns;
} | [
"protected",
"function",
"fetchColumnDefsDb",
"(",
"string",
"$",
"table",
")",
"{",
"$",
"cdefs",
"=",
"$",
"this",
"->",
"query",
"(",
"'pragma table_info('",
".",
"$",
"this",
"->",
"prefixTable",
"(",
"$",
"table",
",",
"false",
")",
".",
"')'",
")",... | Get the columns for a table..
@param string $table The table to get the columns for.
@return array|null Returns an array of columns. | [
"Get",
"the",
"columns",
"for",
"a",
"table",
".."
] | 2634229fb7a161f649ad371e59a973ccbbe72247 | https://github.com/vanilla/garden-db/blob/2634229fb7a161f649ad371e59a973ccbbe72247/src/Drivers/SqliteDb.php#L342-L379 | train |
vanilla/garden-db | src/Drivers/SqliteDb.php | SqliteDb.fetchIndexesDb | protected function fetchIndexesDb($table = '') {
$indexes = [];
$indexInfos = $this->query('pragma index_list('.$this->prefixTable($table).')')->fetchAll(PDO::FETCH_ASSOC);
foreach ($indexInfos as $row) {
$indexName = $row['name'];
if ($row['unique']) {
$type = Db::INDEX_UNIQUE;
} else {
$type = Db::INDEX_IX;
}
// Query the columns in the index.
$columns = $this->query('pragma index_info('.$this->quote($indexName).')')->fetchAll(PDO::FETCH_ASSOC);
$index = [
'name' => $indexName,
'columns' => array_column($columns, 'name'),
'type' => $type
];
$indexes[] = $index;
}
return $indexes;
} | php | protected function fetchIndexesDb($table = '') {
$indexes = [];
$indexInfos = $this->query('pragma index_list('.$this->prefixTable($table).')')->fetchAll(PDO::FETCH_ASSOC);
foreach ($indexInfos as $row) {
$indexName = $row['name'];
if ($row['unique']) {
$type = Db::INDEX_UNIQUE;
} else {
$type = Db::INDEX_IX;
}
// Query the columns in the index.
$columns = $this->query('pragma index_info('.$this->quote($indexName).')')->fetchAll(PDO::FETCH_ASSOC);
$index = [
'name' => $indexName,
'columns' => array_column($columns, 'name'),
'type' => $type
];
$indexes[] = $index;
}
return $indexes;
} | [
"protected",
"function",
"fetchIndexesDb",
"(",
"$",
"table",
"=",
"''",
")",
"{",
"$",
"indexes",
"=",
"[",
"]",
";",
"$",
"indexInfos",
"=",
"$",
"this",
"->",
"query",
"(",
"'pragma index_list('",
".",
"$",
"this",
"->",
"prefixTable",
"(",
"$",
"ta... | Get the indexes for a table.
@param string $table The name of the table to get the indexes for or an empty string to get all indexes.
@return array|null | [
"Get",
"the",
"indexes",
"for",
"a",
"table",
"."
] | 2634229fb7a161f649ad371e59a973ccbbe72247 | https://github.com/vanilla/garden-db/blob/2634229fb7a161f649ad371e59a973ccbbe72247/src/Drivers/SqliteDb.php#L387-L411 | train |
vanilla/garden-db | src/Drivers/SqliteDb.php | SqliteDb.getPKValue | private function getPKValue($table, array $row, $quick = false) {
if ($quick && isset($row[$table.'ID'])) {
return [$table.'ID' => $row[$table.'ID']];
}
$tdef = $this->fetchTableDef($table);
$cols = [];
foreach ($tdef['columns'] as $name => $cdef) {
if (empty($cdef['primary'])) {
break;
}
if (!array_key_exists($name, $row)) {
return null;
}
$cols[$name] = $row[$name];
}
return $cols;
} | php | private function getPKValue($table, array $row, $quick = false) {
if ($quick && isset($row[$table.'ID'])) {
return [$table.'ID' => $row[$table.'ID']];
}
$tdef = $this->fetchTableDef($table);
$cols = [];
foreach ($tdef['columns'] as $name => $cdef) {
if (empty($cdef['primary'])) {
break;
}
if (!array_key_exists($name, $row)) {
return null;
}
$cols[$name] = $row[$name];
}
return $cols;
} | [
"private",
"function",
"getPKValue",
"(",
"$",
"table",
",",
"array",
"$",
"row",
",",
"$",
"quick",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"quick",
"&&",
"isset",
"(",
"$",
"row",
"[",
"$",
"table",
".",
"'ID'",
"]",
")",
")",
"{",
"return",
... | Get the primary or secondary keys from the given rows.
@param string $table The name of the table.
@param array $row The row to examine.
@param bool $quick Whether or not to quickly look for <tablename>ID for the primary key.
@return array|null Returns the primary keys and values from {@link $rows} or null if the primary key isn't found. | [
"Get",
"the",
"primary",
"or",
"secondary",
"keys",
"from",
"the",
"given",
"rows",
"."
] | 2634229fb7a161f649ad371e59a973ccbbe72247 | https://github.com/vanilla/garden-db/blob/2634229fb7a161f649ad371e59a973ccbbe72247/src/Drivers/SqliteDb.php#L421-L439 | train |
vanilla/garden-db | src/Drivers/SqliteDb.php | SqliteDb.fetchTableNamesDb | protected function fetchTableNamesDb() {
// Get the table names.
$tables = $this->get(
new Identifier('sqlite_master'),
[
'type' => 'table',
'name' => [Db::OP_LIKE => $this->escapeLike($this->getPx()).'%']
],
[
'columns' => ['name']
]
)->fetchAll(PDO::FETCH_COLUMN);
// Remove internal tables.
$tables = array_filter($tables, function ($name) {
return substr($name, 0, 7) !== 'sqlite_';
});
return $tables;
} | php | protected function fetchTableNamesDb() {
// Get the table names.
$tables = $this->get(
new Identifier('sqlite_master'),
[
'type' => 'table',
'name' => [Db::OP_LIKE => $this->escapeLike($this->getPx()).'%']
],
[
'columns' => ['name']
]
)->fetchAll(PDO::FETCH_COLUMN);
// Remove internal tables.
$tables = array_filter($tables, function ($name) {
return substr($name, 0, 7) !== 'sqlite_';
});
return $tables;
} | [
"protected",
"function",
"fetchTableNamesDb",
"(",
")",
"{",
"// Get the table names.",
"$",
"tables",
"=",
"$",
"this",
"->",
"get",
"(",
"new",
"Identifier",
"(",
"'sqlite_master'",
")",
",",
"[",
"'type'",
"=>",
"'table'",
",",
"'name'",
"=>",
"[",
"Db",
... | Get the all of table names in the database.
@return array Returns an array of table names. | [
"Get",
"the",
"all",
"of",
"table",
"names",
"in",
"the",
"database",
"."
] | 2634229fb7a161f649ad371e59a973ccbbe72247 | https://github.com/vanilla/garden-db/blob/2634229fb7a161f649ad371e59a973ccbbe72247/src/Drivers/SqliteDb.php#L446-L465 | train |
PitonCMS/Engine | app/Library/Handlers/CsrfGuard.php | CsrfGuard.forbidden | public function forbidden(ServerRequestInterface $request, ResponseInterface $response)
{
$contentType = $this->determineContentType($request);
switch ($contentType) {
case 'application/json':
$output = $this->renderJsonErrorMessage();
break;
case 'text/html':
$output = $this->renderHtmlErrorMessage();
break;
default:
throw new Exception('Cannot render unknown content type ' . $contentType);
}
return $response
->withStatus(403)
->withHeader('Content-type', $contentType)
->write($output);
} | php | public function forbidden(ServerRequestInterface $request, ResponseInterface $response)
{
$contentType = $this->determineContentType($request);
switch ($contentType) {
case 'application/json':
$output = $this->renderJsonErrorMessage();
break;
case 'text/html':
$output = $this->renderHtmlErrorMessage();
break;
default:
throw new Exception('Cannot render unknown content type ' . $contentType);
}
return $response
->withStatus(403)
->withHeader('Content-type', $contentType)
->write($output);
} | [
"public",
"function",
"forbidden",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"contentType",
"=",
"$",
"this",
"->",
"determineContentType",
"(",
"$",
"request",
")",
";",
"switch",
"(",
"$",
"conte... | Forbidden HTTP 403 Response
Code borrowed and modified from Slim Error
Respond with HTTP 403 Forbidden
@param ServerRequestInterface $request The most recent Request object
@param ResponseInterface $response The most recent Response object
@return HTTP 403 Forbidden | [
"Forbidden",
"HTTP",
"403",
"Response"
] | 51622658cbd21946757abc27f6928cb482384659 | https://github.com/PitonCMS/Engine/blob/51622658cbd21946757abc27f6928cb482384659/app/Library/Handlers/CsrfGuard.php#L170-L190 | train |
au-research/ANDS-DOI-Service | src/MdsClient.php | MdsClient.request | public function request($url, $content = false, $customRequest = false)
{
$request_parts = explode('/', $url);
$request = $request_parts[3];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(strpos($url,'test')){
curl_setopt($ch, CURLOPT_USERPWD,
$this->username . ":" . $this->testPassword);
}else{
curl_setopt($ch, CURLOPT_USERPWD,
$this->username . ":" . $this->password);
}
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type:application/xml;charset=UTF-8"));
if ($content && !$customRequest) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
}
if ($customRequest) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $customRequest);
}
$output = curl_exec($ch);
$outputINFO = curl_getinfo($ch);
$this->log([
"httpcode" => $outputINFO['http_code'],
"url" => $url,
"endpoint" => $request,
"output" => $output
]);
if ($outputINFO['http_code'] >= 400 || curl_errno($ch)) {
$this->log(curl_error($ch), "error");
$this->log($output, "error");
} else {
$this->log(".datacite.".$request.".response:".$output);
}
curl_close($ch);
return $output;
} | php | public function request($url, $content = false, $customRequest = false)
{
$request_parts = explode('/', $url);
$request = $request_parts[3];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(strpos($url,'test')){
curl_setopt($ch, CURLOPT_USERPWD,
$this->username . ":" . $this->testPassword);
}else{
curl_setopt($ch, CURLOPT_USERPWD,
$this->username . ":" . $this->password);
}
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-Type:application/xml;charset=UTF-8"));
if ($content && !$customRequest) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
}
if ($customRequest) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $customRequest);
}
$output = curl_exec($ch);
$outputINFO = curl_getinfo($ch);
$this->log([
"httpcode" => $outputINFO['http_code'],
"url" => $url,
"endpoint" => $request,
"output" => $output
]);
if ($outputINFO['http_code'] >= 400 || curl_errno($ch)) {
$this->log(curl_error($ch), "error");
$this->log($output, "error");
} else {
$this->log(".datacite.".$request.".response:".$output);
}
curl_close($ch);
return $output;
} | [
"public",
"function",
"request",
"(",
"$",
"url",
",",
"$",
"content",
"=",
"false",
",",
"$",
"customRequest",
"=",
"false",
")",
"{",
"$",
"request_parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"url",
")",
";",
"$",
"request",
"=",
"$",
"request_pa... | Do an actual request to the specified URL
@todo don't use curl, use guzzle
@param $url
@param bool $content
@param bool $customRequest
@return mixed | [
"Do",
"an",
"actual",
"request",
"to",
"the",
"specified",
"URL"
] | c8e2cc98eca23a0c550af9a45b5c5dee230da1c9 | https://github.com/au-research/ANDS-DOI-Service/blob/c8e2cc98eca23a0c550af9a45b5c5dee230da1c9/src/MdsClient.php#L135-L184 | train |
s9e/RegexpBuilder | src/Passes/CoalesceSingleCharacterPrefix.php | CoalesceSingleCharacterPrefix.filterEligibleKeys | protected function filterEligibleKeys(array $eligibleKeys)
{
$filteredKeys = [];
foreach ($eligibleKeys as $k => $keys)
{
if (count($keys) > 1)
{
$filteredKeys[] = $keys;
}
}
return $filteredKeys;
} | php | protected function filterEligibleKeys(array $eligibleKeys)
{
$filteredKeys = [];
foreach ($eligibleKeys as $k => $keys)
{
if (count($keys) > 1)
{
$filteredKeys[] = $keys;
}
}
return $filteredKeys;
} | [
"protected",
"function",
"filterEligibleKeys",
"(",
"array",
"$",
"eligibleKeys",
")",
"{",
"$",
"filteredKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"eligibleKeys",
"as",
"$",
"k",
"=>",
"$",
"keys",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"keys",... | Filter the list of eligible keys and keep those that have at least two matches
@param array[] $eligibleKeys List of lists of keys
@return array[] | [
"Filter",
"the",
"list",
"of",
"eligible",
"keys",
"and",
"keep",
"those",
"that",
"have",
"at",
"least",
"two",
"matches"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Passes/CoalesceSingleCharacterPrefix.php#L47-L59 | train |
s9e/RegexpBuilder | src/Passes/CoalesceSingleCharacterPrefix.php | CoalesceSingleCharacterPrefix.getEligibleKeys | protected function getEligibleKeys(array $strings)
{
$eligibleKeys = [];
foreach ($strings as $k => $string)
{
if (!is_array($string[0]) && isset($string[1]))
{
$suffix = serialize(array_slice($string, 1));
$eligibleKeys[$suffix][] = $k;
}
}
return $this->filterEligibleKeys($eligibleKeys);
} | php | protected function getEligibleKeys(array $strings)
{
$eligibleKeys = [];
foreach ($strings as $k => $string)
{
if (!is_array($string[0]) && isset($string[1]))
{
$suffix = serialize(array_slice($string, 1));
$eligibleKeys[$suffix][] = $k;
}
}
return $this->filterEligibleKeys($eligibleKeys);
} | [
"protected",
"function",
"getEligibleKeys",
"(",
"array",
"$",
"strings",
")",
"{",
"$",
"eligibleKeys",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"strings",
"as",
"$",
"k",
"=>",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"string"... | Get a list of keys of strings eligible to be merged together, grouped by suffix
@param array[] $strings
@return array[] | [
"Get",
"a",
"list",
"of",
"keys",
"of",
"strings",
"eligible",
"to",
"be",
"merged",
"together",
"grouped",
"by",
"suffix"
] | 59d0167a909659d718f53964f7653d2c83a5f8fe | https://github.com/s9e/RegexpBuilder/blob/59d0167a909659d718f53964f7653d2c83a5f8fe/src/Passes/CoalesceSingleCharacterPrefix.php#L67-L80 | train |
unikent/lib-php-readinglists | src/ReadingList.php | ReadingList.get_time_period | public function get_time_period() {
$period = $this->data[Parser::INDEX_LISTS_TIME_PERIOD][0]['value'];
return substr($period, strpos($period, Parser::INDEX_TIME_PERIOD) + strlen(Parser::INDEX_TIME_PERIOD));
} | php | public function get_time_period() {
$period = $this->data[Parser::INDEX_LISTS_TIME_PERIOD][0]['value'];
return substr($period, strpos($period, Parser::INDEX_TIME_PERIOD) + strlen(Parser::INDEX_TIME_PERIOD));
} | [
"public",
"function",
"get_time_period",
"(",
")",
"{",
"$",
"period",
"=",
"$",
"this",
"->",
"data",
"[",
"Parser",
"::",
"INDEX_LISTS_TIME_PERIOD",
"]",
"[",
"0",
"]",
"[",
"'value'",
"]",
";",
"return",
"substr",
"(",
"$",
"period",
",",
"strpos",
... | Which time period is this list in? | [
"Which",
"time",
"period",
"is",
"this",
"list",
"in?"
] | e14bfaee0ec52319c3f95a0599d01222948b6d76 | https://github.com/unikent/lib-php-readinglists/blob/e14bfaee0ec52319c3f95a0599d01222948b6d76/src/ReadingList.php#L67-L70 | train |
unikent/lib-php-readinglists | src/ReadingList.php | ReadingList.get_items | public function get_items() {
if (!isset($this->data[Parser::INDEX_CHILDREN_SPEC])) {
return array();
}
$items = array();
foreach ($this->data[Parser::INDEX_CHILDREN_SPEC] as $k => $data) {
$items[] = $this->api->get_item($data['value']);
}
return $items;
} | php | public function get_items() {
if (!isset($this->data[Parser::INDEX_CHILDREN_SPEC])) {
return array();
}
$items = array();
foreach ($this->data[Parser::INDEX_CHILDREN_SPEC] as $k => $data) {
$items[] = $this->api->get_item($data['value']);
}
return $items;
} | [
"public",
"function",
"get_items",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"Parser",
"::",
"INDEX_CHILDREN_SPEC",
"]",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"items",
"=",
"array",
"(",
")",
... | Items in the list. | [
"Items",
"in",
"the",
"list",
"."
] | e14bfaee0ec52319c3f95a0599d01222948b6d76 | https://github.com/unikent/lib-php-readinglists/blob/e14bfaee0ec52319c3f95a0599d01222948b6d76/src/ReadingList.php#L103-L114 | train |
unikent/lib-php-readinglists | src/ReadingList.php | ReadingList.get_item_count | public function get_item_count() {
$data = $this->data;
$count = 0;
if (isset($data[Parser::INDEX_LISTS_LIST_ITEMS])) {
foreach ($data[Parser::INDEX_LISTS_LIST_ITEMS] as $things) {
if (preg_match('#/items/#', $things['value'])) {
$count++;
}
}
}
return $count;
} | php | public function get_item_count() {
$data = $this->data;
$count = 0;
if (isset($data[Parser::INDEX_LISTS_LIST_ITEMS])) {
foreach ($data[Parser::INDEX_LISTS_LIST_ITEMS] as $things) {
if (preg_match('#/items/#', $things['value'])) {
$count++;
}
}
}
return $count;
} | [
"public",
"function",
"get_item_count",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"data",
";",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"Parser",
"::",
"INDEX_LISTS_LIST_ITEMS",
"]",
")",
")",
"{",
"foreach",
... | Counts the number of items in a list. | [
"Counts",
"the",
"number",
"of",
"items",
"in",
"a",
"list",
"."
] | e14bfaee0ec52319c3f95a0599d01222948b6d76 | https://github.com/unikent/lib-php-readinglists/blob/e14bfaee0ec52319c3f95a0599d01222948b6d76/src/ReadingList.php#L119-L132 | train |
unikent/lib-php-readinglists | src/ReadingList.php | ReadingList.get_categories | public function get_categories() {
$data = $this->data;
if (empty($data[Parser::INDEX_PARENT_SPEC])) {
return array();
}
// Okay. We first grab all of our categories.
$categories = array();
foreach ($data[Parser::INDEX_PARENT_SPEC] as $category) {
$categories[] = $this->api->get_category($category['value']);
}
return $categories;
} | php | public function get_categories() {
$data = $this->data;
if (empty($data[Parser::INDEX_PARENT_SPEC])) {
return array();
}
// Okay. We first grab all of our categories.
$categories = array();
foreach ($data[Parser::INDEX_PARENT_SPEC] as $category) {
$categories[] = $this->api->get_category($category['value']);
}
return $categories;
} | [
"public",
"function",
"get_categories",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"data",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"Parser",
"::",
"INDEX_PARENT_SPEC",
"]",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"// ... | Returns a list's categories. | [
"Returns",
"a",
"list",
"s",
"categories",
"."
] | e14bfaee0ec52319c3f95a0599d01222948b6d76 | https://github.com/unikent/lib-php-readinglists/blob/e14bfaee0ec52319c3f95a0599d01222948b6d76/src/ReadingList.php#L137-L151 | train |
unikent/lib-php-readinglists | src/ReadingList.php | ReadingList.get_last_updated | public function get_last_updated($asstring = false) {
$data = $this->data;
$time = null;
if (isset($data[Parser::INDEX_LISTS_LIST_UPDATED])) {
$time = $data[Parser::INDEX_LISTS_LIST_UPDATED][0]['value'];
$time = strtotime($time);
}
if ($asstring && $time) {
return $this->contextual_time($time);
}
return $time;
} | php | public function get_last_updated($asstring = false) {
$data = $this->data;
$time = null;
if (isset($data[Parser::INDEX_LISTS_LIST_UPDATED])) {
$time = $data[Parser::INDEX_LISTS_LIST_UPDATED][0]['value'];
$time = strtotime($time);
}
if ($asstring && $time) {
return $this->contextual_time($time);
}
return $time;
} | [
"public",
"function",
"get_last_updated",
"(",
"$",
"asstring",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"data",
";",
"$",
"time",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"Parser",
"::",
"INDEX_LISTS_LIST_UPDATE... | Get the time a list was last updated.
@param bool $asstring Return the time as a contextual string? | [
"Get",
"the",
"time",
"a",
"list",
"was",
"last",
"updated",
"."
] | e14bfaee0ec52319c3f95a0599d01222948b6d76 | https://github.com/unikent/lib-php-readinglists/blob/e14bfaee0ec52319c3f95a0599d01222948b6d76/src/ReadingList.php#L158-L172 | train |
locomotivemtl/charcoal-email | src/Charcoal/Email/EmailAwareTrait.php | EmailAwareTrait.emailFromArray | protected function emailFromArray(array $arr)
{
if (isset($arr['address'])) {
$arr['email'] = $arr['address'];
unset($arr['address']);
}
if (!isset($arr['email'])) {
throw new InvalidArgumentException(
'The array must contain at least the "address" key.'
);
}
$email = strval(filter_var($arr['email'], FILTER_SANITIZE_EMAIL));
if (!isset($arr['name']) || $arr['name'] === '') {
return $email;
}
$name = str_replace('"', '', filter_var($arr['name'], FILTER_SANITIZE_STRING));
return sprintf('"%s" <%s>', $name, $email);
} | php | protected function emailFromArray(array $arr)
{
if (isset($arr['address'])) {
$arr['email'] = $arr['address'];
unset($arr['address']);
}
if (!isset($arr['email'])) {
throw new InvalidArgumentException(
'The array must contain at least the "address" key.'
);
}
$email = strval(filter_var($arr['email'], FILTER_SANITIZE_EMAIL));
if (!isset($arr['name']) || $arr['name'] === '') {
return $email;
}
$name = str_replace('"', '', filter_var($arr['name'], FILTER_SANITIZE_STRING));
return sprintf('"%s" <%s>', $name, $email);
} | [
"protected",
"function",
"emailFromArray",
"(",
"array",
"$",
"arr",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"arr",
"[",
"'address'",
"]",
")",
")",
"{",
"$",
"arr",
"[",
"'email'",
"]",
"=",
"$",
"arr",
"[",
"'address'",
"]",
";",
"unset",
"(",
... | Convert an email address array to a RFC-822 string notation.
@param array $arr An email array (containing an "email" key and optionally a "name" key).
@throws InvalidArgumentException If the email array is invalid.
@return string | [
"Convert",
"an",
"email",
"address",
"array",
"to",
"a",
"RFC",
"-",
"822",
"string",
"notation",
"."
] | 99ccabcd0a91802e308177e0b6b626eaf0f940da | https://github.com/locomotivemtl/charcoal-email/blob/99ccabcd0a91802e308177e0b6b626eaf0f940da/src/Charcoal/Email/EmailAwareTrait.php#L76-L97 | train |
mirko-pagliai/me-cms | src/Controller/Admin/BannersPositionsController.php | BannersPositionsController.add | public function add()
{
$position = $this->BannersPositions->newEntity();
if ($this->request->is('post')) {
$position = $this->BannersPositions->patchEntity($position, $this->request->getData());
if ($this->BannersPositions->save($position)) {
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('position'));
} | php | public function add()
{
$position = $this->BannersPositions->newEntity();
if ($this->request->is('post')) {
$position = $this->BannersPositions->patchEntity($position, $this->request->getData());
if ($this->BannersPositions->save($position)) {
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('position'));
} | [
"public",
"function",
"add",
"(",
")",
"{",
"$",
"position",
"=",
"$",
"this",
"->",
"BannersPositions",
"->",
"newEntity",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"is",
"(",
"'post'",
")",
")",
"{",
"$",
"position",
"=",
"$",... | Adds banners position
@return \Cake\Network\Response|null|void | [
"Adds",
"banners",
"position"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/Admin/BannersPositionsController.php#L53-L70 | train |
mirko-pagliai/me-cms | src/Controller/Admin/BannersPositionsController.php | BannersPositionsController.edit | public function edit($id = null)
{
$position = $this->BannersPositions->get($id);
if ($this->request->is(['patch', 'post', 'put'])) {
$position = $this->BannersPositions->patchEntity($position, $this->request->getData());
if ($this->BannersPositions->save($position)) {
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('position'));
} | php | public function edit($id = null)
{
$position = $this->BannersPositions->get($id);
if ($this->request->is(['patch', 'post', 'put'])) {
$position = $this->BannersPositions->patchEntity($position, $this->request->getData());
if ($this->BannersPositions->save($position)) {
$this->Flash->success(I18N_OPERATION_OK);
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(I18N_OPERATION_NOT_OK);
}
$this->set(compact('position'));
} | [
"public",
"function",
"edit",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"position",
"=",
"$",
"this",
"->",
"BannersPositions",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"is",
"(",
"[",
"'patch'",
","... | Edits banners position
@param string $id Banners Position ID
@return \Cake\Network\Response|null|void | [
"Edits",
"banners",
"position"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/Admin/BannersPositionsController.php#L77-L94 | train |
mirko-pagliai/me-cms | src/Controller/Admin/BannersPositionsController.php | BannersPositionsController.delete | public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$position = $this->BannersPositions->get($id);
//Before deleting, it checks if the position has some banners
if (!$position->banner_count) {
$this->BannersPositions->deleteOrFail($position);
$this->Flash->success(I18N_OPERATION_OK);
} else {
$this->Flash->alert(I18N_BEFORE_DELETE);
}
return $this->redirect(['action' => 'index']);
} | php | public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$position = $this->BannersPositions->get($id);
//Before deleting, it checks if the position has some banners
if (!$position->banner_count) {
$this->BannersPositions->deleteOrFail($position);
$this->Flash->success(I18N_OPERATION_OK);
} else {
$this->Flash->alert(I18N_BEFORE_DELETE);
}
return $this->redirect(['action' => 'index']);
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"request",
"->",
"allowMethod",
"(",
"[",
"'post'",
",",
"'delete'",
"]",
")",
";",
"$",
"position",
"=",
"$",
"this",
"->",
"BannersPositions",
"->",
"get",
"(... | Deletes banners position
@param string $id Banners Position ID
@return \Cake\Network\Response|null | [
"Deletes",
"banners",
"position"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/Admin/BannersPositionsController.php#L100-L115 | train |
aimeos/ai-gettext | lib/custom/src/MW/Translation/Gettext.php | Gettext.getTranslations | protected function getTranslations( $domain )
{
if( !isset( $this->files[$domain] ) )
{
if ( !isset( $this->sources[$domain] ) )
{
$msg = sprintf( 'No translation directory for domain "%1$s" available', $domain );
throw new \Aimeos\MW\Translation\Exception( $msg );
}
// Reverse locations so the former gets not overwritten by the later
$locations = array_reverse( $this->getTranslationFileLocations( $this->sources[$domain], $this->getLocale() ) );
foreach( $locations as $location ) {
$this->files[$domain][$location] = new \Aimeos\MW\Translation\File\Mo( $location );
}
}
return ( isset( $this->files[$domain] ) ? $this->files[$domain] : [] );
} | php | protected function getTranslations( $domain )
{
if( !isset( $this->files[$domain] ) )
{
if ( !isset( $this->sources[$domain] ) )
{
$msg = sprintf( 'No translation directory for domain "%1$s" available', $domain );
throw new \Aimeos\MW\Translation\Exception( $msg );
}
// Reverse locations so the former gets not overwritten by the later
$locations = array_reverse( $this->getTranslationFileLocations( $this->sources[$domain], $this->getLocale() ) );
foreach( $locations as $location ) {
$this->files[$domain][$location] = new \Aimeos\MW\Translation\File\Mo( $location );
}
}
return ( isset( $this->files[$domain] ) ? $this->files[$domain] : [] );
} | [
"protected",
"function",
"getTranslations",
"(",
"$",
"domain",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"files",
"[",
"$",
"domain",
"]",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"sources",
"[",
"$",
"dom... | Returns the MO file objects which contain the translations.
@param string $domain Translation domain
@return array List of translation objects implementing \Aimeos\MW\Translation\File\Mo
@throws \Aimeos\MW\Translation\Exception If initialization fails | [
"Returns",
"the",
"MO",
"file",
"objects",
"which",
"contain",
"the",
"translations",
"."
] | 0e823215bf4b35e7e037f8c6c567e85a92d990e7 | https://github.com/aimeos/ai-gettext/blob/0e823215bf4b35e7e037f8c6c567e85a92d990e7/lib/custom/src/MW/Translation/Gettext.php#L120-L139 | train |
locomotivemtl/charcoal-attachment | src/Charcoal/Attachment/Script/MigrateScript.php | MigrateScript.syncRelatedFields | protected function syncRelatedFields(
IdProperty $newProp,
PropertyField $newField,
IdProperty $oldProp,
PropertyField $oldField
) {
unset($newProp, $oldProp, $oldField);
$cli = $this->climate();
if (!$this->quiet()) {
$cli->br();
$cli->comment('Syncing new IDs to pivot table.');
}
$pivot = $this->pivotModel();
$attach = $this->targetModel();
$pivotSource = $pivot->source();
$pivotTable = $pivotSource->table();
$attachSource = $attach->source();
$attachTable = $attachSource->table();
$db = $attachSource->db();
$binds = [
// Join Model
'%pivotTable' => $pivotTable,
'%objectType' => 'object_type',
'%objectId' => 'object_id',
'%targetId' => 'attachment_id',
// Attachment Model
'%targetTable' => $attachTable,
'%targetType' => 'type',
'%newKey' => $newField->ident(),
'%oldKey' => $attach->key(),
];
// Update simple object → attachment associations
$sql = 'UPDATE `%pivotTable` AS p
JOIN `%targetTable` AS a
ON p.`%targetId` = a.`%oldKey`
SET p.`%targetId` = a.`%newKey`;';
$db->query(strtr($sql, $binds));
// Update nested attachment → attachment associations
$sql = 'UPDATE `%pivotTable` AS p
JOIN `%targetTable` AS a
ON p.`%objectId` = a.`%oldKey` AND p.`%objectType` = a.`%targetType`
SET p.`%objectId` = a.`%newKey`;';
$db->query(strtr($sql, $binds));
return $this;
} | php | protected function syncRelatedFields(
IdProperty $newProp,
PropertyField $newField,
IdProperty $oldProp,
PropertyField $oldField
) {
unset($newProp, $oldProp, $oldField);
$cli = $this->climate();
if (!$this->quiet()) {
$cli->br();
$cli->comment('Syncing new IDs to pivot table.');
}
$pivot = $this->pivotModel();
$attach = $this->targetModel();
$pivotSource = $pivot->source();
$pivotTable = $pivotSource->table();
$attachSource = $attach->source();
$attachTable = $attachSource->table();
$db = $attachSource->db();
$binds = [
// Join Model
'%pivotTable' => $pivotTable,
'%objectType' => 'object_type',
'%objectId' => 'object_id',
'%targetId' => 'attachment_id',
// Attachment Model
'%targetTable' => $attachTable,
'%targetType' => 'type',
'%newKey' => $newField->ident(),
'%oldKey' => $attach->key(),
];
// Update simple object → attachment associations
$sql = 'UPDATE `%pivotTable` AS p
JOIN `%targetTable` AS a
ON p.`%targetId` = a.`%oldKey`
SET p.`%targetId` = a.`%newKey`;';
$db->query(strtr($sql, $binds));
// Update nested attachment → attachment associations
$sql = 'UPDATE `%pivotTable` AS p
JOIN `%targetTable` AS a
ON p.`%objectId` = a.`%oldKey` AND p.`%objectType` = a.`%targetType`
SET p.`%objectId` = a.`%newKey`;';
$db->query(strtr($sql, $binds));
return $this;
} | [
"protected",
"function",
"syncRelatedFields",
"(",
"IdProperty",
"$",
"newProp",
",",
"PropertyField",
"$",
"newField",
",",
"IdProperty",
"$",
"oldProp",
",",
"PropertyField",
"$",
"oldField",
")",
"{",
"unset",
"(",
"$",
"newProp",
",",
"$",
"oldProp",
",",
... | Sync the new primary keys to pivot table.
@param IdProperty $newProp The new ID property.
@param PropertyField $newField The new ID field.
@param IdProperty $oldProp The previous ID property.
@param PropertyField $oldField The previous ID field.
@throws InvalidArgumentException If the new property does not implement the proper mode.
@return self | [
"Sync",
"the",
"new",
"primary",
"keys",
"to",
"pivot",
"table",
"."
] | 82963e414483e7a0fc75e30894db0bba376dbd2d | https://github.com/locomotivemtl/charcoal-attachment/blob/82963e414483e7a0fc75e30894db0bba376dbd2d/src/Charcoal/Attachment/Script/MigrateScript.php#L184-L238 | train |
locomotivemtl/charcoal-attachment | src/Charcoal/Attachment/Script/MigrateScript.php | MigrateScript.targetModel | public function targetModel()
{
if (!isset($this->targetModel)) {
$this->targetModel = $this->modelFactory()->get(Attachment::class);
}
return $this->targetModel;
} | php | public function targetModel()
{
if (!isset($this->targetModel)) {
$this->targetModel = $this->modelFactory()->get(Attachment::class);
}
return $this->targetModel;
} | [
"public",
"function",
"targetModel",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"targetModel",
")",
")",
"{",
"$",
"this",
"->",
"targetModel",
"=",
"$",
"this",
"->",
"modelFactory",
"(",
")",
"->",
"get",
"(",
"Attachment",
"::... | Retrieve the model to alter.
@return ModelInterface | [
"Retrieve",
"the",
"model",
"to",
"alter",
"."
] | 82963e414483e7a0fc75e30894db0bba376dbd2d | https://github.com/locomotivemtl/charcoal-attachment/blob/82963e414483e7a0fc75e30894db0bba376dbd2d/src/Charcoal/Attachment/Script/MigrateScript.php#L274-L281 | train |
locomotivemtl/charcoal-attachment | src/Charcoal/Attachment/Script/MigrateScript.php | MigrateScript.pivotModel | public function pivotModel()
{
if (!isset($this->pivotModel)) {
$this->pivotModel = $this->modelFactory()->get(Join::class);
}
return $this->pivotModel;
} | php | public function pivotModel()
{
if (!isset($this->pivotModel)) {
$this->pivotModel = $this->modelFactory()->get(Join::class);
}
return $this->pivotModel;
} | [
"public",
"function",
"pivotModel",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"pivotModel",
")",
")",
"{",
"$",
"this",
"->",
"pivotModel",
"=",
"$",
"this",
"->",
"modelFactory",
"(",
")",
"->",
"get",
"(",
"Join",
"::",
"cla... | Retrieve the attachment association model.
@return ModelInterface | [
"Retrieve",
"the",
"attachment",
"association",
"model",
"."
] | 82963e414483e7a0fc75e30894db0bba376dbd2d | https://github.com/locomotivemtl/charcoal-attachment/blob/82963e414483e7a0fc75e30894db0bba376dbd2d/src/Charcoal/Attachment/Script/MigrateScript.php#L288-L295 | train |
froq/froq-http | src/Message.php | Message.getCookie | public final function getCookie(string $name, ?string $valueDefault = null): ?string
{
return $this->cookies[$name] ?? $valueDefault;
} | php | public final function getCookie(string $name, ?string $valueDefault = null): ?string
{
return $this->cookies[$name] ?? $valueDefault;
} | [
"public",
"final",
"function",
"getCookie",
"(",
"string",
"$",
"name",
",",
"?",
"string",
"$",
"valueDefault",
"=",
"null",
")",
":",
"?",
"string",
"{",
"return",
"$",
"this",
"->",
"cookies",
"[",
"$",
"name",
"]",
"??",
"$",
"valueDefault",
";",
... | Get cookie.
@param string $name
@param ?string $valueDefault
@return ?string | [
"Get",
"cookie",
"."
] | 067207669b5054b867b7df2b5557acf1d43f572a | https://github.com/froq/froq-http/blob/067207669b5054b867b7df2b5557acf1d43f572a/src/Message.php#L283-L286 | train |
froq/froq-http | src/Message.php | Message.removeCookie | public function removeCookie(string $name, bool $defer = false): self
{
if ($this->type == self::TYPE_REQUEST) {
throw new HttpException('You cannot modify request cookies');
}
unset($this->cookies[$name]);
if (!$defer) { // remove instantly
$this->sendCookie($name, null, 0);
}
return $this;
} | php | public function removeCookie(string $name, bool $defer = false): self
{
if ($this->type == self::TYPE_REQUEST) {
throw new HttpException('You cannot modify request cookies');
}
unset($this->cookies[$name]);
if (!$defer) { // remove instantly
$this->sendCookie($name, null, 0);
}
return $this;
} | [
"public",
"function",
"removeCookie",
"(",
"string",
"$",
"name",
",",
"bool",
"$",
"defer",
"=",
"false",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"self",
"::",
"TYPE_REQUEST",
")",
"{",
"throw",
"new",
"HttpException",
"(",
... | Remove cookie.
@param string $name
@param bool $defer
@return self
@throws froq\http\HttpException | [
"Remove",
"cookie",
"."
] | 067207669b5054b867b7df2b5557acf1d43f572a | https://github.com/froq/froq-http/blob/067207669b5054b867b7df2b5557acf1d43f572a/src/Message.php#L295-L307 | train |
mirko-pagliai/me-cms | src/Controller/UsersController.php | UsersController.loginWithCookie | protected function loginWithCookie()
{
$username = $this->request->getCookie('login.username');
$password = $this->request->getCookie('login.password');
//Checks if the cookies exist
if (!$username || !$password) {
return;
}
//Tries to login
$this->request = $this->request->withParsedBody(compact('username', 'password'));
$user = $this->Auth->identify();
if (!$user || !$user['active'] || $user['banned']) {
return $this->buildLogout();
}
$this->Auth->setUser($user);
$this->LoginRecorder->setConfig('user', $user['id'])->write();
return $this->redirect($this->Auth->redirectUrl());
} | php | protected function loginWithCookie()
{
$username = $this->request->getCookie('login.username');
$password = $this->request->getCookie('login.password');
//Checks if the cookies exist
if (!$username || !$password) {
return;
}
//Tries to login
$this->request = $this->request->withParsedBody(compact('username', 'password'));
$user = $this->Auth->identify();
if (!$user || !$user['active'] || $user['banned']) {
return $this->buildLogout();
}
$this->Auth->setUser($user);
$this->LoginRecorder->setConfig('user', $user['id'])->write();
return $this->redirect($this->Auth->redirectUrl());
} | [
"protected",
"function",
"loginWithCookie",
"(",
")",
"{",
"$",
"username",
"=",
"$",
"this",
"->",
"request",
"->",
"getCookie",
"(",
"'login.username'",
")",
";",
"$",
"password",
"=",
"$",
"this",
"->",
"request",
"->",
"getCookie",
"(",
"'login.password'... | Internal method to login with cookie
@return \Cake\Network\Response|null|void
@uses MeCms\Controller\Component\LoginRecorderComponent::write()
@uses buildLogout() | [
"Internal",
"method",
"to",
"login",
"with",
"cookie"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/UsersController.php#L38-L59 | train |
mirko-pagliai/me-cms | src/Controller/UsersController.php | UsersController.buildLogout | protected function buildLogout()
{
//Deletes some cookies and KCFinder session
$cookies = $this->request->getCookieCollection()->remove('login')->remove('sidebar-lastmenu');
$this->request = $this->request->withCookieCollection($cookies);
$this->request->getSession()->delete('KCFINDER');
return $this->redirect($this->Auth->logout());
} | php | protected function buildLogout()
{
//Deletes some cookies and KCFinder session
$cookies = $this->request->getCookieCollection()->remove('login')->remove('sidebar-lastmenu');
$this->request = $this->request->withCookieCollection($cookies);
$this->request->getSession()->delete('KCFINDER');
return $this->redirect($this->Auth->logout());
} | [
"protected",
"function",
"buildLogout",
"(",
")",
"{",
"//Deletes some cookies and KCFinder session",
"$",
"cookies",
"=",
"$",
"this",
"->",
"request",
"->",
"getCookieCollection",
"(",
")",
"->",
"remove",
"(",
"'login'",
")",
"->",
"remove",
"(",
"'sidebar-last... | Internal method to logout
@return \Cake\Network\Response|null | [
"Internal",
"method",
"to",
"logout"
] | df668ad8e3ee221497c47578d474e487f24ce92a | https://github.com/mirko-pagliai/me-cms/blob/df668ad8e3ee221497c47578d474e487f24ce92a/src/Controller/UsersController.php#L65-L73 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.