repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
1HappyPlace/ansi-terminal
src/ANSI/Color/Color.php
Color.next
public function next() { // if this is a valid name if ($this->isValid()) { // find it on the index of colors $colorNames = Colors::getW3CIndex(); // get the position of the name in the color index $pos = array_search($this->name,$colorNames); // if it was found on the array if ($pos !== false) { // if is the last item on the list if ($pos === (count($colorNames)-1)) { // return the first item return $colorNames[0]; // it is not last } else { // simply return the next item on the list return $colorNames[$pos+1]; } // name not found in list } else { // if it is not a W3C color, return null return null; } // invalid color } else { return null; } }
php
public function next() { // if this is a valid name if ($this->isValid()) { // find it on the index of colors $colorNames = Colors::getW3CIndex(); // get the position of the name in the color index $pos = array_search($this->name,$colorNames); // if it was found on the array if ($pos !== false) { // if is the last item on the list if ($pos === (count($colorNames)-1)) { // return the first item return $colorNames[0]; // it is not last } else { // simply return the next item on the list return $colorNames[$pos+1]; } // name not found in list } else { // if it is not a W3C color, return null return null; } // invalid color } else { return null; } }
[ "public", "function", "next", "(", ")", "{", "// if this is a valid name", "if", "(", "$", "this", "->", "isValid", "(", ")", ")", "{", "// find it on the index of colors", "$", "colorNames", "=", "Colors", "::", "getW3CIndex", "(", ")", ";", "// get the position of the name in the color index", "$", "pos", "=", "array_search", "(", "$", "this", "->", "name", ",", "$", "colorNames", ")", ";", "// if it was found on the array", "if", "(", "$", "pos", "!==", "false", ")", "{", "// if is the last item on the list", "if", "(", "$", "pos", "===", "(", "count", "(", "$", "colorNames", ")", "-", "1", ")", ")", "{", "// return the first item", "return", "$", "colorNames", "[", "0", "]", ";", "// it is not last", "}", "else", "{", "// simply return the next item on the list", "return", "$", "colorNames", "[", "$", "pos", "+", "1", "]", ";", "}", "// name not found in list", "}", "else", "{", "// if it is not a W3C color, return null", "return", "null", ";", "}", "// invalid color", "}", "else", "{", "return", "null", ";", "}", "}" ]
Return the next name on the main Colors name index @return string | null - return null if this color is not valid, otherwise, return the next name or the first name, if this is the last name
[ "Return", "the", "next", "name", "on", "the", "main", "Colors", "name", "index" ]
3a550eadb21bb87a6909436c3b961919d2731923
https://github.com/1HappyPlace/ansi-terminal/blob/3a550eadb21bb87a6909436c3b961919d2731923/src/ANSI/Color/Color.php#L540-L583
train
gplcart/ga_report
controllers/Settings.php
Settings.editSettings
public function editSettings() { $this->setTitleEditSettings(); $this->setBreadcrumbEditSettings(); $this->setData('stores', $this->store->getList()); $this->setData('credentials', $this->getCredentialSettings()); $this->setData('handlers', $this->report_model->getHandlers()); $this->setData('settings', $this->module->getSettings('ga_report')); $this->submitSettings(); $this->outputEditSettings(); }
php
public function editSettings() { $this->setTitleEditSettings(); $this->setBreadcrumbEditSettings(); $this->setData('stores', $this->store->getList()); $this->setData('credentials', $this->getCredentialSettings()); $this->setData('handlers', $this->report_model->getHandlers()); $this->setData('settings', $this->module->getSettings('ga_report')); $this->submitSettings(); $this->outputEditSettings(); }
[ "public", "function", "editSettings", "(", ")", "{", "$", "this", "->", "setTitleEditSettings", "(", ")", ";", "$", "this", "->", "setBreadcrumbEditSettings", "(", ")", ";", "$", "this", "->", "setData", "(", "'stores'", ",", "$", "this", "->", "store", "->", "getList", "(", ")", ")", ";", "$", "this", "->", "setData", "(", "'credentials'", ",", "$", "this", "->", "getCredentialSettings", "(", ")", ")", ";", "$", "this", "->", "setData", "(", "'handlers'", ",", "$", "this", "->", "report_model", "->", "getHandlers", "(", ")", ")", ";", "$", "this", "->", "setData", "(", "'settings'", ",", "$", "this", "->", "module", "->", "getSettings", "(", "'ga_report'", ")", ")", ";", "$", "this", "->", "submitSettings", "(", ")", ";", "$", "this", "->", "outputEditSettings", "(", ")", ";", "}" ]
Route page callback Displays the module settings page
[ "Route", "page", "callback", "Displays", "the", "module", "settings", "page" ]
856a480e394bb3feaeea4785ccccad56abaac499
https://github.com/gplcart/ga_report/blob/856a480e394bb3feaeea4785ccccad56abaac499/controllers/Settings.php#L42-L54
train
gplcart/ga_report
controllers/Settings.php
Settings.validateGaProfileSettings
protected function validateGaProfileSettings() { $profiles = $this->getSubmitted('ga_profile_id', array()); if (empty($profiles)) { $this->setError('ga_profile_id', $this->text('Profile ID is required')); return false; } $stores = $this->store->getList(); foreach ($profiles as $store_id => $profile_id) { if (empty($profile_id)) { $this->setError('ga_profile_id', $this->text('Profile ID is required')); return false; } if (empty($stores[$store_id])) { $this->setError('ga_profile_id', $this->text('Unknown store ID')); return false; } } return true; }
php
protected function validateGaProfileSettings() { $profiles = $this->getSubmitted('ga_profile_id', array()); if (empty($profiles)) { $this->setError('ga_profile_id', $this->text('Profile ID is required')); return false; } $stores = $this->store->getList(); foreach ($profiles as $store_id => $profile_id) { if (empty($profile_id)) { $this->setError('ga_profile_id', $this->text('Profile ID is required')); return false; } if (empty($stores[$store_id])) { $this->setError('ga_profile_id', $this->text('Unknown store ID')); return false; } } return true; }
[ "protected", "function", "validateGaProfileSettings", "(", ")", "{", "$", "profiles", "=", "$", "this", "->", "getSubmitted", "(", "'ga_profile_id'", ",", "array", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "profiles", ")", ")", "{", "$", "this", "->", "setError", "(", "'ga_profile_id'", ",", "$", "this", "->", "text", "(", "'Profile ID is required'", ")", ")", ";", "return", "false", ";", "}", "$", "stores", "=", "$", "this", "->", "store", "->", "getList", "(", ")", ";", "foreach", "(", "$", "profiles", "as", "$", "store_id", "=>", "$", "profile_id", ")", "{", "if", "(", "empty", "(", "$", "profile_id", ")", ")", "{", "$", "this", "->", "setError", "(", "'ga_profile_id'", ",", "$", "this", "->", "text", "(", "'Profile ID is required'", ")", ")", ";", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "stores", "[", "$", "store_id", "]", ")", ")", "{", "$", "this", "->", "setError", "(", "'ga_profile_id'", ",", "$", "this", "->", "text", "(", "'Unknown store ID'", ")", ")", ";", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Validates Google Analytics profiles
[ "Validates", "Google", "Analytics", "profiles" ]
856a480e394bb3feaeea4785ccccad56abaac499
https://github.com/gplcart/ga_report/blob/856a480e394bb3feaeea4785ccccad56abaac499/controllers/Settings.php#L136-L161
train
eliasis-framework/complement
src/Traits/ComplementImport.php
ComplementImport.install
public function install() { if (! isset($this->complement['installation-files'])) { self::$errors[] = [ 'message' => $this->complement['path']['root'] ]; return false; } $this->deleteDirectory(); $this->changeState(); $installed = $this->installComplement( $this->complement['installation-files'], $this->complement['path']['root'], $this->complement['slug'] ); if ($installed) { self::load( $this->complement['config-file'], $this->complement['path']['root'] ); $this->changeState(); return true; } return false; }
php
public function install() { if (! isset($this->complement['installation-files'])) { self::$errors[] = [ 'message' => $this->complement['path']['root'] ]; return false; } $this->deleteDirectory(); $this->changeState(); $installed = $this->installComplement( $this->complement['installation-files'], $this->complement['path']['root'], $this->complement['slug'] ); if ($installed) { self::load( $this->complement['config-file'], $this->complement['path']['root'] ); $this->changeState(); return true; } return false; }
[ "public", "function", "install", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "complement", "[", "'installation-files'", "]", ")", ")", "{", "self", "::", "$", "errors", "[", "]", "=", "[", "'message'", "=>", "$", "this", "->", "complement", "[", "'path'", "]", "[", "'root'", "]", "]", ";", "return", "false", ";", "}", "$", "this", "->", "deleteDirectory", "(", ")", ";", "$", "this", "->", "changeState", "(", ")", ";", "$", "installed", "=", "$", "this", "->", "installComplement", "(", "$", "this", "->", "complement", "[", "'installation-files'", "]", ",", "$", "this", "->", "complement", "[", "'path'", "]", "[", "'root'", "]", ",", "$", "this", "->", "complement", "[", "'slug'", "]", ")", ";", "if", "(", "$", "installed", ")", "{", "self", "::", "load", "(", "$", "this", "->", "complement", "[", "'config-file'", "]", ",", "$", "this", "->", "complement", "[", "'path'", "]", "[", "'root'", "]", ")", ";", "$", "this", "->", "changeState", "(", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Complement installation handler. @uses \Eliasis\Complement\Traits\ComplementState->changeState() @uses \Eliasis\Complement\Complement->$complement @return bool
[ "Complement", "installation", "handler", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementImport.php#L67-L98
train
eliasis-framework/complement
src/Traits/ComplementImport.php
ComplementImport.remove
public function remove() { $this->setState('uninstall'); $this->changeState(); if (! $this->deleteDirectory()) { $this->setState('uninstalled'); } return true; }
php
public function remove() { $this->setState('uninstall'); $this->changeState(); if (! $this->deleteDirectory()) { $this->setState('uninstalled'); } return true; }
[ "public", "function", "remove", "(", ")", "{", "$", "this", "->", "setState", "(", "'uninstall'", ")", ";", "$", "this", "->", "changeState", "(", ")", ";", "if", "(", "!", "$", "this", "->", "deleteDirectory", "(", ")", ")", "{", "$", "this", "->", "setState", "(", "'uninstalled'", ")", ";", "}", "return", "true", ";", "}" ]
Delete complement. @uses \Eliasis\Complement\Traits\ComplementState->getState() @uses \Eliasis\Complement\Traits\ComplementState->setState() @uses \Eliasis\Complement\Traits\ComplementState->changeState() @return bool true
[ "Delete", "complement", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementImport.php#L109-L120
train
eliasis-framework/complement
src/Traits/ComplementImport.php
ComplementImport.deleteDirectory
private function deleteDirectory() { $path = $this->complement['path']['root']; if (! $this->validateRoute($path)) { return false; } $isUninstall = ($this->getState() === 'inactive'); if (! File::deleteDirRecursively($path) && $isUninstall) { $type = self::getType('ucfirst', false); $msg = $type . " doesn't exist in '$path' or couldn't be deleted."; self::$errors[] = ['message' => $msg]; return false; } return true; }
php
private function deleteDirectory() { $path = $this->complement['path']['root']; if (! $this->validateRoute($path)) { return false; } $isUninstall = ($this->getState() === 'inactive'); if (! File::deleteDirRecursively($path) && $isUninstall) { $type = self::getType('ucfirst', false); $msg = $type . " doesn't exist in '$path' or couldn't be deleted."; self::$errors[] = ['message' => $msg]; return false; } return true; }
[ "private", "function", "deleteDirectory", "(", ")", "{", "$", "path", "=", "$", "this", "->", "complement", "[", "'path'", "]", "[", "'root'", "]", ";", "if", "(", "!", "$", "this", "->", "validateRoute", "(", "$", "path", ")", ")", "{", "return", "false", ";", "}", "$", "isUninstall", "=", "(", "$", "this", "->", "getState", "(", ")", "===", "'inactive'", ")", ";", "if", "(", "!", "File", "::", "deleteDirRecursively", "(", "$", "path", ")", "&&", "$", "isUninstall", ")", "{", "$", "type", "=", "self", "::", "getType", "(", "'ucfirst'", ",", "false", ")", ";", "$", "msg", "=", "$", "type", ".", "\" doesn't exist in '$path' or couldn't be deleted.\"", ";", "self", "::", "$", "errors", "[", "]", "=", "[", "'message'", "=>", "$", "msg", "]", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Delete complement directory. @uses \Eliasis\Complement\Complement->$complement @uses \Eliasis\Complement\Complement::$errors @uses \Eliasis\Complement\Traits\ComplementHandler::getType() @uses \Josantonius\File\File::deleteDirRecursively() @return string → complement state
[ "Delete", "complement", "directory", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementImport.php#L132-L153
train
eliasis-framework/complement
src/Traits/ComplementImport.php
ComplementImport.installComplement
private function installComplement($complement, $path, $slug, $root = true) { $path = ($root) ? $path : $path . key($complement) . '/'; if (! $this->validateRoute($path)) { return false; } if (! File::createDir($path)) { $msg = "The directory exists or couldn't be created in: $path"; self::$errors[] = ['message' => $msg]; return false; } foreach ($complement as $folder => $file) { foreach ($file as $key => $val) { if (is_array($val)) { $this->installComplement([$key => $val], $path, $slug, 0); continue; } $filePath = $path . $val; $complementType = self::getType('strtoupper'); $complementPath = App::$complementType() . $slug . '/'; $url = Url::addBackSlash($this->complement['url-import']); $route = str_replace($complementPath, '', $filePath); $fileUrl = $url . '/' . $route; $this->saveRemoteFile($fileUrl, $filePath); } } return true; }
php
private function installComplement($complement, $path, $slug, $root = true) { $path = ($root) ? $path : $path . key($complement) . '/'; if (! $this->validateRoute($path)) { return false; } if (! File::createDir($path)) { $msg = "The directory exists or couldn't be created in: $path"; self::$errors[] = ['message' => $msg]; return false; } foreach ($complement as $folder => $file) { foreach ($file as $key => $val) { if (is_array($val)) { $this->installComplement([$key => $val], $path, $slug, 0); continue; } $filePath = $path . $val; $complementType = self::getType('strtoupper'); $complementPath = App::$complementType() . $slug . '/'; $url = Url::addBackSlash($this->complement['url-import']); $route = str_replace($complementPath, '', $filePath); $fileUrl = $url . '/' . $route; $this->saveRemoteFile($fileUrl, $filePath); } } return true; }
[ "private", "function", "installComplement", "(", "$", "complement", ",", "$", "path", ",", "$", "slug", ",", "$", "root", "=", "true", ")", "{", "$", "path", "=", "(", "$", "root", ")", "?", "$", "path", ":", "$", "path", ".", "key", "(", "$", "complement", ")", ".", "'/'", ";", "if", "(", "!", "$", "this", "->", "validateRoute", "(", "$", "path", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "File", "::", "createDir", "(", "$", "path", ")", ")", "{", "$", "msg", "=", "\"The directory exists or couldn't be created in: $path\"", ";", "self", "::", "$", "errors", "[", "]", "=", "[", "'message'", "=>", "$", "msg", "]", ";", "return", "false", ";", "}", "foreach", "(", "$", "complement", "as", "$", "folder", "=>", "$", "file", ")", "{", "foreach", "(", "$", "file", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "is_array", "(", "$", "val", ")", ")", "{", "$", "this", "->", "installComplement", "(", "[", "$", "key", "=>", "$", "val", "]", ",", "$", "path", ",", "$", "slug", ",", "0", ")", ";", "continue", ";", "}", "$", "filePath", "=", "$", "path", ".", "$", "val", ";", "$", "complementType", "=", "self", "::", "getType", "(", "'strtoupper'", ")", ";", "$", "complementPath", "=", "App", "::", "$", "complementType", "(", ")", ".", "$", "slug", ".", "'/'", ";", "$", "url", "=", "Url", "::", "addBackSlash", "(", "$", "this", "->", "complement", "[", "'url-import'", "]", ")", ";", "$", "route", "=", "str_replace", "(", "$", "complementPath", ",", "''", ",", "$", "filePath", ")", ";", "$", "fileUrl", "=", "$", "url", ".", "'/'", ".", "$", "route", ";", "$", "this", "->", "saveRemoteFile", "(", "$", "fileUrl", ",", "$", "filePath", ")", ";", "}", "}", "return", "true", ";", "}" ]
Install complement. @param array $complement → complement files @param string $path → complement path @param string $slug → complement slug @param bool $root → root folder @uses \Eliasis\Framework\App::COMPLEMENT_URL() @uses \Eliasis\Complement\Traits\ComplementHandler::getType() @uses \Josantonius\File\File::createDir() @return bool
[ "Install", "complement", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementImport.php#L169-L205
train
eliasis-framework/complement
src/Traits/ComplementImport.php
ComplementImport.saveRemoteFile
private function saveRemoteFile($fileUrl, $filePath) { if (! $file = @file_get_contents($fileUrl)) { self::$errors[] = [ 'message' => 'Error to download file: ' . $fileUrl ]; return false; } if (! @file_put_contents($filePath, $file)) { self::$errors[] = [ 'message' => 'Failed to save file to: ' . $filePath ]; return false; } return true; }
php
private function saveRemoteFile($fileUrl, $filePath) { if (! $file = @file_get_contents($fileUrl)) { self::$errors[] = [ 'message' => 'Error to download file: ' . $fileUrl ]; return false; } if (! @file_put_contents($filePath, $file)) { self::$errors[] = [ 'message' => 'Failed to save file to: ' . $filePath ]; return false; } return true; }
[ "private", "function", "saveRemoteFile", "(", "$", "fileUrl", ",", "$", "filePath", ")", "{", "if", "(", "!", "$", "file", "=", "@", "file_get_contents", "(", "$", "fileUrl", ")", ")", "{", "self", "::", "$", "errors", "[", "]", "=", "[", "'message'", "=>", "'Error to download file: '", ".", "$", "fileUrl", "]", ";", "return", "false", ";", "}", "if", "(", "!", "@", "file_put_contents", "(", "$", "filePath", ",", "$", "file", ")", ")", "{", "self", "::", "$", "errors", "[", "]", "=", "[", "'message'", "=>", "'Failed to save file to: '", ".", "$", "filePath", "]", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
Save remote file. @param string $fileUrl → remote file url @param string $filePath → file path to save @return bool
[ "Save", "remote", "file", "." ]
d50e92cf01600ff4573bf1761c312069044748c3
https://github.com/eliasis-framework/complement/blob/d50e92cf01600ff4573bf1761c312069044748c3/src/Traits/ComplementImport.php#L215-L234
train
modulusphp/security
Remember.php
Remember.boot
public function boot() { if (!is_dir(Remember::$tokensDir)) { mkdir(Remember::$tokensDir, 0777, true); } $this->hasTokens(); $this->configure(); $this->start(); }
php
public function boot() { if (!is_dir(Remember::$tokensDir)) { mkdir(Remember::$tokensDir, 0777, true); } $this->hasTokens(); $this->configure(); $this->start(); }
[ "public", "function", "boot", "(", ")", "{", "if", "(", "!", "is_dir", "(", "Remember", "::", "$", "tokensDir", ")", ")", "{", "mkdir", "(", "Remember", "::", "$", "tokensDir", ",", "0777", ",", "true", ")", ";", "}", "$", "this", "->", "hasTokens", "(", ")", ";", "$", "this", "->", "configure", "(", ")", ";", "$", "this", "->", "start", "(", ")", ";", "}" ]
Boot remember me component @return void
[ "Boot", "remember", "me", "component" ]
7a0b7f7a23f682588a3582b810d61266f7c14567
https://github.com/modulusphp/security/blob/7a0b7f7a23f682588a3582b810d61266f7c14567/Remember.php#L46-L55
train
modulusphp/security
Remember.php
Remember.hasTokens
public function hasTokens() { if (!is_writable(Remember::$tokensDir) || !is_dir(Remember::$tokensDir)) { $tokens = Remember::$tokensDir; return $this->exception("'$tokens' does not exist or is not writable by the web server"); } }
php
public function hasTokens() { if (!is_writable(Remember::$tokensDir) || !is_dir(Remember::$tokensDir)) { $tokens = Remember::$tokensDir; return $this->exception("'$tokens' does not exist or is not writable by the web server"); } }
[ "public", "function", "hasTokens", "(", ")", "{", "if", "(", "!", "is_writable", "(", "Remember", "::", "$", "tokensDir", ")", "||", "!", "is_dir", "(", "Remember", "::", "$", "tokensDir", ")", ")", "{", "$", "tokens", "=", "Remember", "::", "$", "tokensDir", ";", "return", "$", "this", "->", "exception", "(", "\"'$tokens' does not exist or is not writable by the web server\"", ")", ";", "}", "}" ]
Check if the tokens directory exists or is writable @return void
[ "Check", "if", "the", "tokens", "directory", "exists", "or", "is", "writable" ]
7a0b7f7a23f682588a3582b810d61266f7c14567
https://github.com/modulusphp/security/blob/7a0b7f7a23f682588a3582b810d61266f7c14567/Remember.php#L62-L68
train
modulusphp/security
Remember.php
Remember.configure
public function configure() { $tokenGenerator = new DefaultToken(94, DefaultToken::FORMAT_BASE64); $expire = strtotime(Remember::$expire, 0); $cookie = new PHPCookie("application_session", $expire, "/", "", true, true); Remember::$storage = new FileStorage(Remember::$tokensDir); Remember::$rememberMe = new Authenticator(Remember::$storage, $tokenGenerator, $cookie); }
php
public function configure() { $tokenGenerator = new DefaultToken(94, DefaultToken::FORMAT_BASE64); $expire = strtotime(Remember::$expire, 0); $cookie = new PHPCookie("application_session", $expire, "/", "", true, true); Remember::$storage = new FileStorage(Remember::$tokensDir); Remember::$rememberMe = new Authenticator(Remember::$storage, $tokenGenerator, $cookie); }
[ "public", "function", "configure", "(", ")", "{", "$", "tokenGenerator", "=", "new", "DefaultToken", "(", "94", ",", "DefaultToken", "::", "FORMAT_BASE64", ")", ";", "$", "expire", "=", "strtotime", "(", "Remember", "::", "$", "expire", ",", "0", ")", ";", "$", "cookie", "=", "new", "PHPCookie", "(", "\"application_session\"", ",", "$", "expire", ",", "\"/\"", ",", "\"\"", ",", "true", ",", "true", ")", ";", "Remember", "::", "$", "storage", "=", "new", "FileStorage", "(", "Remember", "::", "$", "tokensDir", ")", ";", "Remember", "::", "$", "rememberMe", "=", "new", "Authenticator", "(", "Remember", "::", "$", "storage", ",", "$", "tokenGenerator", ",", "$", "cookie", ")", ";", "}" ]
Configure remember me @return void
[ "Configure", "remember", "me" ]
7a0b7f7a23f682588a3582b810d61266f7c14567
https://github.com/modulusphp/security/blob/7a0b7f7a23f682588a3582b810d61266f7c14567/Remember.php#L75-L84
train
modulusphp/security
Remember.php
Remember.start
public function start() { $rememberMe = Remember::$rememberMe; $loginResult = $rememberMe->login(); if ($loginResult->isSuccess()) { $_SESSION['_uas'] = $loginResult->getCredential(); $_SESSION['remembered_by_cookie'] = true; return; } if ($loginResult->hasPossibleManipulation()) { exit(); } if ($loginResult->isExpired() && !empty($_SESSION['_uas']) && !empty($_SESSION['remembered_by_cookie'])) { $rememberMe->clearCookie(); unset($_SESSION['_uas']); unset($_SESSION['remembered_by_cookie']); exit(); } if ($loginResult->isExpired() && !empty($_SESSION['_uas'])) { sleep(5); } }
php
public function start() { $rememberMe = Remember::$rememberMe; $loginResult = $rememberMe->login(); if ($loginResult->isSuccess()) { $_SESSION['_uas'] = $loginResult->getCredential(); $_SESSION['remembered_by_cookie'] = true; return; } if ($loginResult->hasPossibleManipulation()) { exit(); } if ($loginResult->isExpired() && !empty($_SESSION['_uas']) && !empty($_SESSION['remembered_by_cookie'])) { $rememberMe->clearCookie(); unset($_SESSION['_uas']); unset($_SESSION['remembered_by_cookie']); exit(); } if ($loginResult->isExpired() && !empty($_SESSION['_uas'])) { sleep(5); } }
[ "public", "function", "start", "(", ")", "{", "$", "rememberMe", "=", "Remember", "::", "$", "rememberMe", ";", "$", "loginResult", "=", "$", "rememberMe", "->", "login", "(", ")", ";", "if", "(", "$", "loginResult", "->", "isSuccess", "(", ")", ")", "{", "$", "_SESSION", "[", "'_uas'", "]", "=", "$", "loginResult", "->", "getCredential", "(", ")", ";", "$", "_SESSION", "[", "'remembered_by_cookie'", "]", "=", "true", ";", "return", ";", "}", "if", "(", "$", "loginResult", "->", "hasPossibleManipulation", "(", ")", ")", "{", "exit", "(", ")", ";", "}", "if", "(", "$", "loginResult", "->", "isExpired", "(", ")", "&&", "!", "empty", "(", "$", "_SESSION", "[", "'_uas'", "]", ")", "&&", "!", "empty", "(", "$", "_SESSION", "[", "'remembered_by_cookie'", "]", ")", ")", "{", "$", "rememberMe", "->", "clearCookie", "(", ")", ";", "unset", "(", "$", "_SESSION", "[", "'_uas'", "]", ")", ";", "unset", "(", "$", "_SESSION", "[", "'remembered_by_cookie'", "]", ")", ";", "exit", "(", ")", ";", "}", "if", "(", "$", "loginResult", "->", "isExpired", "(", ")", "&&", "!", "empty", "(", "$", "_SESSION", "[", "'_uas'", "]", ")", ")", "{", "sleep", "(", "5", ")", ";", "}", "}" ]
Start remember me @return void
[ "Start", "remember", "me" ]
7a0b7f7a23f682588a3582b810d61266f7c14567
https://github.com/modulusphp/security/blob/7a0b7f7a23f682588a3582b810d61266f7c14567/Remember.php#L91-L115
train
MosaicPHP/Common
src/Arr.php
Arr.unwrap
public static function unwrap(array $input, $default = null) { if (count($input) > 1) { return $input; } return ! empty($input) ? current($input) : $default; }
php
public static function unwrap(array $input, $default = null) { if (count($input) > 1) { return $input; } return ! empty($input) ? current($input) : $default; }
[ "public", "static", "function", "unwrap", "(", "array", "$", "input", ",", "$", "default", "=", "null", ")", "{", "if", "(", "count", "(", "$", "input", ")", ">", "1", ")", "{", "return", "$", "input", ";", "}", "return", "!", "empty", "(", "$", "input", ")", "?", "current", "(", "$", "input", ")", ":", "$", "default", ";", "}" ]
Unwraps a single item array into the item. If the array contains more than one item, it will be returned as-is. A default value can be provided, and will be used when an empty array is given. @param array $input @param mixed|null $default @return mixed
[ "Unwraps", "a", "single", "item", "array", "into", "the", "item", ".", "If", "the", "array", "contains", "more", "than", "one", "item", "it", "will", "be", "returned", "as", "-", "is", ".", "A", "default", "value", "can", "be", "provided", "and", "will", "be", "used", "when", "an", "empty", "array", "is", "given", "." ]
f8b347f11401fb34e32f66ca3cec0cd9e743c0d4
https://github.com/MosaicPHP/Common/blob/f8b347f11401fb34e32f66ca3cec0cd9e743c0d4/src/Arr.php#L32-L39
train
PenoaksDev/Milky-Framework
src/Milky/Binding/ServiceResolver.php
ServiceResolver.resolveClass
public function resolveClass( $class ) { if ( !is_string( $class ) ) throw new ResolverException( "Class must be a string" ); // Check if a class has been mapped to a key if ( array_key_exists( $class, $this->classAlias ) ) try { return $this->resolve( null, $this->classAlias[$class] ); } catch ( ResolverException $e ) { // Ignore } // Check if the class has been initialized foreach ( $this->instances as $instance ) if ( get_class( $instance ) == $class ) return $instance; // TODO Other methods to check? return false; }
php
public function resolveClass( $class ) { if ( !is_string( $class ) ) throw new ResolverException( "Class must be a string" ); // Check if a class has been mapped to a key if ( array_key_exists( $class, $this->classAlias ) ) try { return $this->resolve( null, $this->classAlias[$class] ); } catch ( ResolverException $e ) { // Ignore } // Check if the class has been initialized foreach ( $this->instances as $instance ) if ( get_class( $instance ) == $class ) return $instance; // TODO Other methods to check? return false; }
[ "public", "function", "resolveClass", "(", "$", "class", ")", "{", "if", "(", "!", "is_string", "(", "$", "class", ")", ")", "throw", "new", "ResolverException", "(", "\"Class must be a string\"", ")", ";", "// Check if a class has been mapped to a key", "if", "(", "array_key_exists", "(", "$", "class", ",", "$", "this", "->", "classAlias", ")", ")", "try", "{", "return", "$", "this", "->", "resolve", "(", "null", ",", "$", "this", "->", "classAlias", "[", "$", "class", "]", ")", ";", "}", "catch", "(", "ResolverException", "$", "e", ")", "{", "// Ignore", "}", "// Check if the class has been initialized", "foreach", "(", "$", "this", "->", "instances", "as", "$", "instance", ")", "if", "(", "get_class", "(", "$", "instance", ")", "==", "$", "class", ")", "return", "$", "instance", ";", "// TODO Other methods to check?", "return", "false", ";", "}" ]
Called the a class needs resolving. Each registered resolver will be called for this purpose, the first to return non-false will succeed. @param string $class
[ "Called", "the", "a", "class", "needs", "resolving", ".", "Each", "registered", "resolver", "will", "be", "called", "for", "this", "purpose", "the", "first", "to", "return", "non", "-", "false", "will", "succeed", "." ]
8afd7156610a70371aa5b1df50b8a212bf7b142c
https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Binding/ServiceResolver.php#L159-L183
train
gilbertsoft/typo3-gscacheconfig
Classes/Extension/Configurator.php
Configurator.additionalConfiguration
public static function additionalConfiguration($extensionKey) { // Get the configuration $extConf = self::getSanitizedExtConf($extensionKey); if ($extConf['cachingConfigEnable'] == 1) { self::handleCachingConfiguration($extConf); } }
php
public static function additionalConfiguration($extensionKey) { // Get the configuration $extConf = self::getSanitizedExtConf($extensionKey); if ($extConf['cachingConfigEnable'] == 1) { self::handleCachingConfiguration($extConf); } }
[ "public", "static", "function", "additionalConfiguration", "(", "$", "extensionKey", ")", "{", "// Get the configuration", "$", "extConf", "=", "self", "::", "getSanitizedExtConf", "(", "$", "extensionKey", ")", ";", "if", "(", "$", "extConf", "[", "'cachingConfigEnable'", "]", "==", "1", ")", "{", "self", "::", "handleCachingConfiguration", "(", "$", "extConf", ")", ";", "}", "}" ]
Called from additionalConfiguration.php. @param string $extensionKey Extension key @return void
[ "Called", "from", "additionalConfiguration", ".", "php", "." ]
dc6c3131b9e3d714b6c79c802c09ef1d165296d1
https://github.com/gilbertsoft/typo3-gscacheconfig/blob/dc6c3131b9e3d714b6c79c802c09ef1d165296d1/Classes/Extension/Configurator.php#L177-L185
train
polusphp/polus
src/Traits/ResponseTrait.php
ResponseTrait.setResponseBody
public function setResponseBody($data) { if (!is_string($data)) { $data = json_encode($data, \JSON_PRETTY_PRINT); } $this->response->getBody()->write($data); return $this; }
php
public function setResponseBody($data) { if (!is_string($data)) { $data = json_encode($data, \JSON_PRETTY_PRINT); } $this->response->getBody()->write($data); return $this; }
[ "public", "function", "setResponseBody", "(", "$", "data", ")", "{", "if", "(", "!", "is_string", "(", "$", "data", ")", ")", "{", "$", "data", "=", "json_encode", "(", "$", "data", ",", "\\", "JSON_PRETTY_PRINT", ")", ";", "}", "$", "this", "->", "response", "->", "getBody", "(", ")", "->", "write", "(", "$", "data", ")", ";", "return", "$", "this", ";", "}" ]
Set response body if is not string json_encode @param mixed $data @return $this
[ "Set", "response", "body", "if", "is", "not", "string", "json_encode" ]
2de7c13e6ceaa8104a48172957cdb166e64bf342
https://github.com/polusphp/polus/blob/2de7c13e6ceaa8104a48172957cdb166e64bf342/src/Traits/ResponseTrait.php#L35-L42
train
olobu/olobu
fs/upload.php
Upload._curl
protected function _curl($data, $url) { //kalo tidak ada library curl, langsung gagal if ( ! function_exists("curl_init")) { return array( "output" => NULL, "status" => -1 ); } $data_string = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_REFERER, "batudaa"); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Content-Length: " . strlen($data_string) )); curl_setopt($curl, CURLOPT_URL, $url); $out = json_decode(curl_exec($curl)); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); return array( "output" => $out, "status" => $status ); }
php
protected function _curl($data, $url) { //kalo tidak ada library curl, langsung gagal if ( ! function_exists("curl_init")) { return array( "output" => NULL, "status" => -1 ); } $data_string = json_encode($data); $curl = curl_init(); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_REFERER, "batudaa"); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Content-Length: " . strlen($data_string) )); curl_setopt($curl, CURLOPT_URL, $url); $out = json_decode(curl_exec($curl)); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); return array( "output" => $out, "status" => $status ); }
[ "protected", "function", "_curl", "(", "$", "data", ",", "$", "url", ")", "{", "//kalo tidak ada library curl, langsung gagal", "if", "(", "!", "function_exists", "(", "\"curl_init\"", ")", ")", "{", "return", "array", "(", "\"output\"", "=>", "NULL", ",", "\"status\"", "=>", "-", "1", ")", ";", "}", "$", "data_string", "=", "json_encode", "(", "$", "data", ")", ";", "$", "curl", "=", "curl_init", "(", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POST", ",", "true", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_POSTFIELDS", ",", "$", "data_string", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_FOLLOWLOCATION", ",", "true", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_SSL_VERIFYPEER", ",", "false", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_SSL_VERIFYHOST", ",", "false", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_REFERER", ",", "\"batudaa\"", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_HTTPHEADER", ",", "array", "(", "\"Content-Type: application/json\"", ",", "\"Content-Length: \"", ".", "strlen", "(", "$", "data_string", ")", ")", ")", ";", "curl_setopt", "(", "$", "curl", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "$", "out", "=", "json_decode", "(", "curl_exec", "(", "$", "curl", ")", ")", ";", "$", "status", "=", "curl_getinfo", "(", "$", "curl", ",", "CURLINFO_HTTP_CODE", ")", ";", "curl_close", "(", "$", "curl", ")", ";", "return", "array", "(", "\"output\"", "=>", "$", "out", ",", "\"status\"", "=>", "$", "status", ")", ";", "}" ]
request berupa CURL
[ "request", "berupa", "CURL" ]
05bea2bff63d3e38b458fb42e8f07f1d850ae211
https://github.com/olobu/olobu/blob/05bea2bff63d3e38b458fb42e8f07f1d850ae211/fs/upload.php#L308-L343
train
AndyDune/DateTime
src/DateTime.php
DateTime.setAction
public function setAction(AbstractAction $action) : DateTime { $this->action = $action; $this->action->setDateTime($this); return $this; }
php
public function setAction(AbstractAction $action) : DateTime { $this->action = $action; $this->action->setDateTime($this); return $this; }
[ "public", "function", "setAction", "(", "AbstractAction", "$", "action", ")", ":", "DateTime", "{", "$", "this", "->", "action", "=", "$", "action", ";", "$", "this", "->", "action", "->", "setDateTime", "(", "$", "this", ")", ";", "return", "$", "this", ";", "}" ]
Set strategy pattern action for modification array. Action callable object resieves whole array in container and return array ro replace. @param AbstractAction $action @return $this
[ "Set", "strategy", "pattern", "action", "for", "modification", "array", ".", "Action", "callable", "object", "resieves", "whole", "array", "in", "container", "and", "return", "array", "ro", "replace", "." ]
4f49f449b23072ac6d2ae0f1ea4b8e34804b760f
https://github.com/AndyDune/DateTime/blob/4f49f449b23072ac6d2ae0f1ea4b8e34804b760f/src/DateTime.php#L78-L83
train
AndyDune/DateTime
src/DateTime.php
DateTime.add
public function add($interval) : DateTime { if ($interval instanceof DateInterval) { $this->value->add($interval); return $this; } $i = $this->tryToCreateIntervalByDesignators($interval); if (!$i) { $i = DateInterval::createFromDateString($interval); } $this->value->add($i); return $this; }
php
public function add($interval) : DateTime { if ($interval instanceof DateInterval) { $this->value->add($interval); return $this; } $i = $this->tryToCreateIntervalByDesignators($interval); if (!$i) { $i = DateInterval::createFromDateString($interval); } $this->value->add($i); return $this; }
[ "public", "function", "add", "(", "$", "interval", ")", ":", "DateTime", "{", "if", "(", "$", "interval", "instanceof", "DateInterval", ")", "{", "$", "this", "->", "value", "->", "add", "(", "$", "interval", ")", ";", "return", "$", "this", ";", "}", "$", "i", "=", "$", "this", "->", "tryToCreateIntervalByDesignators", "(", "$", "interval", ")", ";", "if", "(", "!", "$", "i", ")", "{", "$", "i", "=", "DateInterval", "::", "createFromDateString", "(", "$", "interval", ")", ";", "}", "$", "this", "->", "value", "->", "add", "(", "$", "i", ")", ";", "return", "$", "this", ";", "}" ]
Performs dates arithmetic. http://php.net/manual/en/datetime.formats.relative.php Each duration period is represented by an integer value followed by a period designator. If the duration contains time elements, that portion of the specification is preceded by the letter T. Period Designators: Y - years, M - months, D - days, W - weeks, H - hours, M - minutes, S - seconds. Examples: two days - 2D, two seconds - T2S, six years and five minutes - 6YT5M. The unit types must be entered from the largest scale unit on the left to the smallest scale unit on the right. Use first "-" char for negative periods. OR Relative period. Examples: "+5 weeks", "12 day", "-7 weekdays", '3 months - 5 days' @param string|DateInterval $interval Time interval to add. @return DateTime
[ "Performs", "dates", "arithmetic", "." ]
4f49f449b23072ac6d2ae0f1ea4b8e34804b760f
https://github.com/AndyDune/DateTime/blob/4f49f449b23072ac6d2ae0f1ea4b8e34804b760f/src/DateTime.php#L155-L170
train
AndyDune/DateTime
src/DateTime.php
DateTime.getDateMonday
public function getDateMonday($format = 'Y-m-d') { $weekDay = $this->format('N') - 1; $dateTime = clone $this; if ($weekDay) { $dateTime->add(sprintf('- %d days', $weekDay)); } if ($format) { return $dateTime->format($format); } return $dateTime; }
php
public function getDateMonday($format = 'Y-m-d') { $weekDay = $this->format('N') - 1; $dateTime = clone $this; if ($weekDay) { $dateTime->add(sprintf('- %d days', $weekDay)); } if ($format) { return $dateTime->format($format); } return $dateTime; }
[ "public", "function", "getDateMonday", "(", "$", "format", "=", "'Y-m-d'", ")", "{", "$", "weekDay", "=", "$", "this", "->", "format", "(", "'N'", ")", "-", "1", ";", "$", "dateTime", "=", "clone", "$", "this", ";", "if", "(", "$", "weekDay", ")", "{", "$", "dateTime", "->", "add", "(", "sprintf", "(", "'- %d days'", ",", "$", "weekDay", ")", ")", ";", "}", "if", "(", "$", "format", ")", "{", "return", "$", "dateTime", "->", "format", "(", "$", "format", ")", ";", "}", "return", "$", "dateTime", ";", "}" ]
Returns monday date. @param string $format @return string|DateTime returns DateTime if empty param $format
[ "Returns", "monday", "date", "." ]
4f49f449b23072ac6d2ae0f1ea4b8e34804b760f
https://github.com/AndyDune/DateTime/blob/4f49f449b23072ac6d2ae0f1ea4b8e34804b760f/src/DateTime.php#L209-L220
train
ApatisArchive/ArrayStorage
src/CollectionSerializable.php
CollectionSerializable.unserialize
public function unserialize($serialized) { $serialized = @unserialize($serialized); if (!is_array($serialized)) { throw new \InvalidArgumentException( 'Invalid argument 1, arguments must be serialized of array.', E_USER_ERROR ); } $this->replace($serialized); }
php
public function unserialize($serialized) { $serialized = @unserialize($serialized); if (!is_array($serialized)) { throw new \InvalidArgumentException( 'Invalid argument 1, arguments must be serialized of array.', E_USER_ERROR ); } $this->replace($serialized); }
[ "public", "function", "unserialize", "(", "$", "serialized", ")", "{", "$", "serialized", "=", "@", "unserialize", "(", "$", "serialized", ")", ";", "if", "(", "!", "is_array", "(", "$", "serialized", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid argument 1, arguments must be serialized of array.'", ",", "E_USER_ERROR", ")", ";", "}", "$", "this", "->", "replace", "(", "$", "serialized", ")", ";", "}" ]
Un-serialize Magic Method @param string $serialized
[ "Un", "-", "serialize", "Magic", "Method" ]
4f6515164352f2997275278b89884fc1e885e7d9
https://github.com/ApatisArchive/ArrayStorage/blob/4f6515164352f2997275278b89884fc1e885e7d9/src/CollectionSerializable.php#L27-L38
train
RudyMas/Emvc_Email
src/Email.php
Email.setup
public function setup(string $host, string $username, string $password, string $security, bool $use_smtp = true): void { $this->use_smtp = $use_smtp; $this->email_host = $host; $this->email_username = $username; $this->email_password = $password; $this->email_security = $security; }
php
public function setup(string $host, string $username, string $password, string $security, bool $use_smtp = true): void { $this->use_smtp = $use_smtp; $this->email_host = $host; $this->email_username = $username; $this->email_password = $password; $this->email_security = $security; }
[ "public", "function", "setup", "(", "string", "$", "host", ",", "string", "$", "username", ",", "string", "$", "password", ",", "string", "$", "security", ",", "bool", "$", "use_smtp", "=", "true", ")", ":", "void", "{", "$", "this", "->", "use_smtp", "=", "$", "use_smtp", ";", "$", "this", "->", "email_host", "=", "$", "host", ";", "$", "this", "->", "email_username", "=", "$", "username", ";", "$", "this", "->", "email_password", "=", "$", "password", ";", "$", "this", "->", "email_security", "=", "$", "security", ";", "}" ]
Use this function when you use it in your own project @param string $host @param string $username @param string $password @param string $security @param bool $use_smtp
[ "Use", "this", "function", "when", "you", "use", "it", "in", "your", "own", "project" ]
9ac2380c6863549fdc30ea64e446bbc6a9ebbb06
https://github.com/RudyMas/Emvc_Email/blob/9ac2380c6863549fdc30ea64e446bbc6a9ebbb06/src/Email.php#L49-L56
train
RudyMas/Emvc_Email
src/Email.php
Email.emvc_config
public function emvc_config(): void { $this->use_smtp = USE_SMTP; $this->email_host = EMAIL_HOST; $this->email_username = EMAIL_USERNAME; $this->email_password = EMAIL_PASSWORD; $this->email_security = EMAIL_SECURITY; }
php
public function emvc_config(): void { $this->use_smtp = USE_SMTP; $this->email_host = EMAIL_HOST; $this->email_username = EMAIL_USERNAME; $this->email_password = EMAIL_PASSWORD; $this->email_security = EMAIL_SECURITY; }
[ "public", "function", "emvc_config", "(", ")", ":", "void", "{", "$", "this", "->", "use_smtp", "=", "USE_SMTP", ";", "$", "this", "->", "email_host", "=", "EMAIL_HOST", ";", "$", "this", "->", "email_username", "=", "EMAIL_USERNAME", ";", "$", "this", "->", "email_password", "=", "EMAIL_PASSWORD", ";", "$", "this", "->", "email_security", "=", "EMAIL_SECURITY", ";", "}" ]
Use this function when you use it in the EasyMVC framework
[ "Use", "this", "function", "when", "you", "use", "it", "in", "the", "EasyMVC", "framework" ]
9ac2380c6863549fdc30ea64e446bbc6a9ebbb06
https://github.com/RudyMas/Emvc_Email/blob/9ac2380c6863549fdc30ea64e446bbc6a9ebbb06/src/Email.php#L61-L68
train
RudyMas/Emvc_Email
src/Email.php
Email.setTextMessage
public function setTextMessage(array $to, string $subject, string $body, array $attachment = null, array $cc = null, array $bcc = EMAIL_BCC): void { $this->email->setFrom($this->from); foreach ($to as $value) { $this->email->addTo($value); } if ($cc != null) { foreach ($cc as $value) { $this->email->addCc($value); } } if ($bcc != null) { foreach ($bcc as $value) { $this->email->addBcc($value); } } if ($attachment != null) { foreach ($attachment as $file) { $this->email->addAttachment($file); } } $this->email->setSubject($subject); $this->email->setBody($body); }
php
public function setTextMessage(array $to, string $subject, string $body, array $attachment = null, array $cc = null, array $bcc = EMAIL_BCC): void { $this->email->setFrom($this->from); foreach ($to as $value) { $this->email->addTo($value); } if ($cc != null) { foreach ($cc as $value) { $this->email->addCc($value); } } if ($bcc != null) { foreach ($bcc as $value) { $this->email->addBcc($value); } } if ($attachment != null) { foreach ($attachment as $file) { $this->email->addAttachment($file); } } $this->email->setSubject($subject); $this->email->setBody($body); }
[ "public", "function", "setTextMessage", "(", "array", "$", "to", ",", "string", "$", "subject", ",", "string", "$", "body", ",", "array", "$", "attachment", "=", "null", ",", "array", "$", "cc", "=", "null", ",", "array", "$", "bcc", "=", "EMAIL_BCC", ")", ":", "void", "{", "$", "this", "->", "email", "->", "setFrom", "(", "$", "this", "->", "from", ")", ";", "foreach", "(", "$", "to", "as", "$", "value", ")", "{", "$", "this", "->", "email", "->", "addTo", "(", "$", "value", ")", ";", "}", "if", "(", "$", "cc", "!=", "null", ")", "{", "foreach", "(", "$", "cc", "as", "$", "value", ")", "{", "$", "this", "->", "email", "->", "addCc", "(", "$", "value", ")", ";", "}", "}", "if", "(", "$", "bcc", "!=", "null", ")", "{", "foreach", "(", "$", "bcc", "as", "$", "value", ")", "{", "$", "this", "->", "email", "->", "addBcc", "(", "$", "value", ")", ";", "}", "}", "if", "(", "$", "attachment", "!=", "null", ")", "{", "foreach", "(", "$", "attachment", "as", "$", "file", ")", "{", "$", "this", "->", "email", "->", "addAttachment", "(", "$", "file", ")", ";", "}", "}", "$", "this", "->", "email", "->", "setSubject", "(", "$", "subject", ")", ";", "$", "this", "->", "email", "->", "setBody", "(", "$", "body", ")", ";", "}" ]
Prepare a plain text E-mail @param array $to @param string $subject @param string $body @param array|null $attachment @param array|null $cc @param array $bcc
[ "Prepare", "a", "plain", "text", "E", "-", "mail" ]
9ac2380c6863549fdc30ea64e446bbc6a9ebbb06
https://github.com/RudyMas/Emvc_Email/blob/9ac2380c6863549fdc30ea64e446bbc6a9ebbb06/src/Email.php#L90-L118
train
RudyMas/Emvc_Email
src/Email.php
Email.sendMail
public function sendMail(): void { if ($this->use_smtp) { $mailer = new SmtpMailer([ 'host' => $this->email_host, 'username' => $this->email_username, 'password' => $this->email_password, 'secure' => $this->email_security ]); } else { $mailer = new SendmailMailer(); } $mailer->send($this->email); }
php
public function sendMail(): void { if ($this->use_smtp) { $mailer = new SmtpMailer([ 'host' => $this->email_host, 'username' => $this->email_username, 'password' => $this->email_password, 'secure' => $this->email_security ]); } else { $mailer = new SendmailMailer(); } $mailer->send($this->email); }
[ "public", "function", "sendMail", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "use_smtp", ")", "{", "$", "mailer", "=", "new", "SmtpMailer", "(", "[", "'host'", "=>", "$", "this", "->", "email_host", ",", "'username'", "=>", "$", "this", "->", "email_username", ",", "'password'", "=>", "$", "this", "->", "email_password", ",", "'secure'", "=>", "$", "this", "->", "email_security", "]", ")", ";", "}", "else", "{", "$", "mailer", "=", "new", "SendmailMailer", "(", ")", ";", "}", "$", "mailer", "->", "send", "(", "$", "this", "->", "email", ")", ";", "}" ]
Use this after your E-mail has been prepared
[ "Use", "this", "after", "your", "E", "-", "mail", "has", "been", "prepared" ]
9ac2380c6863549fdc30ea64e446bbc6a9ebbb06
https://github.com/RudyMas/Emvc_Email/blob/9ac2380c6863549fdc30ea64e446bbc6a9ebbb06/src/Email.php#L163-L176
train
RudyMas/Emvc_Email
src/Email.php
Email.emvcRenderHtml
public function emvcRenderHtml(string $latteFile, array $data): string { $latte = new Engine(); $latte->setTempDirectory($_SERVER['DOCUMENT_ROOT'] . BASE_URL . '/tmp/latte'); return $latte->renderToString($_SERVER['DOCUMENT_ROOT'] . BASE_URL . '/private/latte/' . $latteFile, $data); }
php
public function emvcRenderHtml(string $latteFile, array $data): string { $latte = new Engine(); $latte->setTempDirectory($_SERVER['DOCUMENT_ROOT'] . BASE_URL . '/tmp/latte'); return $latte->renderToString($_SERVER['DOCUMENT_ROOT'] . BASE_URL . '/private/latte/' . $latteFile, $data); }
[ "public", "function", "emvcRenderHtml", "(", "string", "$", "latteFile", ",", "array", "$", "data", ")", ":", "string", "{", "$", "latte", "=", "new", "Engine", "(", ")", ";", "$", "latte", "->", "setTempDirectory", "(", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ".", "BASE_URL", ".", "'/tmp/latte'", ")", ";", "return", "$", "latte", "->", "renderToString", "(", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ".", "BASE_URL", ".", "'/private/latte/'", ".", "$", "latteFile", ",", "$", "data", ")", ";", "}" ]
Use Latte for rendering HTML E-mails in the EasyMVC framework @param string $latteFile @param array $data @return string
[ "Use", "Latte", "for", "rendering", "HTML", "E", "-", "mails", "in", "the", "EasyMVC", "framework" ]
9ac2380c6863549fdc30ea64e446bbc6a9ebbb06
https://github.com/RudyMas/Emvc_Email/blob/9ac2380c6863549fdc30ea64e446bbc6a9ebbb06/src/Email.php#L185-L190
train
RudyMas/Emvc_Email
src/Email.php
Email.renderHtml
public function renderHtml(string $latteFile, array $data, string $tempFolderLatte = '/tmp/latte'): string { $latte = new Engine(); $latte->setTempDirectory($tempFolderLatte); return $latte->renderToString($latteFile, $data); }
php
public function renderHtml(string $latteFile, array $data, string $tempFolderLatte = '/tmp/latte'): string { $latte = new Engine(); $latte->setTempDirectory($tempFolderLatte); return $latte->renderToString($latteFile, $data); }
[ "public", "function", "renderHtml", "(", "string", "$", "latteFile", ",", "array", "$", "data", ",", "string", "$", "tempFolderLatte", "=", "'/tmp/latte'", ")", ":", "string", "{", "$", "latte", "=", "new", "Engine", "(", ")", ";", "$", "latte", "->", "setTempDirectory", "(", "$", "tempFolderLatte", ")", ";", "return", "$", "latte", "->", "renderToString", "(", "$", "latteFile", ",", "$", "data", ")", ";", "}" ]
Use Latte for rendering HTML E-mails in your own project @param string $latteFile @param array $data @param string $tempFolderLatte @return string
[ "Use", "Latte", "for", "rendering", "HTML", "E", "-", "mails", "in", "your", "own", "project" ]
9ac2380c6863549fdc30ea64e446bbc6a9ebbb06
https://github.com/RudyMas/Emvc_Email/blob/9ac2380c6863549fdc30ea64e446bbc6a9ebbb06/src/Email.php#L200-L205
train
netbull/CoreBundle
Utils/PrintLabels.php
PrintLabels.labelSetFormat
public function labelSetFormat($format, $unit) { $this->format = $format; $this->paperSize = $this->getFormatValue('paper-size'); $this->orientation = $this->getFormatValue('orientation'); $this->fontName = $this->getFormatValue('font-name'); $this->charSize = $this->getFormatValue('font-size'); $this->fontStyle = $this->getFormatValue('font-style'); $this->xNumber = $this->getFormatValue('NX'); $this->yNumber = $this->getFormatValue('NY'); $this->metricDoc = $unit; $this->marginLeft = $this->getFormatValue('lMargin', true); $this->marginTop = $this->getFormatValue('tMargin', true); $this->xSpace = $this->getFormatValue('SpaceX', true); $this->ySpace = $this->getFormatValue('SpaceY', true); $this->width = $this->getFormatValue('width', true); $this->height = $this->getFormatValue('height', true); $this->paddingLeft = $this->getFormatValue('lPadding', true); $this->paddingTop = $this->getFormatValue('tPadding', true); $this->paper_dimensions = 'A4'; }
php
public function labelSetFormat($format, $unit) { $this->format = $format; $this->paperSize = $this->getFormatValue('paper-size'); $this->orientation = $this->getFormatValue('orientation'); $this->fontName = $this->getFormatValue('font-name'); $this->charSize = $this->getFormatValue('font-size'); $this->fontStyle = $this->getFormatValue('font-style'); $this->xNumber = $this->getFormatValue('NX'); $this->yNumber = $this->getFormatValue('NY'); $this->metricDoc = $unit; $this->marginLeft = $this->getFormatValue('lMargin', true); $this->marginTop = $this->getFormatValue('tMargin', true); $this->xSpace = $this->getFormatValue('SpaceX', true); $this->ySpace = $this->getFormatValue('SpaceY', true); $this->width = $this->getFormatValue('width', true); $this->height = $this->getFormatValue('height', true); $this->paddingLeft = $this->getFormatValue('lPadding', true); $this->paddingTop = $this->getFormatValue('tPadding', true); $this->paper_dimensions = 'A4'; }
[ "public", "function", "labelSetFormat", "(", "$", "format", ",", "$", "unit", ")", "{", "$", "this", "->", "format", "=", "$", "format", ";", "$", "this", "->", "paperSize", "=", "$", "this", "->", "getFormatValue", "(", "'paper-size'", ")", ";", "$", "this", "->", "orientation", "=", "$", "this", "->", "getFormatValue", "(", "'orientation'", ")", ";", "$", "this", "->", "fontName", "=", "$", "this", "->", "getFormatValue", "(", "'font-name'", ")", ";", "$", "this", "->", "charSize", "=", "$", "this", "->", "getFormatValue", "(", "'font-size'", ")", ";", "$", "this", "->", "fontStyle", "=", "$", "this", "->", "getFormatValue", "(", "'font-style'", ")", ";", "$", "this", "->", "xNumber", "=", "$", "this", "->", "getFormatValue", "(", "'NX'", ")", ";", "$", "this", "->", "yNumber", "=", "$", "this", "->", "getFormatValue", "(", "'NY'", ")", ";", "$", "this", "->", "metricDoc", "=", "$", "unit", ";", "$", "this", "->", "marginLeft", "=", "$", "this", "->", "getFormatValue", "(", "'lMargin'", ",", "true", ")", ";", "$", "this", "->", "marginTop", "=", "$", "this", "->", "getFormatValue", "(", "'tMargin'", ",", "true", ")", ";", "$", "this", "->", "xSpace", "=", "$", "this", "->", "getFormatValue", "(", "'SpaceX'", ",", "true", ")", ";", "$", "this", "->", "ySpace", "=", "$", "this", "->", "getFormatValue", "(", "'SpaceY'", ",", "true", ")", ";", "$", "this", "->", "width", "=", "$", "this", "->", "getFormatValue", "(", "'width'", ",", "true", ")", ";", "$", "this", "->", "height", "=", "$", "this", "->", "getFormatValue", "(", "'height'", ",", "true", ")", ";", "$", "this", "->", "paddingLeft", "=", "$", "this", "->", "getFormatValue", "(", "'lPadding'", ",", "true", ")", ";", "$", "this", "->", "paddingTop", "=", "$", "this", "->", "getFormatValue", "(", "'tPadding'", ",", "true", ")", ";", "$", "this", "->", "paper_dimensions", "=", "'A4'", ";", "}" ]
initialize label format settings. @param $format @param $unit
[ "initialize", "label", "format", "settings", "." ]
0bacc1d9e4733b6da613027400c48421e5a14645
https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/Utils/PrintLabels.php#L137-L157
train
netbull/CoreBundle
Utils/PrintLabels.php
PrintLabels.addPdfLabel
public function addPdfLabel(string $text) { if ($this->countX == $this->xNumber) { // Page full, we start a new one $this->AddPage(); $this->countX = 0; $this->countY = 0; } $posX = $this->marginLeft + ($this->countX * ($this->width + $this->xSpace)); $posY = $this->marginTop + ($this->countY * ($this->height + $this->ySpace)); $this->SetXY($posX + $this->paddingLeft, $posY + $this->paddingTop); $this->generateLabel($text); $this->countY++; if ($this->countY == $this->yNumber) { // End of column reached, we start a new one $this->countX++; $this->countY = 0; } }
php
public function addPdfLabel(string $text) { if ($this->countX == $this->xNumber) { // Page full, we start a new one $this->AddPage(); $this->countX = 0; $this->countY = 0; } $posX = $this->marginLeft + ($this->countX * ($this->width + $this->xSpace)); $posY = $this->marginTop + ($this->countY * ($this->height + $this->ySpace)); $this->SetXY($posX + $this->paddingLeft, $posY + $this->paddingTop); $this->generateLabel($text); $this->countY++; if ($this->countY == $this->yNumber) { // End of column reached, we start a new one $this->countX++; $this->countY = 0; } }
[ "public", "function", "addPdfLabel", "(", "string", "$", "text", ")", "{", "if", "(", "$", "this", "->", "countX", "==", "$", "this", "->", "xNumber", ")", "{", "// Page full, we start a new one", "$", "this", "->", "AddPage", "(", ")", ";", "$", "this", "->", "countX", "=", "0", ";", "$", "this", "->", "countY", "=", "0", ";", "}", "$", "posX", "=", "$", "this", "->", "marginLeft", "+", "(", "$", "this", "->", "countX", "*", "(", "$", "this", "->", "width", "+", "$", "this", "->", "xSpace", ")", ")", ";", "$", "posY", "=", "$", "this", "->", "marginTop", "+", "(", "$", "this", "->", "countY", "*", "(", "$", "this", "->", "height", "+", "$", "this", "->", "ySpace", ")", ")", ";", "$", "this", "->", "SetXY", "(", "$", "posX", "+", "$", "this", "->", "paddingLeft", ",", "$", "posY", "+", "$", "this", "->", "paddingTop", ")", ";", "$", "this", "->", "generateLabel", "(", "$", "text", ")", ";", "$", "this", "->", "countY", "++", ";", "if", "(", "$", "this", "->", "countY", "==", "$", "this", "->", "yNumber", ")", "{", "// End of column reached, we start a new one", "$", "this", "->", "countX", "++", ";", "$", "this", "->", "countY", "=", "0", ";", "}", "}" ]
Print a label. @param string $text
[ "Print", "a", "label", "." ]
0bacc1d9e4733b6da613027400c48421e5a14645
https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/Utils/PrintLabels.php#L206-L228
train
linpax/microphp-framework
src/file/Type.php
Type.arrayWalkRecursive
public static function arrayWalkRecursive(array $data, callable $function) { if (!is_array($data)) { return call_user_func($function, $data); } foreach ($data as $k => &$item) { $item = self::arrayWalkRecursive($data[$k], $function); } return $data; }
php
public static function arrayWalkRecursive(array $data, callable $function) { if (!is_array($data)) { return call_user_func($function, $data); } foreach ($data as $k => &$item) { $item = self::arrayWalkRecursive($data[$k], $function); } return $data; }
[ "public", "static", "function", "arrayWalkRecursive", "(", "array", "$", "data", ",", "callable", "$", "function", ")", "{", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "{", "return", "call_user_func", "(", "$", "function", ",", "$", "data", ")", ";", "}", "foreach", "(", "$", "data", "as", "$", "k", "=>", "&", "$", "item", ")", "{", "$", "item", "=", "self", "::", "arrayWalkRecursive", "(", "$", "data", "[", "$", "k", "]", ",", "$", "function", ")", ";", "}", "return", "$", "data", ";", "}" ]
Array walk recursive @access public @param array $data array to walk @param callable $function callable function @return array|mixed @static
[ "Array", "walk", "recursive" ]
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/file/Type.php#L70-L81
train
linpax/microphp-framework
src/file/Type.php
Type.getSubArrayFromArrayByKeys
public static function getSubArrayFromArrayByKeys(array $array, array $keys) { $result = []; foreach ($keys as $key) { if (array_key_exists($key, $array)) { $result[$key] = $array[$key]; } } return $result; }
php
public static function getSubArrayFromArrayByKeys(array $array, array $keys) { $result = []; foreach ($keys as $key) { if (array_key_exists($key, $array)) { $result[$key] = $array[$key]; } } return $result; }
[ "public", "static", "function", "getSubArrayFromArrayByKeys", "(", "array", "$", "array", ",", "array", "$", "keys", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "array", ")", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "array", "[", "$", "key", "]", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get SubArray from array by keys @access public @param array $array @param array $keys @return array @static
[ "Get", "SubArray", "from", "array", "by", "keys" ]
11f3370f3f64c516cce9b84ecd8276c6e9ae8df9
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/file/Type.php#L94-L105
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Map/M2PTableMap.php
M2PTableMap.doDelete
public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(M2PTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; } elseif ($values instanceof \Attogram\SharedMedia\Orm\M2P) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks $criteria = new Criteria(M2PTableMap::DATABASE_NAME); // primary key is composite; we therefore, expect // the primary key passed to be an array of pkey values if (count($values) == count($values, COUNT_RECURSIVE)) { // array is not multi-dimensional $values = array($values); } foreach ($values as $value) { $criterion = $criteria->getNewCriterion(M2PTableMap::COL_MEDIA_ID, $value[0]); $criterion->addAnd($criteria->getNewCriterion(M2PTableMap::COL_PAGE_ID, $value[1])); $criteria->addOr($criterion); } } $query = M2PQuery::create()->mergeWith($criteria); if ($values instanceof Criteria) { M2PTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks foreach ((array) $values as $singleval) { M2PTableMap::removeInstanceFromPool($singleval); } } return $query->delete($con); }
php
public static function doDelete($values, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(M2PTableMap::DATABASE_NAME); } if ($values instanceof Criteria) { // rename for clarity $criteria = $values; } elseif ($values instanceof \Attogram\SharedMedia\Orm\M2P) { // it's a model object // create criteria based on pk values $criteria = $values->buildPkeyCriteria(); } else { // it's a primary key, or an array of pks $criteria = new Criteria(M2PTableMap::DATABASE_NAME); // primary key is composite; we therefore, expect // the primary key passed to be an array of pkey values if (count($values) == count($values, COUNT_RECURSIVE)) { // array is not multi-dimensional $values = array($values); } foreach ($values as $value) { $criterion = $criteria->getNewCriterion(M2PTableMap::COL_MEDIA_ID, $value[0]); $criterion->addAnd($criteria->getNewCriterion(M2PTableMap::COL_PAGE_ID, $value[1])); $criteria->addOr($criterion); } } $query = M2PQuery::create()->mergeWith($criteria); if ($values instanceof Criteria) { M2PTableMap::clearInstancePool(); } elseif (!is_object($values)) { // it's a primary key, or an array of pks foreach ((array) $values as $singleval) { M2PTableMap::removeInstanceFromPool($singleval); } } return $query->delete($con); }
[ "public", "static", "function", "doDelete", "(", "$", "values", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "if", "(", "null", "===", "$", "con", ")", "{", "$", "con", "=", "Propel", "::", "getServiceContainer", "(", ")", "->", "getWriteConnection", "(", "M2PTableMap", "::", "DATABASE_NAME", ")", ";", "}", "if", "(", "$", "values", "instanceof", "Criteria", ")", "{", "// rename for clarity", "$", "criteria", "=", "$", "values", ";", "}", "elseif", "(", "$", "values", "instanceof", "\\", "Attogram", "\\", "SharedMedia", "\\", "Orm", "\\", "M2P", ")", "{", "// it's a model object", "// create criteria based on pk values", "$", "criteria", "=", "$", "values", "->", "buildPkeyCriteria", "(", ")", ";", "}", "else", "{", "// it's a primary key, or an array of pks", "$", "criteria", "=", "new", "Criteria", "(", "M2PTableMap", "::", "DATABASE_NAME", ")", ";", "// primary key is composite; we therefore, expect", "// the primary key passed to be an array of pkey values", "if", "(", "count", "(", "$", "values", ")", "==", "count", "(", "$", "values", ",", "COUNT_RECURSIVE", ")", ")", "{", "// array is not multi-dimensional", "$", "values", "=", "array", "(", "$", "values", ")", ";", "}", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "$", "criterion", "=", "$", "criteria", "->", "getNewCriterion", "(", "M2PTableMap", "::", "COL_MEDIA_ID", ",", "$", "value", "[", "0", "]", ")", ";", "$", "criterion", "->", "addAnd", "(", "$", "criteria", "->", "getNewCriterion", "(", "M2PTableMap", "::", "COL_PAGE_ID", ",", "$", "value", "[", "1", "]", ")", ")", ";", "$", "criteria", "->", "addOr", "(", "$", "criterion", ")", ";", "}", "}", "$", "query", "=", "M2PQuery", "::", "create", "(", ")", "->", "mergeWith", "(", "$", "criteria", ")", ";", "if", "(", "$", "values", "instanceof", "Criteria", ")", "{", "M2PTableMap", "::", "clearInstancePool", "(", ")", ";", "}", "elseif", "(", "!", "is_object", "(", "$", "values", ")", ")", "{", "// it's a primary key, or an array of pks", "foreach", "(", "(", "array", ")", "$", "values", "as", "$", "singleval", ")", "{", "M2PTableMap", "::", "removeInstanceFromPool", "(", "$", "singleval", ")", ";", "}", "}", "return", "$", "query", "->", "delete", "(", "$", "con", ")", ";", "}" ]
Performs a DELETE on the database, given a M2P or Criteria object OR a primary key value. @param mixed $values Criteria or M2P object or primary key or array of primary keys which is used to create the DELETE statement @param ConnectionInterface $con the connection to use @return int The number of affected rows (if supported by underlying database driver). This includes CASCADE-related rows if supported by native driver or if emulated using Propel. @throws PropelException Any exceptions caught during processing will be rethrown wrapped into a PropelException.
[ "Performs", "a", "DELETE", "on", "the", "database", "given", "a", "M2P", "or", "Criteria", "object", "OR", "a", "primary", "key", "value", "." ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Map/M2PTableMap.php#L404-L442
train
attogram/shared-media-orm
src/Attogram/SharedMedia/Orm/Map/M2PTableMap.php
M2PTableMap.doInsert
public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(M2PTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from M2P object } // Set the correct dbName $query = M2PQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use ($con, $query) { return $query->doInsert($con); }); }
php
public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(M2PTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from M2P object } // Set the correct dbName $query = M2PQuery::create()->mergeWith($criteria); // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) return $con->transaction(function () use ($con, $query) { return $query->doInsert($con); }); }
[ "public", "static", "function", "doInsert", "(", "$", "criteria", ",", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "if", "(", "null", "===", "$", "con", ")", "{", "$", "con", "=", "Propel", "::", "getServiceContainer", "(", ")", "->", "getWriteConnection", "(", "M2PTableMap", "::", "DATABASE_NAME", ")", ";", "}", "if", "(", "$", "criteria", "instanceof", "Criteria", ")", "{", "$", "criteria", "=", "clone", "$", "criteria", ";", "// rename for clarity", "}", "else", "{", "$", "criteria", "=", "$", "criteria", "->", "buildCriteria", "(", ")", ";", "// build Criteria from M2P object", "}", "// Set the correct dbName", "$", "query", "=", "M2PQuery", "::", "create", "(", ")", "->", "mergeWith", "(", "$", "criteria", ")", ";", "// use transaction because $criteria could contain info", "// for more than one table (I guess, conceivably)", "return", "$", "con", "->", "transaction", "(", "function", "(", ")", "use", "(", "$", "con", ",", "$", "query", ")", "{", "return", "$", "query", "->", "doInsert", "(", "$", "con", ")", ";", "}", ")", ";", "}" ]
Performs an INSERT on the database, given a M2P or Criteria object. @param mixed $criteria Criteria or M2P object containing data that is used to create the INSERT statement. @param ConnectionInterface $con the ConnectionInterface connection to use @return mixed The new primary key. @throws PropelException Any exceptions caught during processing will be rethrown wrapped into a PropelException.
[ "Performs", "an", "INSERT", "on", "the", "database", "given", "a", "M2P", "or", "Criteria", "object", "." ]
81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8
https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Map/M2PTableMap.php#L464-L485
train
fiiSoft/fiisoft-logger
src/Logger/Reader/LogsMonitor/AbstractLogsMonitor.php
AbstractLogsMonitor.filterByLevel
final public function filterByLevel($level, array $levels = []) { if ($level !== $this->minLevel) { $this->minLevel = $level; $this->consumer = null; } if (!empty($levels)) { $this->levels = $levels; $this->consumer = null; } return $this; }
php
final public function filterByLevel($level, array $levels = []) { if ($level !== $this->minLevel) { $this->minLevel = $level; $this->consumer = null; } if (!empty($levels)) { $this->levels = $levels; $this->consumer = null; } return $this; }
[ "final", "public", "function", "filterByLevel", "(", "$", "level", ",", "array", "$", "levels", "=", "[", "]", ")", "{", "if", "(", "$", "level", "!==", "$", "this", "->", "minLevel", ")", "{", "$", "this", "->", "minLevel", "=", "$", "level", ";", "$", "this", "->", "consumer", "=", "null", ";", "}", "if", "(", "!", "empty", "(", "$", "levels", ")", ")", "{", "$", "this", "->", "levels", "=", "$", "levels", ";", "$", "this", "->", "consumer", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
One can set minimum level of logs that will be streamed to OutputWriter by this LogsMonitor. This is optional and if method is not call, all available logs are supposed to be streamed. If second param is not empty then use this set of levels instead of defaults. The list of Levels must be ordered from the most to the least significant. @param string $level @param array $levels @return $this fluent interface
[ "One", "can", "set", "minimum", "level", "of", "logs", "that", "will", "be", "streamed", "to", "OutputWriter", "by", "this", "LogsMonitor", ".", "This", "is", "optional", "and", "if", "method", "is", "not", "call", "all", "available", "logs", "are", "supposed", "to", "be", "streamed", "." ]
3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5
https://github.com/fiiSoft/fiisoft-logger/blob/3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5/src/Logger/Reader/LogsMonitor/AbstractLogsMonitor.php#L66-L79
train
fiiSoft/fiisoft-logger
src/Logger/Reader/LogsMonitor/AbstractLogsMonitor.php
AbstractLogsMonitor.filterByContext
final public function filterByContext(array $context) { if ($context !== $this->withContext) { $this->withContext = $context; $this->consumer = null; } return $this; }
php
final public function filterByContext(array $context) { if ($context !== $this->withContext) { $this->withContext = $context; $this->consumer = null; } return $this; }
[ "final", "public", "function", "filterByContext", "(", "array", "$", "context", ")", "{", "if", "(", "$", "context", "!==", "$", "this", "->", "withContext", ")", "{", "$", "this", "->", "withContext", "=", "$", "context", ";", "$", "this", "->", "consumer", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
One can set context that is required to stream logs to OutputWriter by this LogsMonitor. This is optional and if method is not call, all available logs are supposed to be streamed. @param array $context @return $this fluent interface
[ "One", "can", "set", "context", "that", "is", "required", "to", "stream", "logs", "to", "OutputWriter", "by", "this", "LogsMonitor", ".", "This", "is", "optional", "and", "if", "method", "is", "not", "call", "all", "available", "logs", "are", "supposed", "to", "be", "streamed", "." ]
3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5
https://github.com/fiiSoft/fiisoft-logger/blob/3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5/src/Logger/Reader/LogsMonitor/AbstractLogsMonitor.php#L88-L96
train
fiiSoft/fiisoft-logger
src/Logger/Reader/LogsMonitor/AbstractLogsMonitor.php
AbstractLogsMonitor.setOutputWriter
final public function setOutputWriter(OutputWriter $outputWriter) { if ($outputWriter !== $this->outputWriter) { $this->outputWriter = $outputWriter; $this->consumer = null; } return $this; }
php
final public function setOutputWriter(OutputWriter $outputWriter) { if ($outputWriter !== $this->outputWriter) { $this->outputWriter = $outputWriter; $this->consumer = null; } return $this; }
[ "final", "public", "function", "setOutputWriter", "(", "OutputWriter", "$", "outputWriter", ")", "{", "if", "(", "$", "outputWriter", "!==", "$", "this", "->", "outputWriter", ")", "{", "$", "this", "->", "outputWriter", "=", "$", "outputWriter", ";", "$", "this", "->", "consumer", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
Call of this method is required before logs are streamed to OutputWriter. @param OutputWriter $outputWriter @return $this fluent interface
[ "Call", "of", "this", "method", "is", "required", "before", "logs", "are", "streamed", "to", "OutputWriter", "." ]
3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5
https://github.com/fiiSoft/fiisoft-logger/blob/3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5/src/Logger/Reader/LogsMonitor/AbstractLogsMonitor.php#L104-L112
train
Kris-Kuiper/sFire-Framework
src/Image/Color.php
Color.name
public static function name($color) { if(false === is_string($color)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($color)), E_USER_ERROR); } if(1 !== preg_match('#^[0-9a-fA-F]{6,6}$#', $color)) { return trigger_error(sprintf('Argument 1 passed to %s() must be a 6 character hexadecimal string', __METHOD__), E_USER_ERROR); } $color = strtoupper($color); $rgb = static :: rgb($color); $r = $rgb -> r; $g = $rgb -> g; $b = $rgb -> b; $hsl = static :: hsl($color); $h = $hsl -> h; $s = $hsl -> s; $l = $hsl -> l; $ndf1 = 0; $ndf2 = 0; $ndf = 0; $cl = -1; $df = -1; //Index all the colors if(null === static :: $list) { new ColorList(); static :: index(); } foreach(static :: $list as $hex => $color) { $ndf1 = pow($r - $color -> r, 2) + pow($g - $color -> g, 2) + pow($b - $color -> b, 2); $ndf2 = pow($h - $color -> h, 2) + pow($s - $color -> s, 2) + pow($l - $color -> l, 2); $ndf = $ndf1 + $ndf2 * 2; if($df < 0 || $df > $ndf) { $df = $ndf; $cl = $hex; } } if(true === isset(static :: $list[$cl])) { return static :: $list[$cl]; } return null; }
php
public static function name($color) { if(false === is_string($color)) { return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($color)), E_USER_ERROR); } if(1 !== preg_match('#^[0-9a-fA-F]{6,6}$#', $color)) { return trigger_error(sprintf('Argument 1 passed to %s() must be a 6 character hexadecimal string', __METHOD__), E_USER_ERROR); } $color = strtoupper($color); $rgb = static :: rgb($color); $r = $rgb -> r; $g = $rgb -> g; $b = $rgb -> b; $hsl = static :: hsl($color); $h = $hsl -> h; $s = $hsl -> s; $l = $hsl -> l; $ndf1 = 0; $ndf2 = 0; $ndf = 0; $cl = -1; $df = -1; //Index all the colors if(null === static :: $list) { new ColorList(); static :: index(); } foreach(static :: $list as $hex => $color) { $ndf1 = pow($r - $color -> r, 2) + pow($g - $color -> g, 2) + pow($b - $color -> b, 2); $ndf2 = pow($h - $color -> h, 2) + pow($s - $color -> s, 2) + pow($l - $color -> l, 2); $ndf = $ndf1 + $ndf2 * 2; if($df < 0 || $df > $ndf) { $df = $ndf; $cl = $hex; } } if(true === isset(static :: $list[$cl])) { return static :: $list[$cl]; } return null; }
[ "public", "static", "function", "name", "(", "$", "color", ")", "{", "if", "(", "false", "===", "is_string", "(", "$", "color", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be of the type string, \"%s\" given'", ",", "__METHOD__", ",", "gettype", "(", "$", "color", ")", ")", ",", "E_USER_ERROR", ")", ";", "}", "if", "(", "1", "!==", "preg_match", "(", "'#^[0-9a-fA-F]{6,6}$#'", ",", "$", "color", ")", ")", "{", "return", "trigger_error", "(", "sprintf", "(", "'Argument 1 passed to %s() must be a 6 character hexadecimal string'", ",", "__METHOD__", ")", ",", "E_USER_ERROR", ")", ";", "}", "$", "color", "=", "strtoupper", "(", "$", "color", ")", ";", "$", "rgb", "=", "static", "::", "rgb", "(", "$", "color", ")", ";", "$", "r", "=", "$", "rgb", "->", "r", ";", "$", "g", "=", "$", "rgb", "->", "g", ";", "$", "b", "=", "$", "rgb", "->", "b", ";", "$", "hsl", "=", "static", "::", "hsl", "(", "$", "color", ")", ";", "$", "h", "=", "$", "hsl", "->", "h", ";", "$", "s", "=", "$", "hsl", "->", "s", ";", "$", "l", "=", "$", "hsl", "->", "l", ";", "$", "ndf1", "=", "0", ";", "$", "ndf2", "=", "0", ";", "$", "ndf", "=", "0", ";", "$", "cl", "=", "-", "1", ";", "$", "df", "=", "-", "1", ";", "//Index all the colors\r", "if", "(", "null", "===", "static", "::", "$", "list", ")", "{", "new", "ColorList", "(", ")", ";", "static", "::", "index", "(", ")", ";", "}", "foreach", "(", "static", "::", "$", "list", "as", "$", "hex", "=>", "$", "color", ")", "{", "$", "ndf1", "=", "pow", "(", "$", "r", "-", "$", "color", "->", "r", ",", "2", ")", "+", "pow", "(", "$", "g", "-", "$", "color", "->", "g", ",", "2", ")", "+", "pow", "(", "$", "b", "-", "$", "color", "->", "b", ",", "2", ")", ";", "$", "ndf2", "=", "pow", "(", "$", "h", "-", "$", "color", "->", "h", ",", "2", ")", "+", "pow", "(", "$", "s", "-", "$", "color", "->", "s", ",", "2", ")", "+", "pow", "(", "$", "l", "-", "$", "color", "->", "l", ",", "2", ")", ";", "$", "ndf", "=", "$", "ndf1", "+", "$", "ndf2", "*", "2", ";", "if", "(", "$", "df", "<", "0", "||", "$", "df", ">", "$", "ndf", ")", "{", "$", "df", "=", "$", "ndf", ";", "$", "cl", "=", "$", "hex", ";", "}", "}", "if", "(", "true", "===", "isset", "(", "static", "::", "$", "list", "[", "$", "cl", "]", ")", ")", "{", "return", "static", "::", "$", "list", "[", "$", "cl", "]", ";", "}", "return", "null", ";", "}" ]
Convert a hexadecimal color to color name in human language @param string $color @return null|stdClass Object
[ "Convert", "a", "hexadecimal", "color", "to", "color", "name", "in", "human", "language" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Color.php#L28-L78
train
Kris-Kuiper/sFire-Framework
src/Image/Color.php
Color.index
private static function index() { $colors = ColorList :: get('colors'); foreach($colors as $hex => $color) { $rgb = static :: rgb($hex); $hsl = static :: hsl($hex); $shade = ColorList :: get(['shades', $color['s']]); $base = ColorList :: get(['base', $shade['b']]); static :: $list[$hex] = (object) [ 'r' => $rgb -> r, 'g' => $rgb -> g, 'b' => $rgb -> b, 'h' => $hsl -> h, 's' => $hsl -> s, 'l' => $hsl -> l, 'hex' => $hex, 'title' => $color['t'], 'shade' => (object) [ 'id' => $color['s'], 'hex' => $shade['h'] ], 'base' => (object) [ 'id' => $shade['b'], 'hex' => $base['h'], 'title' => $base['t'] ] ]; } }
php
private static function index() { $colors = ColorList :: get('colors'); foreach($colors as $hex => $color) { $rgb = static :: rgb($hex); $hsl = static :: hsl($hex); $shade = ColorList :: get(['shades', $color['s']]); $base = ColorList :: get(['base', $shade['b']]); static :: $list[$hex] = (object) [ 'r' => $rgb -> r, 'g' => $rgb -> g, 'b' => $rgb -> b, 'h' => $hsl -> h, 's' => $hsl -> s, 'l' => $hsl -> l, 'hex' => $hex, 'title' => $color['t'], 'shade' => (object) [ 'id' => $color['s'], 'hex' => $shade['h'] ], 'base' => (object) [ 'id' => $shade['b'], 'hex' => $base['h'], 'title' => $base['t'] ] ]; } }
[ "private", "static", "function", "index", "(", ")", "{", "$", "colors", "=", "ColorList", "::", "get", "(", "'colors'", ")", ";", "foreach", "(", "$", "colors", "as", "$", "hex", "=>", "$", "color", ")", "{", "$", "rgb", "=", "static", "::", "rgb", "(", "$", "hex", ")", ";", "$", "hsl", "=", "static", "::", "hsl", "(", "$", "hex", ")", ";", "$", "shade", "=", "ColorList", "::", "get", "(", "[", "'shades'", ",", "$", "color", "[", "'s'", "]", "]", ")", ";", "$", "base", "=", "ColorList", "::", "get", "(", "[", "'base'", ",", "$", "shade", "[", "'b'", "]", "]", ")", ";", "static", "::", "$", "list", "[", "$", "hex", "]", "=", "(", "object", ")", "[", "'r'", "=>", "$", "rgb", "->", "r", ",", "'g'", "=>", "$", "rgb", "->", "g", ",", "'b'", "=>", "$", "rgb", "->", "b", ",", "'h'", "=>", "$", "hsl", "->", "h", ",", "'s'", "=>", "$", "hsl", "->", "s", ",", "'l'", "=>", "$", "hsl", "->", "l", ",", "'hex'", "=>", "$", "hex", ",", "'title'", "=>", "$", "color", "[", "'t'", "]", ",", "'shade'", "=>", "(", "object", ")", "[", "'id'", "=>", "$", "color", "[", "'s'", "]", ",", "'hex'", "=>", "$", "shade", "[", "'h'", "]", "]", ",", "'base'", "=>", "(", "object", ")", "[", "'id'", "=>", "$", "shade", "[", "'b'", "]", ",", "'hex'", "=>", "$", "base", "[", "'h'", "]", ",", "'title'", "=>", "$", "base", "[", "'t'", "]", "]", "]", ";", "}", "}" ]
Initialise all colors
[ "Initialise", "all", "colors" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Color.php#L84-L119
train
Kris-Kuiper/sFire-Framework
src/Image/Color.php
Color.rgb
private static function rgb($color) { return (object) [ 'r' => intval(hexdec(substr($color, 0, 2))), 'g' => intval(hexdec(substr($color, 2, 2))), 'b' => intval(hexdec(substr($color, 4, 2))) ]; }
php
private static function rgb($color) { return (object) [ 'r' => intval(hexdec(substr($color, 0, 2))), 'g' => intval(hexdec(substr($color, 2, 2))), 'b' => intval(hexdec(substr($color, 4, 2))) ]; }
[ "private", "static", "function", "rgb", "(", "$", "color", ")", "{", "return", "(", "object", ")", "[", "'r'", "=>", "intval", "(", "hexdec", "(", "substr", "(", "$", "color", ",", "0", ",", "2", ")", ")", ")", ",", "'g'", "=>", "intval", "(", "hexdec", "(", "substr", "(", "$", "color", ",", "2", ",", "2", ")", ")", ")", ",", "'b'", "=>", "intval", "(", "hexdec", "(", "substr", "(", "$", "color", ",", "4", ",", "2", ")", ")", ")", "]", ";", "}" ]
Convert hexadecimal color to RGB @param string $color @return stdClass Object
[ "Convert", "hexadecimal", "color", "to", "RGB" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Color.php#L127-L135
train
Kris-Kuiper/sFire-Framework
src/Image/Color.php
Color.hsl
private static function hsl($color) { $r = intval(hexdec(substr($color, 0, 2))) / 255; $g = intval(hexdec(substr($color, 2, 2))) / 255; $b = intval(hexdec(substr($color, 4, 2))) / 255; $min = min($r, $g, $b); $max = max($r, $g, $b); $delta = $max - $min; $l = ($min + $max) / 2; $s = 0; $h = 0; if($l > 0 && $l < 1) { $s = $delta / ($l < 0.5 ? (2 * $l) : (2 - 2 * $l)); } if($delta > 0) { if($max == $r && $max != $g) { $h += ($g - $b) / $delta; } if($max == $g && $max != $b) { $h += (2 + ($b - $r) / $delta); } if($max == $b && $max != $r) { $h += (4 + ($r - $g) / $delta); } $h /= 6; } return (object) [ 'h' => intval($h * 255), 's' => intval($s * 255), 'l' => intval($l * 255) ]; }
php
private static function hsl($color) { $r = intval(hexdec(substr($color, 0, 2))) / 255; $g = intval(hexdec(substr($color, 2, 2))) / 255; $b = intval(hexdec(substr($color, 4, 2))) / 255; $min = min($r, $g, $b); $max = max($r, $g, $b); $delta = $max - $min; $l = ($min + $max) / 2; $s = 0; $h = 0; if($l > 0 && $l < 1) { $s = $delta / ($l < 0.5 ? (2 * $l) : (2 - 2 * $l)); } if($delta > 0) { if($max == $r && $max != $g) { $h += ($g - $b) / $delta; } if($max == $g && $max != $b) { $h += (2 + ($b - $r) / $delta); } if($max == $b && $max != $r) { $h += (4 + ($r - $g) / $delta); } $h /= 6; } return (object) [ 'h' => intval($h * 255), 's' => intval($s * 255), 'l' => intval($l * 255) ]; }
[ "private", "static", "function", "hsl", "(", "$", "color", ")", "{", "$", "r", "=", "intval", "(", "hexdec", "(", "substr", "(", "$", "color", ",", "0", ",", "2", ")", ")", ")", "/", "255", ";", "$", "g", "=", "intval", "(", "hexdec", "(", "substr", "(", "$", "color", ",", "2", ",", "2", ")", ")", ")", "/", "255", ";", "$", "b", "=", "intval", "(", "hexdec", "(", "substr", "(", "$", "color", ",", "4", ",", "2", ")", ")", ")", "/", "255", ";", "$", "min", "=", "min", "(", "$", "r", ",", "$", "g", ",", "$", "b", ")", ";", "$", "max", "=", "max", "(", "$", "r", ",", "$", "g", ",", "$", "b", ")", ";", "$", "delta", "=", "$", "max", "-", "$", "min", ";", "$", "l", "=", "(", "$", "min", "+", "$", "max", ")", "/", "2", ";", "$", "s", "=", "0", ";", "$", "h", "=", "0", ";", "if", "(", "$", "l", ">", "0", "&&", "$", "l", "<", "1", ")", "{", "$", "s", "=", "$", "delta", "/", "(", "$", "l", "<", "0.5", "?", "(", "2", "*", "$", "l", ")", ":", "(", "2", "-", "2", "*", "$", "l", ")", ")", ";", "}", "if", "(", "$", "delta", ">", "0", ")", "{", "if", "(", "$", "max", "==", "$", "r", "&&", "$", "max", "!=", "$", "g", ")", "{", "$", "h", "+=", "(", "$", "g", "-", "$", "b", ")", "/", "$", "delta", ";", "}", "if", "(", "$", "max", "==", "$", "g", "&&", "$", "max", "!=", "$", "b", ")", "{", "$", "h", "+=", "(", "2", "+", "(", "$", "b", "-", "$", "r", ")", "/", "$", "delta", ")", ";", "}", "if", "(", "$", "max", "==", "$", "b", "&&", "$", "max", "!=", "$", "r", ")", "{", "$", "h", "+=", "(", "4", "+", "(", "$", "r", "-", "$", "g", ")", "/", "$", "delta", ")", ";", "}", "$", "h", "/=", "6", ";", "}", "return", "(", "object", ")", "[", "'h'", "=>", "intval", "(", "$", "h", "*", "255", ")", ",", "'s'", "=>", "intval", "(", "$", "s", "*", "255", ")", ",", "'l'", "=>", "intval", "(", "$", "l", "*", "255", ")", "]", ";", "}" ]
Convert hexadecimal color to HSL @param string $color @return stdClass Object
[ "Convert", "hexadecimal", "color", "to", "HSL" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Image/Color.php#L143-L183
train
koolkode/lexer
src/AbstractToken.php
AbstractToken.serialize
public function serialize(SerializedTokenIterator $it) { $it->append($this->type); $it->append($this->text); }
php
public function serialize(SerializedTokenIterator $it) { $it->append($this->type); $it->append($this->text); }
[ "public", "function", "serialize", "(", "SerializedTokenIterator", "$", "it", ")", "{", "$", "it", "->", "append", "(", "$", "this", "->", "type", ")", ";", "$", "it", "->", "append", "(", "$", "this", "->", "text", ")", ";", "}" ]
Serialize the token into the given token interation. @param SerializedTokenIterator $it
[ "Serialize", "the", "token", "into", "the", "given", "token", "interation", "." ]
1f33fb4e95bf3b6b21c63187e503bbe612a1646c
https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractToken.php#L129-L133
train
koolkode/lexer
src/AbstractToken.php
AbstractToken.getTypeName
public static function getTypeName($type) { static $ref = []; $key = static::class; if(empty($ref[$key])) { $ref[$key] = new \ReflectionClass($key); } foreach($ref[$key]->getConstants() as $k => $v) { if($v === $type && strpos($k, 'T_') === 0) { return $k; } } return static::UNKNOWN; }
php
public static function getTypeName($type) { static $ref = []; $key = static::class; if(empty($ref[$key])) { $ref[$key] = new \ReflectionClass($key); } foreach($ref[$key]->getConstants() as $k => $v) { if($v === $type && strpos($k, 'T_') === 0) { return $k; } } return static::UNKNOWN; }
[ "public", "static", "function", "getTypeName", "(", "$", "type", ")", "{", "static", "$", "ref", "=", "[", "]", ";", "$", "key", "=", "static", "::", "class", ";", "if", "(", "empty", "(", "$", "ref", "[", "$", "key", "]", ")", ")", "{", "$", "ref", "[", "$", "key", "]", "=", "new", "\\", "ReflectionClass", "(", "$", "key", ")", ";", "}", "foreach", "(", "$", "ref", "[", "$", "key", "]", "->", "getConstants", "(", ")", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "v", "===", "$", "type", "&&", "strpos", "(", "$", "k", ",", "'T_'", ")", "===", "0", ")", "{", "return", "$", "k", ";", "}", "}", "return", "static", "::", "UNKNOWN", ";", "}" ]
Get a human-readable name of the given token type. @param integer $type @return string
[ "Get", "a", "human", "-", "readable", "name", "of", "the", "given", "token", "type", "." ]
1f33fb4e95bf3b6b21c63187e503bbe612a1646c
https://github.com/koolkode/lexer/blob/1f33fb4e95bf3b6b21c63187e503bbe612a1646c/src/AbstractToken.php#L141-L161
train
Erdiko/doctrine
src/EntityManager.php
EntityManager.getEntityManager
public static function getEntityManager($db = null, $context = 'shared') { // Get db config info from file $dbConfig = \erdiko\core\Helper::getConfig("database", $context); if($db == null) $db = $dbConfig['default']; $dbParams = $dbConfig['connections'][$db]; $dbParams['dbname'] = $dbParams['database']; $dbParams['user'] = $dbParams['username']; $paths = array(ERDIKO_ROOT.$dbConfig['entities']); $isDevMode = isset($dbConfig['is_dev_mode']) ? (bool)$dbConfig['is_dev_mode'] : false; $config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); // Create and return the entity manager return \Doctrine\ORM\EntityManager::create($dbParams, $config); }
php
public static function getEntityManager($db = null, $context = 'shared') { // Get db config info from file $dbConfig = \erdiko\core\Helper::getConfig("database", $context); if($db == null) $db = $dbConfig['default']; $dbParams = $dbConfig['connections'][$db]; $dbParams['dbname'] = $dbParams['database']; $dbParams['user'] = $dbParams['username']; $paths = array(ERDIKO_ROOT.$dbConfig['entities']); $isDevMode = isset($dbConfig['is_dev_mode']) ? (bool)$dbConfig['is_dev_mode'] : false; $config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); // Create and return the entity manager return \Doctrine\ORM\EntityManager::create($dbParams, $config); }
[ "public", "static", "function", "getEntityManager", "(", "$", "db", "=", "null", ",", "$", "context", "=", "'shared'", ")", "{", "// Get db config info from file", "$", "dbConfig", "=", "\\", "erdiko", "\\", "core", "\\", "Helper", "::", "getConfig", "(", "\"database\"", ",", "$", "context", ")", ";", "if", "(", "$", "db", "==", "null", ")", "$", "db", "=", "$", "dbConfig", "[", "'default'", "]", ";", "$", "dbParams", "=", "$", "dbConfig", "[", "'connections'", "]", "[", "$", "db", "]", ";", "$", "dbParams", "[", "'dbname'", "]", "=", "$", "dbParams", "[", "'database'", "]", ";", "$", "dbParams", "[", "'user'", "]", "=", "$", "dbParams", "[", "'username'", "]", ";", "$", "paths", "=", "array", "(", "ERDIKO_ROOT", ".", "$", "dbConfig", "[", "'entities'", "]", ")", ";", "$", "isDevMode", "=", "isset", "(", "$", "dbConfig", "[", "'is_dev_mode'", "]", ")", "?", "(", "bool", ")", "$", "dbConfig", "[", "'is_dev_mode'", "]", ":", "false", ";", "$", "config", "=", "\\", "Doctrine", "\\", "ORM", "\\", "Tools", "\\", "Setup", "::", "createAnnotationMetadataConfiguration", "(", "$", "paths", ",", "$", "isDevMode", ")", ";", "// Create and return the entity manager", "return", "\\", "Doctrine", "\\", "ORM", "\\", "EntityManager", "::", "create", "(", "$", "dbParams", ",", "$", "config", ")", ";", "}" ]
Get Doctrine entity manager @param string $db, default to the 'default' database in the config @param string
[ "Get", "Doctrine", "entity", "manager" ]
b8fdba2f34a67c862cafc0448d1d613a2fa4da16
https://github.com/Erdiko/doctrine/blob/b8fdba2f34a67c862cafc0448d1d613a2fa4da16/src/EntityManager.php#L18-L34
train
Erdiko/doctrine
src/EntityManager.php
EntityManager.update
public static function update($entity) { $entityManager = self::getEntityManager(); $entity = $entityManager->merge($entity); $entityManager->flush(); // transact return $entity; }
php
public static function update($entity) { $entityManager = self::getEntityManager(); $entity = $entityManager->merge($entity); $entityManager->flush(); // transact return $entity; }
[ "public", "static", "function", "update", "(", "$", "entity", ")", "{", "$", "entityManager", "=", "self", "::", "getEntityManager", "(", ")", ";", "$", "entity", "=", "$", "entityManager", "->", "merge", "(", "$", "entity", ")", ";", "$", "entityManager", "->", "flush", "(", ")", ";", "// transact", "return", "$", "entity", ";", "}" ]
Update a single record Convenience method to update a row. You should use the Doctrine EntityManager directly to take control of the Entity merge process. @note do we need this?
[ "Update", "a", "single", "record", "Convenience", "method", "to", "update", "a", "row", ".", "You", "should", "use", "the", "Doctrine", "EntityManager", "directly", "to", "take", "control", "of", "the", "Entity", "merge", "process", "." ]
b8fdba2f34a67c862cafc0448d1d613a2fa4da16
https://github.com/Erdiko/doctrine/blob/b8fdba2f34a67c862cafc0448d1d613a2fa4da16/src/EntityManager.php#L42-L49
train
sil-project/SeedBatchBundle
src/Entity/Plot.php
Plot.addSeedBatch
public function addSeedBatch(\Librinfo\SeedBatchBundle\Entity\SeedBatch $seedBatch) { $this->seedBatches[] = $seedBatch; return $this; }
php
public function addSeedBatch(\Librinfo\SeedBatchBundle\Entity\SeedBatch $seedBatch) { $this->seedBatches[] = $seedBatch; return $this; }
[ "public", "function", "addSeedBatch", "(", "\\", "Librinfo", "\\", "SeedBatchBundle", "\\", "Entity", "\\", "SeedBatch", "$", "seedBatch", ")", "{", "$", "this", "->", "seedBatches", "[", "]", "=", "$", "seedBatch", ";", "return", "$", "this", ";", "}" ]
Add seedBatch. @param \Librinfo\SeedBatchBundle\Entity\SeedBatch $seedBatch @return Plot
[ "Add", "seedBatch", "." ]
a2640b5359fe31d3bdb9c9fa2f72141ac841729c
https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/Entity/Plot.php#L114-L119
train
sil-project/SeedBatchBundle
src/Entity/Plot.php
Plot.removeSeedBatch
public function removeSeedBatch(\Librinfo\SeedBatchBundle\Entity\SeedBatch $seedBatch) { return $this->seedBatches->removeElement($seedBatch); }
php
public function removeSeedBatch(\Librinfo\SeedBatchBundle\Entity\SeedBatch $seedBatch) { return $this->seedBatches->removeElement($seedBatch); }
[ "public", "function", "removeSeedBatch", "(", "\\", "Librinfo", "\\", "SeedBatchBundle", "\\", "Entity", "\\", "SeedBatch", "$", "seedBatch", ")", "{", "return", "$", "this", "->", "seedBatches", "->", "removeElement", "(", "$", "seedBatch", ")", ";", "}" ]
Remove seedBatch. @param \Librinfo\SeedBatchBundle\Entity\SeedBatch $seedBatch @return bool tRUE if this collection contained the specified element, FALSE otherwise
[ "Remove", "seedBatch", "." ]
a2640b5359fe31d3bdb9c9fa2f72141ac841729c
https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/Entity/Plot.php#L128-L131
train
sil-project/SeedBatchBundle
src/Entity/Plot.php
Plot.setProducer
public function setProducer(\Librinfo\CRMBundle\Entity\Organism $producer = null) { $this->producer = $producer; return $this; }
php
public function setProducer(\Librinfo\CRMBundle\Entity\Organism $producer = null) { $this->producer = $producer; return $this; }
[ "public", "function", "setProducer", "(", "\\", "Librinfo", "\\", "CRMBundle", "\\", "Entity", "\\", "Organism", "$", "producer", "=", "null", ")", "{", "$", "this", "->", "producer", "=", "$", "producer", ";", "return", "$", "this", ";", "}" ]
Set producer. @param \Librinfo\CRMBundle\Entity\Organism $producer @return Plot
[ "Set", "producer", "." ]
a2640b5359fe31d3bdb9c9fa2f72141ac841729c
https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/Entity/Plot.php#L150-L155
train
sil-project/SeedBatchBundle
src/Entity/Plot.php
Plot.addCertification
public function addCertification(\Librinfo\SeedBatchBundle\Entity\Certification $certifications) { $this->certifications[] = $certifications; return $this; }
php
public function addCertification(\Librinfo\SeedBatchBundle\Entity\Certification $certifications) { $this->certifications[] = $certifications; return $this; }
[ "public", "function", "addCertification", "(", "\\", "Librinfo", "\\", "SeedBatchBundle", "\\", "Entity", "\\", "Certification", "$", "certifications", ")", "{", "$", "this", "->", "certifications", "[", "]", "=", "$", "certifications", ";", "return", "$", "this", ";", "}" ]
Add certifications. @param \Librinfo\SeedBatchBundle\Entity\Certification $certifications @return Plot
[ "Add", "certifications", "." ]
a2640b5359fe31d3bdb9c9fa2f72141ac841729c
https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/Entity/Plot.php#L188-L193
train
sil-project/SeedBatchBundle
src/Entity/Plot.php
Plot.removeCertification
public function removeCertification(\Librinfo\SeedBatchBundle\Entity\Certification $certification) { $this->certifications->removeElement($certification); }
php
public function removeCertification(\Librinfo\SeedBatchBundle\Entity\Certification $certification) { $this->certifications->removeElement($certification); }
[ "public", "function", "removeCertification", "(", "\\", "Librinfo", "\\", "SeedBatchBundle", "\\", "Entity", "\\", "Certification", "$", "certification", ")", "{", "$", "this", "->", "certifications", "->", "removeElement", "(", "$", "certification", ")", ";", "}" ]
Remove certification. @param \Librinfo\SeedBatchBundle\Entity\Certification $certification
[ "Remove", "certification", "." ]
a2640b5359fe31d3bdb9c9fa2f72141ac841729c
https://github.com/sil-project/SeedBatchBundle/blob/a2640b5359fe31d3bdb9c9fa2f72141ac841729c/src/Entity/Plot.php#L200-L203
train
mrstroz/yii2-wavecms-form
models/FormSettings.php
FormSettings.replaceTags
public function replaceTags($model) { if (isset($model->attributes)) { foreach ($model->attributes as $key => $attribute) { if (in_array($key, $this->dataAttributes)) { $val = Yii::$app->formatter->asDatetime($model->{$key}, 'short'); } else { $val = $model->{$key}; } $this->subject = str_replace('{' . $key . '}', $val, $this->subject); $this->user_subject = str_replace('{' . $key . '}', $val, $this->user_subject); $this->text = str_replace('{' . $key . '}', $val, $this->text); $this->user_text = str_replace('{' . $key . '}', $val, $this->user_text); } } $table = EmailDetailView::widget([ 'model' => $model, 'attributes' => $model::$emailAttributes ]); $this->text = str_replace('{table}', $table, $this->text); $this->user_text = str_replace('{table}', $table, $this->user_text); }
php
public function replaceTags($model) { if (isset($model->attributes)) { foreach ($model->attributes as $key => $attribute) { if (in_array($key, $this->dataAttributes)) { $val = Yii::$app->formatter->asDatetime($model->{$key}, 'short'); } else { $val = $model->{$key}; } $this->subject = str_replace('{' . $key . '}', $val, $this->subject); $this->user_subject = str_replace('{' . $key . '}', $val, $this->user_subject); $this->text = str_replace('{' . $key . '}', $val, $this->text); $this->user_text = str_replace('{' . $key . '}', $val, $this->user_text); } } $table = EmailDetailView::widget([ 'model' => $model, 'attributes' => $model::$emailAttributes ]); $this->text = str_replace('{table}', $table, $this->text); $this->user_text = str_replace('{table}', $table, $this->user_text); }
[ "public", "function", "replaceTags", "(", "$", "model", ")", "{", "if", "(", "isset", "(", "$", "model", "->", "attributes", ")", ")", "{", "foreach", "(", "$", "model", "->", "attributes", "as", "$", "key", "=>", "$", "attribute", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "this", "->", "dataAttributes", ")", ")", "{", "$", "val", "=", "Yii", "::", "$", "app", "->", "formatter", "->", "asDatetime", "(", "$", "model", "->", "{", "$", "key", "}", ",", "'short'", ")", ";", "}", "else", "{", "$", "val", "=", "$", "model", "->", "{", "$", "key", "}", ";", "}", "$", "this", "->", "subject", "=", "str_replace", "(", "'{'", ".", "$", "key", ".", "'}'", ",", "$", "val", ",", "$", "this", "->", "subject", ")", ";", "$", "this", "->", "user_subject", "=", "str_replace", "(", "'{'", ".", "$", "key", ".", "'}'", ",", "$", "val", ",", "$", "this", "->", "user_subject", ")", ";", "$", "this", "->", "text", "=", "str_replace", "(", "'{'", ".", "$", "key", ".", "'}'", ",", "$", "val", ",", "$", "this", "->", "text", ")", ";", "$", "this", "->", "user_text", "=", "str_replace", "(", "'{'", ".", "$", "key", ".", "'}'", ",", "$", "val", ",", "$", "this", "->", "user_text", ")", ";", "}", "}", "$", "table", "=", "EmailDetailView", "::", "widget", "(", "[", "'model'", "=>", "$", "model", ",", "'attributes'", "=>", "$", "model", "::", "$", "emailAttributes", "]", ")", ";", "$", "this", "->", "text", "=", "str_replace", "(", "'{table}'", ",", "$", "table", ",", "$", "this", "->", "text", ")", ";", "$", "this", "->", "user_text", "=", "str_replace", "(", "'{table}'", ",", "$", "table", ",", "$", "this", "->", "user_text", ")", ";", "}" ]
Replace tags by values in text and subject field @param Form $model @throws \yii\base\InvalidArgumentException @throws \yii\base\InvalidConfigException @throws \yii\base\InvalidParamException @throws \Exception
[ "Replace", "tags", "by", "values", "in", "text", "and", "subject", "field" ]
9ada0dbbe07b2281fb20905f7cfd07e4075bd065
https://github.com/mrstroz/yii2-wavecms-form/blob/9ada0dbbe07b2281fb20905f7cfd07e4075bd065/models/FormSettings.php#L125-L150
train
mrstroz/yii2-wavecms-form
models/FormSettings.php
FormSettings.replaceExtraTag
public function replaceExtraTag($tag, $value) { $this->subject = str_replace('{' . $tag . '}', $value, $this->subject); $this->user_subject = str_replace('{' . $tag . '}', $value, $this->user_subject); $this->text = str_replace('{' . $tag . '}', $value, $this->text); $this->user_text = str_replace('{' . $tag . '}', $value, $this->user_text); }
php
public function replaceExtraTag($tag, $value) { $this->subject = str_replace('{' . $tag . '}', $value, $this->subject); $this->user_subject = str_replace('{' . $tag . '}', $value, $this->user_subject); $this->text = str_replace('{' . $tag . '}', $value, $this->text); $this->user_text = str_replace('{' . $tag . '}', $value, $this->user_text); }
[ "public", "function", "replaceExtraTag", "(", "$", "tag", ",", "$", "value", ")", "{", "$", "this", "->", "subject", "=", "str_replace", "(", "'{'", ".", "$", "tag", ".", "'}'", ",", "$", "value", ",", "$", "this", "->", "subject", ")", ";", "$", "this", "->", "user_subject", "=", "str_replace", "(", "'{'", ".", "$", "tag", ".", "'}'", ",", "$", "value", ",", "$", "this", "->", "user_subject", ")", ";", "$", "this", "->", "text", "=", "str_replace", "(", "'{'", ".", "$", "tag", ".", "'}'", ",", "$", "value", ",", "$", "this", "->", "text", ")", ";", "$", "this", "->", "user_text", "=", "str_replace", "(", "'{'", ".", "$", "tag", ".", "'}'", ",", "$", "value", ",", "$", "this", "->", "user_text", ")", ";", "}" ]
Replace additional tags in email subject and text @param $tag @param $value
[ "Replace", "additional", "tags", "in", "email", "subject", "and", "text" ]
9ada0dbbe07b2281fb20905f7cfd07e4075bd065
https://github.com/mrstroz/yii2-wavecms-form/blob/9ada0dbbe07b2281fb20905f7cfd07e4075bd065/models/FormSettings.php#L157-L163
train
Soneritics/Database
Soneritics/Database/Query/Count.php
Count.fields
public function fields($fields) { if (!is_string($fields)) { throw new FatalException('Only strings are allowed in COUNT query'); } $this->fields = sprintf( 'COUNT(%s)', DatabaseConnectionFactory::get()->quoteIdentifier($fields) ); return $this; }
php
public function fields($fields) { if (!is_string($fields)) { throw new FatalException('Only strings are allowed in COUNT query'); } $this->fields = sprintf( 'COUNT(%s)', DatabaseConnectionFactory::get()->quoteIdentifier($fields) ); return $this; }
[ "public", "function", "fields", "(", "$", "fields", ")", "{", "if", "(", "!", "is_string", "(", "$", "fields", ")", ")", "{", "throw", "new", "FatalException", "(", "'Only strings are allowed in COUNT query'", ")", ";", "}", "$", "this", "->", "fields", "=", "sprintf", "(", "'COUNT(%s)'", ",", "DatabaseConnectionFactory", "::", "get", "(", ")", "->", "quoteIdentifier", "(", "$", "fields", ")", ")", ";", "return", "$", "this", ";", "}" ]
Set the field to count. @param $fields @return $this @throws FatalException
[ "Set", "the", "field", "to", "count", "." ]
20cb74f2a2ee8d9161d3144b5c061a6da11cd066
https://github.com/Soneritics/Database/blob/20cb74f2a2ee8d9161d3144b5c061a6da11cd066/Soneritics/Database/Query/Count.php#L47-L59
train
libreworks/caridea-container
src/Provider.php
Provider.get
public function get(Container $container) { if ($this->singleton) { if ($this->instance === null) { $f = $this->factory; $this->instance = $f($container); } return $this->instance; } else { $f = $this->factory; return $f($container); } }
php
public function get(Container $container) { if ($this->singleton) { if ($this->instance === null) { $f = $this->factory; $this->instance = $f($container); } return $this->instance; } else { $f = $this->factory; return $f($container); } }
[ "public", "function", "get", "(", "Container", "$", "container", ")", "{", "if", "(", "$", "this", "->", "singleton", ")", "{", "if", "(", "$", "this", "->", "instance", "===", "null", ")", "{", "$", "f", "=", "$", "this", "->", "factory", ";", "$", "this", "->", "instance", "=", "$", "f", "(", "$", "container", ")", ";", "}", "return", "$", "this", "->", "instance", ";", "}", "else", "{", "$", "f", "=", "$", "this", "->", "factory", ";", "return", "$", "f", "(", "$", "container", ")", ";", "}", "}" ]
Gets the value instance. @param \Caridea\Container\Container $container The owning container @return mixed The value instance
[ "Gets", "the", "value", "instance", "." ]
b93087ff5bf49f5885025da691575093335bfe8f
https://github.com/libreworks/caridea-container/blob/b93087ff5bf49f5885025da691575093335bfe8f/src/Provider.php#L70-L82
train
bytic/MediaLibrary
src/Loaders/AbstractLoader.php
AbstractLoader.loadMedia
public function loadMedia() { $files = $this->getMediaFiles(); foreach ($files as $file) { $mediaFile = $this->getCollection()->newMedia(); $mediaFile->setFile($file); $this->appendMediaInCollection($mediaFile); } }
php
public function loadMedia() { $files = $this->getMediaFiles(); foreach ($files as $file) { $mediaFile = $this->getCollection()->newMedia(); $mediaFile->setFile($file); $this->appendMediaInCollection($mediaFile); } }
[ "public", "function", "loadMedia", "(", ")", "{", "$", "files", "=", "$", "this", "->", "getMediaFiles", "(", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "mediaFile", "=", "$", "this", "->", "getCollection", "(", ")", "->", "newMedia", "(", ")", ";", "$", "mediaFile", "->", "setFile", "(", "$", "file", ")", ";", "$", "this", "->", "appendMediaInCollection", "(", "$", "mediaFile", ")", ";", "}", "}" ]
Load media for a collection
[ "Load", "media", "for", "a", "collection" ]
c52783e726b512184bd72e04d829d6f93242a61d
https://github.com/bytic/MediaLibrary/blob/c52783e726b512184bd72e04d829d6f93242a61d/src/Loaders/AbstractLoader.php#L47-L56
train
Palmabit-IT/library
src/Palmabit/Library/ImportExport/Reader.php
Reader.istantiateObjects
public function istantiateObjects() { $this->validateObjectClassName(); $objects_iterator = new ArrayIterator; $this->appendObjectDataToIterator($objects_iterator); $this->objects_istantiated = $objects_iterator; return $this->objects_istantiated; }
php
public function istantiateObjects() { $this->validateObjectClassName(); $objects_iterator = new ArrayIterator; $this->appendObjectDataToIterator($objects_iterator); $this->objects_istantiated = $objects_iterator; return $this->objects_istantiated; }
[ "public", "function", "istantiateObjects", "(", ")", "{", "$", "this", "->", "validateObjectClassName", "(", ")", ";", "$", "objects_iterator", "=", "new", "ArrayIterator", ";", "$", "this", "->", "appendObjectDataToIterator", "(", "$", "objects_iterator", ")", ";", "$", "this", "->", "objects_istantiated", "=", "$", "objects_iterator", ";", "return", "$", "this", "->", "objects_istantiated", ";", "}" ]
Assuming that we can pass all the proprieties to that object as an array we istantiate each of that StdClass as a IstantiatedObject @return \ArrayIterator @throws \Exception
[ "Assuming", "that", "we", "can", "pass", "all", "the", "proprieties", "to", "that", "object", "as", "an", "array", "we", "istantiate", "each", "of", "that", "StdClass", "as", "a", "IstantiatedObject" ]
ec49a3c333eb4e94d9610a0f58d82c9ea1ade4b9
https://github.com/Palmabit-IT/library/blob/ec49a3c333eb4e94d9610a0f58d82c9ea1ade4b9/src/Palmabit/Library/ImportExport/Reader.php#L53-L63
train
TomK/CronParser
src/CronParser.php
CronParser.isDue
public static function isDue($pattern, \DateTime $time = null) { if($time === null) { $time = new \DateTime(); } // trim time back to last round minute $time->setTime($time->format('H'), $time->format('i')); $expression = Expression::createFromPattern($pattern); foreach(self::$_formats as $pos => $fmt) { if($pos > 4 && !isset($expression[$pos])) { continue; } $cmp = intval($time->format($fmt)); $posSuccess = false; foreach($expression[$pos] as $part) { if($part['full'] == '*' || $part['full'] == $cmp || $posSuccess) { $posSuccess = true; break; } // process order: range, modulus // doesn't match val if(isset($part['val']) && $part['val'] != '*' && $cmp != $part['val']) { continue; } // out of range if(isset($part['min']) && isset($part['max']) && ($cmp < $part['min'] || $cmp > $part['max'])) { continue; } $offset = isset($part['min']) ? $part['min'] : 0; if(isset($part['mod']) && (($cmp - $offset) % $part['mod']) != 0) { continue; } $posSuccess = true; } if(!$posSuccess) { return false; } } return true; }
php
public static function isDue($pattern, \DateTime $time = null) { if($time === null) { $time = new \DateTime(); } // trim time back to last round minute $time->setTime($time->format('H'), $time->format('i')); $expression = Expression::createFromPattern($pattern); foreach(self::$_formats as $pos => $fmt) { if($pos > 4 && !isset($expression[$pos])) { continue; } $cmp = intval($time->format($fmt)); $posSuccess = false; foreach($expression[$pos] as $part) { if($part['full'] == '*' || $part['full'] == $cmp || $posSuccess) { $posSuccess = true; break; } // process order: range, modulus // doesn't match val if(isset($part['val']) && $part['val'] != '*' && $cmp != $part['val']) { continue; } // out of range if(isset($part['min']) && isset($part['max']) && ($cmp < $part['min'] || $cmp > $part['max'])) { continue; } $offset = isset($part['min']) ? $part['min'] : 0; if(isset($part['mod']) && (($cmp - $offset) % $part['mod']) != 0) { continue; } $posSuccess = true; } if(!$posSuccess) { return false; } } return true; }
[ "public", "static", "function", "isDue", "(", "$", "pattern", ",", "\\", "DateTime", "$", "time", "=", "null", ")", "{", "if", "(", "$", "time", "===", "null", ")", "{", "$", "time", "=", "new", "\\", "DateTime", "(", ")", ";", "}", "// trim time back to last round minute", "$", "time", "->", "setTime", "(", "$", "time", "->", "format", "(", "'H'", ")", ",", "$", "time", "->", "format", "(", "'i'", ")", ")", ";", "$", "expression", "=", "Expression", "::", "createFromPattern", "(", "$", "pattern", ")", ";", "foreach", "(", "self", "::", "$", "_formats", "as", "$", "pos", "=>", "$", "fmt", ")", "{", "if", "(", "$", "pos", ">", "4", "&&", "!", "isset", "(", "$", "expression", "[", "$", "pos", "]", ")", ")", "{", "continue", ";", "}", "$", "cmp", "=", "intval", "(", "$", "time", "->", "format", "(", "$", "fmt", ")", ")", ";", "$", "posSuccess", "=", "false", ";", "foreach", "(", "$", "expression", "[", "$", "pos", "]", "as", "$", "part", ")", "{", "if", "(", "$", "part", "[", "'full'", "]", "==", "'*'", "||", "$", "part", "[", "'full'", "]", "==", "$", "cmp", "||", "$", "posSuccess", ")", "{", "$", "posSuccess", "=", "true", ";", "break", ";", "}", "// process order: range, modulus", "// doesn't match val", "if", "(", "isset", "(", "$", "part", "[", "'val'", "]", ")", "&&", "$", "part", "[", "'val'", "]", "!=", "'*'", "&&", "$", "cmp", "!=", "$", "part", "[", "'val'", "]", ")", "{", "continue", ";", "}", "// out of range", "if", "(", "isset", "(", "$", "part", "[", "'min'", "]", ")", "&&", "isset", "(", "$", "part", "[", "'max'", "]", ")", "&&", "(", "$", "cmp", "<", "$", "part", "[", "'min'", "]", "||", "$", "cmp", ">", "$", "part", "[", "'max'", "]", ")", ")", "{", "continue", ";", "}", "$", "offset", "=", "isset", "(", "$", "part", "[", "'min'", "]", ")", "?", "$", "part", "[", "'min'", "]", ":", "0", ";", "if", "(", "isset", "(", "$", "part", "[", "'mod'", "]", ")", "&&", "(", "(", "$", "cmp", "-", "$", "offset", ")", "%", "$", "part", "[", "'mod'", "]", ")", "!=", "0", ")", "{", "continue", ";", "}", "$", "posSuccess", "=", "true", ";", "}", "if", "(", "!", "$", "posSuccess", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Returns true if the time matches the pattern supplied. Time defaults to current time. @param $pattern @param \DateTime $time @return bool
[ "Returns", "true", "if", "the", "time", "matches", "the", "pattern", "supplied", ".", "Time", "defaults", "to", "current", "time", "." ]
cdb1133e49ac2f68b45665f6df2a551bfb9824c1
https://github.com/TomK/CronParser/blob/cdb1133e49ac2f68b45665f6df2a551bfb9824c1/src/CronParser.php#L142-L199
train
ezra-obiwale/dSCore
src/Form/Fieldset.php
Fieldset.getAttributes
final public function getAttributes($parsed = false) { if (!is_array($this->attributes)) { $this->attributes = array(); } return ($parsed) ? $this->parseAttributes() : $this->attributes; }
php
final public function getAttributes($parsed = false) { if (!is_array($this->attributes)) { $this->attributes = array(); } return ($parsed) ? $this->parseAttributes() : $this->attributes; }
[ "final", "public", "function", "getAttributes", "(", "$", "parsed", "=", "false", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "attributes", ")", ")", "{", "$", "this", "->", "attributes", "=", "array", "(", ")", ";", "}", "return", "(", "$", "parsed", ")", "?", "$", "this", "->", "parseAttributes", "(", ")", ":", "$", "this", "->", "attributes", ";", "}" ]
Fetches the attributes of the fieldset @param boolean $parsed @return string|array
[ "Fetches", "the", "attributes", "of", "the", "fieldset" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Fieldset.php#L106-L111
train
ezra-obiwale/dSCore
src/Form/Fieldset.php
Fieldset.setModel
final public function setModel(IModel $model) { $this->model = $model; $this->setData($model->toArray(false, true)); return $this; }
php
final public function setModel(IModel $model) { $this->model = $model; $this->setData($model->toArray(false, true)); return $this; }
[ "final", "public", "function", "setModel", "(", "IModel", "$", "model", ")", "{", "$", "this", "->", "model", "=", "$", "model", ";", "$", "this", "->", "setData", "(", "$", "model", "->", "toArray", "(", "false", ",", "true", ")", ")", ";", "return", "$", "this", ";", "}" ]
Maps the form to a model @param IModel $model @return Form
[ "Maps", "the", "form", "to", "a", "model" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Fieldset.php#L132-L136
train
ezra-obiwale/dSCore
src/Form/Fieldset.php
Fieldset.getModel
public function getModel() { if (!$this->model) return null; $data = $this->data; if ($this->isValid() && $this->model) { foreach ($this->fieldsets as $name) { if (!isset($this->elements[$name])) continue; $fieldset = $this->elements[$name]->options->value; $fieldsetModel = $fieldset->getModel(); $data[$name] = $fieldsetModel ? $fieldsetModel : $fieldset->getData(); } $this->model->populate($data); } return $this->model; }
php
public function getModel() { if (!$this->model) return null; $data = $this->data; if ($this->isValid() && $this->model) { foreach ($this->fieldsets as $name) { if (!isset($this->elements[$name])) continue; $fieldset = $this->elements[$name]->options->value; $fieldsetModel = $fieldset->getModel(); $data[$name] = $fieldsetModel ? $fieldsetModel : $fieldset->getData(); } $this->model->populate($data); } return $this->model; }
[ "public", "function", "getModel", "(", ")", "{", "if", "(", "!", "$", "this", "->", "model", ")", "return", "null", ";", "$", "data", "=", "$", "this", "->", "data", ";", "if", "(", "$", "this", "->", "isValid", "(", ")", "&&", "$", "this", "->", "model", ")", "{", "foreach", "(", "$", "this", "->", "fieldsets", "as", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "elements", "[", "$", "name", "]", ")", ")", "continue", ";", "$", "fieldset", "=", "$", "this", "->", "elements", "[", "$", "name", "]", "->", "options", "->", "value", ";", "$", "fieldsetModel", "=", "$", "fieldset", "->", "getModel", "(", ")", ";", "$", "data", "[", "$", "name", "]", "=", "$", "fieldsetModel", "?", "$", "fieldsetModel", ":", "$", "fieldset", "->", "getData", "(", ")", ";", "}", "$", "this", "->", "model", "->", "populate", "(", "$", "data", ")", ";", "}", "return", "$", "this", "->", "model", ";", "}" ]
Fetches the populated model @return IModel
[ "Fetches", "the", "populated", "model" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Fieldset.php#L146-L164
train
ezra-obiwale/dSCore
src/Form/Fieldset.php
Fieldset.add
public function add($element) { if ((is_object($element) && !is_a($element, 'DScribe\Form\Element')) || (!is_object($element) && !is_array($element))) throw new Exception('Form elements must be either an array or an object subclass of DScribe\Form\Element'); else if (is_array($element)) { if (!isset($element['type'])) { throw new \Exception('Form elements must of key type'); } $elementClass = 'DScribe\Form\Element\\' . ucfirst($element['type']); $element = class_exists($elementClass) ? new $elementClass($element, true, 'values') : new Element($element, true, 'values'); } if ($this->data[$element->name]) { $element->data = $this->data[$element->name]; unset($this->data[$element->name]); } if (in_array($element->type, array('checkbox', 'radio'))) { $this->booleans[$element->name] = $element->name; } else if ($element->type === 'fieldset') { $this->fieldsets[] = $element->name; } else if ($element->type === 'hidden' && $element->name === 'csrf') $element->setCsrfKey($this->getName()); $this->elements[$element->name] = $element; if (!$element->filters) { $filters = $this->getFilters(); if ($filters[$element->name]) $element->filters = $filters[$element->name]; } return $this; }
php
public function add($element) { if ((is_object($element) && !is_a($element, 'DScribe\Form\Element')) || (!is_object($element) && !is_array($element))) throw new Exception('Form elements must be either an array or an object subclass of DScribe\Form\Element'); else if (is_array($element)) { if (!isset($element['type'])) { throw new \Exception('Form elements must of key type'); } $elementClass = 'DScribe\Form\Element\\' . ucfirst($element['type']); $element = class_exists($elementClass) ? new $elementClass($element, true, 'values') : new Element($element, true, 'values'); } if ($this->data[$element->name]) { $element->data = $this->data[$element->name]; unset($this->data[$element->name]); } if (in_array($element->type, array('checkbox', 'radio'))) { $this->booleans[$element->name] = $element->name; } else if ($element->type === 'fieldset') { $this->fieldsets[] = $element->name; } else if ($element->type === 'hidden' && $element->name === 'csrf') $element->setCsrfKey($this->getName()); $this->elements[$element->name] = $element; if (!$element->filters) { $filters = $this->getFilters(); if ($filters[$element->name]) $element->filters = $filters[$element->name]; } return $this; }
[ "public", "function", "add", "(", "$", "element", ")", "{", "if", "(", "(", "is_object", "(", "$", "element", ")", "&&", "!", "is_a", "(", "$", "element", ",", "'DScribe\\Form\\Element'", ")", ")", "||", "(", "!", "is_object", "(", "$", "element", ")", "&&", "!", "is_array", "(", "$", "element", ")", ")", ")", "throw", "new", "Exception", "(", "'Form elements must be either an array or an object subclass of DScribe\\Form\\Element'", ")", ";", "else", "if", "(", "is_array", "(", "$", "element", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "element", "[", "'type'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Form elements must of key type'", ")", ";", "}", "$", "elementClass", "=", "'DScribe\\Form\\Element\\\\'", ".", "ucfirst", "(", "$", "element", "[", "'type'", "]", ")", ";", "$", "element", "=", "class_exists", "(", "$", "elementClass", ")", "?", "new", "$", "elementClass", "(", "$", "element", ",", "true", ",", "'values'", ")", ":", "new", "Element", "(", "$", "element", ",", "true", ",", "'values'", ")", ";", "}", "if", "(", "$", "this", "->", "data", "[", "$", "element", "->", "name", "]", ")", "{", "$", "element", "->", "data", "=", "$", "this", "->", "data", "[", "$", "element", "->", "name", "]", ";", "unset", "(", "$", "this", "->", "data", "[", "$", "element", "->", "name", "]", ")", ";", "}", "if", "(", "in_array", "(", "$", "element", "->", "type", ",", "array", "(", "'checkbox'", ",", "'radio'", ")", ")", ")", "{", "$", "this", "->", "booleans", "[", "$", "element", "->", "name", "]", "=", "$", "element", "->", "name", ";", "}", "else", "if", "(", "$", "element", "->", "type", "===", "'fieldset'", ")", "{", "$", "this", "->", "fieldsets", "[", "]", "=", "$", "element", "->", "name", ";", "}", "else", "if", "(", "$", "element", "->", "type", "===", "'hidden'", "&&", "$", "element", "->", "name", "===", "'csrf'", ")", "$", "element", "->", "setCsrfKey", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "$", "this", "->", "elements", "[", "$", "element", "->", "name", "]", "=", "$", "element", ";", "if", "(", "!", "$", "element", "->", "filters", ")", "{", "$", "filters", "=", "$", "this", "->", "getFilters", "(", ")", ";", "if", "(", "$", "filters", "[", "$", "element", "->", "name", "]", ")", "$", "element", "->", "filters", "=", "$", "filters", "[", "$", "element", "->", "name", "]", ";", "}", "return", "$", "this", ";", "}" ]
Adds an element to the fieldset @param array | \DScribe\Form\Element $element @return Fieldset @throws Exception
[ "Adds", "an", "element", "to", "the", "fieldset" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Fieldset.php#L183-L215
train
ezra-obiwale/dSCore
src/Form/Fieldset.php
Fieldset.setData
final public function setData($data) { if ((is_object($data) && !is_a($data, 'Object')) || (!is_object($data) && !is_array($data))) throw new \Exception('Data must be either an array or an object that extends Object: ' . gettype($data)); $data = is_array($data) ? $data : $data->toArray(); foreach ($data as $attr => $value) { if ($this->elements[$attr]) { $this->elements[$attr]->setData($value); } else $this->data[$attr] = $value; } $this->valid = null; return $this; }
php
final public function setData($data) { if ((is_object($data) && !is_a($data, 'Object')) || (!is_object($data) && !is_array($data))) throw new \Exception('Data must be either an array or an object that extends Object: ' . gettype($data)); $data = is_array($data) ? $data : $data->toArray(); foreach ($data as $attr => $value) { if ($this->elements[$attr]) { $this->elements[$attr]->setData($value); } else $this->data[$attr] = $value; } $this->valid = null; return $this; }
[ "final", "public", "function", "setData", "(", "$", "data", ")", "{", "if", "(", "(", "is_object", "(", "$", "data", ")", "&&", "!", "is_a", "(", "$", "data", ",", "'Object'", ")", ")", "||", "(", "!", "is_object", "(", "$", "data", ")", "&&", "!", "is_array", "(", "$", "data", ")", ")", ")", "throw", "new", "\\", "Exception", "(", "'Data must be either an array or an object that extends Object: '", ".", "gettype", "(", "$", "data", ")", ")", ";", "$", "data", "=", "is_array", "(", "$", "data", ")", "?", "$", "data", ":", "$", "data", "->", "toArray", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "attr", "=>", "$", "value", ")", "{", "if", "(", "$", "this", "->", "elements", "[", "$", "attr", "]", ")", "{", "$", "this", "->", "elements", "[", "$", "attr", "]", "->", "setData", "(", "$", "value", ")", ";", "}", "else", "$", "this", "->", "data", "[", "$", "attr", "]", "=", "$", "value", ";", "}", "$", "this", "->", "valid", "=", "null", ";", "return", "$", "this", ";", "}" ]
Sets data to validate @param \Object | array $data @return Fieldset|Element @throws Exception
[ "Sets", "data", "to", "validate" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Fieldset.php#L278-L290
train
ezra-obiwale/dSCore
src/Form/Fieldset.php
Fieldset.getData
final public function getData($toArray = false) { if (is_null($this->valid)) throw new \Exception('Form must be validated before you can get data'); if ($toArray) return ($this->data) ? $this->data : array(); else return ($this->data) ? new \Object($this->data) : new \Object(); }
php
final public function getData($toArray = false) { if (is_null($this->valid)) throw new \Exception('Form must be validated before you can get data'); if ($toArray) return ($this->data) ? $this->data : array(); else return ($this->data) ? new \Object($this->data) : new \Object(); }
[ "final", "public", "function", "getData", "(", "$", "toArray", "=", "false", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "valid", ")", ")", "throw", "new", "\\", "Exception", "(", "'Form must be validated before you can get data'", ")", ";", "if", "(", "$", "toArray", ")", "return", "(", "$", "this", "->", "data", ")", "?", "$", "this", "->", "data", ":", "array", "(", ")", ";", "else", "return", "(", "$", "this", "->", "data", ")", "?", "new", "\\", "Object", "(", "$", "this", "->", "data", ")", ":", "new", "\\", "Object", "(", ")", ";", "}" ]
Fetches the filtered data @return Object
[ "Fetches", "the", "filtered", "data" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Fieldset.php#L296-L304
train
ezra-obiwale/dSCore
src/Form/Fieldset.php
Fieldset.render
public function render() { $rendered = ''; foreach ($this->elements as $element) { if (!method_exists($this, 'openTag')) { $element->name = $this->multiple ? $element->name . '[]' : $this->getName() . '[' . $element->name . ']'; $element->parent = $this->getName(); } $rendered .= $element->render(); } return $rendered; }
php
public function render() { $rendered = ''; foreach ($this->elements as $element) { if (!method_exists($this, 'openTag')) { $element->name = $this->multiple ? $element->name . '[]' : $this->getName() . '[' . $element->name . ']'; $element->parent = $this->getName(); } $rendered .= $element->render(); } return $rendered; }
[ "public", "function", "render", "(", ")", "{", "$", "rendered", "=", "''", ";", "foreach", "(", "$", "this", "->", "elements", "as", "$", "element", ")", "{", "if", "(", "!", "method_exists", "(", "$", "this", ",", "'openTag'", ")", ")", "{", "$", "element", "->", "name", "=", "$", "this", "->", "multiple", "?", "$", "element", "->", "name", ".", "'[]'", ":", "$", "this", "->", "getName", "(", ")", ".", "'['", ".", "$", "element", "->", "name", ".", "']'", ";", "$", "element", "->", "parent", "=", "$", "this", "->", "getName", "(", ")", ";", "}", "$", "rendered", ".=", "$", "element", "->", "render", "(", ")", ";", "}", "return", "$", "rendered", ";", "}" ]
Renders the elements of the fieldset out @return string
[ "Renders", "the", "elements", "of", "the", "fieldset", "out" ]
dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d
https://github.com/ezra-obiwale/dSCore/blob/dd51246e0dc2c64d4d44de7992d7ff1b5165ab2d/src/Form/Fieldset.php#L315-L328
train
Polosa/shade-framework-core
app/Converter.php
Converter.formatBytes
public static function formatBytes($bytes, $precision = 2) { if ($bytes < 1024) { return $bytes.' B'; } elseif ($bytes < 1048576) { return round($bytes / 1024, $precision).' KB'; } elseif ($bytes < 1073741824) { return round($bytes / 1048576, $precision).' MB'; } elseif ($bytes < 1099511627776) { return round($bytes / 1073741824, $precision).' GB'; } else { return round($bytes / 1099511627776, $precision).' TB'; } }
php
public static function formatBytes($bytes, $precision = 2) { if ($bytes < 1024) { return $bytes.' B'; } elseif ($bytes < 1048576) { return round($bytes / 1024, $precision).' KB'; } elseif ($bytes < 1073741824) { return round($bytes / 1048576, $precision).' MB'; } elseif ($bytes < 1099511627776) { return round($bytes / 1073741824, $precision).' GB'; } else { return round($bytes / 1099511627776, $precision).' TB'; } }
[ "public", "static", "function", "formatBytes", "(", "$", "bytes", ",", "$", "precision", "=", "2", ")", "{", "if", "(", "$", "bytes", "<", "1024", ")", "{", "return", "$", "bytes", ".", "' B'", ";", "}", "elseif", "(", "$", "bytes", "<", "1048576", ")", "{", "return", "round", "(", "$", "bytes", "/", "1024", ",", "$", "precision", ")", ".", "' KB'", ";", "}", "elseif", "(", "$", "bytes", "<", "1073741824", ")", "{", "return", "round", "(", "$", "bytes", "/", "1048576", ",", "$", "precision", ")", ".", "' MB'", ";", "}", "elseif", "(", "$", "bytes", "<", "1099511627776", ")", "{", "return", "round", "(", "$", "bytes", "/", "1073741824", ",", "$", "precision", ")", ".", "' GB'", ";", "}", "else", "{", "return", "round", "(", "$", "bytes", "/", "1099511627776", ",", "$", "precision", ")", ".", "' TB'", ";", "}", "}" ]
Convert size in bytes to human readable format @param integer $bytes Size in Bytes @param integer $precision Number of decimal digits to round to @return string
[ "Convert", "size", "in", "bytes", "to", "human", "readable", "format" ]
d735d3e8e0616fb9cf4ffc25b8425762ed07940f
https://github.com/Polosa/shade-framework-core/blob/d735d3e8e0616fb9cf4ffc25b8425762ed07940f/app/Converter.php#L28-L41
train
congraphcms/core
Bus/CommandDispatcher.php
CommandDispatcher.validate
public function validate($command) { if ($command instanceof SelfValidating) { return $this->container->call([$command, 'validate']); } $validatorClass = $this->getValidatorClass($command); if(!$validatorClass) { return; } $validator = $this->container->make($validatorClass); $method = $this->getValidatorMethod($command); call_user_func([$validator, $method], $command); }
php
public function validate($command) { if ($command instanceof SelfValidating) { return $this->container->call([$command, 'validate']); } $validatorClass = $this->getValidatorClass($command); if(!$validatorClass) { return; } $validator = $this->container->make($validatorClass); $method = $this->getValidatorMethod($command); call_user_func([$validator, $method], $command); }
[ "public", "function", "validate", "(", "$", "command", ")", "{", "if", "(", "$", "command", "instanceof", "SelfValidating", ")", "{", "return", "$", "this", "->", "container", "->", "call", "(", "[", "$", "command", ",", "'validate'", "]", ")", ";", "}", "$", "validatorClass", "=", "$", "this", "->", "getValidatorClass", "(", "$", "command", ")", ";", "if", "(", "!", "$", "validatorClass", ")", "{", "return", ";", "}", "$", "validator", "=", "$", "this", "->", "container", "->", "make", "(", "$", "validatorClass", ")", ";", "$", "method", "=", "$", "this", "->", "getValidatorMethod", "(", "$", "command", ")", ";", "call_user_func", "(", "[", "$", "validator", ",", "$", "method", "]", ",", "$", "command", ")", ";", "}" ]
Validate a command with its appropriate validator. @param mixed $command @return mixed
[ "Validate", "a", "command", "with", "its", "appropriate", "validator", "." ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Bus/CommandDispatcher.php#L150-L165
train
koolkode/stream
src/ChunkDecodedInputStream.php
ChunkDecodedInputStream.loadBuffer
protected function loadBuffer() { $this->remainder = 0; if($this->ended) { return; } while(!$this->stream->eof() && strlen($this->buffer) < self::BUFFER_SIZE) { $this->buffer .= $this->stream->read(self::BUFFER_SIZE); } $m = NULL; if(preg_match("'^\r?\n?([a-fA-F0-9]+).*\r\n'", $this->buffer, $m)) { $this->remainder = hexdec($m[1]); $this->buffer = (string)substr($this->buffer, strlen($m[0])); if($this->remainder === 0) { $this->buffer = ''; $this->ended = true; } else { while(!$this->stream->eof() && strlen($this->buffer) < $this->remainder) { $this->buffer .= $this->stream->read($this->remainder); } if(strlen($this->buffer) < $this->remainder) { $this->buffer = ''; $this->ended = true; } } } else { $this->buffer = ''; $this->ended = true; } }
php
protected function loadBuffer() { $this->remainder = 0; if($this->ended) { return; } while(!$this->stream->eof() && strlen($this->buffer) < self::BUFFER_SIZE) { $this->buffer .= $this->stream->read(self::BUFFER_SIZE); } $m = NULL; if(preg_match("'^\r?\n?([a-fA-F0-9]+).*\r\n'", $this->buffer, $m)) { $this->remainder = hexdec($m[1]); $this->buffer = (string)substr($this->buffer, strlen($m[0])); if($this->remainder === 0) { $this->buffer = ''; $this->ended = true; } else { while(!$this->stream->eof() && strlen($this->buffer) < $this->remainder) { $this->buffer .= $this->stream->read($this->remainder); } if(strlen($this->buffer) < $this->remainder) { $this->buffer = ''; $this->ended = true; } } } else { $this->buffer = ''; $this->ended = true; } }
[ "protected", "function", "loadBuffer", "(", ")", "{", "$", "this", "->", "remainder", "=", "0", ";", "if", "(", "$", "this", "->", "ended", ")", "{", "return", ";", "}", "while", "(", "!", "$", "this", "->", "stream", "->", "eof", "(", ")", "&&", "strlen", "(", "$", "this", "->", "buffer", ")", "<", "self", "::", "BUFFER_SIZE", ")", "{", "$", "this", "->", "buffer", ".=", "$", "this", "->", "stream", "->", "read", "(", "self", "::", "BUFFER_SIZE", ")", ";", "}", "$", "m", "=", "NULL", ";", "if", "(", "preg_match", "(", "\"'^\\r?\\n?([a-fA-F0-9]+).*\\r\\n'\"", ",", "$", "this", "->", "buffer", ",", "$", "m", ")", ")", "{", "$", "this", "->", "remainder", "=", "hexdec", "(", "$", "m", "[", "1", "]", ")", ";", "$", "this", "->", "buffer", "=", "(", "string", ")", "substr", "(", "$", "this", "->", "buffer", ",", "strlen", "(", "$", "m", "[", "0", "]", ")", ")", ";", "if", "(", "$", "this", "->", "remainder", "===", "0", ")", "{", "$", "this", "->", "buffer", "=", "''", ";", "$", "this", "->", "ended", "=", "true", ";", "}", "else", "{", "while", "(", "!", "$", "this", "->", "stream", "->", "eof", "(", ")", "&&", "strlen", "(", "$", "this", "->", "buffer", ")", "<", "$", "this", "->", "remainder", ")", "{", "$", "this", "->", "buffer", ".=", "$", "this", "->", "stream", "->", "read", "(", "$", "this", "->", "remainder", ")", ";", "}", "if", "(", "strlen", "(", "$", "this", "->", "buffer", ")", "<", "$", "this", "->", "remainder", ")", "{", "$", "this", "->", "buffer", "=", "''", ";", "$", "this", "->", "ended", "=", "true", ";", "}", "}", "}", "else", "{", "$", "this", "->", "buffer", "=", "''", ";", "$", "this", "->", "ended", "=", "true", ";", "}", "}" ]
Load data of the next chunk into memory.
[ "Load", "data", "of", "the", "next", "chunk", "into", "memory", "." ]
05e83efd76e1cb9e40a972711986b4a7e38bc141
https://github.com/koolkode/stream/blob/05e83efd76e1cb9e40a972711986b4a7e38bc141/src/ChunkDecodedInputStream.php#L148-L193
train
spoom-php/core
src/extension/Helper/Wrapper.php
Wrapper.wrap
protected function wrap( StorageInterface $input, array $definition ) { foreach( $definition as $property => $class ) { // wrap the whole value in a class, or every subvalue $is_array = $class{0} == '[' && $class{1} == ']'; /** @var self $class */ $class = ltrim( $class, '[]' ); // choose between wrap modes $value = $input[ $property ]; if( !class_exists( $class ) || !is_subclass_of( $class, self::class ) ) $input[ $property ] = null; else if( !$is_array ) $input[ $property ] = $class::instance( $value ); else { $list = []; if( Collection::is( $value, true ) ) { foreach( $value as $i => $t ) { $list[ $i ] = $class::instance( $t ); } } $input[ $property ] = $list; } } }
php
protected function wrap( StorageInterface $input, array $definition ) { foreach( $definition as $property => $class ) { // wrap the whole value in a class, or every subvalue $is_array = $class{0} == '[' && $class{1} == ']'; /** @var self $class */ $class = ltrim( $class, '[]' ); // choose between wrap modes $value = $input[ $property ]; if( !class_exists( $class ) || !is_subclass_of( $class, self::class ) ) $input[ $property ] = null; else if( !$is_array ) $input[ $property ] = $class::instance( $value ); else { $list = []; if( Collection::is( $value, true ) ) { foreach( $value as $i => $t ) { $list[ $i ] = $class::instance( $t ); } } $input[ $property ] = $list; } } }
[ "protected", "function", "wrap", "(", "StorageInterface", "$", "input", ",", "array", "$", "definition", ")", "{", "foreach", "(", "$", "definition", "as", "$", "property", "=>", "$", "class", ")", "{", "// wrap the whole value in a class, or every subvalue", "$", "is_array", "=", "$", "class", "{", "0", "}", "==", "'['", "&&", "$", "class", "{", "1", "}", "==", "']'", ";", "/** @var self $class */", "$", "class", "=", "ltrim", "(", "$", "class", ",", "'[]'", ")", ";", "// choose between wrap modes", "$", "value", "=", "$", "input", "[", "$", "property", "]", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", "||", "!", "is_subclass_of", "(", "$", "class", ",", "self", "::", "class", ")", ")", "$", "input", "[", "$", "property", "]", "=", "null", ";", "else", "if", "(", "!", "$", "is_array", ")", "$", "input", "[", "$", "property", "]", "=", "$", "class", "::", "instance", "(", "$", "value", ")", ";", "else", "{", "$", "list", "=", "[", "]", ";", "if", "(", "Collection", "::", "is", "(", "$", "value", ",", "true", ")", ")", "{", "foreach", "(", "$", "value", "as", "$", "i", "=>", "$", "t", ")", "{", "$", "list", "[", "$", "i", "]", "=", "$", "class", "::", "instance", "(", "$", "t", ")", ";", "}", "}", "$", "input", "[", "$", "property", "]", "=", "$", "list", ";", "}", "}", "}" ]
Wrap input elements in classes @param StorageInterface $input @param array $definition Defined operations @throws \TypeError
[ "Wrap", "input", "elements", "in", "classes" ]
ea7184213352fa2fad7636927a019e5798734e04
https://github.com/spoom-php/core/blob/ea7184213352fa2fad7636927a019e5798734e04/src/extension/Helper/Wrapper.php#L76-L100
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/stores/SQLLiteCacheStore.php
SQLLiteCacheStore.getData
protected function getData($key) { $query = $this->db->query("SELECT value FROM cache WHERE key='" . $this->key($key) . "' AND expire >= datetime('now')"); return $query->fetch(); }
php
protected function getData($key) { $query = $this->db->query("SELECT value FROM cache WHERE key='" . $this->key($key) . "' AND expire >= datetime('now')"); return $query->fetch(); }
[ "protected", "function", "getData", "(", "$", "key", ")", "{", "$", "query", "=", "$", "this", "->", "db", "->", "query", "(", "\"SELECT value FROM cache WHERE key='\"", ".", "$", "this", "->", "key", "(", "$", "key", ")", ".", "\"' AND expire >= datetime('now')\"", ")", ";", "return", "$", "query", "->", "fetch", "(", ")", ";", "}" ]
Retrieves the data from the database @param string $key The key to retrieve @return array An array containing 'key', 'value', and 'expire' keys
[ "Retrieves", "the", "data", "from", "the", "database" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/SQLLiteCacheStore.php#L79-L83
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/stores/SQLLiteCacheStore.php
SQLLiteCacheStore.writeData
protected function writeData($key, $value, $ttl) { if (!is_numeric($ttl) || $ttl < 0) throw new CacheException('TTL invalid: '. $ttl); if ($ttl == 0) $expiration = "datetime('now', '+100 years')"; // This will make the cache expire after you die, so it's effectively forever. else $expiration = "datetime('now', '+{$ttl} seconds')"; return $this->db->queryExec("INSERT OR REPLACE INTO cache (key, value, expire) VALUES ('" . $this->key($key) . "', '". sqlite_escape_string($value) . "',". "{$expiration})"); }
php
protected function writeData($key, $value, $ttl) { if (!is_numeric($ttl) || $ttl < 0) throw new CacheException('TTL invalid: '. $ttl); if ($ttl == 0) $expiration = "datetime('now', '+100 years')"; // This will make the cache expire after you die, so it's effectively forever. else $expiration = "datetime('now', '+{$ttl} seconds')"; return $this->db->queryExec("INSERT OR REPLACE INTO cache (key, value, expire) VALUES ('" . $this->key($key) . "', '". sqlite_escape_string($value) . "',". "{$expiration})"); }
[ "protected", "function", "writeData", "(", "$", "key", ",", "$", "value", ",", "$", "ttl", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "ttl", ")", "||", "$", "ttl", "<", "0", ")", "throw", "new", "CacheException", "(", "'TTL invalid: '", ".", "$", "ttl", ")", ";", "if", "(", "$", "ttl", "==", "0", ")", "$", "expiration", "=", "\"datetime('now', '+100 years')\"", ";", "// This will make the cache expire after you die, so it's effectively forever.", "else", "$", "expiration", "=", "\"datetime('now', '+{$ttl} seconds')\"", ";", "return", "$", "this", "->", "db", "->", "queryExec", "(", "\"INSERT OR REPLACE INTO cache (key, value, expire) VALUES ('\"", ".", "$", "this", "->", "key", "(", "$", "key", ")", ".", "\"', '\"", ".", "sqlite_escape_string", "(", "$", "value", ")", ".", "\"',\"", ".", "\"{$expiration})\"", ")", ";", "}" ]
Writes the data to the database @param string $key The key to write @param string $value The value to store @param integer $ttl The length of time in seconds for the data to live. @return boolean true if successful
[ "Writes", "the", "data", "to", "the", "database" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/stores/SQLLiteCacheStore.php#L94-L107
train
naucon/Utility
src/IteratorAbstract.php
IteratorAbstract.previous
public function previous() { $this->_itemValid = true; if (!prev($this->_items)) { $this->_itemValid = false; } else { $this->_itemPosition--; } }
php
public function previous() { $this->_itemValid = true; if (!prev($this->_items)) { $this->_itemValid = false; } else { $this->_itemPosition--; } }
[ "public", "function", "previous", "(", ")", "{", "$", "this", "->", "_itemValid", "=", "true", ";", "if", "(", "!", "prev", "(", "$", "this", "->", "_items", ")", ")", "{", "$", "this", "->", "_itemValid", "=", "false", ";", "}", "else", "{", "$", "this", "->", "_itemPosition", "--", ";", "}", "}" ]
set previous item as current item @return void
[ "set", "previous", "item", "as", "current", "item" ]
d225bb5d09d82400917f710c9d502949a66442c4
https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/IteratorAbstract.php#L131-L140
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/feedparser/FeedParser.php
FeedParser.parseFeed
public function parseFeed($url, $nativeOrder = false, $force = false) { require_once PATH_SYSTEM.'/vendors/SimplePie.php'; $feed = new SimplePie(); $feed->set_timeout($this->timeout); $feed->set_feed_url($url); $feed->enable_order_by_date(!$nativeOrder); $feed->force_feed($force); if($this->cacheDuration != null) $feed->set_cache_duration(intval($this->cacheDuration)); if($this->cacheDirectory != null) $feed->set_cache_location($this->cacheDirectory); if($this->stripHtmlTags != null) $feed->strip_htmltags($this->stripHtmlTags); @$feed->init(); if($err = $feed->error()) throw new FeedParserException($err); return $feed; }
php
public function parseFeed($url, $nativeOrder = false, $force = false) { require_once PATH_SYSTEM.'/vendors/SimplePie.php'; $feed = new SimplePie(); $feed->set_timeout($this->timeout); $feed->set_feed_url($url); $feed->enable_order_by_date(!$nativeOrder); $feed->force_feed($force); if($this->cacheDuration != null) $feed->set_cache_duration(intval($this->cacheDuration)); if($this->cacheDirectory != null) $feed->set_cache_location($this->cacheDirectory); if($this->stripHtmlTags != null) $feed->strip_htmltags($this->stripHtmlTags); @$feed->init(); if($err = $feed->error()) throw new FeedParserException($err); return $feed; }
[ "public", "function", "parseFeed", "(", "$", "url", ",", "$", "nativeOrder", "=", "false", ",", "$", "force", "=", "false", ")", "{", "require_once", "PATH_SYSTEM", ".", "'/vendors/SimplePie.php'", ";", "$", "feed", "=", "new", "SimplePie", "(", ")", ";", "$", "feed", "->", "set_timeout", "(", "$", "this", "->", "timeout", ")", ";", "$", "feed", "->", "set_feed_url", "(", "$", "url", ")", ";", "$", "feed", "->", "enable_order_by_date", "(", "!", "$", "nativeOrder", ")", ";", "$", "feed", "->", "force_feed", "(", "$", "force", ")", ";", "if", "(", "$", "this", "->", "cacheDuration", "!=", "null", ")", "$", "feed", "->", "set_cache_duration", "(", "intval", "(", "$", "this", "->", "cacheDuration", ")", ")", ";", "if", "(", "$", "this", "->", "cacheDirectory", "!=", "null", ")", "$", "feed", "->", "set_cache_location", "(", "$", "this", "->", "cacheDirectory", ")", ";", "if", "(", "$", "this", "->", "stripHtmlTags", "!=", "null", ")", "$", "feed", "->", "strip_htmltags", "(", "$", "this", "->", "stripHtmlTags", ")", ";", "@", "$", "feed", "->", "init", "(", ")", ";", "if", "(", "$", "err", "=", "$", "feed", "->", "error", "(", ")", ")", "throw", "new", "FeedParserException", "(", "$", "err", ")", ";", "return", "$", "feed", ";", "}" ]
Opens an RSS feed, parses and loads the contents. @param string $url The URL of the RSS feed @param bool $nativeOrder If true, disable order by date to preserve native ordering @param bool $force Force SimplePie to parse the feed despite errors @return object An object that encapsulates the feed contents and operations on those contents. @throws FeedParserException If opening or parsing feed fails
[ "Opens", "an", "RSS", "feed", "parses", "and", "loads", "the", "contents", "." ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/feedparser/FeedParser.php#L61-L86
train
Linkvalue-Interne/MajoraGeneratorBundle
src/Majora/Bundle/GeneratorBundle/Generator/ContentModifier/AbstractContentModifier.php
AbstractContentModifier.setUp
public function setUp( $kernelDir, FileLocatorInterface $fileLocator ) { $this->kernelDir = realpath($kernelDir); $this->fileLocator = $fileLocator; }
php
public function setUp( $kernelDir, FileLocatorInterface $fileLocator ) { $this->kernelDir = realpath($kernelDir); $this->fileLocator = $fileLocator; }
[ "public", "function", "setUp", "(", "$", "kernelDir", ",", "FileLocatorInterface", "$", "fileLocator", ")", "{", "$", "this", "->", "kernelDir", "=", "realpath", "(", "$", "kernelDir", ")", ";", "$", "this", "->", "fileLocator", "=", "$", "fileLocator", ";", "}" ]
abstract class setting up method @param string $kernelDir @param FileLocatorInterface $fileLocator
[ "abstract", "class", "setting", "up", "method" ]
9f745c1f64e913df90d86b4fd0770121c563552d
https://github.com/Linkvalue-Interne/MajoraGeneratorBundle/blob/9f745c1f64e913df90d86b4fd0770121c563552d/src/Majora/Bundle/GeneratorBundle/Generator/ContentModifier/AbstractContentModifier.php#L22-L29
train
Linkvalue-Interne/MajoraGeneratorBundle
src/Majora/Bundle/GeneratorBundle/Generator/ContentModifier/AbstractContentModifier.php
AbstractContentModifier.resolveTargetFilePath
protected function resolveTargetFilePath($target, $basePath) { switch (true) { // resource case strpos($target, '@') === 0: $targetPath = $this->fileLocator->locate($target); break; // kernel related case strpos($target, '/') === 0: $targetPath = sprintf('%s%s', $this->kernelDir, $target ); break; // related file default: $targetPath = sprintf('%s/%s', $basePath, $target); break; } if (!is_writable($targetPath)) { throw new \InvalidArgumentException(sprintf( 'Unable to resolve "%s" target, resolved into "%s" file path which is not writable.', $target, $targetPath )); } return $targetPath; }
php
protected function resolveTargetFilePath($target, $basePath) { switch (true) { // resource case strpos($target, '@') === 0: $targetPath = $this->fileLocator->locate($target); break; // kernel related case strpos($target, '/') === 0: $targetPath = sprintf('%s%s', $this->kernelDir, $target ); break; // related file default: $targetPath = sprintf('%s/%s', $basePath, $target); break; } if (!is_writable($targetPath)) { throw new \InvalidArgumentException(sprintf( 'Unable to resolve "%s" target, resolved into "%s" file path which is not writable.', $target, $targetPath )); } return $targetPath; }
[ "protected", "function", "resolveTargetFilePath", "(", "$", "target", ",", "$", "basePath", ")", "{", "switch", "(", "true", ")", "{", "// resource", "case", "strpos", "(", "$", "target", ",", "'@'", ")", "===", "0", ":", "$", "targetPath", "=", "$", "this", "->", "fileLocator", "->", "locate", "(", "$", "target", ")", ";", "break", ";", "// kernel related", "case", "strpos", "(", "$", "target", ",", "'/'", ")", "===", "0", ":", "$", "targetPath", "=", "sprintf", "(", "'%s%s'", ",", "$", "this", "->", "kernelDir", ",", "$", "target", ")", ";", "break", ";", "// related file", "default", ":", "$", "targetPath", "=", "sprintf", "(", "'%s/%s'", ",", "$", "basePath", ",", "$", "target", ")", ";", "break", ";", "}", "if", "(", "!", "is_writable", "(", "$", "targetPath", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Unable to resolve \"%s\" target, resolved into \"%s\" file path which is not writable.'", ",", "$", "target", ",", "$", "targetPath", ")", ")", ";", "}", "return", "$", "targetPath", ";", "}" ]
resolve given target file path @param string $target @param string $basePath @return string @throws \InvalidArgumentException if path cannot be resolved
[ "resolve", "given", "target", "file", "path" ]
9f745c1f64e913df90d86b4fd0770121c563552d
https://github.com/Linkvalue-Interne/MajoraGeneratorBundle/blob/9f745c1f64e913df90d86b4fd0770121c563552d/src/Majora/Bundle/GeneratorBundle/Generator/ContentModifier/AbstractContentModifier.php#L41-L73
train
makinacorpus/drupal-apubsub
src/Backend/TypeRegistry.php
TypeRegistry.getTypeId
public function getTypeId($type, $createIfMissing = true) { if (null === $this->types) { $this->loadCache(); } if (false === ($key = array_search($type, $this->types, true))) { if (!$createIfMissing) { return null; } try { $this ->backend ->getConnection() ->insert('apb_msg_type') ->fields(array('type' => $type)) ->execute() ; } catch (\PDOException $e) { // Another thread went doing this at the same time and created // the same type, ignore error and continue } $this->loadCache(); return array_search($type, $this->types, true); } else { return $key; } }
php
public function getTypeId($type, $createIfMissing = true) { if (null === $this->types) { $this->loadCache(); } if (false === ($key = array_search($type, $this->types, true))) { if (!$createIfMissing) { return null; } try { $this ->backend ->getConnection() ->insert('apb_msg_type') ->fields(array('type' => $type)) ->execute() ; } catch (\PDOException $e) { // Another thread went doing this at the same time and created // the same type, ignore error and continue } $this->loadCache(); return array_search($type, $this->types, true); } else { return $key; } }
[ "public", "function", "getTypeId", "(", "$", "type", ",", "$", "createIfMissing", "=", "true", ")", "{", "if", "(", "null", "===", "$", "this", "->", "types", ")", "{", "$", "this", "->", "loadCache", "(", ")", ";", "}", "if", "(", "false", "===", "(", "$", "key", "=", "array_search", "(", "$", "type", ",", "$", "this", "->", "types", ",", "true", ")", ")", ")", "{", "if", "(", "!", "$", "createIfMissing", ")", "{", "return", "null", ";", "}", "try", "{", "$", "this", "->", "backend", "->", "getConnection", "(", ")", "->", "insert", "(", "'apb_msg_type'", ")", "->", "fields", "(", "array", "(", "'type'", "=>", "$", "type", ")", ")", "->", "execute", "(", ")", ";", "}", "catch", "(", "\\", "PDOException", "$", "e", ")", "{", "// Another thread went doing this at the same time and created", "// the same type, ignore error and continue", "}", "$", "this", "->", "loadCache", "(", ")", ";", "return", "array_search", "(", "$", "type", ",", "$", "this", "->", "types", ",", "true", ")", ";", "}", "else", "{", "return", "$", "key", ";", "}", "}" ]
Get type identifier @param string $type Message type @param boolean $createIfMissing Create it if missing @return int Message type id
[ "Get", "type", "identifier" ]
534fbecf67c880996ae02210c0bfdb3e0d3699b6
https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/TypeRegistry.php#L53-L86
train
makinacorpus/drupal-apubsub
src/Backend/TypeRegistry.php
TypeRegistry.getType
public function getType($id) { if (null === $id) { // The caller might call us using a row from database that contains // a strict null, it is useless for us to do any query since null // typed messages are valid by the MessageInterface signature return null; } if (null === $this->types) { $this->loadCache(); } if (!isset($this->types[$id])) { // Someone may have created it before we loaded the cache $this->loadCache(); if (!isset($this->types[$id])) { // It seems that the type really does not exists, mark it as // being wrong in order to avoid to refresh the cache too often // and return a null type $this->types[$id] = false; } } if (false === $this->types[$id]) { return null; } else { return $this->types[$id]; } }
php
public function getType($id) { if (null === $id) { // The caller might call us using a row from database that contains // a strict null, it is useless for us to do any query since null // typed messages are valid by the MessageInterface signature return null; } if (null === $this->types) { $this->loadCache(); } if (!isset($this->types[$id])) { // Someone may have created it before we loaded the cache $this->loadCache(); if (!isset($this->types[$id])) { // It seems that the type really does not exists, mark it as // being wrong in order to avoid to refresh the cache too often // and return a null type $this->types[$id] = false; } } if (false === $this->types[$id]) { return null; } else { return $this->types[$id]; } }
[ "public", "function", "getType", "(", "$", "id", ")", "{", "if", "(", "null", "===", "$", "id", ")", "{", "// The caller might call us using a row from database that contains", "// a strict null, it is useless for us to do any query since null", "// typed messages are valid by the MessageInterface signature", "return", "null", ";", "}", "if", "(", "null", "===", "$", "this", "->", "types", ")", "{", "$", "this", "->", "loadCache", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "types", "[", "$", "id", "]", ")", ")", "{", "// Someone may have created it before we loaded the cache", "$", "this", "->", "loadCache", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "types", "[", "$", "id", "]", ")", ")", "{", "// It seems that the type really does not exists, mark it as", "// being wrong in order to avoid to refresh the cache too often", "// and return a null type", "$", "this", "->", "types", "[", "$", "id", "]", "=", "false", ";", "}", "}", "if", "(", "false", "===", "$", "this", "->", "types", "[", "$", "id", "]", ")", "{", "return", "null", ";", "}", "else", "{", "return", "$", "this", "->", "types", "[", "$", "id", "]", ";", "}", "}" ]
Get type from identifier @param int $id Message type id @return string Message type
[ "Get", "type", "from", "identifier" ]
534fbecf67c880996ae02210c0bfdb3e0d3699b6
https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/TypeRegistry.php#L95-L125
train
makinacorpus/drupal-apubsub
src/Backend/TypeRegistry.php
TypeRegistry.convertQueryCondition
public function convertQueryCondition($value) { // First fetch the type if (null === $value) { return 0; } if (!is_array($value)) { $value = [$value]; } $hasOperator = false; // FIXME Sorry for this if (!Misc::isIndexed($value)) { // We have an operator. $operator = array_keys($value)[0]; $values = $value[$operator][0]; $hasOperator = true; } else { $values = $value; } foreach ($values as $key => $type) { if (null === $type) { $values[$key] = 0; } else if ($typeId = $this->getTypeId($type, false)) { $values[$key] = $typeId; } else { unset($values[$key]); } } if (empty($values)) { // It should not have been empty, this is an impossible // condition $values = [-1]; } if ($hasOperator) { return [$operator => $values]; } else { return $values; } }
php
public function convertQueryCondition($value) { // First fetch the type if (null === $value) { return 0; } if (!is_array($value)) { $value = [$value]; } $hasOperator = false; // FIXME Sorry for this if (!Misc::isIndexed($value)) { // We have an operator. $operator = array_keys($value)[0]; $values = $value[$operator][0]; $hasOperator = true; } else { $values = $value; } foreach ($values as $key => $type) { if (null === $type) { $values[$key] = 0; } else if ($typeId = $this->getTypeId($type, false)) { $values[$key] = $typeId; } else { unset($values[$key]); } } if (empty($values)) { // It should not have been empty, this is an impossible // condition $values = [-1]; } if ($hasOperator) { return [$operator => $values]; } else { return $values; } }
[ "public", "function", "convertQueryCondition", "(", "$", "value", ")", "{", "// First fetch the type", "if", "(", "null", "===", "$", "value", ")", "{", "return", "0", ";", "}", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "[", "$", "value", "]", ";", "}", "$", "hasOperator", "=", "false", ";", "// FIXME Sorry for this", "if", "(", "!", "Misc", "::", "isIndexed", "(", "$", "value", ")", ")", "{", "// We have an operator.", "$", "operator", "=", "array_keys", "(", "$", "value", ")", "[", "0", "]", ";", "$", "values", "=", "$", "value", "[", "$", "operator", "]", "[", "0", "]", ";", "$", "hasOperator", "=", "true", ";", "}", "else", "{", "$", "values", "=", "$", "value", ";", "}", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "type", ")", "{", "if", "(", "null", "===", "$", "type", ")", "{", "$", "values", "[", "$", "key", "]", "=", "0", ";", "}", "else", "if", "(", "$", "typeId", "=", "$", "this", "->", "getTypeId", "(", "$", "type", ",", "false", ")", ")", "{", "$", "values", "[", "$", "key", "]", "=", "$", "typeId", ";", "}", "else", "{", "unset", "(", "$", "values", "[", "$", "key", "]", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "values", ")", ")", "{", "// It should not have been empty, this is an impossible", "// condition", "$", "values", "=", "[", "-", "1", "]", ";", "}", "if", "(", "$", "hasOperator", ")", "{", "return", "[", "$", "operator", "=>", "$", "values", "]", ";", "}", "else", "{", "return", "$", "values", ";", "}", "}" ]
Convert given query condition value which is supposed to contain types identifiers to integer identifiers This function will take care of awaited query format
[ "Convert", "given", "query", "condition", "value", "which", "is", "supposed", "to", "contain", "types", "identifiers", "to", "integer", "identifiers" ]
534fbecf67c880996ae02210c0bfdb3e0d3699b6
https://github.com/makinacorpus/drupal-apubsub/blob/534fbecf67c880996ae02210c0bfdb3e0d3699b6/src/Backend/TypeRegistry.php#L133-L177
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/interfaces/FileCache.php
FileCache.getUsingFileTimestamps
public function getUsingFileTimestamps($key) { $value = $this->get($this->cacheKey($key)); $timestamps = $this->get($this->cachetskey($key)); if ($value !== false && $timestamps !== false) { foreach ($timestamps as $file => $timestamp) { if (filemtime($file) !== $timestamp) return false; } return $value; } return false; }
php
public function getUsingFileTimestamps($key) { $value = $this->get($this->cacheKey($key)); $timestamps = $this->get($this->cachetskey($key)); if ($value !== false && $timestamps !== false) { foreach ($timestamps as $file => $timestamp) { if (filemtime($file) !== $timestamp) return false; } return $value; } return false; }
[ "public", "function", "getUsingFileTimestamps", "(", "$", "key", ")", "{", "$", "value", "=", "$", "this", "->", "get", "(", "$", "this", "->", "cacheKey", "(", "$", "key", ")", ")", ";", "$", "timestamps", "=", "$", "this", "->", "get", "(", "$", "this", "->", "cachetskey", "(", "$", "key", ")", ")", ";", "if", "(", "$", "value", "!==", "false", "&&", "$", "timestamps", "!==", "false", ")", "{", "foreach", "(", "$", "timestamps", "as", "$", "file", "=>", "$", "timestamp", ")", "{", "if", "(", "filemtime", "(", "$", "file", ")", "!==", "$", "timestamp", ")", "return", "false", ";", "}", "return", "$", "value", ";", "}", "return", "false", ";", "}" ]
get cache using key, but check associated timestamps on cached file array @param string $key The key of the cache item to retrieve @return mixed the value of the stored cache item
[ "get", "cache", "using", "key", "but", "check", "associated", "timestamps", "on", "cached", "file", "array" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/interfaces/FileCache.php#L46-L63
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/interfaces/FileCache.php
FileCache.putUsingFileTimestamps
public function putUsingFileTimestamps($key, $value, array $filenames, $duration = null) { if (empty($duration)) $duration = 0; $files = array(); foreach ($filenames as $file) { $files[$file] = filemtime($file); } $timestamps = md5($files); // Populate all caches. $this->put($this->cacheKey($key), array('v' => $value, 't' => $timestamps), $duration); // $this->put($this->cachetskey($key), $timestamps, $duration); return true; }
php
public function putUsingFileTimestamps($key, $value, array $filenames, $duration = null) { if (empty($duration)) $duration = 0; $files = array(); foreach ($filenames as $file) { $files[$file] = filemtime($file); } $timestamps = md5($files); // Populate all caches. $this->put($this->cacheKey($key), array('v' => $value, 't' => $timestamps), $duration); // $this->put($this->cachetskey($key), $timestamps, $duration); return true; }
[ "public", "function", "putUsingFileTimestamps", "(", "$", "key", ",", "$", "value", ",", "array", "$", "filenames", ",", "$", "duration", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "duration", ")", ")", "$", "duration", "=", "0", ";", "$", "files", "=", "array", "(", ")", ";", "foreach", "(", "$", "filenames", "as", "$", "file", ")", "{", "$", "files", "[", "$", "file", "]", "=", "filemtime", "(", "$", "file", ")", ";", "}", "$", "timestamps", "=", "md5", "(", "$", "files", ")", ";", "// Populate all caches.", "$", "this", "->", "put", "(", "$", "this", "->", "cacheKey", "(", "$", "key", ")", ",", "array", "(", "'v'", "=>", "$", "value", ",", "'t'", "=>", "$", "timestamps", ")", ",", "$", "duration", ")", ";", "// $this->put($this->cachetskey($key), $timestamps, $duration);", "return", "true", ";", "}" ]
put cache value into cache store using timestamps of supplied files as a tie on the validity of the cache @param string $key The key for the cache @param string $value The Value to store @param array $filenames An array of filenames to update @param string $duration The time-to-live for the cache data @return boolean TRUE if successful @throws CacheException on error
[ "put", "cache", "value", "into", "cache", "store", "using", "timestamps", "of", "supplied", "files", "as", "a", "tie", "on", "the", "validity", "of", "the", "cache" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/interfaces/FileCache.php#L77-L94
train
wb-crowdfusion/crowdfusion
system/core/classes/libraries/caching/interfaces/FileCache.php
FileCache.getFileContents
public function getFileContents($filename) { $cachecontents = $this->get($this->cachefilekey($filename)); // $timestamp = $this->get($this->cachefiletskey($filename)); if ($cachecontents !== false && is_array($cachecontents)) { $contents = array_key_exists('v', $cachecontents)?$cachecontents['v']:false; $timestamp = array_key_exists('t', $cachecontents)?$cachecontents['t']:false; if (filemtime($filename) === (int)$timestamp) return $contents; } $contents = file_get_contents($filename); $ts = filemtime($filename); // Populate all caches. $this->put($this->cachefilekey($filename), array('v' => $contents, 't'=> $ts), 0); // $this->put($this->cachefiletskey($filename), "{$filename};{$ts}", 0); return $contents; }
php
public function getFileContents($filename) { $cachecontents = $this->get($this->cachefilekey($filename)); // $timestamp = $this->get($this->cachefiletskey($filename)); if ($cachecontents !== false && is_array($cachecontents)) { $contents = array_key_exists('v', $cachecontents)?$cachecontents['v']:false; $timestamp = array_key_exists('t', $cachecontents)?$cachecontents['t']:false; if (filemtime($filename) === (int)$timestamp) return $contents; } $contents = file_get_contents($filename); $ts = filemtime($filename); // Populate all caches. $this->put($this->cachefilekey($filename), array('v' => $contents, 't'=> $ts), 0); // $this->put($this->cachefiletskey($filename), "{$filename};{$ts}", 0); return $contents; }
[ "public", "function", "getFileContents", "(", "$", "filename", ")", "{", "$", "cachecontents", "=", "$", "this", "->", "get", "(", "$", "this", "->", "cachefilekey", "(", "$", "filename", ")", ")", ";", "// $timestamp = $this->get($this->cachefiletskey($filename));", "if", "(", "$", "cachecontents", "!==", "false", "&&", "is_array", "(", "$", "cachecontents", ")", ")", "{", "$", "contents", "=", "array_key_exists", "(", "'v'", ",", "$", "cachecontents", ")", "?", "$", "cachecontents", "[", "'v'", "]", ":", "false", ";", "$", "timestamp", "=", "array_key_exists", "(", "'t'", ",", "$", "cachecontents", ")", "?", "$", "cachecontents", "[", "'t'", "]", ":", "false", ";", "if", "(", "filemtime", "(", "$", "filename", ")", "===", "(", "int", ")", "$", "timestamp", ")", "return", "$", "contents", ";", "}", "$", "contents", "=", "file_get_contents", "(", "$", "filename", ")", ";", "$", "ts", "=", "filemtime", "(", "$", "filename", ")", ";", "// Populate all caches.", "$", "this", "->", "put", "(", "$", "this", "->", "cachefilekey", "(", "$", "filename", ")", ",", "array", "(", "'v'", "=>", "$", "contents", ",", "'t'", "=>", "$", "ts", ")", ",", "0", ")", ";", "// $this->put($this->cachefiletskey($filename), \"{$filename};{$ts}\", 0);", "return", "$", "contents", ";", "}" ]
return the file contents, but cache the results indefinitely, break cache if timestamp changes @param string $filename The filename to load @return string the contents of the file specified.
[ "return", "the", "file", "contents", "but", "cache", "the", "results", "indefinitely", "break", "cache", "if", "timestamp", "changes" ]
8cad7988f046a6fefbed07d026cb4ae6706c1217
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/caching/interfaces/FileCache.php#L104-L127
train
Montage-Inc/php-montage
src/Montage.php
Montage.request
public function request($type, $url, $args = []) { $response = $this->getHTTPClient() ->$type($url, $args) ->getBody() ->getContents(); return json_decode($response); }
php
public function request($type, $url, $args = []) { $response = $this->getHTTPClient() ->$type($url, $args) ->getBody() ->getContents(); return json_decode($response); }
[ "public", "function", "request", "(", "$", "type", ",", "$", "url", ",", "$", "args", "=", "[", "]", ")", "{", "$", "response", "=", "$", "this", "->", "getHTTPClient", "(", ")", "->", "$", "type", "(", "$", "url", ",", "$", "args", ")", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ";", "return", "json_decode", "(", "$", "response", ")", ";", "}" ]
Our main request method to Montage. Uses Guzzle under the hood to make the request, and will return the json_decoded response from Montage. @param $type @param $url @param array $args @return mixed
[ "Our", "main", "request", "method", "to", "Montage", ".", "Uses", "Guzzle", "under", "the", "hood", "to", "make", "the", "request", "and", "will", "return", "the", "json_decoded", "response", "from", "Montage", "." ]
bcd526985447a31c7e5b74555058e167242b23ed
https://github.com/Montage-Inc/php-montage/blob/bcd526985447a31c7e5b74555058e167242b23ed/src/Montage.php#L76-L84
train
Montage-Inc/php-montage
src/Montage.php
Montage.auth
public function auth($user = null, $password = null) { if ($this->token) return $this; if (is_null($user) || is_null($password)) { throw new MontageAuthException('Must provide a username and password.'); } try { $response = $this->request('post', $this->url('auth'), [ 'form_params' => [ 'username' => $user, 'password' => $password ] ]); $this->token = $response->data->token; return $this; } catch (ClientException $e) { throw new MontageAuthException('Could not authenticate with Montage.'); } }
php
public function auth($user = null, $password = null) { if ($this->token) return $this; if (is_null($user) || is_null($password)) { throw new MontageAuthException('Must provide a username and password.'); } try { $response = $this->request('post', $this->url('auth'), [ 'form_params' => [ 'username' => $user, 'password' => $password ] ]); $this->token = $response->data->token; return $this; } catch (ClientException $e) { throw new MontageAuthException('Could not authenticate with Montage.'); } }
[ "public", "function", "auth", "(", "$", "user", "=", "null", ",", "$", "password", "=", "null", ")", "{", "if", "(", "$", "this", "->", "token", ")", "return", "$", "this", ";", "if", "(", "is_null", "(", "$", "user", ")", "||", "is_null", "(", "$", "password", ")", ")", "{", "throw", "new", "MontageAuthException", "(", "'Must provide a username and password.'", ")", ";", "}", "try", "{", "$", "response", "=", "$", "this", "->", "request", "(", "'post'", ",", "$", "this", "->", "url", "(", "'auth'", ")", ",", "[", "'form_params'", "=>", "[", "'username'", "=>", "$", "user", ",", "'password'", "=>", "$", "password", "]", "]", ")", ";", "$", "this", "->", "token", "=", "$", "response", "->", "data", "->", "token", ";", "return", "$", "this", ";", "}", "catch", "(", "ClientException", "$", "e", ")", "{", "throw", "new", "MontageAuthException", "(", "'Could not authenticate with Montage.'", ")", ";", "}", "}" ]
Authenticate with Montage and set the local token. @param null $user @param null $password @return $this @throws MontageAuthException
[ "Authenticate", "with", "Montage", "and", "set", "the", "local", "token", "." ]
bcd526985447a31c7e5b74555058e167242b23ed
https://github.com/Montage-Inc/php-montage/blob/bcd526985447a31c7e5b74555058e167242b23ed/src/Montage.php#L94-L117
train
Montage-Inc/php-montage
src/Montage.php
Montage.url
public function url($endpoint, $schema = null, $doc_id = null, $file_id = null) { return sprintf('api/v%d/%s', $this->version, $this->endpoint( $endpoint, $schema, $doc_id, $file_id )); }
php
public function url($endpoint, $schema = null, $doc_id = null, $file_id = null) { return sprintf('api/v%d/%s', $this->version, $this->endpoint( $endpoint, $schema, $doc_id, $file_id )); }
[ "public", "function", "url", "(", "$", "endpoint", ",", "$", "schema", "=", "null", ",", "$", "doc_id", "=", "null", ",", "$", "file_id", "=", "null", ")", "{", "return", "sprintf", "(", "'api/v%d/%s'", ",", "$", "this", "->", "version", ",", "$", "this", "->", "endpoint", "(", "$", "endpoint", ",", "$", "schema", ",", "$", "doc_id", ",", "$", "file_id", ")", ")", ";", "}" ]
Gets a formatted Montage endpoint, prefixed with api version. @param $endpoint @param null $schema @param null $doc_id @param null $file_id @return string @throws MontageUnknownEndpointException
[ "Gets", "a", "formatted", "Montage", "endpoint", "prefixed", "with", "api", "version", "." ]
bcd526985447a31c7e5b74555058e167242b23ed
https://github.com/Montage-Inc/php-montage/blob/bcd526985447a31c7e5b74555058e167242b23ed/src/Montage.php#L159-L167
train
Montage-Inc/php-montage
src/Montage.php
Montage.getHTTPClient
private function getHTTPClient() { $config = [ 'base_uri' => sprintf( 'http://%s.%s/', $this->subdomain, $this->domain ), 'headers' => [ 'Accept' => 'application/json', 'User-Agent' => sprintf('Montage PHP v%d', $this->version), 'X-Requested-With' => 'XMLHttpRequest' ] ]; //Set the token if it exists if ($this->token) { $config['headers']['Authorization'] = sprintf('Token %s', $this->token); } if ($this->debug) { $config['debug'] = true; } return new Client($config); }
php
private function getHTTPClient() { $config = [ 'base_uri' => sprintf( 'http://%s.%s/', $this->subdomain, $this->domain ), 'headers' => [ 'Accept' => 'application/json', 'User-Agent' => sprintf('Montage PHP v%d', $this->version), 'X-Requested-With' => 'XMLHttpRequest' ] ]; //Set the token if it exists if ($this->token) { $config['headers']['Authorization'] = sprintf('Token %s', $this->token); } if ($this->debug) { $config['debug'] = true; } return new Client($config); }
[ "private", "function", "getHTTPClient", "(", ")", "{", "$", "config", "=", "[", "'base_uri'", "=>", "sprintf", "(", "'http://%s.%s/'", ",", "$", "this", "->", "subdomain", ",", "$", "this", "->", "domain", ")", ",", "'headers'", "=>", "[", "'Accept'", "=>", "'application/json'", ",", "'User-Agent'", "=>", "sprintf", "(", "'Montage PHP v%d'", ",", "$", "this", "->", "version", ")", ",", "'X-Requested-With'", "=>", "'XMLHttpRequest'", "]", "]", ";", "//Set the token if it exists", "if", "(", "$", "this", "->", "token", ")", "{", "$", "config", "[", "'headers'", "]", "[", "'Authorization'", "]", "=", "sprintf", "(", "'Token %s'", ",", "$", "this", "->", "token", ")", ";", "}", "if", "(", "$", "this", "->", "debug", ")", "{", "$", "config", "[", "'debug'", "]", "=", "true", ";", "}", "return", "new", "Client", "(", "$", "config", ")", ";", "}" ]
Does what it says. Gets a guzzle client, with an Authorization header set in case of an existing token. @return Client
[ "Does", "what", "it", "says", ".", "Gets", "a", "guzzle", "client", "with", "an", "Authorization", "header", "set", "in", "case", "of", "an", "existing", "token", "." ]
bcd526985447a31c7e5b74555058e167242b23ed
https://github.com/Montage-Inc/php-montage/blob/bcd526985447a31c7e5b74555058e167242b23ed/src/Montage.php#L175-L202
train
Montage-Inc/php-montage
src/Montage.php
Montage.endpoint
private function endpoint($endpoint, $schema = null, $doc_id = null, $file_id = null) { $endpoints = [ 'auth' => 'auth/', 'user' => 'auth/user/', 'schema-list' => 'schemas/', 'schema-detail' => 'schemas/%s/', 'document-query' => 'schemas/%s/query/', 'document-save' => 'schemas/%s/save/', 'document-detail' => 'schemas/%s/%s/', 'file-list' => 'files/', 'file-detail' => 'files/%s/', ]; if (!array_key_exists($endpoint, $endpoints)) { throw new MontageUnknownEndpointException( sprintf('Unknown endpoint "%s" requested.', $endpoint) ); } //do the endpoint formatting if (!is_null($file_id)) { return sprintf($endpoints[$endpoint], $file_id); } else if (!is_null($schema) && !is_null($doc_id)) { return sprintf($endpoints[$endpoint], $schema, $doc_id); } else if (!is_null($schema)) { return sprintf($endpoints[$endpoint], $schema); } return $endpoints[$endpoint]; }
php
private function endpoint($endpoint, $schema = null, $doc_id = null, $file_id = null) { $endpoints = [ 'auth' => 'auth/', 'user' => 'auth/user/', 'schema-list' => 'schemas/', 'schema-detail' => 'schemas/%s/', 'document-query' => 'schemas/%s/query/', 'document-save' => 'schemas/%s/save/', 'document-detail' => 'schemas/%s/%s/', 'file-list' => 'files/', 'file-detail' => 'files/%s/', ]; if (!array_key_exists($endpoint, $endpoints)) { throw new MontageUnknownEndpointException( sprintf('Unknown endpoint "%s" requested.', $endpoint) ); } //do the endpoint formatting if (!is_null($file_id)) { return sprintf($endpoints[$endpoint], $file_id); } else if (!is_null($schema) && !is_null($doc_id)) { return sprintf($endpoints[$endpoint], $schema, $doc_id); } else if (!is_null($schema)) { return sprintf($endpoints[$endpoint], $schema); } return $endpoints[$endpoint]; }
[ "private", "function", "endpoint", "(", "$", "endpoint", ",", "$", "schema", "=", "null", ",", "$", "doc_id", "=", "null", ",", "$", "file_id", "=", "null", ")", "{", "$", "endpoints", "=", "[", "'auth'", "=>", "'auth/'", ",", "'user'", "=>", "'auth/user/'", ",", "'schema-list'", "=>", "'schemas/'", ",", "'schema-detail'", "=>", "'schemas/%s/'", ",", "'document-query'", "=>", "'schemas/%s/query/'", ",", "'document-save'", "=>", "'schemas/%s/save/'", ",", "'document-detail'", "=>", "'schemas/%s/%s/'", ",", "'file-list'", "=>", "'files/'", ",", "'file-detail'", "=>", "'files/%s/'", ",", "]", ";", "if", "(", "!", "array_key_exists", "(", "$", "endpoint", ",", "$", "endpoints", ")", ")", "{", "throw", "new", "MontageUnknownEndpointException", "(", "sprintf", "(", "'Unknown endpoint \"%s\" requested.'", ",", "$", "endpoint", ")", ")", ";", "}", "//do the endpoint formatting", "if", "(", "!", "is_null", "(", "$", "file_id", ")", ")", "{", "return", "sprintf", "(", "$", "endpoints", "[", "$", "endpoint", "]", ",", "$", "file_id", ")", ";", "}", "else", "if", "(", "!", "is_null", "(", "$", "schema", ")", "&&", "!", "is_null", "(", "$", "doc_id", ")", ")", "{", "return", "sprintf", "(", "$", "endpoints", "[", "$", "endpoint", "]", ",", "$", "schema", ",", "$", "doc_id", ")", ";", "}", "else", "if", "(", "!", "is_null", "(", "$", "schema", ")", ")", "{", "return", "sprintf", "(", "$", "endpoints", "[", "$", "endpoint", "]", ",", "$", "schema", ")", ";", "}", "return", "$", "endpoints", "[", "$", "endpoint", "]", ";", "}" ]
Creates a formatted Montage API endpoint string. @param $endpoint @param null $schema @param null $doc_id @param null $file_id @return string @throws MontageUnknownEndpointException
[ "Creates", "a", "formatted", "Montage", "API", "endpoint", "string", "." ]
bcd526985447a31c7e5b74555058e167242b23ed
https://github.com/Montage-Inc/php-montage/blob/bcd526985447a31c7e5b74555058e167242b23ed/src/Montage.php#L214-L245
train
Montage-Inc/php-montage
src/Montage.php
Montage.schemas
public function schemas($schemaName = null) { if (is_null($schemaName)) { $url = $this->url('schema-list'); return $this->request('get', $url); } return $this->schema($schemaName); }
php
public function schemas($schemaName = null) { if (is_null($schemaName)) { $url = $this->url('schema-list'); return $this->request('get', $url); } return $this->schema($schemaName); }
[ "public", "function", "schemas", "(", "$", "schemaName", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "schemaName", ")", ")", "{", "$", "url", "=", "$", "this", "->", "url", "(", "'schema-list'", ")", ";", "return", "$", "this", "->", "request", "(", "'get'", ",", "$", "url", ")", ";", "}", "return", "$", "this", "->", "schema", "(", "$", "schemaName", ")", ";", "}" ]
Get a list of all schemas for the given users token. @return mixed
[ "Get", "a", "list", "of", "all", "schemas", "for", "the", "given", "users", "token", "." ]
bcd526985447a31c7e5b74555058e167242b23ed
https://github.com/Montage-Inc/php-montage/blob/bcd526985447a31c7e5b74555058e167242b23ed/src/Montage.php#L252-L260
train
Innmind/Math
src/Geometry/Theorem/Pythagora.php
Pythagora.hypotenuse
public static function hypotenuse( Segment $a, Segment $b ): Segment { $hypotenuse = $a ->length() ->power(new Integer(2)) ->add($b->length()->power(new Integer(2))) ->squareRoot(); return new Segment($hypotenuse); }
php
public static function hypotenuse( Segment $a, Segment $b ): Segment { $hypotenuse = $a ->length() ->power(new Integer(2)) ->add($b->length()->power(new Integer(2))) ->squareRoot(); return new Segment($hypotenuse); }
[ "public", "static", "function", "hypotenuse", "(", "Segment", "$", "a", ",", "Segment", "$", "b", ")", ":", "Segment", "{", "$", "hypotenuse", "=", "$", "a", "->", "length", "(", ")", "->", "power", "(", "new", "Integer", "(", "2", ")", ")", "->", "add", "(", "$", "b", "->", "length", "(", ")", "->", "power", "(", "new", "Integer", "(", "2", ")", ")", ")", "->", "squareRoot", "(", ")", ";", "return", "new", "Segment", "(", "$", "hypotenuse", ")", ";", "}" ]
Compute the hypotenuse for adjacent sides A and B
[ "Compute", "the", "hypotenuse", "for", "adjacent", "sides", "A", "and", "B" ]
ac9ad4dd1852c145e90f5edc0f38a873b125a50b
https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Geometry/Theorem/Pythagora.php#L19-L30
train
Innmind/Math
src/Geometry/Theorem/Pythagora.php
Pythagora.adjacentSide
public static function adjacentSide( Segment $hypotenuse, Segment $adjacentSide ): Segment { $side = $hypotenuse ->length() ->power(new Integer(2)) ->subtract($adjacentSide->length()->power(new Integer(2))) ->squareRoot(); return new Segment($side); }
php
public static function adjacentSide( Segment $hypotenuse, Segment $adjacentSide ): Segment { $side = $hypotenuse ->length() ->power(new Integer(2)) ->subtract($adjacentSide->length()->power(new Integer(2))) ->squareRoot(); return new Segment($side); }
[ "public", "static", "function", "adjacentSide", "(", "Segment", "$", "hypotenuse", ",", "Segment", "$", "adjacentSide", ")", ":", "Segment", "{", "$", "side", "=", "$", "hypotenuse", "->", "length", "(", ")", "->", "power", "(", "new", "Integer", "(", "2", ")", ")", "->", "subtract", "(", "$", "adjacentSide", "->", "length", "(", ")", "->", "power", "(", "new", "Integer", "(", "2", ")", ")", ")", "->", "squareRoot", "(", ")", ";", "return", "new", "Segment", "(", "$", "side", ")", ";", "}" ]
Compute a side A or B from the hypotenuse and one side
[ "Compute", "a", "side", "A", "or", "B", "from", "the", "hypotenuse", "and", "one", "side" ]
ac9ad4dd1852c145e90f5edc0f38a873b125a50b
https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Geometry/Theorem/Pythagora.php#L35-L46
train
kambalabs/KmbDomain
src/KmbDomain/Service/RevisionFactory.php
RevisionFactory.createFromImportedData
public function createFromImportedData($data) { $revision = new Revision(); $revision->setReleasedAt(new \DateTime($data['released_at'])); $revision->setReleasedBy($data['released_by']); $revision->setComment($data['comment']); foreach ($data['groups'] as $groupData) { $revision->addGroup($this->getGroupFactory()->createFromImportedData($groupData)); } return $revision; }
php
public function createFromImportedData($data) { $revision = new Revision(); $revision->setReleasedAt(new \DateTime($data['released_at'])); $revision->setReleasedBy($data['released_by']); $revision->setComment($data['comment']); foreach ($data['groups'] as $groupData) { $revision->addGroup($this->getGroupFactory()->createFromImportedData($groupData)); } return $revision; }
[ "public", "function", "createFromImportedData", "(", "$", "data", ")", "{", "$", "revision", "=", "new", "Revision", "(", ")", ";", "$", "revision", "->", "setReleasedAt", "(", "new", "\\", "DateTime", "(", "$", "data", "[", "'released_at'", "]", ")", ")", ";", "$", "revision", "->", "setReleasedBy", "(", "$", "data", "[", "'released_by'", "]", ")", ";", "$", "revision", "->", "setComment", "(", "$", "data", "[", "'comment'", "]", ")", ";", "foreach", "(", "$", "data", "[", "'groups'", "]", "as", "$", "groupData", ")", "{", "$", "revision", "->", "addGroup", "(", "$", "this", "->", "getGroupFactory", "(", ")", "->", "createFromImportedData", "(", "$", "groupData", ")", ")", ";", "}", "return", "$", "revision", ";", "}" ]
Create Revision instance from imported data. @param array $data @return Revision
[ "Create", "Revision", "instance", "from", "imported", "data", "." ]
b1631bd936c6c6798076b51dfaebd706e1bdc8c2
https://github.com/kambalabs/KmbDomain/blob/b1631bd936c6c6798076b51dfaebd706e1bdc8c2/src/KmbDomain/Service/RevisionFactory.php#L36-L46
train
Wedeto/DB
src/Driver/Driver.php
Driver.identQuote
public function identQuote(string $name) { return $this->iquotechar . str_replace($this->iquotechar, $this->iquotechar . $this->iquotechar, $name) . $this->iquotechar; }
php
public function identQuote(string $name) { return $this->iquotechar . str_replace($this->iquotechar, $this->iquotechar . $this->iquotechar, $name) . $this->iquotechar; }
[ "public", "function", "identQuote", "(", "string", "$", "name", ")", "{", "return", "$", "this", "->", "iquotechar", ".", "str_replace", "(", "$", "this", "->", "iquotechar", ",", "$", "this", "->", "iquotechar", ".", "$", "this", "->", "iquotechar", ",", "$", "name", ")", ".", "$", "this", "->", "iquotechar", ";", "}" ]
Quote the name of an identity @param $name string The name to quote @return string The quoted name
[ "Quote", "the", "name", "of", "an", "identity" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Driver/Driver.php#L89-L92
train
Wedeto/DB
src/Driver/Driver.php
Driver.getName
public function getName($entity, $quote = true) { if (is_object($entity)) $entity = $entity->getName(); if (!is_string($entity)) throw new InvalidTypeException("Provide a string or a object with a getName method"); $entity = $this->table_prefix . $entity; return $quote ? $this->identQuote($entity) : $entity; }
php
public function getName($entity, $quote = true) { if (is_object($entity)) $entity = $entity->getName(); if (!is_string($entity)) throw new InvalidTypeException("Provide a string or a object with a getName method"); $entity = $this->table_prefix . $entity; return $quote ? $this->identQuote($entity) : $entity; }
[ "public", "function", "getName", "(", "$", "entity", ",", "$", "quote", "=", "true", ")", "{", "if", "(", "is_object", "(", "$", "entity", ")", ")", "$", "entity", "=", "$", "entity", "->", "getName", "(", ")", ";", "if", "(", "!", "is_string", "(", "$", "entity", ")", ")", "throw", "new", "InvalidTypeException", "(", "\"Provide a string or a object with a getName method\"", ")", ";", "$", "entity", "=", "$", "this", "->", "table_prefix", ".", "$", "entity", ";", "return", "$", "quote", "?", "$", "this", "->", "identQuote", "(", "$", "entity", ")", ":", "$", "entity", ";", "}" ]
Return the identity name quoted and prefixed with the configured prefix. @param $entity mixed A string with the name or a Table, Index or ForeignKey object with a getName method. @return string The quoted, prefixed name
[ "Return", "the", "identity", "name", "quoted", "and", "prefixed", "with", "the", "configured", "prefix", "." ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Driver/Driver.php#L101-L109
train
Wedeto/DB
src/Driver/Driver.php
Driver.truncateTable
public function truncateTable($table) { $query = "TRUNCATE " . $this->getName($table->getName()); $this->db->exec($query); return $this; }
php
public function truncateTable($table) { $query = "TRUNCATE " . $this->getName($table->getName()); $this->db->exec($query); return $this; }
[ "public", "function", "truncateTable", "(", "$", "table", ")", "{", "$", "query", "=", "\"TRUNCATE \"", ".", "$", "this", "->", "getName", "(", "$", "table", "->", "getName", "(", ")", ")", ";", "$", "this", "->", "db", "->", "exec", "(", "$", "query", ")", ";", "return", "$", "this", ";", "}" ]
Remove all rows from the table @param $table mixed The table from which to remove @return Driver Provides fluent interface
[ "Remove", "all", "rows", "from", "the", "table" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Driver/Driver.php#L183-L188
train
Wedeto/DB
src/Driver/Driver.php
Driver.toSQL
public function toSQL(Parameters $params, Query\Clause $clause, bool $inner_clause = false) { $params->setDriver($this); return $clause->toSQL($params, $inner_clause); }
php
public function toSQL(Parameters $params, Query\Clause $clause, bool $inner_clause = false) { $params->setDriver($this); return $clause->toSQL($params, $inner_clause); }
[ "public", "function", "toSQL", "(", "Parameters", "$", "params", ",", "Query", "\\", "Clause", "$", "clause", ",", "bool", "$", "inner_clause", "=", "false", ")", "{", "$", "params", "->", "setDriver", "(", "$", "this", ")", ";", "return", "$", "clause", "->", "toSQL", "(", "$", "params", ",", "$", "inner_clause", ")", ";", "}" ]
Write an query clause as SQL query syntax @param Parameters $params The query parameters: tables and placeholder values @param Clause $clause The clause to write @param bool $inner_clause Whether this is a inner or outer clause. An inner clause will be wrapped in braces when it's a binary operator. @return string The generated SQL
[ "Write", "an", "query", "clause", "as", "SQL", "query", "syntax" ]
715f8f2e3ae6b53c511c40b620921cb9c87e6f62
https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Driver/Driver.php#L267-L271
train
cubicmushroom/valueobjects
src/DateTime/Time.php
Time.fromNative
public static function fromNative() { $args = func_get_args(); $hour = new Hour($args[0]); $minute = new Minute($args[1]); $second = new Second($args[2]); return new static($hour, $minute, $second); }
php
public static function fromNative() { $args = func_get_args(); $hour = new Hour($args[0]); $minute = new Minute($args[1]); $second = new Second($args[2]); return new static($hour, $minute, $second); }
[ "public", "static", "function", "fromNative", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "hour", "=", "new", "Hour", "(", "$", "args", "[", "0", "]", ")", ";", "$", "minute", "=", "new", "Minute", "(", "$", "args", "[", "1", "]", ")", ";", "$", "second", "=", "new", "Second", "(", "$", "args", "[", "2", "]", ")", ";", "return", "new", "static", "(", "$", "hour", ",", "$", "minute", ",", "$", "second", ")", ";", "}" ]
Returns a nee Time object from native int hour, minute and second @param int $hour @param int $minute @param int $second @return self
[ "Returns", "a", "nee", "Time", "object", "from", "native", "int", "hour", "minute", "and", "second" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/DateTime/Time.php#L27-L36
train
cubicmushroom/valueobjects
src/DateTime/Time.php
Time.fromNativeDateTime
public static function fromNativeDateTime(\DateTime $time) { $hour = \intval($time->format('G')); $minute = \intval($time->format('i')); $second = \intval($time->format('s')); return static::fromNative($hour, $minute, $second); }
php
public static function fromNativeDateTime(\DateTime $time) { $hour = \intval($time->format('G')); $minute = \intval($time->format('i')); $second = \intval($time->format('s')); return static::fromNative($hour, $minute, $second); }
[ "public", "static", "function", "fromNativeDateTime", "(", "\\", "DateTime", "$", "time", ")", "{", "$", "hour", "=", "\\", "intval", "(", "$", "time", "->", "format", "(", "'G'", ")", ")", ";", "$", "minute", "=", "\\", "intval", "(", "$", "time", "->", "format", "(", "'i'", ")", ")", ";", "$", "second", "=", "\\", "intval", "(", "$", "time", "->", "format", "(", "'s'", ")", ")", ";", "return", "static", "::", "fromNative", "(", "$", "hour", ",", "$", "minute", ",", "$", "second", ")", ";", "}" ]
Returns a new Time from a native PHP \DateTime @param \DateTime $time @return self
[ "Returns", "a", "new", "Time", "from", "a", "native", "PHP", "\\", "DateTime" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/DateTime/Time.php#L44-L51
train
cubicmushroom/valueobjects
src/DateTime/Time.php
Time.sameValueAs
public function sameValueAs(ValueObjectInterface $time) { if (false === Util::classEquals($this, $time)) { return false; } return $this->getHour()->sameValueAs($time->getHour()) && $this->getMinute()->sameValueAs($time->getMinute()) && $this->getSecond()->sameValueAs($time->getSecond()); }
php
public function sameValueAs(ValueObjectInterface $time) { if (false === Util::classEquals($this, $time)) { return false; } return $this->getHour()->sameValueAs($time->getHour()) && $this->getMinute()->sameValueAs($time->getMinute()) && $this->getSecond()->sameValueAs($time->getSecond()); }
[ "public", "function", "sameValueAs", "(", "ValueObjectInterface", "$", "time", ")", "{", "if", "(", "false", "===", "Util", "::", "classEquals", "(", "$", "this", ",", "$", "time", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "getHour", "(", ")", "->", "sameValueAs", "(", "$", "time", "->", "getHour", "(", ")", ")", "&&", "$", "this", "->", "getMinute", "(", ")", "->", "sameValueAs", "(", "$", "time", "->", "getMinute", "(", ")", ")", "&&", "$", "this", "->", "getSecond", "(", ")", "->", "sameValueAs", "(", "$", "time", "->", "getSecond", "(", ")", ")", ";", "}" ]
Tells whether two Time are equal by comparing their values @param ValueObjectInterface $time @return bool
[ "Tells", "whether", "two", "Time", "are", "equal", "by", "comparing", "their", "values" ]
4554239ab75d65eeb9773219aa5b07e9fbfabb92
https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/DateTime/Time.php#L97-L104
train
horntell/php-sdk
lib/guzzle/GuzzleHttp/Stream/Stream.php
Stream.factory
public static function factory($resource = '', $size = null) { $type = gettype($resource); if ($type == 'string') { $stream = fopen('php://temp', 'r+'); if ($resource !== '') { fwrite($stream, $resource); fseek($stream, 0); } return new self($stream); } if ($type == 'resource') { return new self($resource, $size); } if ($resource instanceof StreamInterface) { return $resource; } if ($type == 'object' && method_exists($resource, '__toString')) { return self::factory((string) $resource, $size); } throw new \InvalidArgumentException('Invalid resource type: ' . $type); }
php
public static function factory($resource = '', $size = null) { $type = gettype($resource); if ($type == 'string') { $stream = fopen('php://temp', 'r+'); if ($resource !== '') { fwrite($stream, $resource); fseek($stream, 0); } return new self($stream); } if ($type == 'resource') { return new self($resource, $size); } if ($resource instanceof StreamInterface) { return $resource; } if ($type == 'object' && method_exists($resource, '__toString')) { return self::factory((string) $resource, $size); } throw new \InvalidArgumentException('Invalid resource type: ' . $type); }
[ "public", "static", "function", "factory", "(", "$", "resource", "=", "''", ",", "$", "size", "=", "null", ")", "{", "$", "type", "=", "gettype", "(", "$", "resource", ")", ";", "if", "(", "$", "type", "==", "'string'", ")", "{", "$", "stream", "=", "fopen", "(", "'php://temp'", ",", "'r+'", ")", ";", "if", "(", "$", "resource", "!==", "''", ")", "{", "fwrite", "(", "$", "stream", ",", "$", "resource", ")", ";", "fseek", "(", "$", "stream", ",", "0", ")", ";", "}", "return", "new", "self", "(", "$", "stream", ")", ";", "}", "if", "(", "$", "type", "==", "'resource'", ")", "{", "return", "new", "self", "(", "$", "resource", ",", "$", "size", ")", ";", "}", "if", "(", "$", "resource", "instanceof", "StreamInterface", ")", "{", "return", "$", "resource", ";", "}", "if", "(", "$", "type", "==", "'object'", "&&", "method_exists", "(", "$", "resource", ",", "'__toString'", ")", ")", "{", "return", "self", "::", "factory", "(", "(", "string", ")", "$", "resource", ",", "$", "size", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid resource type: '", ".", "$", "type", ")", ";", "}" ]
Create a new stream based on the input type @param resource|string|StreamInterface $resource Entity body data @param int $size Size of the data contained in the resource @return Stream @throws \InvalidArgumentException if the $resource arg is not valid.
[ "Create", "a", "new", "stream", "based", "on", "the", "input", "type" ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Stream/Stream.php#L41-L67
train
opis-colibri/core
src/Module.php
Module.getModuleInfo
protected function getModuleInfo(): array { if ($this->moduleInfo === null) { $this->moduleInfo = $this->package()->getExtra()['module'] ?? []; } return $this->moduleInfo; }
php
protected function getModuleInfo(): array { if ($this->moduleInfo === null) { $this->moduleInfo = $this->package()->getExtra()['module'] ?? []; } return $this->moduleInfo; }
[ "protected", "function", "getModuleInfo", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "moduleInfo", "===", "null", ")", "{", "$", "this", "->", "moduleInfo", "=", "$", "this", "->", "package", "(", ")", "->", "getExtra", "(", ")", "[", "'module'", "]", "??", "[", "]", ";", "}", "return", "$", "this", "->", "moduleInfo", ";", "}" ]
Resolve module info @return array
[ "Resolve", "module", "info" ]
77efaf8e2034293588d3759e0b8711e96757d954
https://github.com/opis-colibri/core/blob/77efaf8e2034293588d3759e0b8711e96757d954/src/Module.php#L330-L337
train
opis-colibri/core
src/Module.php
Module.resolveTitle
protected function resolveTitle(): string { $title = trim($this->getModuleInfo()['title'] ?? ''); if (empty($title)) { $name = substr($this->name, strpos($this->name, '/') + 1); $name = array_map(function ($value) { return strtolower($value); }, explode('-', $name)); $title = ucfirst(implode(' ', $name)); } return $title; }
php
protected function resolveTitle(): string { $title = trim($this->getModuleInfo()['title'] ?? ''); if (empty($title)) { $name = substr($this->name, strpos($this->name, '/') + 1); $name = array_map(function ($value) { return strtolower($value); }, explode('-', $name)); $title = ucfirst(implode(' ', $name)); } return $title; }
[ "protected", "function", "resolveTitle", "(", ")", ":", "string", "{", "$", "title", "=", "trim", "(", "$", "this", "->", "getModuleInfo", "(", ")", "[", "'title'", "]", "??", "''", ")", ";", "if", "(", "empty", "(", "$", "title", ")", ")", "{", "$", "name", "=", "substr", "(", "$", "this", "->", "name", ",", "strpos", "(", "$", "this", "->", "name", ",", "'/'", ")", "+", "1", ")", ";", "$", "name", "=", "array_map", "(", "function", "(", "$", "value", ")", "{", "return", "strtolower", "(", "$", "value", ")", ";", "}", ",", "explode", "(", "'-'", ",", "$", "name", ")", ")", ";", "$", "title", "=", "ucfirst", "(", "implode", "(", "' '", ",", "$", "name", ")", ")", ";", "}", "return", "$", "title", ";", "}" ]
Resolve module's title @return string
[ "Resolve", "module", "s", "title" ]
77efaf8e2034293588d3759e0b8711e96757d954
https://github.com/opis-colibri/core/blob/77efaf8e2034293588d3759e0b8711e96757d954/src/Module.php#L344-L357
train
opis-colibri/core
src/Module.php
Module.resolveDirectory
protected function resolveDirectory(string $name): string { $dir = rtrim($this->manager->vendorDir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $dir .= rtrim(implode(DIRECTORY_SEPARATOR, explode('/', $name)), DIRECTORY_SEPARATOR); return $dir; }
php
protected function resolveDirectory(string $name): string { $dir = rtrim($this->manager->vendorDir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $dir .= rtrim(implode(DIRECTORY_SEPARATOR, explode('/', $name)), DIRECTORY_SEPARATOR); return $dir; }
[ "protected", "function", "resolveDirectory", "(", "string", "$", "name", ")", ":", "string", "{", "$", "dir", "=", "rtrim", "(", "$", "this", "->", "manager", "->", "vendorDir", "(", ")", ",", "DIRECTORY_SEPARATOR", ")", ".", "DIRECTORY_SEPARATOR", ";", "$", "dir", ".=", "rtrim", "(", "implode", "(", "DIRECTORY_SEPARATOR", ",", "explode", "(", "'/'", ",", "$", "name", ")", ")", ",", "DIRECTORY_SEPARATOR", ")", ";", "return", "$", "dir", ";", "}" ]
Resolve module's directory @param string $name @return string
[ "Resolve", "module", "s", "directory" ]
77efaf8e2034293588d3759e0b8711e96757d954
https://github.com/opis-colibri/core/blob/77efaf8e2034293588d3759e0b8711e96757d954/src/Module.php#L375-L380
train
opis-colibri/core
src/Module.php
Module.resolveCollector
protected function resolveCollector(): ?string { $value = $this->getModuleInfo()['collector'] ?? null; return is_string($value) ? $value : null; }
php
protected function resolveCollector(): ?string { $value = $this->getModuleInfo()['collector'] ?? null; return is_string($value) ? $value : null; }
[ "protected", "function", "resolveCollector", "(", ")", ":", "?", "string", "{", "$", "value", "=", "$", "this", "->", "getModuleInfo", "(", ")", "[", "'collector'", "]", "??", "null", ";", "return", "is_string", "(", "$", "value", ")", "?", "$", "value", ":", "null", ";", "}" ]
Resolve collector class @return string|null
[ "Resolve", "collector", "class" ]
77efaf8e2034293588d3759e0b8711e96757d954
https://github.com/opis-colibri/core/blob/77efaf8e2034293588d3759e0b8711e96757d954/src/Module.php#L387-L392
train