id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
228,800
contao-bootstrap/templates
src/EventListener/ThemeConfigurationListener.php
ThemeConfigurationListener.onBuildContextConfig
public function onBuildContextConfig(BuildContextConfig $command): void { $context = $command->getContext(); if (!$context instanceof ThemeContext) { return; } $theme = ThemeModel::findByPk($context->getThemeId()); if (!$theme) { return; } $templateConfig = []; $templateConfig = $this->buildGravatarConfig($theme, $templateConfig); $templateConfig = $this->buildTemplateMappingConfig($theme, $templateConfig); if (count($templateConfig) > 0) { $config = $command->getConfig()->merge( [ 'templates' => $templateConfig ] ); $command->setConfig($config); } }
php
public function onBuildContextConfig(BuildContextConfig $command): void { $context = $command->getContext(); if (!$context instanceof ThemeContext) { return; } $theme = ThemeModel::findByPk($context->getThemeId()); if (!$theme) { return; } $templateConfig = []; $templateConfig = $this->buildGravatarConfig($theme, $templateConfig); $templateConfig = $this->buildTemplateMappingConfig($theme, $templateConfig); if (count($templateConfig) > 0) { $config = $command->getConfig()->merge( [ 'templates' => $templateConfig ] ); $command->setConfig($config); } }
[ "public", "function", "onBuildContextConfig", "(", "BuildContextConfig", "$", "command", ")", ":", "void", "{", "$", "context", "=", "$", "command", "->", "getContext", "(", ")", ";", "if", "(", "!", "$", "context", "instanceof", "ThemeContext", ")", "{", "return", ";", "}", "$", "theme", "=", "ThemeModel", "::", "findByPk", "(", "$", "context", "->", "getThemeId", "(", ")", ")", ";", "if", "(", "!", "$", "theme", ")", "{", "return", ";", "}", "$", "templateConfig", "=", "[", "]", ";", "$", "templateConfig", "=", "$", "this", "->", "buildGravatarConfig", "(", "$", "theme", ",", "$", "templateConfig", ")", ";", "$", "templateConfig", "=", "$", "this", "->", "buildTemplateMappingConfig", "(", "$", "theme", ",", "$", "templateConfig", ")", ";", "if", "(", "count", "(", "$", "templateConfig", ")", ">", "0", ")", "{", "$", "config", "=", "$", "command", "->", "getConfig", "(", ")", "->", "merge", "(", "[", "'templates'", "=>", "$", "templateConfig", "]", ")", ";", "$", "command", "->", "setConfig", "(", "$", "config", ")", ";", "}", "}" ]
Build the context config. @param BuildContextConfig $command The command. @return void
[ "Build", "the", "context", "config", "." ]
cf507af3a194895923c6b84d97aa224e8b5b6d2f
https://github.com/contao-bootstrap/templates/blob/cf507af3a194895923c6b84d97aa224e8b5b6d2f/src/EventListener/ThemeConfigurationListener.php#L36-L62
228,801
contao-bootstrap/templates
src/EventListener/ThemeConfigurationListener.php
ThemeConfigurationListener.buildGravatarConfig
private function buildGravatarConfig(ThemeModel $theme, array $config): array { $file = FilesModel::findByPk($theme->bs_gravatar_default); if ($file) { $config['gravatar']['default'] = Environment::get('base') . $file->path; } if ($theme->bs_gravatar_size) { $config['gravatar']['size'] = (int) $theme->bs_gravatar_size; } return $config; }
php
private function buildGravatarConfig(ThemeModel $theme, array $config): array { $file = FilesModel::findByPk($theme->bs_gravatar_default); if ($file) { $config['gravatar']['default'] = Environment::get('base') . $file->path; } if ($theme->bs_gravatar_size) { $config['gravatar']['size'] = (int) $theme->bs_gravatar_size; } return $config; }
[ "private", "function", "buildGravatarConfig", "(", "ThemeModel", "$", "theme", ",", "array", "$", "config", ")", ":", "array", "{", "$", "file", "=", "FilesModel", "::", "findByPk", "(", "$", "theme", "->", "bs_gravatar_default", ")", ";", "if", "(", "$", "file", ")", "{", "$", "config", "[", "'gravatar'", "]", "[", "'default'", "]", "=", "Environment", "::", "get", "(", "'base'", ")", ".", "$", "file", "->", "path", ";", "}", "if", "(", "$", "theme", "->", "bs_gravatar_size", ")", "{", "$", "config", "[", "'gravatar'", "]", "[", "'size'", "]", "=", "(", "int", ")", "$", "theme", "->", "bs_gravatar_size", ";", "}", "return", "$", "config", ";", "}" ]
Build the gravatar config. @param ThemeModel $theme The theme model. @param array $config The theme config. @return array
[ "Build", "the", "gravatar", "config", "." ]
cf507af3a194895923c6b84d97aa224e8b5b6d2f
https://github.com/contao-bootstrap/templates/blob/cf507af3a194895923c6b84d97aa224e8b5b6d2f/src/EventListener/ThemeConfigurationListener.php#L72-L85
228,802
minmb/phpmailer
class.smtp.php
SMTP.Connected
public function Connected() { if(!empty($this->smtp_conn)) { $sock_status = socket_get_status($this->smtp_conn); if($sock_status["eof"]) { // the socket is valid but we are not connected if($this->do_debug >= 1) { $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"); } $this->Close(); return false; } return true; // everything looks good } return false; }
php
public function Connected() { if(!empty($this->smtp_conn)) { $sock_status = socket_get_status($this->smtp_conn); if($sock_status["eof"]) { // the socket is valid but we are not connected if($this->do_debug >= 1) { $this->edebug("SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected"); } $this->Close(); return false; } return true; // everything looks good } return false; }
[ "public", "function", "Connected", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "smtp_conn", ")", ")", "{", "$", "sock_status", "=", "socket_get_status", "(", "$", "this", "->", "smtp_conn", ")", ";", "if", "(", "$", "sock_status", "[", "\"eof\"", "]", ")", "{", "// the socket is valid but we are not connected", "if", "(", "$", "this", "->", "do_debug", ">=", "1", ")", "{", "$", "this", "->", "edebug", "(", "\"SMTP -> NOTICE:\"", ".", "$", "this", "->", "CRLF", ".", "\"EOF caught while checking if connected\"", ")", ";", "}", "$", "this", "->", "Close", "(", ")", ";", "return", "false", ";", "}", "return", "true", ";", "// everything looks good", "}", "return", "false", ";", "}" ]
Returns true if connected to a server otherwise false @access public @return bool
[ "Returns", "true", "if", "connected", "to", "a", "server", "otherwise", "false" ]
df443234ad0ca10cbf91a0c0a728b256afcab1d1
https://github.com/minmb/phpmailer/blob/df443234ad0ca10cbf91a0c0a728b256afcab1d1/class.smtp.php#L408-L422
228,803
czim/laravel-cms-upload-module
src/Repositories/FileRepository.php
FileRepository.create
public function create($path, array $data) { $data = array_merge($data, ['path' => $path]); return File::create($data); }
php
public function create($path, array $data) { $data = array_merge($data, ['path' => $path]); return File::create($data); }
[ "public", "function", "create", "(", "$", "path", ",", "array", "$", "data", ")", "{", "$", "data", "=", "array_merge", "(", "$", "data", ",", "[", "'path'", "=>", "$", "path", "]", ")", ";", "return", "File", "::", "create", "(", "$", "data", ")", ";", "}" ]
Creates a new record for a semi-permanent uploaded file. @param string $path local path to uploaded file @param array $data @return \Czim\CmsUploadModule\Models\File
[ "Creates", "a", "new", "record", "for", "a", "semi", "-", "permanent", "uploaded", "file", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Repositories/FileRepository.php#L20-L25
228,804
czim/laravel-cms-upload-module
src/Repositories/FileRepository.php
FileRepository.delete
public function delete($id, $unlink = true) { if ( ! ($file = $this->findById($id))) { return true; } if (FileFacade::exists($file->path)) { FileFacade::delete($file->path); } return $file->delete(); }
php
public function delete($id, $unlink = true) { if ( ! ($file = $this->findById($id))) { return true; } if (FileFacade::exists($file->path)) { FileFacade::delete($file->path); } return $file->delete(); }
[ "public", "function", "delete", "(", "$", "id", ",", "$", "unlink", "=", "true", ")", "{", "if", "(", "!", "(", "$", "file", "=", "$", "this", "->", "findById", "(", "$", "id", ")", ")", ")", "{", "return", "true", ";", "}", "if", "(", "FileFacade", "::", "exists", "(", "$", "file", "->", "path", ")", ")", "{", "FileFacade", "::", "delete", "(", "$", "file", "->", "path", ")", ";", "}", "return", "$", "file", "->", "delete", "(", ")", ";", "}" ]
Deletes an uploaded file. @param int $id @param bool $unlink if true, also deletes the referenced file @return bool
[ "Deletes", "an", "uploaded", "file", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Repositories/FileRepository.php#L66-L77
228,805
czim/laravel-cms-upload-module
src/Repositories/FileRepository.php
FileRepository.cleanup
public function cleanup() { // Find all files older than the given gc age $fileIds = File::query() ->where('created_at', '<', Carbon::now()->subMinutes($this->getGarbageAgeInMinutes())) ->pluck('id'); if ( ! count($fileIds)) { return 0; } $success = 0; foreach ($fileIds as $fileId) { $success += (int) $this->delete($fileId); } return $success; }
php
public function cleanup() { // Find all files older than the given gc age $fileIds = File::query() ->where('created_at', '<', Carbon::now()->subMinutes($this->getGarbageAgeInMinutes())) ->pluck('id'); if ( ! count($fileIds)) { return 0; } $success = 0; foreach ($fileIds as $fileId) { $success += (int) $this->delete($fileId); } return $success; }
[ "public", "function", "cleanup", "(", ")", "{", "// Find all files older than the given gc age", "$", "fileIds", "=", "File", "::", "query", "(", ")", "->", "where", "(", "'created_at'", ",", "'<'", ",", "Carbon", "::", "now", "(", ")", "->", "subMinutes", "(", "$", "this", "->", "getGarbageAgeInMinutes", "(", ")", ")", ")", "->", "pluck", "(", "'id'", ")", ";", "if", "(", "!", "count", "(", "$", "fileIds", ")", ")", "{", "return", "0", ";", "}", "$", "success", "=", "0", ";", "foreach", "(", "$", "fileIds", "as", "$", "fileId", ")", "{", "$", "success", "+=", "(", "int", ")", "$", "this", "->", "delete", "(", "$", "fileId", ")", ";", "}", "return", "$", "success", ";", "}" ]
Cleans up old upload records and files. @return int Records deleted
[ "Cleans", "up", "old", "upload", "records", "and", "files", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Repositories/FileRepository.php#L84-L102
228,806
mariano/disque-php
src/Connection/Node/ConservativeJobCountPrioritizer.php
ConservativeJobCountPrioritizer.calculateNodePriority
private function calculateNodePriority(Node $node, $currentNodeId) { $priority = $node->getJobCount(); if ($node->getId() === $currentNodeId) { $margin = 1 + $this->marginToSwitch; $priority = $priority * $margin; } // Apply a weight determined by the node priority as assigned by Disque. // Priority 1 means the node is healthy. // Priority 10 to 100 means the node is probably failing, or has failed $disquePriority = $node->getPriority(); // Disque node priority should never be lower than 1, but let's be sure if ($disquePriority < Node::PRIORITY_OK) { $disquePriorityWeight = 1; } elseif (Node::PRIORITY_OK <= $disquePriority && $disquePriority < Node::PRIORITY_POSSIBLE_FAILURE) { // Node is OK, but Disque may have assigned a lower priority to it // We use the base-10 logarithm in the formula, so priorities // 1 to 10 transform into a weight of 1 to 0.5. When Disque starts // using more priority steps, priority 9 will discount about a half // of the job count. $disquePriorityWeight = 1 / (1 + log10($disquePriority)); } else { // Node is failing, or it has failed $disquePriorityWeight = 0; } $priority = $priority * $disquePriorityWeight; return (float) $priority; }
php
private function calculateNodePriority(Node $node, $currentNodeId) { $priority = $node->getJobCount(); if ($node->getId() === $currentNodeId) { $margin = 1 + $this->marginToSwitch; $priority = $priority * $margin; } // Apply a weight determined by the node priority as assigned by Disque. // Priority 1 means the node is healthy. // Priority 10 to 100 means the node is probably failing, or has failed $disquePriority = $node->getPriority(); // Disque node priority should never be lower than 1, but let's be sure if ($disquePriority < Node::PRIORITY_OK) { $disquePriorityWeight = 1; } elseif (Node::PRIORITY_OK <= $disquePriority && $disquePriority < Node::PRIORITY_POSSIBLE_FAILURE) { // Node is OK, but Disque may have assigned a lower priority to it // We use the base-10 logarithm in the formula, so priorities // 1 to 10 transform into a weight of 1 to 0.5. When Disque starts // using more priority steps, priority 9 will discount about a half // of the job count. $disquePriorityWeight = 1 / (1 + log10($disquePriority)); } else { // Node is failing, or it has failed $disquePriorityWeight = 0; } $priority = $priority * $disquePriorityWeight; return (float) $priority; }
[ "private", "function", "calculateNodePriority", "(", "Node", "$", "node", ",", "$", "currentNodeId", ")", "{", "$", "priority", "=", "$", "node", "->", "getJobCount", "(", ")", ";", "if", "(", "$", "node", "->", "getId", "(", ")", "===", "$", "currentNodeId", ")", "{", "$", "margin", "=", "1", "+", "$", "this", "->", "marginToSwitch", ";", "$", "priority", "=", "$", "priority", "*", "$", "margin", ";", "}", "// Apply a weight determined by the node priority as assigned by Disque.", "// Priority 1 means the node is healthy.", "// Priority 10 to 100 means the node is probably failing, or has failed", "$", "disquePriority", "=", "$", "node", "->", "getPriority", "(", ")", ";", "// Disque node priority should never be lower than 1, but let's be sure", "if", "(", "$", "disquePriority", "<", "Node", "::", "PRIORITY_OK", ")", "{", "$", "disquePriorityWeight", "=", "1", ";", "}", "elseif", "(", "Node", "::", "PRIORITY_OK", "<=", "$", "disquePriority", "&&", "$", "disquePriority", "<", "Node", "::", "PRIORITY_POSSIBLE_FAILURE", ")", "{", "// Node is OK, but Disque may have assigned a lower priority to it", "// We use the base-10 logarithm in the formula, so priorities", "// 1 to 10 transform into a weight of 1 to 0.5. When Disque starts", "// using more priority steps, priority 9 will discount about a half", "// of the job count.", "$", "disquePriorityWeight", "=", "1", "/", "(", "1", "+", "log10", "(", "$", "disquePriority", ")", ")", ";", "}", "else", "{", "// Node is failing, or it has failed", "$", "disquePriorityWeight", "=", "0", ";", "}", "$", "priority", "=", "$", "priority", "*", "$", "disquePriorityWeight", ";", "return", "(", "float", ")", "$", "priority", ";", "}" ]
Calculate the node priority from its job count, stick to the current node As the priority is based on the number of jobs, higher is better. @param Node $node @param string $currentNodeId @return float Node priority
[ "Calculate", "the", "node", "priority", "from", "its", "job", "count", "stick", "to", "the", "current", "node" ]
56cf00d97e739fec861717484657dbef2888df60
https://github.com/mariano/disque-php/blob/56cf00d97e739fec861717484657dbef2888df60/src/Connection/Node/ConservativeJobCountPrioritizer.php#L94-L125
228,807
contao-bootstrap/templates
src/View/Gravatar.php
Gravatar.generateUrl
public function generateUrl($email, $size = null, $default = null) { if ($size == null) { $size = $this->environment->getConfig()->get(['templates', 'gravatar', 'size']); } if ($default == null) { $default = $this->environment->getConfig()->get(['templates', 'gravatar', 'default']); } $separator = '?'; $link = static::$baseUrl . md5(strtolower(trim($email))); if ($size) { $link .= $separator . 's=' . $size; $separator = '&'; } if ($default) { $link .= $separator . 'd=' . urlencode($default); } return $link; }
php
public function generateUrl($email, $size = null, $default = null) { if ($size == null) { $size = $this->environment->getConfig()->get(['templates', 'gravatar', 'size']); } if ($default == null) { $default = $this->environment->getConfig()->get(['templates', 'gravatar', 'default']); } $separator = '?'; $link = static::$baseUrl . md5(strtolower(trim($email))); if ($size) { $link .= $separator . 's=' . $size; $separator = '&'; } if ($default) { $link .= $separator . 'd=' . urlencode($default); } return $link; }
[ "public", "function", "generateUrl", "(", "$", "email", ",", "$", "size", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "size", "==", "null", ")", "{", "$", "size", "=", "$", "this", "->", "environment", "->", "getConfig", "(", ")", "->", "get", "(", "[", "'templates'", ",", "'gravatar'", ",", "'size'", "]", ")", ";", "}", "if", "(", "$", "default", "==", "null", ")", "{", "$", "default", "=", "$", "this", "->", "environment", "->", "getConfig", "(", ")", "->", "get", "(", "[", "'templates'", ",", "'gravatar'", ",", "'default'", "]", ")", ";", "}", "$", "separator", "=", "'?'", ";", "$", "link", "=", "static", "::", "$", "baseUrl", ".", "md5", "(", "strtolower", "(", "trim", "(", "$", "email", ")", ")", ")", ";", "if", "(", "$", "size", ")", "{", "$", "link", ".=", "$", "separator", ".", "'s='", ".", "$", "size", ";", "$", "separator", "=", "'&'", ";", "}", "if", "(", "$", "default", ")", "{", "$", "link", ".=", "$", "separator", ".", "'d='", ".", "urlencode", "(", "$", "default", ")", ";", "}", "return", "$", "link", ";", "}" ]
Generate the gravatar url. @param string $email The given email. @param null $size Optional size. @param null $default Optional default image url. @return string @SuppressWarnings(PHPMD.Superglobals)
[ "Generate", "the", "gravatar", "url", "." ]
cf507af3a194895923c6b84d97aa224e8b5b6d2f
https://github.com/contao-bootstrap/templates/blob/cf507af3a194895923c6b84d97aa224e8b5b6d2f/src/View/Gravatar.php#L60-L83
228,808
dnunez24/craft-laravel-mix
models/Mix_ManifestModel.php
Mix_ManifestModel.getAssetPath
public function getAssetPath(string $sourcePath) { $manifest = $this->readFile(); $path = $this->pathHelper->prefix($sourcePath); if (!array_key_exists($path, $manifest)) { throw new Exception("Unable to locate path '{$path}' in Mix manifest."); } return $this->urlHelper->getUrl($manifest[$path]); }
php
public function getAssetPath(string $sourcePath) { $manifest = $this->readFile(); $path = $this->pathHelper->prefix($sourcePath); if (!array_key_exists($path, $manifest)) { throw new Exception("Unable to locate path '{$path}' in Mix manifest."); } return $this->urlHelper->getUrl($manifest[$path]); }
[ "public", "function", "getAssetPath", "(", "string", "$", "sourcePath", ")", "{", "$", "manifest", "=", "$", "this", "->", "readFile", "(", ")", ";", "$", "path", "=", "$", "this", "->", "pathHelper", "->", "prefix", "(", "$", "sourcePath", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "path", ",", "$", "manifest", ")", ")", "{", "throw", "new", "Exception", "(", "\"Unable to locate path '{$path}' in Mix manifest.\"", ")", ";", "}", "return", "$", "this", "->", "urlHelper", "->", "getUrl", "(", "$", "manifest", "[", "$", "path", "]", ")", ";", "}" ]
Get mapped asset path from manifest file @param string $sourcePath @return string @throws Exception
[ "Get", "mapped", "asset", "path", "from", "manifest", "file" ]
c2f060f87be351d30e7d00123bb0ac25dd035490
https://github.com/dnunez24/craft-laravel-mix/blob/c2f060f87be351d30e7d00123bb0ac25dd035490/models/Mix_ManifestModel.php#L63-L73
228,809
dnunez24/craft-laravel-mix
models/Mix_ManifestModel.php
Mix_ManifestModel.getFile
protected function getFile() { $path = $this->directory.'/'.self::MANIFEST_FILENAME; $file = $this->pathHelper->getPublicPath($path, true); return $file; }
php
protected function getFile() { $path = $this->directory.'/'.self::MANIFEST_FILENAME; $file = $this->pathHelper->getPublicPath($path, true); return $file; }
[ "protected", "function", "getFile", "(", ")", "{", "$", "path", "=", "$", "this", "->", "directory", ".", "'/'", ".", "self", "::", "MANIFEST_FILENAME", ";", "$", "file", "=", "$", "this", "->", "pathHelper", "->", "getPublicPath", "(", "$", "path", ",", "true", ")", ";", "return", "$", "file", ";", "}" ]
Get manifest file @return string
[ "Get", "manifest", "file" ]
c2f060f87be351d30e7d00123bb0ac25dd035490
https://github.com/dnunez24/craft-laravel-mix/blob/c2f060f87be351d30e7d00123bb0ac25dd035490/models/Mix_ManifestModel.php#L80-L85
228,810
dnunez24/craft-laravel-mix
models/Mix_ManifestModel.php
Mix_ManifestModel.readFile
protected function readFile() { $file = $this->getFile(); $raw = $this->ioHelper->getFileContents($file); return $this->jsonHelper->decode($raw); }
php
protected function readFile() { $file = $this->getFile(); $raw = $this->ioHelper->getFileContents($file); return $this->jsonHelper->decode($raw); }
[ "protected", "function", "readFile", "(", ")", "{", "$", "file", "=", "$", "this", "->", "getFile", "(", ")", ";", "$", "raw", "=", "$", "this", "->", "ioHelper", "->", "getFileContents", "(", "$", "file", ")", ";", "return", "$", "this", "->", "jsonHelper", "->", "decode", "(", "$", "raw", ")", ";", "}" ]
Read & decode contents of manifest file @return mixed
[ "Read", "&", "decode", "contents", "of", "manifest", "file" ]
c2f060f87be351d30e7d00123bb0ac25dd035490
https://github.com/dnunez24/craft-laravel-mix/blob/c2f060f87be351d30e7d00123bb0ac25dd035490/models/Mix_ManifestModel.php#L92-L97
228,811
sop/crypto-types
lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php
SignatureAlgorithmIdentifierFactory.algoForAsymmetricCrypto
public static function algoForAsymmetricCrypto( AsymmetricCryptoAlgorithmIdentifier $crypto_algo, HashAlgorithmIdentifier $hash_algo): SignatureAlgorithmIdentifier { switch ($crypto_algo->oid()) { case AlgorithmIdentifier::OID_RSA_ENCRYPTION: $oid = self::_oidForRSA($hash_algo); break; case AlgorithmIdentifier::OID_EC_PUBLIC_KEY: $oid = self::_oidForEC($hash_algo); break; default: throw new \UnexpectedValueException( sprintf("Crypto algorithm %s not supported.", $crypto_algo->name())); } $cls = (new AlgorithmIdentifierFactory())->getClass($oid); return new $cls(); }
php
public static function algoForAsymmetricCrypto( AsymmetricCryptoAlgorithmIdentifier $crypto_algo, HashAlgorithmIdentifier $hash_algo): SignatureAlgorithmIdentifier { switch ($crypto_algo->oid()) { case AlgorithmIdentifier::OID_RSA_ENCRYPTION: $oid = self::_oidForRSA($hash_algo); break; case AlgorithmIdentifier::OID_EC_PUBLIC_KEY: $oid = self::_oidForEC($hash_algo); break; default: throw new \UnexpectedValueException( sprintf("Crypto algorithm %s not supported.", $crypto_algo->name())); } $cls = (new AlgorithmIdentifierFactory())->getClass($oid); return new $cls(); }
[ "public", "static", "function", "algoForAsymmetricCrypto", "(", "AsymmetricCryptoAlgorithmIdentifier", "$", "crypto_algo", ",", "HashAlgorithmIdentifier", "$", "hash_algo", ")", ":", "SignatureAlgorithmIdentifier", "{", "switch", "(", "$", "crypto_algo", "->", "oid", "(", ")", ")", "{", "case", "AlgorithmIdentifier", "::", "OID_RSA_ENCRYPTION", ":", "$", "oid", "=", "self", "::", "_oidForRSA", "(", "$", "hash_algo", ")", ";", "break", ";", "case", "AlgorithmIdentifier", "::", "OID_EC_PUBLIC_KEY", ":", "$", "oid", "=", "self", "::", "_oidForEC", "(", "$", "hash_algo", ")", ";", "break", ";", "default", ":", "throw", "new", "\\", "UnexpectedValueException", "(", "sprintf", "(", "\"Crypto algorithm %s not supported.\"", ",", "$", "crypto_algo", "->", "name", "(", ")", ")", ")", ";", "}", "$", "cls", "=", "(", "new", "AlgorithmIdentifierFactory", "(", ")", ")", "->", "getClass", "(", "$", "oid", ")", ";", "return", "new", "$", "cls", "(", ")", ";", "}" ]
Get signature algorithm identifier of given asymmetric cryptographic type utilizing given hash algorithm. @param AsymmetricCryptoAlgorithmIdentifier $crypto_algo Cryptographic algorithm identifier, eg. RSA or EC @param HashAlgorithmIdentifier $hash_algo Hash algorithm identifier @throws \UnexpectedValueException @return SignatureAlgorithmIdentifier
[ "Get", "signature", "algorithm", "identifier", "of", "given", "asymmetric", "cryptographic", "type", "utilizing", "given", "hash", "algorithm", "." ]
1d36250a110b07300aeb003a20aeaadfc6445501
https://github.com/sop/crypto-types/blob/1d36250a110b07300aeb003a20aeaadfc6445501/lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php#L63-L81
228,812
sop/crypto-types
lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php
SignatureAlgorithmIdentifierFactory._oidForRSA
private static function _oidForRSA(HashAlgorithmIdentifier $hash_algo): string { if (!array_key_exists($hash_algo->oid(), self::MAP_RSA_OID)) { throw new \UnexpectedValueException( sprintf("No RSA signature algorithm for %s.", $hash_algo->name())); } return self::MAP_RSA_OID[$hash_algo->oid()]; }
php
private static function _oidForRSA(HashAlgorithmIdentifier $hash_algo): string { if (!array_key_exists($hash_algo->oid(), self::MAP_RSA_OID)) { throw new \UnexpectedValueException( sprintf("No RSA signature algorithm for %s.", $hash_algo->name())); } return self::MAP_RSA_OID[$hash_algo->oid()]; }
[ "private", "static", "function", "_oidForRSA", "(", "HashAlgorithmIdentifier", "$", "hash_algo", ")", ":", "string", "{", "if", "(", "!", "array_key_exists", "(", "$", "hash_algo", "->", "oid", "(", ")", ",", "self", "::", "MAP_RSA_OID", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "sprintf", "(", "\"No RSA signature algorithm for %s.\"", ",", "$", "hash_algo", "->", "name", "(", ")", ")", ")", ";", "}", "return", "self", "::", "MAP_RSA_OID", "[", "$", "hash_algo", "->", "oid", "(", ")", "]", ";", "}" ]
Get RSA signature algorithm OID for the given hash algorithm identifier. @param HashAlgorithmIdentifier $hash_algo @throws \UnexpectedValueException @return string
[ "Get", "RSA", "signature", "algorithm", "OID", "for", "the", "given", "hash", "algorithm", "identifier", "." ]
1d36250a110b07300aeb003a20aeaadfc6445501
https://github.com/sop/crypto-types/blob/1d36250a110b07300aeb003a20aeaadfc6445501/lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php#L90-L97
228,813
sop/crypto-types
lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php
SignatureAlgorithmIdentifierFactory._oidForEC
private static function _oidForEC(HashAlgorithmIdentifier $hash_algo): string { if (!array_key_exists($hash_algo->oid(), self::MAP_EC_OID)) { throw new \UnexpectedValueException( sprintf("No EC signature algorithm for %s.", $hash_algo->name())); } return self::MAP_EC_OID[$hash_algo->oid()]; }
php
private static function _oidForEC(HashAlgorithmIdentifier $hash_algo): string { if (!array_key_exists($hash_algo->oid(), self::MAP_EC_OID)) { throw new \UnexpectedValueException( sprintf("No EC signature algorithm for %s.", $hash_algo->name())); } return self::MAP_EC_OID[$hash_algo->oid()]; }
[ "private", "static", "function", "_oidForEC", "(", "HashAlgorithmIdentifier", "$", "hash_algo", ")", ":", "string", "{", "if", "(", "!", "array_key_exists", "(", "$", "hash_algo", "->", "oid", "(", ")", ",", "self", "::", "MAP_EC_OID", ")", ")", "{", "throw", "new", "\\", "UnexpectedValueException", "(", "sprintf", "(", "\"No EC signature algorithm for %s.\"", ",", "$", "hash_algo", "->", "name", "(", ")", ")", ")", ";", "}", "return", "self", "::", "MAP_EC_OID", "[", "$", "hash_algo", "->", "oid", "(", ")", "]", ";", "}" ]
Get EC signature algorithm OID for the given hash algorithm identifier. @param HashAlgorithmIdentifier $hash_algo @throws \UnexpectedValueException @return string
[ "Get", "EC", "signature", "algorithm", "OID", "for", "the", "given", "hash", "algorithm", "identifier", "." ]
1d36250a110b07300aeb003a20aeaadfc6445501
https://github.com/sop/crypto-types/blob/1d36250a110b07300aeb003a20aeaadfc6445501/lib/CryptoTypes/AlgorithmIdentifier/Signature/SignatureAlgorithmIdentifierFactory.php#L106-L113
228,814
jeremeamia/FunctionParser
src/Token.php
Token.serialize
public function serialize() { return serialize(array($this->name, $this->value, $this->code, $this->line)); }
php
public function serialize() { return serialize(array($this->name, $this->value, $this->code, $this->line)); }
[ "public", "function", "serialize", "(", ")", "{", "return", "serialize", "(", "array", "(", "$", "this", "->", "name", ",", "$", "this", "->", "value", ",", "$", "this", "->", "code", ",", "$", "this", "->", "line", ")", ")", ";", "}" ]
Serializes the token. @return string The serialized token.
[ "Serializes", "the", "token", "." ]
035b52000b88ea8d72a6647dd4cd39f080cf7ada
https://github.com/jeremeamia/FunctionParser/blob/035b52000b88ea8d72a6647dd4cd39f080cf7ada/src/Token.php#L225-L228
228,815
jeremeamia/FunctionParser
src/Token.php
Token.unserialize
public function unserialize($serialized) { list($this->name, $this->value, $this->code, $this->line) = unserialize($serialized); }
php
public function unserialize($serialized) { list($this->name, $this->value, $this->code, $this->line) = unserialize($serialized); }
[ "public", "function", "unserialize", "(", "$", "serialized", ")", "{", "list", "(", "$", "this", "->", "name", ",", "$", "this", "->", "value", ",", "$", "this", "->", "code", ",", "$", "this", "->", "line", ")", "=", "unserialize", "(", "$", "serialized", ")", ";", "}" ]
Unserializes the token @param string $serialized The serialized token
[ "Unserializes", "the", "token" ]
035b52000b88ea8d72a6647dd4cd39f080cf7ada
https://github.com/jeremeamia/FunctionParser/blob/035b52000b88ea8d72a6647dd4cd39f080cf7ada/src/Token.php#L235-L238
228,816
sop/crypto-types
lib/CryptoTypes/AlgorithmIdentifier/Cipher/CipherAlgorithmIdentifier.php
CipherAlgorithmIdentifier.withInitializationVector
public function withInitializationVector($iv): self { $this->_checkIVSize($iv); $obj = clone $this; $obj->_initializationVector = $iv; return $obj; }
php
public function withInitializationVector($iv): self { $this->_checkIVSize($iv); $obj = clone $this; $obj->_initializationVector = $iv; return $obj; }
[ "public", "function", "withInitializationVector", "(", "$", "iv", ")", ":", "self", "{", "$", "this", "->", "_checkIVSize", "(", "$", "iv", ")", ";", "$", "obj", "=", "clone", "$", "this", ";", "$", "obj", "->", "_initializationVector", "=", "$", "iv", ";", "return", "$", "obj", ";", "}" ]
Get copy of the object with given initialization vector. @param string|null $iv Initialization vector or null to remove @throws \UnexpectedValueException If initialization vector size is invalid @return self
[ "Get", "copy", "of", "the", "object", "with", "given", "initialization", "vector", "." ]
1d36250a110b07300aeb003a20aeaadfc6445501
https://github.com/sop/crypto-types/blob/1d36250a110b07300aeb003a20aeaadfc6445501/lib/CryptoTypes/AlgorithmIdentifier/Cipher/CipherAlgorithmIdentifier.php#L53-L59
228,817
czim/laravel-cms-upload-module
src/Http/Requests/UploadFileRequest.php
UploadFileRequest.getNormalizedValidationRules
public function getNormalizedValidationRules() { $rules = json_decode($this->get('validation'), true); if ( ! is_string($rules) && ! is_array($rules)) { return null; } return $rules; }
php
public function getNormalizedValidationRules() { $rules = json_decode($this->get('validation'), true); if ( ! is_string($rules) && ! is_array($rules)) { return null; } return $rules; }
[ "public", "function", "getNormalizedValidationRules", "(", ")", "{", "$", "rules", "=", "json_decode", "(", "$", "this", "->", "get", "(", "'validation'", ")", ",", "true", ")", ";", "if", "(", "!", "is_string", "(", "$", "rules", ")", "&&", "!", "is_array", "(", "$", "rules", ")", ")", "{", "return", "null", ";", "}", "return", "$", "rules", ";", "}" ]
Returns validation rules as string or array. Anything else will return null. @return string|array|null
[ "Returns", "validation", "rules", "as", "string", "or", "array", ".", "Anything", "else", "will", "return", "null", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Http/Requests/UploadFileRequest.php#L23-L32
228,818
pear/Net_LDAP2
doc/examples/schema_cache.php
MySessionSchemaCache.loadSchema
public function loadSchema() { // Lets see if we have a session, otherwise we cant use this cache // and drop some error that will be returned by Net_LDAP2->schema(). // Minor errors should be indicated by returning false, so Net_LDAP2 // can continue its work. This will result in the same behavior as // no schema cache would have been registered. if (!isset($_SESSION)) { return new Net_LDAP2_Error(__CLASS__.": No PHP Session initialized.". " This cache needs an open PHP session."); } // Here the session is valid, so we return the stores schema. // If we cant find the schema (because cahce is empty),w e return // false to inidicate a minor error to Net_LDAP2. // This causes it to fetch a fresh object from LDAP. if (array_key_exists(__CLASS__, $_SESSION) && $_SESSION[__CLASS__] instanceof Net_LDAP2_SchemaCache) { return $_SESSION[__CLASS__]; } else { return false; } }
php
public function loadSchema() { // Lets see if we have a session, otherwise we cant use this cache // and drop some error that will be returned by Net_LDAP2->schema(). // Minor errors should be indicated by returning false, so Net_LDAP2 // can continue its work. This will result in the same behavior as // no schema cache would have been registered. if (!isset($_SESSION)) { return new Net_LDAP2_Error(__CLASS__.": No PHP Session initialized.". " This cache needs an open PHP session."); } // Here the session is valid, so we return the stores schema. // If we cant find the schema (because cahce is empty),w e return // false to inidicate a minor error to Net_LDAP2. // This causes it to fetch a fresh object from LDAP. if (array_key_exists(__CLASS__, $_SESSION) && $_SESSION[__CLASS__] instanceof Net_LDAP2_SchemaCache) { return $_SESSION[__CLASS__]; } else { return false; } }
[ "public", "function", "loadSchema", "(", ")", "{", "// Lets see if we have a session, otherwise we cant use this cache", "// and drop some error that will be returned by Net_LDAP2->schema().", "// Minor errors should be indicated by returning false, so Net_LDAP2", "// can continue its work. This will result in the same behavior as", "// no schema cache would have been registered.", "if", "(", "!", "isset", "(", "$", "_SESSION", ")", ")", "{", "return", "new", "Net_LDAP2_Error", "(", "__CLASS__", ".", "\": No PHP Session initialized.\"", ".", "\" This cache needs an open PHP session.\"", ")", ";", "}", "// Here the session is valid, so we return the stores schema.", "// If we cant find the schema (because cahce is empty),w e return", "// false to inidicate a minor error to Net_LDAP2.", "// This causes it to fetch a fresh object from LDAP.", "if", "(", "array_key_exists", "(", "__CLASS__", ",", "$", "_SESSION", ")", "&&", "$", "_SESSION", "[", "__CLASS__", "]", "instanceof", "Net_LDAP2_SchemaCache", ")", "{", "return", "$", "_SESSION", "[", "__CLASS__", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Load schema from session For the sake of simplicity we dont implement a cache aging here. This is not a big problem, since php sessions shouldnt last endlessly. @return Net_LDAP2_Schema|Net_LDAP2_Error|false
[ "Load", "schema", "from", "session" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/doc/examples/schema_cache.php#L108-L129
228,819
sop/crypto-types
lib/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifierFactory.php
AlgorithmIdentifierFactory.getClass
public function getClass(string $oid) { // if OID is provided by this factory if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { return self::MAP_OID_TO_CLASS[$oid]; } // try additional providers foreach ($this->_additionalProviders as $provider) { if ($provider->supportsOID($oid)) { return $provider->getClassByOID($oid); } } return null; }
php
public function getClass(string $oid) { // if OID is provided by this factory if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { return self::MAP_OID_TO_CLASS[$oid]; } // try additional providers foreach ($this->_additionalProviders as $provider) { if ($provider->supportsOID($oid)) { return $provider->getClassByOID($oid); } } return null; }
[ "public", "function", "getClass", "(", "string", "$", "oid", ")", "{", "// if OID is provided by this factory", "if", "(", "array_key_exists", "(", "$", "oid", ",", "self", "::", "MAP_OID_TO_CLASS", ")", ")", "{", "return", "self", "::", "MAP_OID_TO_CLASS", "[", "$", "oid", "]", ";", "}", "// try additional providers", "foreach", "(", "$", "this", "->", "_additionalProviders", "as", "$", "provider", ")", "{", "if", "(", "$", "provider", "->", "supportsOID", "(", "$", "oid", ")", ")", "{", "return", "$", "provider", "->", "getClassByOID", "(", "$", "oid", ")", ";", "}", "}", "return", "null", ";", "}" ]
Get the name of a class that implements algorithm identifier for given OID. @param string $oid Object identifier in dotted format @return string|null Fully qualified class name or null if not supported
[ "Get", "the", "name", "of", "a", "class", "that", "implements", "algorithm", "identifier", "for", "given", "OID", "." ]
1d36250a110b07300aeb003a20aeaadfc6445501
https://github.com/sop/crypto-types/blob/1d36250a110b07300aeb003a20aeaadfc6445501/lib/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifierFactory.php#L85-L98
228,820
sop/crypto-types
lib/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifierFactory.php
AlgorithmIdentifierFactory.parse
public function parse(Sequence $seq): AlgorithmIdentifier { $oid = $seq->at(0) ->asObjectIdentifier() ->oid(); $params = $seq->has(1) ? $seq->at(1) : null; /** @var SpecificAlgorithmIdentifier $cls */ $cls = $this->getClass($oid); if ($cls) { return $cls::fromASN1Params($params); } // fallback to generic algorithm identifier return new GenericAlgorithmIdentifier($oid, $params); }
php
public function parse(Sequence $seq): AlgorithmIdentifier { $oid = $seq->at(0) ->asObjectIdentifier() ->oid(); $params = $seq->has(1) ? $seq->at(1) : null; /** @var SpecificAlgorithmIdentifier $cls */ $cls = $this->getClass($oid); if ($cls) { return $cls::fromASN1Params($params); } // fallback to generic algorithm identifier return new GenericAlgorithmIdentifier($oid, $params); }
[ "public", "function", "parse", "(", "Sequence", "$", "seq", ")", ":", "AlgorithmIdentifier", "{", "$", "oid", "=", "$", "seq", "->", "at", "(", "0", ")", "->", "asObjectIdentifier", "(", ")", "->", "oid", "(", ")", ";", "$", "params", "=", "$", "seq", "->", "has", "(", "1", ")", "?", "$", "seq", "->", "at", "(", "1", ")", ":", "null", ";", "/** @var SpecificAlgorithmIdentifier $cls */", "$", "cls", "=", "$", "this", "->", "getClass", "(", "$", "oid", ")", ";", "if", "(", "$", "cls", ")", "{", "return", "$", "cls", "::", "fromASN1Params", "(", "$", "params", ")", ";", "}", "// fallback to generic algorithm identifier", "return", "new", "GenericAlgorithmIdentifier", "(", "$", "oid", ",", "$", "params", ")", ";", "}" ]
Parse AlgorithmIdentifier from an ASN.1 sequence. @param Sequence $seq @return AlgorithmIdentifier
[ "Parse", "AlgorithmIdentifier", "from", "an", "ASN", ".", "1", "sequence", "." ]
1d36250a110b07300aeb003a20aeaadfc6445501
https://github.com/sop/crypto-types/blob/1d36250a110b07300aeb003a20aeaadfc6445501/lib/CryptoTypes/AlgorithmIdentifier/AlgorithmIdentifierFactory.php#L106-L119
228,821
pear/Net_LDAP2
Net/LDAP2/RootDSE.php
Net_LDAP2_RootDSE.fetch
public static function fetch($ldap, $attrs = null) { if (!$ldap instanceof Net_LDAP2) { return PEAR::raiseError("Unable to fetch Schema: Parameter \$ldap must be a Net_LDAP2 object!"); } if (is_array($attrs) && count($attrs) > 0 ) { $attributes = $attrs; } else { $attributes = array('vendorName', 'vendorVersion', 'namingContexts', 'altServer', 'supportedExtension', 'supportedControl', 'supportedSASLMechanisms', 'supportedLDAPVersion', 'subschemaSubentry' ); } $result = $ldap->search('', '(objectClass=*)', array('attributes' => $attributes, 'scope' => 'base')); if (self::isError($result)) { return $result; } $entry = $result->shiftEntry(); if (false === $entry) { return PEAR::raiseError('Could not fetch RootDSE entry'); } $ret = new Net_LDAP2_RootDSE($entry); return $ret; }
php
public static function fetch($ldap, $attrs = null) { if (!$ldap instanceof Net_LDAP2) { return PEAR::raiseError("Unable to fetch Schema: Parameter \$ldap must be a Net_LDAP2 object!"); } if (is_array($attrs) && count($attrs) > 0 ) { $attributes = $attrs; } else { $attributes = array('vendorName', 'vendorVersion', 'namingContexts', 'altServer', 'supportedExtension', 'supportedControl', 'supportedSASLMechanisms', 'supportedLDAPVersion', 'subschemaSubentry' ); } $result = $ldap->search('', '(objectClass=*)', array('attributes' => $attributes, 'scope' => 'base')); if (self::isError($result)) { return $result; } $entry = $result->shiftEntry(); if (false === $entry) { return PEAR::raiseError('Could not fetch RootDSE entry'); } $ret = new Net_LDAP2_RootDSE($entry); return $ret; }
[ "public", "static", "function", "fetch", "(", "$", "ldap", ",", "$", "attrs", "=", "null", ")", "{", "if", "(", "!", "$", "ldap", "instanceof", "Net_LDAP2", ")", "{", "return", "PEAR", "::", "raiseError", "(", "\"Unable to fetch Schema: Parameter \\$ldap must be a Net_LDAP2 object!\"", ")", ";", "}", "if", "(", "is_array", "(", "$", "attrs", ")", "&&", "count", "(", "$", "attrs", ")", ">", "0", ")", "{", "$", "attributes", "=", "$", "attrs", ";", "}", "else", "{", "$", "attributes", "=", "array", "(", "'vendorName'", ",", "'vendorVersion'", ",", "'namingContexts'", ",", "'altServer'", ",", "'supportedExtension'", ",", "'supportedControl'", ",", "'supportedSASLMechanisms'", ",", "'supportedLDAPVersion'", ",", "'subschemaSubentry'", ")", ";", "}", "$", "result", "=", "$", "ldap", "->", "search", "(", "''", ",", "'(objectClass=*)'", ",", "array", "(", "'attributes'", "=>", "$", "attributes", ",", "'scope'", "=>", "'base'", ")", ")", ";", "if", "(", "self", "::", "isError", "(", "$", "result", ")", ")", "{", "return", "$", "result", ";", "}", "$", "entry", "=", "$", "result", "->", "shiftEntry", "(", ")", ";", "if", "(", "false", "===", "$", "entry", ")", "{", "return", "PEAR", "::", "raiseError", "(", "'Could not fetch RootDSE entry'", ")", ";", "}", "$", "ret", "=", "new", "Net_LDAP2_RootDSE", "(", "$", "entry", ")", ";", "return", "$", "ret", ";", "}" ]
Fetches a RootDSE object from an LDAP connection @param Net_LDAP2 $ldap Directory from which the RootDSE should be fetched @param array $attrs Array of attributes to search for @access static @return Net_LDAP2_RootDSE|Net_LDAP2_Error
[ "Fetches", "a", "RootDSE", "object", "from", "an", "LDAP", "connection" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/RootDSE.php#L58-L87
228,822
pear/Net_LDAP2
Net/LDAP2/RootDSE.php
Net_LDAP2_RootDSE.checkAttr
protected function checkAttr($values, $attr) { if (!is_array($values)) $values = array($values); foreach ($values as $value) { if (!@in_array($value, $this->get_value($attr, 'all'))) { return false; } } return true; }
php
protected function checkAttr($values, $attr) { if (!is_array($values)) $values = array($values); foreach ($values as $value) { if (!@in_array($value, $this->get_value($attr, 'all'))) { return false; } } return true; }
[ "protected", "function", "checkAttr", "(", "$", "values", ",", "$", "attr", ")", "{", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "$", "values", "=", "array", "(", "$", "values", ")", ";", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "if", "(", "!", "@", "in_array", "(", "$", "value", ",", "$", "this", "->", "get_value", "(", "$", "attr", ",", "'all'", ")", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks for existance of value in attribute @param array $values values to check @param string $attr attribute name @access protected @return boolean
[ "Checks", "for", "existance", "of", "value", "in", "attribute" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/RootDSE.php#L227-L237
228,823
mlaphp/mlaphp
src/Mlaphp/Router.php
Router.fixPath
protected function fixPath($path) { $len = strlen($this->front); if (substr($path, 0, $len) == $this->front) { $path = substr($path, $len); } return '/' . ltrim($path, '/'); }
php
protected function fixPath($path) { $len = strlen($this->front); if (substr($path, 0, $len) == $this->front) { $path = substr($path, $len); } return '/' . ltrim($path, '/'); }
[ "protected", "function", "fixPath", "(", "$", "path", ")", "{", "$", "len", "=", "strlen", "(", "$", "this", "->", "front", ")", ";", "if", "(", "substr", "(", "$", "path", ",", "0", ",", "$", "len", ")", "==", "$", "this", "->", "front", ")", "{", "$", "path", "=", "substr", "(", "$", "path", ",", "$", "len", ")", ";", "}", "return", "'/'", ".", "ltrim", "(", "$", "path", ",", "'/'", ")", ";", "}" ]
Fixes the incoming URL path to strip the front controller script name. @param string $path The incoming URL path. @return string The fixed path.
[ "Fixes", "the", "incoming", "URL", "path", "to", "strip", "the", "front", "controller", "script", "name", "." ]
c0c90e7217c598c82bb65e5304e8076da381c1f8
https://github.com/mlaphp/mlaphp/blob/c0c90e7217c598c82bb65e5304e8076da381c1f8/src/Mlaphp/Router.php#L135-L144
228,824
mlaphp/mlaphp
src/Mlaphp/Router.php
Router.fixFileRoute
protected function fixFileRoute($route) { if (! $this->pages_dir) { throw new RuntimeException('No pages directory specified.'); } $page = realpath($this->pages_dir . $route); if ($this->pageExists($page)) { return $page; } if ($this->isFileRoute($this->not_found_route)) { return $this->pages_dir . $this->not_found_route; } return $this->not_found_route; }
php
protected function fixFileRoute($route) { if (! $this->pages_dir) { throw new RuntimeException('No pages directory specified.'); } $page = realpath($this->pages_dir . $route); if ($this->pageExists($page)) { return $page; } if ($this->isFileRoute($this->not_found_route)) { return $this->pages_dir . $this->not_found_route; } return $this->not_found_route; }
[ "protected", "function", "fixFileRoute", "(", "$", "route", ")", "{", "if", "(", "!", "$", "this", "->", "pages_dir", ")", "{", "throw", "new", "RuntimeException", "(", "'No pages directory specified.'", ")", ";", "}", "$", "page", "=", "realpath", "(", "$", "this", "->", "pages_dir", ".", "$", "route", ")", ";", "if", "(", "$", "this", "->", "pageExists", "(", "$", "page", ")", ")", "{", "return", "$", "page", ";", "}", "if", "(", "$", "this", "->", "isFileRoute", "(", "$", "this", "->", "not_found_route", ")", ")", "{", "return", "$", "this", "->", "pages_dir", ".", "$", "this", "->", "not_found_route", ";", "}", "return", "$", "this", "->", "not_found_route", ";", "}" ]
Fixes a file route specification by finding the real path to see if it exists in the pages directory and is readable. @param string $route The matched route. @return string The real path if it exists, or the not-found route if it does not. @throws RuntimeException when the route is a file but no pages directory is specified.
[ "Fixes", "a", "file", "route", "specification", "by", "finding", "the", "real", "path", "to", "see", "if", "it", "exists", "in", "the", "pages", "directory", "and", "is", "readable", "." ]
c0c90e7217c598c82bb65e5304e8076da381c1f8
https://github.com/mlaphp/mlaphp/blob/c0c90e7217c598c82bb65e5304e8076da381c1f8/src/Mlaphp/Router.php#L204-L221
228,825
mlaphp/mlaphp
src/Mlaphp/Router.php
Router.pageExists
protected function pageExists($file) { $file = str_replace(DIRECTORY_SEPARATOR, '/', $file); return $file != '' && substr($file, 0, strlen($this->pages_dir)) == $this->pages_dir && file_exists($file) && is_readable($file); }
php
protected function pageExists($file) { $file = str_replace(DIRECTORY_SEPARATOR, '/', $file); return $file != '' && substr($file, 0, strlen($this->pages_dir)) == $this->pages_dir && file_exists($file) && is_readable($file); }
[ "protected", "function", "pageExists", "(", "$", "file", ")", "{", "$", "file", "=", "str_replace", "(", "DIRECTORY_SEPARATOR", ",", "'/'", ",", "$", "file", ")", ";", "return", "$", "file", "!=", "''", "&&", "substr", "(", "$", "file", ",", "0", ",", "strlen", "(", "$", "this", "->", "pages_dir", ")", ")", "==", "$", "this", "->", "pages_dir", "&&", "file_exists", "(", "$", "file", ")", "&&", "is_readable", "(", "$", "file", ")", ";", "}" ]
Does the pages directory have a matching readable file? @param string $file The file to check. @return bool
[ "Does", "the", "pages", "directory", "have", "a", "matching", "readable", "file?" ]
c0c90e7217c598c82bb65e5304e8076da381c1f8
https://github.com/mlaphp/mlaphp/blob/c0c90e7217c598c82bb65e5304e8076da381c1f8/src/Mlaphp/Router.php#L229-L236
228,826
sop/crypto-types
lib/CryptoTypes/Asymmetric/RSA/RSAPublicKey.php
RSAPublicKey.fromDER
public static function fromDER(string $data): RSAPublicKey { return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); }
php
public static function fromDER(string $data): RSAPublicKey { return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); }
[ "public", "static", "function", "fromDER", "(", "string", "$", "data", ")", ":", "RSAPublicKey", "{", "return", "self", "::", "fromASN1", "(", "UnspecifiedType", "::", "fromDER", "(", "$", "data", ")", "->", "asSequence", "(", ")", ")", ";", "}" ]
Initialize from DER data. @param string $data @return self
[ "Initialize", "from", "DER", "data", "." ]
1d36250a110b07300aeb003a20aeaadfc6445501
https://github.com/sop/crypto-types/blob/1d36250a110b07300aeb003a20aeaadfc6445501/lib/CryptoTypes/Asymmetric/RSA/RSAPublicKey.php#L73-L76
228,827
pear/Net_LDAP2
Net/LDAP2/Util.php
Net_LDAP2_Util.escape_dn_value
public static function escape_dn_value($values = array()) { // Parameter validation if (!is_array($values)) { $values = array($values); } foreach ($values as $key => $val) { // Escaping of filter meta characters $val = str_replace('\\', '\\\\', $val); $val = str_replace(',', '\,', $val); $val = str_replace('+', '\+', $val); $val = str_replace('"', '\"', $val); $val = str_replace('<', '\<', $val); $val = str_replace('>', '\>', $val); $val = str_replace(';', '\;', $val); $val = str_replace('#', '\#', $val); $val = str_replace('=', '\=', $val); // ASCII < 32 escaping $val = self::asc2hex32($val); // Convert all leading and trailing spaces to sequences of \20. if (preg_match('/^(\s*)(.+?)(\s*)$/', $val, $matches)) { $val = $matches[2]; for ($i = 0; $i < strlen($matches[1]); $i++) { $val = '\20'.$val; } for ($i = 0; $i < strlen($matches[3]); $i++) { $val = $val.'\20'; } } if (null === $val) $val = '\0'; // apply escaped "null" if string is empty $values[$key] = $val; } return $values; }
php
public static function escape_dn_value($values = array()) { // Parameter validation if (!is_array($values)) { $values = array($values); } foreach ($values as $key => $val) { // Escaping of filter meta characters $val = str_replace('\\', '\\\\', $val); $val = str_replace(',', '\,', $val); $val = str_replace('+', '\+', $val); $val = str_replace('"', '\"', $val); $val = str_replace('<', '\<', $val); $val = str_replace('>', '\>', $val); $val = str_replace(';', '\;', $val); $val = str_replace('#', '\#', $val); $val = str_replace('=', '\=', $val); // ASCII < 32 escaping $val = self::asc2hex32($val); // Convert all leading and trailing spaces to sequences of \20. if (preg_match('/^(\s*)(.+?)(\s*)$/', $val, $matches)) { $val = $matches[2]; for ($i = 0; $i < strlen($matches[1]); $i++) { $val = '\20'.$val; } for ($i = 0; $i < strlen($matches[3]); $i++) { $val = $val.'\20'; } } if (null === $val) $val = '\0'; // apply escaped "null" if string is empty $values[$key] = $val; } return $values; }
[ "public", "static", "function", "escape_dn_value", "(", "$", "values", "=", "array", "(", ")", ")", "{", "// Parameter validation", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "{", "$", "values", "=", "array", "(", "$", "values", ")", ";", "}", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "val", ")", "{", "// Escaping of filter meta characters", "$", "val", "=", "str_replace", "(", "'\\\\'", ",", "'\\\\\\\\'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "','", ",", "'\\,'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "'+'", ",", "'\\+'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "'\"'", ",", "'\\\"'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "'<'", ",", "'\\<'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "'>'", ",", "'\\>'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "';'", ",", "'\\;'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "'#'", ",", "'\\#'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "'='", ",", "'\\='", ",", "$", "val", ")", ";", "// ASCII < 32 escaping", "$", "val", "=", "self", "::", "asc2hex32", "(", "$", "val", ")", ";", "// Convert all leading and trailing spaces to sequences of \\20.", "if", "(", "preg_match", "(", "'/^(\\s*)(.+?)(\\s*)$/'", ",", "$", "val", ",", "$", "matches", ")", ")", "{", "$", "val", "=", "$", "matches", "[", "2", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "matches", "[", "1", "]", ")", ";", "$", "i", "++", ")", "{", "$", "val", "=", "'\\20'", ".", "$", "val", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "matches", "[", "3", "]", ")", ";", "$", "i", "++", ")", "{", "$", "val", "=", "$", "val", ".", "'\\20'", ";", "}", "}", "if", "(", "null", "===", "$", "val", ")", "$", "val", "=", "'\\0'", ";", "// apply escaped \"null\" if string is empty", "$", "values", "[", "$", "key", "]", "=", "$", "val", ";", "}", "return", "$", "values", ";", "}" ]
Escapes a DN value according to RFC 2253 Escapes the given VALUES according to RFC 2253 so that they can be safely used in LDAP DNs. The characters ",", "+", """, "\", "<", ">", ";", "#", "=" with a special meaning in RFC 2252 are preceeded by ba backslash. Control characters with an ASCII code < 32 are represented as \hexpair. Finally all leading and trailing spaces are converted to sequences of \20. @param array $values An array containing the DN values that should be escaped @static @return array The array $values, but escaped
[ "Escapes", "a", "DN", "value", "according", "to", "RFC", "2253" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Util.php#L202-L241
228,828
pear/Net_LDAP2
Net/LDAP2/Util.php
Net_LDAP2_Util.escape_filter_value
public static function escape_filter_value($values = array()) { // Parameter validation if (!is_array($values)) { $values = array($values); } foreach ($values as $key => $val) { // Escaping of filter meta characters $val = str_replace('\\', '\5c', $val); $val = str_replace('*', '\2a', $val); $val = str_replace('(', '\28', $val); $val = str_replace(')', '\29', $val); // ASCII < 32 escaping $val = self::asc2hex32($val); if (null === $val) $val = '\0'; // apply escaped "null" if string is empty $values[$key] = $val; } return $values; }
php
public static function escape_filter_value($values = array()) { // Parameter validation if (!is_array($values)) { $values = array($values); } foreach ($values as $key => $val) { // Escaping of filter meta characters $val = str_replace('\\', '\5c', $val); $val = str_replace('*', '\2a', $val); $val = str_replace('(', '\28', $val); $val = str_replace(')', '\29', $val); // ASCII < 32 escaping $val = self::asc2hex32($val); if (null === $val) $val = '\0'; // apply escaped "null" if string is empty $values[$key] = $val; } return $values; }
[ "public", "static", "function", "escape_filter_value", "(", "$", "values", "=", "array", "(", ")", ")", "{", "// Parameter validation", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "{", "$", "values", "=", "array", "(", "$", "values", ")", ";", "}", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "val", ")", "{", "// Escaping of filter meta characters", "$", "val", "=", "str_replace", "(", "'\\\\'", ",", "'\\5c'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "'*'", ",", "'\\2a'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "'('", ",", "'\\28'", ",", "$", "val", ")", ";", "$", "val", "=", "str_replace", "(", "')'", ",", "'\\29'", ",", "$", "val", ")", ";", "// ASCII < 32 escaping", "$", "val", "=", "self", "::", "asc2hex32", "(", "$", "val", ")", ";", "if", "(", "null", "===", "$", "val", ")", "$", "val", "=", "'\\0'", ";", "// apply escaped \"null\" if string is empty", "$", "values", "[", "$", "key", "]", "=", "$", "val", ";", "}", "return", "$", "values", ";", "}" ]
Escapes the given VALUES according to RFC 2254 so that they can be safely used in LDAP filters. Any control characters with an ACII code < 32 as well as the characters with special meaning in LDAP filters "*", "(", ")", and "\" (the backslash) are converted into the representation of a backslash followed by two hex digits representing the hexadecimal value of the character. @param array $values Array of values to escape @static @return array Array $values, but escaped
[ "Escapes", "the", "given", "VALUES", "according", "to", "RFC", "2254", "so", "that", "they", "can", "be", "safely", "used", "in", "LDAP", "filters", "." ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Util.php#L435-L458
228,829
pear/Net_LDAP2
Net/LDAP2/Util.php
Net_LDAP2_Util.asc2hex32
public static function asc2hex32($string) { for ($i = 0; $i < strlen($string); $i++) { $char = substr($string, $i, 1); if (ord($char) < 32) { $hex = dechex(ord($char)); if (strlen($hex) == 1) $hex = '0'.$hex; $string = str_replace($char, '\\'.$hex, $string); } } return $string; }
php
public static function asc2hex32($string) { for ($i = 0; $i < strlen($string); $i++) { $char = substr($string, $i, 1); if (ord($char) < 32) { $hex = dechex(ord($char)); if (strlen($hex) == 1) $hex = '0'.$hex; $string = str_replace($char, '\\'.$hex, $string); } } return $string; }
[ "public", "static", "function", "asc2hex32", "(", "$", "string", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "string", ")", ";", "$", "i", "++", ")", "{", "$", "char", "=", "substr", "(", "$", "string", ",", "$", "i", ",", "1", ")", ";", "if", "(", "ord", "(", "$", "char", ")", "<", "32", ")", "{", "$", "hex", "=", "dechex", "(", "ord", "(", "$", "char", ")", ")", ";", "if", "(", "strlen", "(", "$", "hex", ")", "==", "1", ")", "$", "hex", "=", "'0'", ".", "$", "hex", ";", "$", "string", "=", "str_replace", "(", "$", "char", ",", "'\\\\'", ".", "$", "hex", ",", "$", "string", ")", ";", "}", "}", "return", "$", "string", ";", "}" ]
Converts all ASCII chars < 32 to "\HEX" @param string $string String to convert @static @return string
[ "Converts", "all", "ASCII", "chars", "<", "32", "to", "\\", "HEX" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Util.php#L493-L504
228,830
pear/Net_LDAP2
Net/LDAP2/Util.php
Net_LDAP2_Util.split_rdn_multival
public static function split_rdn_multival($rdn) { $rdns = preg_split('/(?<!\\\\)\+/', $rdn); $rdns = self::correct_dn_splitting($rdns, '+'); return array_values($rdns); }
php
public static function split_rdn_multival($rdn) { $rdns = preg_split('/(?<!\\\\)\+/', $rdn); $rdns = self::correct_dn_splitting($rdns, '+'); return array_values($rdns); }
[ "public", "static", "function", "split_rdn_multival", "(", "$", "rdn", ")", "{", "$", "rdns", "=", "preg_split", "(", "'/(?<!\\\\\\\\)\\+/'", ",", "$", "rdn", ")", ";", "$", "rdns", "=", "self", "::", "correct_dn_splitting", "(", "$", "rdns", ",", "'+'", ")", ";", "return", "array_values", "(", "$", "rdns", ")", ";", "}" ]
Split an multivalued RDN value into an Array A RDN can contain multiple values, spearated by a plus sign. This function returns each separate ocl=value pair of the RDN part. If no multivalued RDN is detected, an array containing only the original rdn part is returned. For example, the multivalued RDN 'OU=Sales+CN=J. Smith' is exploded to: <kbd>array([0] => 'OU=Sales', [1] => 'CN=J. Smith')</kbd> The method trys to be smart if it encounters unescaped "+" characters, but may fail, so ensure escaped "+"es in attr names and attr values. [BUG] If you have a multivalued RDN with unescaped plus characters and there is a unescaped plus sign at the end of an value followed by an attribute name containing an unescaped plus, then you will get wrong splitting: $rdn = 'OU=Sales+C+N=J. Smith'; returns: array('OU=Sales+C', 'N=J. Smith'); The "C+" is treaten as value of the first pair instead as attr name of the second pair. To prevent this, escape correctly. @param string $rdn Part of an (multivalued) escaped RDN (eg. ou=foo OR ou=foo+cn=bar) @static @return array Array with the components of the multivalued RDN or Error
[ "Split", "an", "multivalued", "RDN", "value", "into", "an", "Array" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Util.php#L556-L561
228,831
pear/Net_LDAP2
Net/LDAP2/Util.php
Net_LDAP2_Util.split_attribute_string
public static function split_attribute_string($attr, $extended=false, $withDelim=false) { if ($withDelim) $withDelim = PREG_SPLIT_DELIM_CAPTURE; if (!$extended) { return preg_split('/(?<!\\\\)(=)/', $attr, 2, $withDelim); } else { return preg_split('/(?<!\\\\)(>=|<=|>|<|~=|=)/', $attr, 2, $withDelim); } }
php
public static function split_attribute_string($attr, $extended=false, $withDelim=false) { if ($withDelim) $withDelim = PREG_SPLIT_DELIM_CAPTURE; if (!$extended) { return preg_split('/(?<!\\\\)(=)/', $attr, 2, $withDelim); } else { return preg_split('/(?<!\\\\)(>=|<=|>|<|~=|=)/', $attr, 2, $withDelim); } }
[ "public", "static", "function", "split_attribute_string", "(", "$", "attr", ",", "$", "extended", "=", "false", ",", "$", "withDelim", "=", "false", ")", "{", "if", "(", "$", "withDelim", ")", "$", "withDelim", "=", "PREG_SPLIT_DELIM_CAPTURE", ";", "if", "(", "!", "$", "extended", ")", "{", "return", "preg_split", "(", "'/(?<!\\\\\\\\)(=)/'", ",", "$", "attr", ",", "2", ",", "$", "withDelim", ")", ";", "}", "else", "{", "return", "preg_split", "(", "'/(?<!\\\\\\\\)(>=|<=|>|<|~=|=)/'", ",", "$", "attr", ",", "2", ",", "$", "withDelim", ")", ";", "}", "}" ]
Splits an attribute=value syntax into an array If escaped delimeters are used, they are returned escaped as well. The split will occur at the first unescaped delimeter character. In case an invalid delimeter is given, no split will be performed and an one element array gets returned. Optional also filter-assertion delimeters can be considered (>, <, >=, <=, ~=). @param string $attr Attribute and Value Syntax ("foo=bar") @param boolean $extended If set to true, also filter-assertion delimeter will be matched @param boolean $withDelim If set to true, the return array contains the delimeter at index 1, putting the value to index 2 @return array Indexed array: 0=attribute name, 1=attribute value OR ($withDelim=true): 0=attr, 1=delimeter, 2=value
[ "Splits", "an", "attribute", "=", "value", "syntax", "into", "an", "array" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Util.php#L578-L587
228,832
pear/Net_LDAP2
Net/LDAP2/Util.php
Net_LDAP2_Util.correct_dn_splitting
protected static function correct_dn_splitting($dn = array(), $separator = ',') { foreach ($dn as $key => $dn_value) { $dn_value = $dn[$key]; // refresh value (foreach caches!) // if the dn_value is not in attr=value format, then we had an // unescaped separator character inside the attr name or the value. // We assume, that it was the attribute value. // [TODO] To solve this, we might ask the schema. Keep in mind, that UTIL class // must remain independent from the other classes or connections. if (!preg_match('/.+(?<!\\\\)=.+/', $dn_value)) { unset($dn[$key]); if (array_key_exists($key-1, $dn)) { $dn[$key-1] = $dn[$key-1].$separator.$dn_value; // append to previous attr value } else { $dn[$key+1] = $dn_value.$separator.$dn[$key+1]; // first element: prepend to next attr name } } } return array_values($dn); }
php
protected static function correct_dn_splitting($dn = array(), $separator = ',') { foreach ($dn as $key => $dn_value) { $dn_value = $dn[$key]; // refresh value (foreach caches!) // if the dn_value is not in attr=value format, then we had an // unescaped separator character inside the attr name or the value. // We assume, that it was the attribute value. // [TODO] To solve this, we might ask the schema. Keep in mind, that UTIL class // must remain independent from the other classes or connections. if (!preg_match('/.+(?<!\\\\)=.+/', $dn_value)) { unset($dn[$key]); if (array_key_exists($key-1, $dn)) { $dn[$key-1] = $dn[$key-1].$separator.$dn_value; // append to previous attr value } else { $dn[$key+1] = $dn_value.$separator.$dn[$key+1]; // first element: prepend to next attr name } } } return array_values($dn); }
[ "protected", "static", "function", "correct_dn_splitting", "(", "$", "dn", "=", "array", "(", ")", ",", "$", "separator", "=", "','", ")", "{", "foreach", "(", "$", "dn", "as", "$", "key", "=>", "$", "dn_value", ")", "{", "$", "dn_value", "=", "$", "dn", "[", "$", "key", "]", ";", "// refresh value (foreach caches!)", "// if the dn_value is not in attr=value format, then we had an", "// unescaped separator character inside the attr name or the value.", "// We assume, that it was the attribute value.", "// [TODO] To solve this, we might ask the schema. Keep in mind, that UTIL class", "// must remain independent from the other classes or connections.", "if", "(", "!", "preg_match", "(", "'/.+(?<!\\\\\\\\)=.+/'", ",", "$", "dn_value", ")", ")", "{", "unset", "(", "$", "dn", "[", "$", "key", "]", ")", ";", "if", "(", "array_key_exists", "(", "$", "key", "-", "1", ",", "$", "dn", ")", ")", "{", "$", "dn", "[", "$", "key", "-", "1", "]", "=", "$", "dn", "[", "$", "key", "-", "1", "]", ".", "$", "separator", ".", "$", "dn_value", ";", "// append to previous attr value", "}", "else", "{", "$", "dn", "[", "$", "key", "+", "1", "]", "=", "$", "dn_value", ".", "$", "separator", ".", "$", "dn", "[", "$", "key", "+", "1", "]", ";", "// first element: prepend to next attr name", "}", "}", "}", "return", "array_values", "(", "$", "dn", ")", ";", "}" ]
Corrects splitting of dn parts @param array $dn Raw DN array @param array $separator Separator that was used when splitting @return array Corrected array @access protected
[ "Corrects", "splitting", "of", "dn", "parts" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Util.php#L598-L617
228,833
coolcsn/CsnCms
src/CsnCms/Controller/CategoryController.php
CategoryController.editAction
public function editAction() { $id = $this->params()->fromRoute('id'); if (!$id) { return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'category', 'action' => 'index')); } $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); try { $category = $entityManager->find('CsnCms\Entity\Category', $id); } catch (\Exception $ex) { echo $ex->getMessage(); // this will never be seen if you don't comment the redirect return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'category', 'action' => 'index')); } $form = $this->getForm($category, $entityManager, 'Update'); //hide the id element(bug in doctrine maybe) //$form->get('id')->setAttribute('type','hidden'); try { $form->get('id')->setAttribute('type','hidden'); } catch (\Exception $ex) { } $form->bind($category); $request = $this->getRequest(); if ($request->isPost()) { $post = $request->getPost(); $form->setData($post); if ($form->isValid()) { //$this->prepareData($category); $entityManager->persist($category); $entityManager->flush(); return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'category', 'action' => 'index')); } } return new ViewModel(array('form' => $form, 'id' => $id)); }
php
public function editAction() { $id = $this->params()->fromRoute('id'); if (!$id) { return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'category', 'action' => 'index')); } $entityManager = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); try { $category = $entityManager->find('CsnCms\Entity\Category', $id); } catch (\Exception $ex) { echo $ex->getMessage(); // this will never be seen if you don't comment the redirect return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'category', 'action' => 'index')); } $form = $this->getForm($category, $entityManager, 'Update'); //hide the id element(bug in doctrine maybe) //$form->get('id')->setAttribute('type','hidden'); try { $form->get('id')->setAttribute('type','hidden'); } catch (\Exception $ex) { } $form->bind($category); $request = $this->getRequest(); if ($request->isPost()) { $post = $request->getPost(); $form->setData($post); if ($form->isValid()) { //$this->prepareData($category); $entityManager->persist($category); $entityManager->flush(); return $this->redirect()->toRoute('csn-cms/default', array('controller' => 'category', 'action' => 'index')); } } return new ViewModel(array('form' => $form, 'id' => $id)); }
[ "public", "function", "editAction", "(", ")", "{", "$", "id", "=", "$", "this", "->", "params", "(", ")", "->", "fromRoute", "(", "'id'", ")", ";", "if", "(", "!", "$", "id", ")", "{", "return", "$", "this", "->", "redirect", "(", ")", "->", "toRoute", "(", "'csn-cms/default'", ",", "array", "(", "'controller'", "=>", "'category'", ",", "'action'", "=>", "'index'", ")", ")", ";", "}", "$", "entityManager", "=", "$", "this", "->", "getServiceLocator", "(", ")", "->", "get", "(", "'doctrine.entitymanager.orm_default'", ")", ";", "try", "{", "$", "category", "=", "$", "entityManager", "->", "find", "(", "'CsnCms\\Entity\\Category'", ",", "$", "id", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "echo", "$", "ex", "->", "getMessage", "(", ")", ";", "// this will never be seen if you don't comment the redirect", "return", "$", "this", "->", "redirect", "(", ")", "->", "toRoute", "(", "'csn-cms/default'", ",", "array", "(", "'controller'", "=>", "'category'", ",", "'action'", "=>", "'index'", ")", ")", ";", "}", "$", "form", "=", "$", "this", "->", "getForm", "(", "$", "category", ",", "$", "entityManager", ",", "'Update'", ")", ";", "//hide the id element(bug in doctrine maybe)", "//$form->get('id')->setAttribute('type','hidden');", "try", "{", "$", "form", "->", "get", "(", "'id'", ")", "->", "setAttribute", "(", "'type'", ",", "'hidden'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "}", "$", "form", "->", "bind", "(", "$", "category", ")", ";", "$", "request", "=", "$", "this", "->", "getRequest", "(", ")", ";", "if", "(", "$", "request", "->", "isPost", "(", ")", ")", "{", "$", "post", "=", "$", "request", "->", "getPost", "(", ")", ";", "$", "form", "->", "setData", "(", "$", "post", ")", ";", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "//$this->prepareData($category);", "$", "entityManager", "->", "persist", "(", "$", "category", ")", ";", "$", "entityManager", "->", "flush", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", ")", "->", "toRoute", "(", "'csn-cms/default'", ",", "array", "(", "'controller'", "=>", "'category'", ",", "'action'", "=>", "'index'", ")", ")", ";", "}", "}", "return", "new", "ViewModel", "(", "array", "(", "'form'", "=>", "$", "form", ",", "'id'", "=>", "$", "id", ")", ")", ";", "}" ]
U - update
[ "U", "-", "update" ]
fd2b163e292836b9f672400694a86f75225b725a
https://github.com/coolcsn/CsnCms/blob/fd2b163e292836b9f672400694a86f75225b725a/src/CsnCms/Controller/CategoryController.php#L61-L104
228,834
JustBlackBird/codeception-config-module
src/Config.php
Config.grabFromConfig
public function grabFromConfig($parameter) { if (!isset($this->config[$parameter])) { throw new ModuleConfigException(get_class($this), sprintf( 'Parameter "%s" is not specified in module\'s configurations.', $parameter )); } return $this->config[$parameter]; }
php
public function grabFromConfig($parameter) { if (!isset($this->config[$parameter])) { throw new ModuleConfigException(get_class($this), sprintf( 'Parameter "%s" is not specified in module\'s configurations.', $parameter )); } return $this->config[$parameter]; }
[ "public", "function", "grabFromConfig", "(", "$", "parameter", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "$", "parameter", "]", ")", ")", "{", "throw", "new", "ModuleConfigException", "(", "get_class", "(", "$", "this", ")", ",", "sprintf", "(", "'Parameter \"%s\" is not specified in module\\'s configurations.'", ",", "$", "parameter", ")", ")", ";", "}", "return", "$", "this", "->", "config", "[", "$", "parameter", "]", ";", "}" ]
Retrieves value for configuration param with the passed in name. @param string $parameter @return mixed @throws ModuleConfigException If the specified parameter was not set in the configs.
[ "Retrieves", "value", "for", "configuration", "param", "with", "the", "passed", "in", "name", "." ]
97c9a68d6a2fe4d67b760449805ac1de10be59f9
https://github.com/JustBlackBird/codeception-config-module/blob/97c9a68d6a2fe4d67b760449805ac1de10be59f9/src/Config.php#L29-L39
228,835
mariano/disque-php
src/Connection/Node/Node.php
Node.connect
public function connect() { if ($this->connection->isConnected() && !empty($this->hello)) { return $this->hello; } $this->connectToTheNode(); $this->authenticateWithPassword(); try { $this->sayHello(); } catch (ResponseException $e) { /** * If the node requires a password but we didn't supply any, * Disque returns a message "NOAUTH Authentication required" * * HELLO is the first place we would get this error. * * @see https://github.com/antirez/disque/blob/master/src/server.c * Look for "noautherr" */ $message = $e->getMessage(); if (stripos($message, self::AUTH_REQUIRED_MESSAGE) === 0) { throw new AuthenticationException($message, 0, $e); } } return $this->hello; }
php
public function connect() { if ($this->connection->isConnected() && !empty($this->hello)) { return $this->hello; } $this->connectToTheNode(); $this->authenticateWithPassword(); try { $this->sayHello(); } catch (ResponseException $e) { /** * If the node requires a password but we didn't supply any, * Disque returns a message "NOAUTH Authentication required" * * HELLO is the first place we would get this error. * * @see https://github.com/antirez/disque/blob/master/src/server.c * Look for "noautherr" */ $message = $e->getMessage(); if (stripos($message, self::AUTH_REQUIRED_MESSAGE) === 0) { throw new AuthenticationException($message, 0, $e); } } return $this->hello; }
[ "public", "function", "connect", "(", ")", "{", "if", "(", "$", "this", "->", "connection", "->", "isConnected", "(", ")", "&&", "!", "empty", "(", "$", "this", "->", "hello", ")", ")", "{", "return", "$", "this", "->", "hello", ";", "}", "$", "this", "->", "connectToTheNode", "(", ")", ";", "$", "this", "->", "authenticateWithPassword", "(", ")", ";", "try", "{", "$", "this", "->", "sayHello", "(", ")", ";", "}", "catch", "(", "ResponseException", "$", "e", ")", "{", "/**\n * If the node requires a password but we didn't supply any,\n * Disque returns a message \"NOAUTH Authentication required\"\n *\n * HELLO is the first place we would get this error.\n *\n * @see https://github.com/antirez/disque/blob/master/src/server.c\n * Look for \"noautherr\"\n */", "$", "message", "=", "$", "e", "->", "getMessage", "(", ")", ";", "if", "(", "stripos", "(", "$", "message", ",", "self", "::", "AUTH_REQUIRED_MESSAGE", ")", "===", "0", ")", "{", "throw", "new", "AuthenticationException", "(", "$", "message", ",", "0", ",", "$", "e", ")", ";", "}", "}", "return", "$", "this", "->", "hello", ";", "}" ]
Connect to the node and return the HELLO response This method is idempotent and can be called multiple times @return array The HELLO response @throws ConnectionException @throws AuthenticationException
[ "Connect", "to", "the", "node", "and", "return", "the", "HELLO", "response" ]
56cf00d97e739fec861717484657dbef2888df60
https://github.com/mariano/disque-php/blob/56cf00d97e739fec861717484657dbef2888df60/src/Connection/Node/Node.php#L231-L259
228,836
mariano/disque-php
src/Connection/Node/Node.php
Node.sayHello
public function sayHello() { $helloCommand = new Hello(); $helloResponse = $this->connection->execute($helloCommand); $this->hello = (array) $helloCommand->parse($helloResponse); $this->id = $this->hello[HelloResponse::NODE_ID]; $this->createPrefix($this->id); $this->priority = $this->readPriorityFromHello($this->hello, $this->id); return $this->hello; }
php
public function sayHello() { $helloCommand = new Hello(); $helloResponse = $this->connection->execute($helloCommand); $this->hello = (array) $helloCommand->parse($helloResponse); $this->id = $this->hello[HelloResponse::NODE_ID]; $this->createPrefix($this->id); $this->priority = $this->readPriorityFromHello($this->hello, $this->id); return $this->hello; }
[ "public", "function", "sayHello", "(", ")", "{", "$", "helloCommand", "=", "new", "Hello", "(", ")", ";", "$", "helloResponse", "=", "$", "this", "->", "connection", "->", "execute", "(", "$", "helloCommand", ")", ";", "$", "this", "->", "hello", "=", "(", "array", ")", "$", "helloCommand", "->", "parse", "(", "$", "helloResponse", ")", ";", "$", "this", "->", "id", "=", "$", "this", "->", "hello", "[", "HelloResponse", "::", "NODE_ID", "]", ";", "$", "this", "->", "createPrefix", "(", "$", "this", "->", "id", ")", ";", "$", "this", "->", "priority", "=", "$", "this", "->", "readPriorityFromHello", "(", "$", "this", "->", "hello", ",", "$", "this", "->", "id", ")", ";", "return", "$", "this", "->", "hello", ";", "}" ]
Say a new HELLO to the node and parse the response @return array The HELLO response @throws ConnectionException
[ "Say", "a", "new", "HELLO", "to", "the", "node", "and", "parse", "the", "response" ]
56cf00d97e739fec861717484657dbef2888df60
https://github.com/mariano/disque-php/blob/56cf00d97e739fec861717484657dbef2888df60/src/Connection/Node/Node.php#L291-L303
228,837
mariano/disque-php
src/Connection/Node/Node.php
Node.connectToTheNode
private function connectToTheNode() { $this->connection->connect( $this->credentials->getConnectionTimeout(), $this->credentials->getResponseTimeout() ); }
php
private function connectToTheNode() { $this->connection->connect( $this->credentials->getConnectionTimeout(), $this->credentials->getResponseTimeout() ); }
[ "private", "function", "connectToTheNode", "(", ")", "{", "$", "this", "->", "connection", "->", "connect", "(", "$", "this", "->", "credentials", "->", "getConnectionTimeout", "(", ")", ",", "$", "this", "->", "credentials", "->", "getResponseTimeout", "(", ")", ")", ";", "}" ]
Connect to the node @throws ConnectionException
[ "Connect", "to", "the", "node" ]
56cf00d97e739fec861717484657dbef2888df60
https://github.com/mariano/disque-php/blob/56cf00d97e739fec861717484657dbef2888df60/src/Connection/Node/Node.php#L310-L316
228,838
mariano/disque-php
src/Connection/Node/Node.php
Node.authenticateWithPassword
private function authenticateWithPassword() { if ($this->credentials->havePassword()) { $authCommand = new Auth(); $authCommand->setArguments([$this->credentials->getPassword()]); $authResponse = $this->connection->execute($authCommand); $response = $authCommand->parse($authResponse); if ($response !== self::AUTH_SUCCESS_MESSAGE) { throw new AuthenticationException(); } } }
php
private function authenticateWithPassword() { if ($this->credentials->havePassword()) { $authCommand = new Auth(); $authCommand->setArguments([$this->credentials->getPassword()]); $authResponse = $this->connection->execute($authCommand); $response = $authCommand->parse($authResponse); if ($response !== self::AUTH_SUCCESS_MESSAGE) { throw new AuthenticationException(); } } }
[ "private", "function", "authenticateWithPassword", "(", ")", "{", "if", "(", "$", "this", "->", "credentials", "->", "havePassword", "(", ")", ")", "{", "$", "authCommand", "=", "new", "Auth", "(", ")", ";", "$", "authCommand", "->", "setArguments", "(", "[", "$", "this", "->", "credentials", "->", "getPassword", "(", ")", "]", ")", ";", "$", "authResponse", "=", "$", "this", "->", "connection", "->", "execute", "(", "$", "authCommand", ")", ";", "$", "response", "=", "$", "authCommand", "->", "parse", "(", "$", "authResponse", ")", ";", "if", "(", "$", "response", "!==", "self", "::", "AUTH_SUCCESS_MESSAGE", ")", "{", "throw", "new", "AuthenticationException", "(", ")", ";", "}", "}", "}" ]
Authenticate with the node with a password, if set @throws AuthenticationException
[ "Authenticate", "with", "the", "node", "with", "a", "password", "if", "set" ]
56cf00d97e739fec861717484657dbef2888df60
https://github.com/mariano/disque-php/blob/56cf00d97e739fec861717484657dbef2888df60/src/Connection/Node/Node.php#L323-L334
228,839
mariano/disque-php
src/Connection/Node/Node.php
Node.createPrefix
private function createPrefix($id) { $this->prefix = substr($id, self::PREFIX_START, self::PREFIX_LENGTH); }
php
private function createPrefix($id) { $this->prefix = substr($id, self::PREFIX_START, self::PREFIX_LENGTH); }
[ "private", "function", "createPrefix", "(", "$", "id", ")", "{", "$", "this", "->", "prefix", "=", "substr", "(", "$", "id", ",", "self", "::", "PREFIX_START", ",", "self", "::", "PREFIX_LENGTH", ")", ";", "}" ]
Create a node prefix from the node ID @param string $id
[ "Create", "a", "node", "prefix", "from", "the", "node", "ID" ]
56cf00d97e739fec861717484657dbef2888df60
https://github.com/mariano/disque-php/blob/56cf00d97e739fec861717484657dbef2888df60/src/Connection/Node/Node.php#L341-L344
228,840
mariano/disque-php
src/Connection/Node/Node.php
Node.readPriorityFromHello
private function readPriorityFromHello($hello, $id) { foreach ($hello[HelloResponse::NODES] as $node) { if ($node[HelloResponse::NODE_ID] === $id) { return $node[HelloResponse::NODE_PRIORITY]; } } // Node not found in the HELLO? This should not happen. // Return a fallback value return self::PRIORITY_FALLBACK; }
php
private function readPriorityFromHello($hello, $id) { foreach ($hello[HelloResponse::NODES] as $node) { if ($node[HelloResponse::NODE_ID] === $id) { return $node[HelloResponse::NODE_PRIORITY]; } } // Node not found in the HELLO? This should not happen. // Return a fallback value return self::PRIORITY_FALLBACK; }
[ "private", "function", "readPriorityFromHello", "(", "$", "hello", ",", "$", "id", ")", "{", "foreach", "(", "$", "hello", "[", "HelloResponse", "::", "NODES", "]", "as", "$", "node", ")", "{", "if", "(", "$", "node", "[", "HelloResponse", "::", "NODE_ID", "]", "===", "$", "id", ")", "{", "return", "$", "node", "[", "HelloResponse", "::", "NODE_PRIORITY", "]", ";", "}", "}", "// Node not found in the HELLO? This should not happen.", "// Return a fallback value", "return", "self", "::", "PRIORITY_FALLBACK", ";", "}" ]
Read out the node's own priority from a HELLO response @param array $hello The HELLO response @param string $id Node ID @return int Node priority
[ "Read", "out", "the", "node", "s", "own", "priority", "from", "a", "HELLO", "response" ]
56cf00d97e739fec861717484657dbef2888df60
https://github.com/mariano/disque-php/blob/56cf00d97e739fec861717484657dbef2888df60/src/Connection/Node/Node.php#L354-L365
228,841
czim/laravel-cms-upload-module
src/Support/Security/FileChecker.php
FileChecker.checkFileName
protected function checkFileName($fileName) { $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); $allow = $this->getWhitelistedExtensions(); $block = $this->getBlacklistedExtensions(); return ( (false === $allow || in_array($extension, $allow)) && (false === $block || ! in_array($extension, $block)) ); }
php
protected function checkFileName($fileName) { $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION)); $allow = $this->getWhitelistedExtensions(); $block = $this->getBlacklistedExtensions(); return ( (false === $allow || in_array($extension, $allow)) && (false === $block || ! in_array($extension, $block)) ); }
[ "protected", "function", "checkFileName", "(", "$", "fileName", ")", "{", "$", "extension", "=", "strtolower", "(", "pathinfo", "(", "$", "fileName", ",", "PATHINFO_EXTENSION", ")", ")", ";", "$", "allow", "=", "$", "this", "->", "getWhitelistedExtensions", "(", ")", ";", "$", "block", "=", "$", "this", "->", "getBlacklistedExtensions", "(", ")", ";", "return", "(", "(", "false", "===", "$", "allow", "||", "in_array", "(", "$", "extension", ",", "$", "allow", ")", ")", "&&", "(", "false", "===", "$", "block", "||", "!", "in_array", "(", "$", "extension", ",", "$", "block", ")", ")", ")", ";", "}" ]
Checks whether the file name is acceptable for upload. @param string $fileName @return bool
[ "Checks", "whether", "the", "file", "name", "is", "acceptable", "for", "upload", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Support/Security/FileChecker.php#L33-L43
228,842
czim/laravel-cms-upload-module
src/Support/Security/FileChecker.php
FileChecker.checkMimeType
protected function checkMimeType($mimeType) { $allow = $this->getWhitelistedMimeTypes(); $block = $this->getBlacklistedMimeTypes(); if (false !== $allow) { foreach ($allow as $pattern) { if ($this->wildCardMatch($mimeType, $pattern)) { return true; } } return false; } if (false !== $block) { foreach ($block as $pattern) { if ($this->wildCardMatch($mimeType, $pattern)) { return false; } } } return true; }
php
protected function checkMimeType($mimeType) { $allow = $this->getWhitelistedMimeTypes(); $block = $this->getBlacklistedMimeTypes(); if (false !== $allow) { foreach ($allow as $pattern) { if ($this->wildCardMatch($mimeType, $pattern)) { return true; } } return false; } if (false !== $block) { foreach ($block as $pattern) { if ($this->wildCardMatch($mimeType, $pattern)) { return false; } } } return true; }
[ "protected", "function", "checkMimeType", "(", "$", "mimeType", ")", "{", "$", "allow", "=", "$", "this", "->", "getWhitelistedMimeTypes", "(", ")", ";", "$", "block", "=", "$", "this", "->", "getBlacklistedMimeTypes", "(", ")", ";", "if", "(", "false", "!==", "$", "allow", ")", "{", "foreach", "(", "$", "allow", "as", "$", "pattern", ")", "{", "if", "(", "$", "this", "->", "wildCardMatch", "(", "$", "mimeType", ",", "$", "pattern", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}", "if", "(", "false", "!==", "$", "block", ")", "{", "foreach", "(", "$", "block", "as", "$", "pattern", ")", "{", "if", "(", "$", "this", "->", "wildCardMatch", "(", "$", "mimeType", ",", "$", "pattern", ")", ")", "{", "return", "false", ";", "}", "}", "}", "return", "true", ";", "}" ]
Checks whether the mimetype is acceptable for upload. @param string $mimeType @return bool
[ "Checks", "whether", "the", "mimetype", "is", "acceptable", "for", "upload", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Support/Security/FileChecker.php#L51-L75
228,843
czim/laravel-cms-upload-module
src/Support/Security/FileChecker.php
FileChecker.getWhitelistedExtensions
protected function getWhitelistedExtensions() { $allow = config('cms-upload-module.upload.restrict.extensions.allow', null); if ( ! is_array($allow) || ! count($allow)) { return false; } return array_map('trim', array_map('strtolower', $allow)); }
php
protected function getWhitelistedExtensions() { $allow = config('cms-upload-module.upload.restrict.extensions.allow', null); if ( ! is_array($allow) || ! count($allow)) { return false; } return array_map('trim', array_map('strtolower', $allow)); }
[ "protected", "function", "getWhitelistedExtensions", "(", ")", "{", "$", "allow", "=", "config", "(", "'cms-upload-module.upload.restrict.extensions.allow'", ",", "null", ")", ";", "if", "(", "!", "is_array", "(", "$", "allow", ")", "||", "!", "count", "(", "$", "allow", ")", ")", "{", "return", "false", ";", "}", "return", "array_map", "(", "'trim'", ",", "array_map", "(", "'strtolower'", ",", "$", "allow", ")", ")", ";", "}" ]
Returns whitelisted extensions, or false if no whitelist is set. @return bool|string[]
[ "Returns", "whitelisted", "extensions", "or", "false", "if", "no", "whitelist", "is", "set", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Support/Security/FileChecker.php#L82-L91
228,844
czim/laravel-cms-upload-module
src/Support/Security/FileChecker.php
FileChecker.getBlacklistedExtensions
protected function getBlacklistedExtensions() { $block = config('cms-upload-module.upload.restrict.extensions.block', null); if ( ! is_array($block) || ! count($block)) { return false; } return array_map('trim', array_map('strtolower', $block)); }
php
protected function getBlacklistedExtensions() { $block = config('cms-upload-module.upload.restrict.extensions.block', null); if ( ! is_array($block) || ! count($block)) { return false; } return array_map('trim', array_map('strtolower', $block)); }
[ "protected", "function", "getBlacklistedExtensions", "(", ")", "{", "$", "block", "=", "config", "(", "'cms-upload-module.upload.restrict.extensions.block'", ",", "null", ")", ";", "if", "(", "!", "is_array", "(", "$", "block", ")", "||", "!", "count", "(", "$", "block", ")", ")", "{", "return", "false", ";", "}", "return", "array_map", "(", "'trim'", ",", "array_map", "(", "'strtolower'", ",", "$", "block", ")", ")", ";", "}" ]
Returns blacklisted extensions, or false if no whitelist is set. @return bool|string[]
[ "Returns", "blacklisted", "extensions", "or", "false", "if", "no", "whitelist", "is", "set", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Support/Security/FileChecker.php#L98-L107
228,845
czim/laravel-cms-upload-module
src/Support/Security/FileChecker.php
FileChecker.getWhitelistedMimeTypes
protected function getWhitelistedMimeTypes() { $allow = config('cms-upload-module.upload.restrict.mimetypes.allow', null); if ( ! is_array($allow) || ! count($allow)) { return false; } return array_map('trim', array_map('strtolower', $allow)); }
php
protected function getWhitelistedMimeTypes() { $allow = config('cms-upload-module.upload.restrict.mimetypes.allow', null); if ( ! is_array($allow) || ! count($allow)) { return false; } return array_map('trim', array_map('strtolower', $allow)); }
[ "protected", "function", "getWhitelistedMimeTypes", "(", ")", "{", "$", "allow", "=", "config", "(", "'cms-upload-module.upload.restrict.mimetypes.allow'", ",", "null", ")", ";", "if", "(", "!", "is_array", "(", "$", "allow", ")", "||", "!", "count", "(", "$", "allow", ")", ")", "{", "return", "false", ";", "}", "return", "array_map", "(", "'trim'", ",", "array_map", "(", "'strtolower'", ",", "$", "allow", ")", ")", ";", "}" ]
Returns whitelisted mimetypes, or false if no whitelist is set. @return bool|string[]
[ "Returns", "whitelisted", "mimetypes", "or", "false", "if", "no", "whitelist", "is", "set", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Support/Security/FileChecker.php#L114-L123
228,846
czim/laravel-cms-upload-module
src/Support/Security/FileChecker.php
FileChecker.getBlacklistedMimeTypes
protected function getBlacklistedMimeTypes() { $block = config('cms-upload-module.upload.restrict.mimetypes.block', null); if ( ! is_array($block) || ! count($block)) { return false; } return array_map('trim', array_map('strtolower', $block)); }
php
protected function getBlacklistedMimeTypes() { $block = config('cms-upload-module.upload.restrict.mimetypes.block', null); if ( ! is_array($block) || ! count($block)) { return false; } return array_map('trim', array_map('strtolower', $block)); }
[ "protected", "function", "getBlacklistedMimeTypes", "(", ")", "{", "$", "block", "=", "config", "(", "'cms-upload-module.upload.restrict.mimetypes.block'", ",", "null", ")", ";", "if", "(", "!", "is_array", "(", "$", "block", ")", "||", "!", "count", "(", "$", "block", ")", ")", "{", "return", "false", ";", "}", "return", "array_map", "(", "'trim'", ",", "array_map", "(", "'strtolower'", ",", "$", "block", ")", ")", ";", "}" ]
Returns blacklisted mimetypes, or false if no whitelist is set. @return bool|string[]
[ "Returns", "blacklisted", "mimetypes", "or", "false", "if", "no", "whitelist", "is", "set", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Support/Security/FileChecker.php#L130-L139
228,847
czim/laravel-cms-upload-module
src/Support/Security/FileChecker.php
FileChecker.wildCardMatch
protected function wildCardMatch($source, $pattern) { $pattern = preg_quote($pattern, '#'); $pattern = str_replace('\?' , '.?', $pattern); $pattern = str_replace('\*' , '.*?', $pattern); return (bool) preg_match('#^' . $pattern . '$#i' , $source); }
php
protected function wildCardMatch($source, $pattern) { $pattern = preg_quote($pattern, '#'); $pattern = str_replace('\?' , '.?', $pattern); $pattern = str_replace('\*' , '.*?', $pattern); return (bool) preg_match('#^' . $pattern . '$#i' , $source); }
[ "protected", "function", "wildCardMatch", "(", "$", "source", ",", "$", "pattern", ")", "{", "$", "pattern", "=", "preg_quote", "(", "$", "pattern", ",", "'#'", ")", ";", "$", "pattern", "=", "str_replace", "(", "'\\?'", ",", "'.?'", ",", "$", "pattern", ")", ";", "$", "pattern", "=", "str_replace", "(", "'\\*'", ",", "'.*?'", ",", "$", "pattern", ")", ";", "return", "(", "bool", ")", "preg_match", "(", "'#^'", ".", "$", "pattern", ".", "'$#i'", ",", "$", "source", ")", ";", "}" ]
Returns whether a string matches against a wildcard pattern. May use * and ? wildcards. @param string $source @param string $pattern @return bool
[ "Returns", "whether", "a", "string", "matches", "against", "a", "wildcard", "pattern", "." ]
3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3
https://github.com/czim/laravel-cms-upload-module/blob/3599801efcfdcf9164e8c75c3e1b2c6e7e3692c3/src/Support/Security/FileChecker.php#L150-L158
228,848
dnunez24/craft-laravel-mix
helpers/Mix_PathHelper.php
Mix_PathHelper.getPublicPath
public function getPublicPath($path = '', $raiseException = false) { $publicDir = $this->config->get('publicDir', self::PLUGIN_HANDLE); $publicPath = $this->ioHelper->getRealPath($publicDir.'/'.$path); if (!$publicPath && $raiseException) { throw new Exception("{$publicPath} does not exist"); } return (string)$publicPath; }
php
public function getPublicPath($path = '', $raiseException = false) { $publicDir = $this->config->get('publicDir', self::PLUGIN_HANDLE); $publicPath = $this->ioHelper->getRealPath($publicDir.'/'.$path); if (!$publicPath && $raiseException) { throw new Exception("{$publicPath} does not exist"); } return (string)$publicPath; }
[ "public", "function", "getPublicPath", "(", "$", "path", "=", "''", ",", "$", "raiseException", "=", "false", ")", "{", "$", "publicDir", "=", "$", "this", "->", "config", "->", "get", "(", "'publicDir'", ",", "self", "::", "PLUGIN_HANDLE", ")", ";", "$", "publicPath", "=", "$", "this", "->", "ioHelper", "->", "getRealPath", "(", "$", "publicDir", ".", "'/'", ".", "$", "path", ")", ";", "if", "(", "!", "$", "publicPath", "&&", "$", "raiseException", ")", "{", "throw", "new", "Exception", "(", "\"{$publicPath} does not exist\"", ")", ";", "}", "return", "(", "string", ")", "$", "publicPath", ";", "}" ]
Get a path relative to the site public directory @param string $path @param bool $raiseException @return string @throws Exception
[ "Get", "a", "path", "relative", "to", "the", "site", "public", "directory" ]
c2f060f87be351d30e7d00123bb0ac25dd035490
https://github.com/dnunez24/craft-laravel-mix/blob/c2f060f87be351d30e7d00123bb0ac25dd035490/helpers/Mix_PathHelper.php#L45-L55
228,849
dnunez24/craft-laravel-mix
helpers/Mix_PathHelper.php
Mix_PathHelper.prefix
public function prefix(string $path, $char = '/') { if (!$this->startsWith($path, $char)) { $path = "{$char}{$path}"; } return $path; }
php
public function prefix(string $path, $char = '/') { if (!$this->startsWith($path, $char)) { $path = "{$char}{$path}"; } return $path; }
[ "public", "function", "prefix", "(", "string", "$", "path", ",", "$", "char", "=", "'/'", ")", "{", "if", "(", "!", "$", "this", "->", "startsWith", "(", "$", "path", ",", "$", "char", ")", ")", "{", "$", "path", "=", "\"{$char}{$path}\"", ";", "}", "return", "$", "path", ";", "}" ]
Prefix character to path if not present @param string $path @return string
[ "Prefix", "character", "to", "path", "if", "not", "present" ]
c2f060f87be351d30e7d00123bb0ac25dd035490
https://github.com/dnunez24/craft-laravel-mix/blob/c2f060f87be351d30e7d00123bb0ac25dd035490/helpers/Mix_PathHelper.php#L64-L71
228,850
sop/crypto-types
lib/CryptoTypes/Asymmetric/PrivateKey.php
PrivateKey.fromPEM
public static function fromPEM(PEM $pem) { switch ($pem->type()) { case PEM::TYPE_RSA_PRIVATE_KEY: return RSA\RSAPrivateKey::fromDER($pem->data()); case PEM::TYPE_EC_PRIVATE_KEY: return EC\ECPrivateKey::fromDER($pem->data()); case PEM::TYPE_PRIVATE_KEY: return PrivateKeyInfo::fromDER($pem->data())->privateKey(); } throw new \UnexpectedValueException( "PEM type " . $pem->type() . " is not a valid private key."); }
php
public static function fromPEM(PEM $pem) { switch ($pem->type()) { case PEM::TYPE_RSA_PRIVATE_KEY: return RSA\RSAPrivateKey::fromDER($pem->data()); case PEM::TYPE_EC_PRIVATE_KEY: return EC\ECPrivateKey::fromDER($pem->data()); case PEM::TYPE_PRIVATE_KEY: return PrivateKeyInfo::fromDER($pem->data())->privateKey(); } throw new \UnexpectedValueException( "PEM type " . $pem->type() . " is not a valid private key."); }
[ "public", "static", "function", "fromPEM", "(", "PEM", "$", "pem", ")", "{", "switch", "(", "$", "pem", "->", "type", "(", ")", ")", "{", "case", "PEM", "::", "TYPE_RSA_PRIVATE_KEY", ":", "return", "RSA", "\\", "RSAPrivateKey", "::", "fromDER", "(", "$", "pem", "->", "data", "(", ")", ")", ";", "case", "PEM", "::", "TYPE_EC_PRIVATE_KEY", ":", "return", "EC", "\\", "ECPrivateKey", "::", "fromDER", "(", "$", "pem", "->", "data", "(", ")", ")", ";", "case", "PEM", "::", "TYPE_PRIVATE_KEY", ":", "return", "PrivateKeyInfo", "::", "fromDER", "(", "$", "pem", "->", "data", "(", ")", ")", "->", "privateKey", "(", ")", ";", "}", "throw", "new", "\\", "UnexpectedValueException", "(", "\"PEM type \"", ".", "$", "pem", "->", "type", "(", ")", ".", "\" is not a valid private key.\"", ")", ";", "}" ]
Initialize private key from PEM. @param PEM $pem @throws \UnexpectedValueException @return PrivateKey
[ "Initialize", "private", "key", "from", "PEM", "." ]
1d36250a110b07300aeb003a20aeaadfc6445501
https://github.com/sop/crypto-types/blob/1d36250a110b07300aeb003a20aeaadfc6445501/lib/CryptoTypes/Asymmetric/PrivateKey.php#L60-L72
228,851
pinfirestudios/yii2-bugsnag
src/BugsnagErrorHandlerTrait.php
BugsnagErrorHandlerTrait.handleException
public function handleException($exception) { Yii::$app->bugsnag->notifyException($exception); $this->inExceptionHandler = true; parent::handleException($exception); }
php
public function handleException($exception) { Yii::$app->bugsnag->notifyException($exception); $this->inExceptionHandler = true; parent::handleException($exception); }
[ "public", "function", "handleException", "(", "$", "exception", ")", "{", "Yii", "::", "$", "app", "->", "bugsnag", "->", "notifyException", "(", "$", "exception", ")", ";", "$", "this", "->", "inExceptionHandler", "=", "true", ";", "parent", "::", "handleException", "(", "$", "exception", ")", ";", "}" ]
Ensures CB logs are written to the DB if an exception occurs
[ "Ensures", "CB", "logs", "are", "written", "to", "the", "DB", "if", "an", "exception", "occurs" ]
032c061e8293e41917b12fc78b59290f3219d2e4
https://github.com/pinfirestudios/yii2-bugsnag/blob/032c061e8293e41917b12fc78b59290f3219d2e4/src/BugsnagErrorHandlerTrait.php#L39-L45
228,852
pinfirestudios/yii2-bugsnag
src/BugsnagErrorHandlerTrait.php
BugsnagErrorHandlerTrait.handleFatalError
public function handleFatalError() { // When running under codeception, a Yii application won't actually exist, so we just have to eat it here... if (is_object(Yii::$app)) { // Call into Bugsnag client's errorhandler since this will potentially kill the script below Yii::$app->bugsnag->runShutdownHandler(); } parent::handleFatalError(); }
php
public function handleFatalError() { // When running under codeception, a Yii application won't actually exist, so we just have to eat it here... if (is_object(Yii::$app)) { // Call into Bugsnag client's errorhandler since this will potentially kill the script below Yii::$app->bugsnag->runShutdownHandler(); } parent::handleFatalError(); }
[ "public", "function", "handleFatalError", "(", ")", "{", "// When running under codeception, a Yii application won't actually exist, so we just have to eat it here...", "if", "(", "is_object", "(", "Yii", "::", "$", "app", ")", ")", "{", "// Call into Bugsnag client's errorhandler since this will potentially kill the script below ", "Yii", "::", "$", "app", "->", "bugsnag", "->", "runShutdownHandler", "(", ")", ";", "}", "parent", "::", "handleFatalError", "(", ")", ";", "}" ]
Handles fatal PHP errors
[ "Handles", "fatal", "PHP", "errors" ]
032c061e8293e41917b12fc78b59290f3219d2e4
https://github.com/pinfirestudios/yii2-bugsnag/blob/032c061e8293e41917b12fc78b59290f3219d2e4/src/BugsnagErrorHandlerTrait.php#L50-L60
228,853
micmania1/silverstripe-lumberjack
code/extensions/Lumberjack.php
Lumberjack.updateCMSFields
public function updateCMSFields(FieldList $fields) { $excluded = $this->owner->getExcludedSiteTreeClassNames(); if(!empty($excluded)) { $pages = SiteTree::get()->filter(array( 'ParentID' => $this->owner->ID, 'ClassName' => $excluded )); $gridField = new GridField( "ChildPages", $this->getLumberjackTitle(), $pages, GridFieldConfig_Lumberjack::create() ); $tab = new Tab('ChildPages', $this->getLumberjackTitle(), $gridField); $fields->insertAfter($tab, 'Main'); } }
php
public function updateCMSFields(FieldList $fields) { $excluded = $this->owner->getExcludedSiteTreeClassNames(); if(!empty($excluded)) { $pages = SiteTree::get()->filter(array( 'ParentID' => $this->owner->ID, 'ClassName' => $excluded )); $gridField = new GridField( "ChildPages", $this->getLumberjackTitle(), $pages, GridFieldConfig_Lumberjack::create() ); $tab = new Tab('ChildPages', $this->getLumberjackTitle(), $gridField); $fields->insertAfter($tab, 'Main'); } }
[ "public", "function", "updateCMSFields", "(", "FieldList", "$", "fields", ")", "{", "$", "excluded", "=", "$", "this", "->", "owner", "->", "getExcludedSiteTreeClassNames", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "excluded", ")", ")", "{", "$", "pages", "=", "SiteTree", "::", "get", "(", ")", "->", "filter", "(", "array", "(", "'ParentID'", "=>", "$", "this", "->", "owner", "->", "ID", ",", "'ClassName'", "=>", "$", "excluded", ")", ")", ";", "$", "gridField", "=", "new", "GridField", "(", "\"ChildPages\"", ",", "$", "this", "->", "getLumberjackTitle", "(", ")", ",", "$", "pages", ",", "GridFieldConfig_Lumberjack", "::", "create", "(", ")", ")", ";", "$", "tab", "=", "new", "Tab", "(", "'ChildPages'", ",", "$", "this", "->", "getLumberjackTitle", "(", ")", ",", "$", "gridField", ")", ";", "$", "fields", "->", "insertAfter", "(", "$", "tab", ",", "'Main'", ")", ";", "}", "}" ]
This is responsible for adding the child pages tab and gridfield. @param FieldList $fields
[ "This", "is", "responsible", "for", "adding", "the", "child", "pages", "tab", "and", "gridfield", "." ]
5582ea0a799041c21df4ed10d0d05e13e7553fea
https://github.com/micmania1/silverstripe-lumberjack/blob/5582ea0a799041c21df4ed10d0d05e13e7553fea/code/extensions/Lumberjack.php#L37-L54
228,854
contao-bootstrap/templates
src/EventListener/TemplateMappingListener.php
TemplateMappingListener.onParseTemplate
public function onParseTemplate(Template $template): void { if (!$this->environment->isEnabled()) { return; } $this->initialize(); if ($this->isAutoMappingDisabled($template->getName())) { return; } $templateName = $this->getMappedTemplateName($template->getName()); if ($templateName) { $template->setName($templateName); } }
php
public function onParseTemplate(Template $template): void { if (!$this->environment->isEnabled()) { return; } $this->initialize(); if ($this->isAutoMappingDisabled($template->getName())) { return; } $templateName = $this->getMappedTemplateName($template->getName()); if ($templateName) { $template->setName($templateName); } }
[ "public", "function", "onParseTemplate", "(", "Template", "$", "template", ")", ":", "void", "{", "if", "(", "!", "$", "this", "->", "environment", "->", "isEnabled", "(", ")", ")", "{", "return", ";", "}", "$", "this", "->", "initialize", "(", ")", ";", "if", "(", "$", "this", "->", "isAutoMappingDisabled", "(", "$", "template", "->", "getName", "(", ")", ")", ")", "{", "return", ";", "}", "$", "templateName", "=", "$", "this", "->", "getMappedTemplateName", "(", "$", "template", "->", "getName", "(", ")", ")", ";", "if", "(", "$", "templateName", ")", "{", "$", "template", "->", "setName", "(", "$", "templateName", ")", ";", "}", "}" ]
Handle the on parse template hook. @param Template $template The template being parsed. @return void
[ "Handle", "the", "on", "parse", "template", "hook", "." ]
cf507af3a194895923c6b84d97aa224e8b5b6d2f
https://github.com/contao-bootstrap/templates/blob/cf507af3a194895923c6b84d97aa224e8b5b6d2f/src/EventListener/TemplateMappingListener.php#L57-L72
228,855
contao-bootstrap/templates
src/EventListener/TemplateMappingListener.php
TemplateMappingListener.initialize
private function initialize(): void { if ($this->mapping === null) { $this->mapping = $this->environment->getConfig()->get('templates.mapping', []); } }
php
private function initialize(): void { if ($this->mapping === null) { $this->mapping = $this->environment->getConfig()->get('templates.mapping', []); } }
[ "private", "function", "initialize", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "mapping", "===", "null", ")", "{", "$", "this", "->", "mapping", "=", "$", "this", "->", "environment", "->", "getConfig", "(", ")", "->", "get", "(", "'templates.mapping'", ",", "[", "]", ")", ";", "}", "}" ]
Initialize the mapping configuration. @return void
[ "Initialize", "the", "mapping", "configuration", "." ]
cf507af3a194895923c6b84d97aa224e8b5b6d2f
https://github.com/contao-bootstrap/templates/blob/cf507af3a194895923c6b84d97aa224e8b5b6d2f/src/EventListener/TemplateMappingListener.php#L79-L84
228,856
contao-bootstrap/templates
src/EventListener/TemplateMappingListener.php
TemplateMappingListener.getMappedTemplateName
private function getMappedTemplateName(string $templateName): ?string { if (isset($this->mapping['mandatory'][$templateName])) { return $this->mapping['mandatory'][$templateName]; } if (isset($this->mapping['optional'][$templateName])) { return $this->mapping['optional'][$templateName]; } return null; }
php
private function getMappedTemplateName(string $templateName): ?string { if (isset($this->mapping['mandatory'][$templateName])) { return $this->mapping['mandatory'][$templateName]; } if (isset($this->mapping['optional'][$templateName])) { return $this->mapping['optional'][$templateName]; } return null; }
[ "private", "function", "getMappedTemplateName", "(", "string", "$", "templateName", ")", ":", "?", "string", "{", "if", "(", "isset", "(", "$", "this", "->", "mapping", "[", "'mandatory'", "]", "[", "$", "templateName", "]", ")", ")", "{", "return", "$", "this", "->", "mapping", "[", "'mandatory'", "]", "[", "$", "templateName", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "mapping", "[", "'optional'", "]", "[", "$", "templateName", "]", ")", ")", "{", "return", "$", "this", "->", "mapping", "[", "'optional'", "]", "[", "$", "templateName", "]", ";", "}", "return", "null", ";", "}" ]
Get the mapped template name. Returns null if not mapped. @param string $templateName The default template name. @return null|string
[ "Get", "the", "mapped", "template", "name", ".", "Returns", "null", "if", "not", "mapped", "." ]
cf507af3a194895923c6b84d97aa224e8b5b6d2f
https://github.com/contao-bootstrap/templates/blob/cf507af3a194895923c6b84d97aa224e8b5b6d2f/src/EventListener/TemplateMappingListener.php#L93-L104
228,857
contao-bootstrap/templates
src/EventListener/TemplateMappingListener.php
TemplateMappingListener.isAutoMappingDisabled
private function isAutoMappingDisabled(string $templateName): bool { if (isset($this->mapping['mandatory'][$templateName])) { return false; } return !$this->environment->getConfig()->get('templates.auto_mapping', true); }
php
private function isAutoMappingDisabled(string $templateName): bool { if (isset($this->mapping['mandatory'][$templateName])) { return false; } return !$this->environment->getConfig()->get('templates.auto_mapping', true); }
[ "private", "function", "isAutoMappingDisabled", "(", "string", "$", "templateName", ")", ":", "bool", "{", "if", "(", "isset", "(", "$", "this", "->", "mapping", "[", "'mandatory'", "]", "[", "$", "templateName", "]", ")", ")", "{", "return", "false", ";", "}", "return", "!", "$", "this", "->", "environment", "->", "getConfig", "(", ")", "->", "get", "(", "'templates.auto_mapping'", ",", "true", ")", ";", "}" ]
Check if template auto mapping is disabled. @param string $templateName The template name. @return bool
[ "Check", "if", "template", "auto", "mapping", "is", "disabled", "." ]
cf507af3a194895923c6b84d97aa224e8b5b6d2f
https://github.com/contao-bootstrap/templates/blob/cf507af3a194895923c6b84d97aa224e8b5b6d2f/src/EventListener/TemplateMappingListener.php#L113-L120
228,858
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.createFresh
public static function createFresh($dn, $attrs = array()) { if (!is_array($attrs)) { return PEAR::raiseError("Unable to create fresh entry: Parameter \$attrs needs to be an array!"); } $entry = new Net_LDAP2_Entry($attrs, $dn); return $entry; }
php
public static function createFresh($dn, $attrs = array()) { if (!is_array($attrs)) { return PEAR::raiseError("Unable to create fresh entry: Parameter \$attrs needs to be an array!"); } $entry = new Net_LDAP2_Entry($attrs, $dn); return $entry; }
[ "public", "static", "function", "createFresh", "(", "$", "dn", ",", "$", "attrs", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "attrs", ")", ")", "{", "return", "PEAR", "::", "raiseError", "(", "\"Unable to create fresh entry: Parameter \\$attrs needs to be an array!\"", ")", ";", "}", "$", "entry", "=", "new", "Net_LDAP2_Entry", "(", "$", "attrs", ",", "$", "dn", ")", ";", "return", "$", "entry", ";", "}" ]
Creates a fresh entry that may be added to the directory later on Use this method, if you want to initialize a fresh entry. The method should be called statically: $entry = Net_LDAP2_Entry::createFresh(); You should put a 'objectClass' attribute into the $attrs so the directory server knows which object you want to create. However, you may omit this in case you don't want to add this entry to a directory server. The attributes parameter is as following: <code> $attrs = array( 'attribute1' => array('value1', 'value2'), 'attribute2' => 'single value' ); </code> @param string $dn DN of the Entry @param array $attrs Attributes of the entry @static @return Net_LDAP2_Entry|Net_LDAP2_Error
[ "Creates", "a", "fresh", "entry", "that", "may", "be", "added", "to", "the", "directory", "later", "on" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L206-L214
228,859
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.createConnected
public static function createConnected($ldap, $entry) { if (!$ldap instanceof Net_LDAP2) { return PEAR::raiseError("Unable to create connected entry: Parameter \$ldap needs to be a Net_LDAP2 object!"); } if (!is_resource($entry)) { return PEAR::raiseError("Unable to create connected entry: Parameter \$entry needs to be a ldap entry resource!"); } $entry = new Net_LDAP2_Entry($ldap, $entry); return $entry; }
php
public static function createConnected($ldap, $entry) { if (!$ldap instanceof Net_LDAP2) { return PEAR::raiseError("Unable to create connected entry: Parameter \$ldap needs to be a Net_LDAP2 object!"); } if (!is_resource($entry)) { return PEAR::raiseError("Unable to create connected entry: Parameter \$entry needs to be a ldap entry resource!"); } $entry = new Net_LDAP2_Entry($ldap, $entry); return $entry; }
[ "public", "static", "function", "createConnected", "(", "$", "ldap", ",", "$", "entry", ")", "{", "if", "(", "!", "$", "ldap", "instanceof", "Net_LDAP2", ")", "{", "return", "PEAR", "::", "raiseError", "(", "\"Unable to create connected entry: Parameter \\$ldap needs to be a Net_LDAP2 object!\"", ")", ";", "}", "if", "(", "!", "is_resource", "(", "$", "entry", ")", ")", "{", "return", "PEAR", "::", "raiseError", "(", "\"Unable to create connected entry: Parameter \\$entry needs to be a ldap entry resource!\"", ")", ";", "}", "$", "entry", "=", "new", "Net_LDAP2_Entry", "(", "$", "ldap", ",", "$", "entry", ")", ";", "return", "$", "entry", ";", "}" ]
Creates a Net_LDAP2_Entry object out of an ldap entry resource Use this method, if you want to initialize an entry object that is already present in some directory and that you have read manually. Please note, that if you want to create an entry object that represents some already existing entry, you should use {@link createExisting()}. The method should be called statically: $entry = Net_LDAP2_Entry::createConnected(); @param Net_LDAP2 $ldap Net_LDA2 object @param resource $entry PHP LDAP entry resource @static @return Net_LDAP2_Entry|Net_LDAP2_Error
[ "Creates", "a", "Net_LDAP2_Entry", "object", "out", "of", "an", "ldap", "entry", "resource" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L233-L244
228,860
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.createExisting
public static function createExisting($dn, $attrs = array()) { if (!is_array($attrs)) { return PEAR::raiseError("Unable to create entry object: Parameter \$attrs needs to be an array!"); } $entry = Net_LDAP2_Entry::createFresh($dn, $attrs); if ($entry instanceof Net_LDAP2_Error) { return $entry; } else { $entry->markAsNew(false); return $entry; } }
php
public static function createExisting($dn, $attrs = array()) { if (!is_array($attrs)) { return PEAR::raiseError("Unable to create entry object: Parameter \$attrs needs to be an array!"); } $entry = Net_LDAP2_Entry::createFresh($dn, $attrs); if ($entry instanceof Net_LDAP2_Error) { return $entry; } else { $entry->markAsNew(false); return $entry; } }
[ "public", "static", "function", "createExisting", "(", "$", "dn", ",", "$", "attrs", "=", "array", "(", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "attrs", ")", ")", "{", "return", "PEAR", "::", "raiseError", "(", "\"Unable to create entry object: Parameter \\$attrs needs to be an array!\"", ")", ";", "}", "$", "entry", "=", "Net_LDAP2_Entry", "::", "createFresh", "(", "$", "dn", ",", "$", "attrs", ")", ";", "if", "(", "$", "entry", "instanceof", "Net_LDAP2_Error", ")", "{", "return", "$", "entry", ";", "}", "else", "{", "$", "entry", "->", "markAsNew", "(", "false", ")", ";", "return", "$", "entry", ";", "}", "}" ]
Creates an Net_LDAP2_Entry object that is considered already existing Use this method, if you want to modify an already existing entry without fetching it first. In most cases however, it is better to fetch the entry via Net_LDAP2->getEntry()! Please note that you should take care if you construct entries manually with this because you may get weird synchronisation problems. The attributes and values as well as the entry itself are considered existent which may produce errors if you try to modify an entry which doesn't really exist or if you try to overwrite some attribute with an value already present. This method is equal to calling createFresh() and after that markAsNew(FALSE). The method should be called statically: $entry = Net_LDAP2_Entry::createExisting(); The attributes parameter is as following: <code> $attrs = array( 'attribute1' => array('value1', 'value2'), 'attribute2' => 'single value' ); </code> @param string $dn DN of the Entry @param array $attrs Attributes of the entry @static @return Net_LDAP2_Entry|Net_LDAP2_Error
[ "Creates", "an", "Net_LDAP2_Entry", "object", "that", "is", "considered", "already", "existing" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L276-L289
228,861
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.dn
public function dn($dn = null) { if (false == is_null($dn)) { if (is_null($this->_dn) ) { $this->_dn = $dn; } else { $this->_newdn = $dn; } return true; } return (isset($this->_newdn) ? $this->_newdn : $this->currentDN()); }
php
public function dn($dn = null) { if (false == is_null($dn)) { if (is_null($this->_dn) ) { $this->_dn = $dn; } else { $this->_newdn = $dn; } return true; } return (isset($this->_newdn) ? $this->_newdn : $this->currentDN()); }
[ "public", "function", "dn", "(", "$", "dn", "=", "null", ")", "{", "if", "(", "false", "==", "is_null", "(", "$", "dn", ")", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_dn", ")", ")", "{", "$", "this", "->", "_dn", "=", "$", "dn", ";", "}", "else", "{", "$", "this", "->", "_newdn", "=", "$", "dn", ";", "}", "return", "true", ";", "}", "return", "(", "isset", "(", "$", "this", "->", "_newdn", ")", "?", "$", "this", "->", "_newdn", ":", "$", "this", "->", "currentDN", "(", ")", ")", ";", "}" ]
Get or set the distinguished name of the entry If called without an argument the current (or the new DN if set) DN gets returned. If you provide an DN, this entry is moved to the new location specified if a DN existed. If the DN was not set, the DN gets initialized. Call {@link update()} to actually create the new Entry in the directory. To fetch the current active DN after setting a new DN but before an update(), you can use {@link currentDN()} to retrieve the DN that is currently active. Please note that special characters (eg german umlauts) should be encoded using utf8_encode(). You may use {@link Net_LDAP2_Util::canonical_dn()} for properly encoding of the DN. @param string $dn New distinguished name @access public @return string|true Distinguished name (or true if a new DN was provided)
[ "Get", "or", "set", "the", "distinguished", "name", "of", "the", "entry" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L309-L320
228,862
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.setAttributes
protected function setAttributes($attributes = null) { /* * fetch attributes from the server */ if (is_null($attributes) && is_resource($this->_entry) && is_resource($this->_link)) { // fetch schema if ($this->_ldap instanceof Net_LDAP2) { $schema = $this->_ldap->schema(); } // fetch attributes $attributes = array(); do { if (empty($attr)) { $ber = null; $attr = @ldap_first_attribute($this->_link, $this->_entry, $ber); } else { $attr = @ldap_next_attribute($this->_link, $this->_entry, $ber); } if ($attr) { $func = 'ldap_get_values'; // standard function to fetch value // Try to get binary values as binary data if ($schema instanceof Net_LDAP2_Schema) { if ($schema->isBinary($attr)) { $func = 'ldap_get_values_len'; } } // fetch attribute value (needs error checking?) $attributes[$attr] = $func($this->_link, $this->_entry, $attr); } } while ($attr); } /* * set attribute data directly, if passed */ if (is_array($attributes) && count($attributes) > 0) { if (isset($attributes["count"]) && is_numeric($attributes["count"])) { unset($attributes["count"]); } foreach ($attributes as $k => $v) { // attribute names should not be numeric if (is_numeric($k)) { continue; } // map generic attribute name to real one $this->_map[strtolower($k)] = $k; // attribute values should be in an array if (false == is_array($v)) { $v = array($v); } // remove the value count (comes from ldap server) if (isset($v["count"])) { unset($v["count"]); } $this->_attributes[$k] = $v; } } // save a copy for later use $this->_original = $this->_attributes; }
php
protected function setAttributes($attributes = null) { /* * fetch attributes from the server */ if (is_null($attributes) && is_resource($this->_entry) && is_resource($this->_link)) { // fetch schema if ($this->_ldap instanceof Net_LDAP2) { $schema = $this->_ldap->schema(); } // fetch attributes $attributes = array(); do { if (empty($attr)) { $ber = null; $attr = @ldap_first_attribute($this->_link, $this->_entry, $ber); } else { $attr = @ldap_next_attribute($this->_link, $this->_entry, $ber); } if ($attr) { $func = 'ldap_get_values'; // standard function to fetch value // Try to get binary values as binary data if ($schema instanceof Net_LDAP2_Schema) { if ($schema->isBinary($attr)) { $func = 'ldap_get_values_len'; } } // fetch attribute value (needs error checking?) $attributes[$attr] = $func($this->_link, $this->_entry, $attr); } } while ($attr); } /* * set attribute data directly, if passed */ if (is_array($attributes) && count($attributes) > 0) { if (isset($attributes["count"]) && is_numeric($attributes["count"])) { unset($attributes["count"]); } foreach ($attributes as $k => $v) { // attribute names should not be numeric if (is_numeric($k)) { continue; } // map generic attribute name to real one $this->_map[strtolower($k)] = $k; // attribute values should be in an array if (false == is_array($v)) { $v = array($v); } // remove the value count (comes from ldap server) if (isset($v["count"])) { unset($v["count"]); } $this->_attributes[$k] = $v; } } // save a copy for later use $this->_original = $this->_attributes; }
[ "protected", "function", "setAttributes", "(", "$", "attributes", "=", "null", ")", "{", "/*\n * fetch attributes from the server\n */", "if", "(", "is_null", "(", "$", "attributes", ")", "&&", "is_resource", "(", "$", "this", "->", "_entry", ")", "&&", "is_resource", "(", "$", "this", "->", "_link", ")", ")", "{", "// fetch schema", "if", "(", "$", "this", "->", "_ldap", "instanceof", "Net_LDAP2", ")", "{", "$", "schema", "=", "$", "this", "->", "_ldap", "->", "schema", "(", ")", ";", "}", "// fetch attributes", "$", "attributes", "=", "array", "(", ")", ";", "do", "{", "if", "(", "empty", "(", "$", "attr", ")", ")", "{", "$", "ber", "=", "null", ";", "$", "attr", "=", "@", "ldap_first_attribute", "(", "$", "this", "->", "_link", ",", "$", "this", "->", "_entry", ",", "$", "ber", ")", ";", "}", "else", "{", "$", "attr", "=", "@", "ldap_next_attribute", "(", "$", "this", "->", "_link", ",", "$", "this", "->", "_entry", ",", "$", "ber", ")", ";", "}", "if", "(", "$", "attr", ")", "{", "$", "func", "=", "'ldap_get_values'", ";", "// standard function to fetch value", "// Try to get binary values as binary data", "if", "(", "$", "schema", "instanceof", "Net_LDAP2_Schema", ")", "{", "if", "(", "$", "schema", "->", "isBinary", "(", "$", "attr", ")", ")", "{", "$", "func", "=", "'ldap_get_values_len'", ";", "}", "}", "// fetch attribute value (needs error checking?)", "$", "attributes", "[", "$", "attr", "]", "=", "$", "func", "(", "$", "this", "->", "_link", ",", "$", "this", "->", "_entry", ",", "$", "attr", ")", ";", "}", "}", "while", "(", "$", "attr", ")", ";", "}", "/*\n * set attribute data directly, if passed\n */", "if", "(", "is_array", "(", "$", "attributes", ")", "&&", "count", "(", "$", "attributes", ")", ">", "0", ")", "{", "if", "(", "isset", "(", "$", "attributes", "[", "\"count\"", "]", ")", "&&", "is_numeric", "(", "$", "attributes", "[", "\"count\"", "]", ")", ")", "{", "unset", "(", "$", "attributes", "[", "\"count\"", "]", ")", ";", "}", "foreach", "(", "$", "attributes", "as", "$", "k", "=>", "$", "v", ")", "{", "// attribute names should not be numeric", "if", "(", "is_numeric", "(", "$", "k", ")", ")", "{", "continue", ";", "}", "// map generic attribute name to real one", "$", "this", "->", "_map", "[", "strtolower", "(", "$", "k", ")", "]", "=", "$", "k", ";", "// attribute values should be in an array", "if", "(", "false", "==", "is_array", "(", "$", "v", ")", ")", "{", "$", "v", "=", "array", "(", "$", "v", ")", ";", "}", "// remove the value count (comes from ldap server)", "if", "(", "isset", "(", "$", "v", "[", "\"count\"", "]", ")", ")", "{", "unset", "(", "$", "v", "[", "\"count\"", "]", ")", ";", "}", "$", "this", "->", "_attributes", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}", "// save a copy for later use", "$", "this", "->", "_original", "=", "$", "this", "->", "_attributes", ";", "}" ]
Sets the internal attributes array This fetches the values for the attributes from the server. The attribute Syntax will be checked so binary attributes will be returned as binary values. Attributes may be passed directly via the $attributes parameter to setup this entry manually. This overrides attribute fetching from the server. @param array $attributes Attributes to set for this entry @access protected @return void
[ "Sets", "the", "internal", "attributes", "array" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L352-L414
228,863
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.getValues
public function getValues() { $attrs = array(); foreach ($this->_attributes as $attr => $value) { $attrs[$attr] = $this->getValue($attr); } return $attrs; }
php
public function getValues() { $attrs = array(); foreach ($this->_attributes as $attr => $value) { $attrs[$attr] = $this->getValue($attr); } return $attrs; }
[ "public", "function", "getValues", "(", ")", "{", "$", "attrs", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_attributes", "as", "$", "attr", "=>", "$", "value", ")", "{", "$", "attrs", "[", "$", "attr", "]", "=", "$", "this", "->", "getValue", "(", "$", "attr", ")", ";", "}", "return", "$", "attrs", ";", "}" ]
Get the values of all attributes in a hash The returned hash has the form <code>array('attributename' => 'single value', 'attributename' => array('value1', value2', value3'))</code> Only attributes present at the entry will be returned. @access public @return array Hash of all attributes with their values
[ "Get", "the", "values", "of", "all", "attributes", "in", "a", "hash" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L427-L434
228,864
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.getValue
public function getValue($attr, $option = null) { $attr = $this->getAttrName($attr); // return depending on set $options if (!array_key_exists($attr, $this->_attributes)) { // attribute not set switch ($option) { case 'single': $value = false; break; case 'all': $value = array(); break; default: $value = ''; } } else { // attribute present switch ($option) { case 'single': $value = $this->_attributes[$attr][0]; break; case 'all': $value = $this->_attributes[$attr]; break; default: $value = $this->_attributes[$attr]; if (count($value) == 1) { $value = array_shift($value); } } } return $value; }
php
public function getValue($attr, $option = null) { $attr = $this->getAttrName($attr); // return depending on set $options if (!array_key_exists($attr, $this->_attributes)) { // attribute not set switch ($option) { case 'single': $value = false; break; case 'all': $value = array(); break; default: $value = ''; } } else { // attribute present switch ($option) { case 'single': $value = $this->_attributes[$attr][0]; break; case 'all': $value = $this->_attributes[$attr]; break; default: $value = $this->_attributes[$attr]; if (count($value) == 1) { $value = array_shift($value); } } } return $value; }
[ "public", "function", "getValue", "(", "$", "attr", ",", "$", "option", "=", "null", ")", "{", "$", "attr", "=", "$", "this", "->", "getAttrName", "(", "$", "attr", ")", ";", "// return depending on set $options", "if", "(", "!", "array_key_exists", "(", "$", "attr", ",", "$", "this", "->", "_attributes", ")", ")", "{", "// attribute not set", "switch", "(", "$", "option", ")", "{", "case", "'single'", ":", "$", "value", "=", "false", ";", "break", ";", "case", "'all'", ":", "$", "value", "=", "array", "(", ")", ";", "break", ";", "default", ":", "$", "value", "=", "''", ";", "}", "}", "else", "{", "// attribute present", "switch", "(", "$", "option", ")", "{", "case", "'single'", ":", "$", "value", "=", "$", "this", "->", "_attributes", "[", "$", "attr", "]", "[", "0", "]", ";", "break", ";", "case", "'all'", ":", "$", "value", "=", "$", "this", "->", "_attributes", "[", "$", "attr", "]", ";", "break", ";", "default", ":", "$", "value", "=", "$", "this", "->", "_attributes", "[", "$", "attr", "]", ";", "if", "(", "count", "(", "$", "value", ")", "==", "1", ")", "{", "$", "value", "=", "array_shift", "(", "$", "value", ")", ";", "}", "}", "}", "return", "$", "value", ";", "}" ]
Get the value of a specific attribute The first parameter is the name of the attribute The second parameter influences the way the value is returned: 'single': only the first value is returned as string 'all': all values are returned in an array 'default': in all other cases an attribute value with a single value is returned as string, if it has multiple values it is returned as an array If the attribute is not set at this entry (no value or not defined in schema), "false" is returned when $option is 'single', an empty string if 'default', and an empty array when 'all'. You may use Net_LDAP2_Schema->checkAttribute() to see if the attribute is defined for the objectClasses of this entry. @param string $attr Attribute name @param string $option Option @access public @return string|array
[ "Get", "the", "value", "of", "a", "specific", "attribute" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L460-L497
228,865
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.exists
public function exists($attr) { $attr = $this->getAttrName($attr); return array_key_exists($attr, $this->_attributes); }
php
public function exists($attr) { $attr = $this->getAttrName($attr); return array_key_exists($attr, $this->_attributes); }
[ "public", "function", "exists", "(", "$", "attr", ")", "{", "$", "attr", "=", "$", "this", "->", "getAttrName", "(", "$", "attr", ")", ";", "return", "array_key_exists", "(", "$", "attr", ",", "$", "this", "->", "_attributes", ")", ";", "}" ]
Returns whether an attribute exists or not @param string $attr Attribute name @access public @return boolean
[ "Returns", "whether", "an", "attribute", "exists", "or", "not" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L530-L534
228,866
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.add
public function add($attr = array()) { if (false == is_array($attr)) { return PEAR::raiseError("Parameter must be an array"); } if ($this->isNew()) { $this->setAttributes($attr); } foreach ($attr as $k => $v) { $k = $this->getAttrName($k); if (false == is_array($v)) { // Do not add empty values if ($v == null) { continue; } else { $v = array($v); } } // add new values to existing attribute or add new attribute if ($this->exists($k)) { $this->_attributes[$k] = array_unique(array_merge($this->_attributes[$k], $v)); } else { $this->_map[strtolower($k)] = $k; $this->_attributes[$k] = $v; } // save changes for update() if (!isset($this->_changes["add"][$k])) { $this->_changes["add"][$k] = array(); } $this->_changes["add"][$k] = array_unique(array_merge($this->_changes["add"][$k], $v)); } $return = true; return $return; }
php
public function add($attr = array()) { if (false == is_array($attr)) { return PEAR::raiseError("Parameter must be an array"); } if ($this->isNew()) { $this->setAttributes($attr); } foreach ($attr as $k => $v) { $k = $this->getAttrName($k); if (false == is_array($v)) { // Do not add empty values if ($v == null) { continue; } else { $v = array($v); } } // add new values to existing attribute or add new attribute if ($this->exists($k)) { $this->_attributes[$k] = array_unique(array_merge($this->_attributes[$k], $v)); } else { $this->_map[strtolower($k)] = $k; $this->_attributes[$k] = $v; } // save changes for update() if (!isset($this->_changes["add"][$k])) { $this->_changes["add"][$k] = array(); } $this->_changes["add"][$k] = array_unique(array_merge($this->_changes["add"][$k], $v)); } $return = true; return $return; }
[ "public", "function", "add", "(", "$", "attr", "=", "array", "(", ")", ")", "{", "if", "(", "false", "==", "is_array", "(", "$", "attr", ")", ")", "{", "return", "PEAR", "::", "raiseError", "(", "\"Parameter must be an array\"", ")", ";", "}", "if", "(", "$", "this", "->", "isNew", "(", ")", ")", "{", "$", "this", "->", "setAttributes", "(", "$", "attr", ")", ";", "}", "foreach", "(", "$", "attr", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "k", "=", "$", "this", "->", "getAttrName", "(", "$", "k", ")", ";", "if", "(", "false", "==", "is_array", "(", "$", "v", ")", ")", "{", "// Do not add empty values", "if", "(", "$", "v", "==", "null", ")", "{", "continue", ";", "}", "else", "{", "$", "v", "=", "array", "(", "$", "v", ")", ";", "}", "}", "// add new values to existing attribute or add new attribute", "if", "(", "$", "this", "->", "exists", "(", "$", "k", ")", ")", "{", "$", "this", "->", "_attributes", "[", "$", "k", "]", "=", "array_unique", "(", "array_merge", "(", "$", "this", "->", "_attributes", "[", "$", "k", "]", ",", "$", "v", ")", ")", ";", "}", "else", "{", "$", "this", "->", "_map", "[", "strtolower", "(", "$", "k", ")", "]", "=", "$", "k", ";", "$", "this", "->", "_attributes", "[", "$", "k", "]", "=", "$", "v", ";", "}", "// save changes for update()", "if", "(", "!", "isset", "(", "$", "this", "->", "_changes", "[", "\"add\"", "]", "[", "$", "k", "]", ")", ")", "{", "$", "this", "->", "_changes", "[", "\"add\"", "]", "[", "$", "k", "]", "=", "array", "(", ")", ";", "}", "$", "this", "->", "_changes", "[", "\"add\"", "]", "[", "$", "k", "]", "=", "array_unique", "(", "array_merge", "(", "$", "this", "->", "_changes", "[", "\"add\"", "]", "[", "$", "k", "]", ",", "$", "v", ")", ")", ";", "}", "$", "return", "=", "true", ";", "return", "$", "return", ";", "}" ]
Adds a new attribute or a new value to an existing attribute The paramter has to be an array of the form: array('attributename' => 'single value', 'attributename' => array('value1', 'value2)) When the attribute already exists the values will be added, else the attribute will be created. These changes are local to the entry and do not affect the entry on the server until update() is called. Note, that you can add values of attributes that you haven't selected, but if you do so, {@link getValue()} and {@link getValues()} will only return the values you added, _NOT_ all values present on the server. To avoid this, just refetch the entry after calling {@link update()} or select the attribute. @param array $attr Attributes to add @access public @return true|Net_LDAP2_Error
[ "Adds", "a", "new", "attribute", "or", "a", "new", "value", "to", "an", "existing", "attribute" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L556-L590
228,867
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.delete
public function delete($attr = null) { if (is_null($attr)) { $this->_delete = true; return true; } if (is_string($attr)) { $attr = array($attr); } // Make the assumption that attribute names cannot be numeric, // therefore this has to be a simple list of attribute names to delete if (is_numeric(key($attr))) { foreach ($attr as $name) { if (is_array($name)) { // someone mixed modes (list mode but specific values given!) $del_attr_name = array_search($name, $attr); $this->delete(array($del_attr_name => $name)); } else { // mark for update() if this attr was not marked before $name = $this->getAttrName($name); if ($this->exists($name)) { $this->_changes["delete"][$name] = null; unset($this->_attributes[$name]); } } } } else { // Here we have a hash with "attributename" => "value to delete" foreach ($attr as $name => $values) { if (is_int($name)) { // someone mixed modes and gave us just an attribute name $this->delete($values); } else { // mark for update() if this attr was not marked before; // this time it must consider the selected values also $name = $this->getAttrName($name); if ($this->exists($name)) { if (false == is_array($values)) { $values = array($values); } // save values to be deleted if (empty($this->_changes["delete"][$name])) { $this->_changes["delete"][$name] = array(); } $this->_changes["delete"][$name] = array_unique(array_merge($this->_changes["delete"][$name], $values)); foreach ($values as $value) { // find the key for the value that should be deleted $key = array_search($value, $this->_attributes[$name]); if (false !== $key) { // delete the value unset($this->_attributes[$name][$key]); } } } } } } $return = true; return $return; }
php
public function delete($attr = null) { if (is_null($attr)) { $this->_delete = true; return true; } if (is_string($attr)) { $attr = array($attr); } // Make the assumption that attribute names cannot be numeric, // therefore this has to be a simple list of attribute names to delete if (is_numeric(key($attr))) { foreach ($attr as $name) { if (is_array($name)) { // someone mixed modes (list mode but specific values given!) $del_attr_name = array_search($name, $attr); $this->delete(array($del_attr_name => $name)); } else { // mark for update() if this attr was not marked before $name = $this->getAttrName($name); if ($this->exists($name)) { $this->_changes["delete"][$name] = null; unset($this->_attributes[$name]); } } } } else { // Here we have a hash with "attributename" => "value to delete" foreach ($attr as $name => $values) { if (is_int($name)) { // someone mixed modes and gave us just an attribute name $this->delete($values); } else { // mark for update() if this attr was not marked before; // this time it must consider the selected values also $name = $this->getAttrName($name); if ($this->exists($name)) { if (false == is_array($values)) { $values = array($values); } // save values to be deleted if (empty($this->_changes["delete"][$name])) { $this->_changes["delete"][$name] = array(); } $this->_changes["delete"][$name] = array_unique(array_merge($this->_changes["delete"][$name], $values)); foreach ($values as $value) { // find the key for the value that should be deleted $key = array_search($value, $this->_attributes[$name]); if (false !== $key) { // delete the value unset($this->_attributes[$name][$key]); } } } } } } $return = true; return $return; }
[ "public", "function", "delete", "(", "$", "attr", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "attr", ")", ")", "{", "$", "this", "->", "_delete", "=", "true", ";", "return", "true", ";", "}", "if", "(", "is_string", "(", "$", "attr", ")", ")", "{", "$", "attr", "=", "array", "(", "$", "attr", ")", ";", "}", "// Make the assumption that attribute names cannot be numeric,", "// therefore this has to be a simple list of attribute names to delete", "if", "(", "is_numeric", "(", "key", "(", "$", "attr", ")", ")", ")", "{", "foreach", "(", "$", "attr", "as", "$", "name", ")", "{", "if", "(", "is_array", "(", "$", "name", ")", ")", "{", "// someone mixed modes (list mode but specific values given!)", "$", "del_attr_name", "=", "array_search", "(", "$", "name", ",", "$", "attr", ")", ";", "$", "this", "->", "delete", "(", "array", "(", "$", "del_attr_name", "=>", "$", "name", ")", ")", ";", "}", "else", "{", "// mark for update() if this attr was not marked before", "$", "name", "=", "$", "this", "->", "getAttrName", "(", "$", "name", ")", ";", "if", "(", "$", "this", "->", "exists", "(", "$", "name", ")", ")", "{", "$", "this", "->", "_changes", "[", "\"delete\"", "]", "[", "$", "name", "]", "=", "null", ";", "unset", "(", "$", "this", "->", "_attributes", "[", "$", "name", "]", ")", ";", "}", "}", "}", "}", "else", "{", "// Here we have a hash with \"attributename\" => \"value to delete\"", "foreach", "(", "$", "attr", "as", "$", "name", "=>", "$", "values", ")", "{", "if", "(", "is_int", "(", "$", "name", ")", ")", "{", "// someone mixed modes and gave us just an attribute name", "$", "this", "->", "delete", "(", "$", "values", ")", ";", "}", "else", "{", "// mark for update() if this attr was not marked before;", "// this time it must consider the selected values also", "$", "name", "=", "$", "this", "->", "getAttrName", "(", "$", "name", ")", ";", "if", "(", "$", "this", "->", "exists", "(", "$", "name", ")", ")", "{", "if", "(", "false", "==", "is_array", "(", "$", "values", ")", ")", "{", "$", "values", "=", "array", "(", "$", "values", ")", ";", "}", "// save values to be deleted", "if", "(", "empty", "(", "$", "this", "->", "_changes", "[", "\"delete\"", "]", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "_changes", "[", "\"delete\"", "]", "[", "$", "name", "]", "=", "array", "(", ")", ";", "}", "$", "this", "->", "_changes", "[", "\"delete\"", "]", "[", "$", "name", "]", "=", "array_unique", "(", "array_merge", "(", "$", "this", "->", "_changes", "[", "\"delete\"", "]", "[", "$", "name", "]", ",", "$", "values", ")", ")", ";", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "// find the key for the value that should be deleted", "$", "key", "=", "array_search", "(", "$", "value", ",", "$", "this", "->", "_attributes", "[", "$", "name", "]", ")", ";", "if", "(", "false", "!==", "$", "key", ")", "{", "// delete the value", "unset", "(", "$", "this", "->", "_attributes", "[", "$", "name", "]", "[", "$", "key", "]", ")", ";", "}", "}", "}", "}", "}", "}", "$", "return", "=", "true", ";", "return", "$", "return", ";", "}" ]
Deletes an whole attribute or a value or the whole entry The parameter can be one of the following: "attributename" - The attribute as a whole will be deleted array("attributename1", "attributename2) - All given attributes will be deleted array("attributename" => "value") - The value will be deleted array("attributename" => array("value1", "value2") - The given values will be deleted If $attr is null or omitted , then the whole Entry will be deleted! These changes are local to the entry and do not affect the entry on the server until {@link update()} is called. Please note that you must select the attribute (at $ldap->search() for example) to be able to delete values of it, Otherwise {@link update()} will silently fail and remove nothing. @param string|array $attr Attributes to delete (NULL or missing to delete whole entry) @access public @return true
[ "Deletes", "an", "whole", "attribute", "or", "a", "value", "or", "the", "whole", "entry" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L617-L677
228,868
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.replace
public function replace($attr = array(), $force = false) { if (false == is_array($attr)) { return PEAR::raiseError("Parameter must be an array"); } foreach ($attr as $k => $v) { $k = $this->getAttrName($k); if (false == is_array($v)) { // delete attributes with empty values; treat ints as string if (is_int($v)) { $v = "$v"; } if ($v == null) { $this->delete($k); continue; } else { $v = array($v); } } // existing attributes will get replaced if ($this->exists($k) || $force) { $this->_changes["replace"][$k] = $v; $this->_attributes[$k] = $v; } else { // new ones just get added $this->add(array($k => $v)); } } $return = true; return $return; }
php
public function replace($attr = array(), $force = false) { if (false == is_array($attr)) { return PEAR::raiseError("Parameter must be an array"); } foreach ($attr as $k => $v) { $k = $this->getAttrName($k); if (false == is_array($v)) { // delete attributes with empty values; treat ints as string if (is_int($v)) { $v = "$v"; } if ($v == null) { $this->delete($k); continue; } else { $v = array($v); } } // existing attributes will get replaced if ($this->exists($k) || $force) { $this->_changes["replace"][$k] = $v; $this->_attributes[$k] = $v; } else { // new ones just get added $this->add(array($k => $v)); } } $return = true; return $return; }
[ "public", "function", "replace", "(", "$", "attr", "=", "array", "(", ")", ",", "$", "force", "=", "false", ")", "{", "if", "(", "false", "==", "is_array", "(", "$", "attr", ")", ")", "{", "return", "PEAR", "::", "raiseError", "(", "\"Parameter must be an array\"", ")", ";", "}", "foreach", "(", "$", "attr", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "k", "=", "$", "this", "->", "getAttrName", "(", "$", "k", ")", ";", "if", "(", "false", "==", "is_array", "(", "$", "v", ")", ")", "{", "// delete attributes with empty values; treat ints as string", "if", "(", "is_int", "(", "$", "v", ")", ")", "{", "$", "v", "=", "\"$v\"", ";", "}", "if", "(", "$", "v", "==", "null", ")", "{", "$", "this", "->", "delete", "(", "$", "k", ")", ";", "continue", ";", "}", "else", "{", "$", "v", "=", "array", "(", "$", "v", ")", ";", "}", "}", "// existing attributes will get replaced", "if", "(", "$", "this", "->", "exists", "(", "$", "k", ")", "||", "$", "force", ")", "{", "$", "this", "->", "_changes", "[", "\"replace\"", "]", "[", "$", "k", "]", "=", "$", "v", ";", "$", "this", "->", "_attributes", "[", "$", "k", "]", "=", "$", "v", ";", "}", "else", "{", "// new ones just get added", "$", "this", "->", "add", "(", "array", "(", "$", "k", "=>", "$", "v", ")", ")", ";", "}", "}", "$", "return", "=", "true", ";", "return", "$", "return", ";", "}" ]
Replaces attributes or its values The parameter has to an array of the following form: array("attributename" => "single value", "attribute2name" => array("value1", "value2"), "deleteme1" => null, "deleteme2" => "") If the attribute does not yet exist it will be added instead (see also $force). If the attribue value is null, the attribute will de deleted. These changes are local to the entry and do not affect the entry on the server until {@link update()} is called. In some cases you are not allowed to read the attributes value (for example the ActiveDirectory attribute unicodePwd) but are allowed to replace the value. In this case replace() would assume that the attribute is not in the directory yet and tries to add it which will result in an LDAP_TYPE_OR_VALUE_EXISTS error. To force replace mode instead of add, you can set $force to true. @param array $attr Attributes to replace @param bool $force Force replacing mode in case we can't read the attr value but are allowed to replace it @access public @return true|Net_LDAP2_Error
[ "Replaces", "attributes", "or", "its", "values" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L706-L736
228,869
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.getAttrName
protected function getAttrName($attr) { $name = strtolower($attr); if (array_key_exists($name, $this->_map)) { $attr = $this->_map[$name]; } return $attr; }
php
protected function getAttrName($attr) { $name = strtolower($attr); if (array_key_exists($name, $this->_map)) { $attr = $this->_map[$name]; } return $attr; }
[ "protected", "function", "getAttrName", "(", "$", "attr", ")", "{", "$", "name", "=", "strtolower", "(", "$", "attr", ")", ";", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "_map", ")", ")", "{", "$", "attr", "=", "$", "this", "->", "_map", "[", "$", "name", "]", ";", "}", "return", "$", "attr", ";", "}" ]
Returns the right attribute name @param string $attr Name of attribute @access protected @return string The right name of the attribute
[ "Returns", "the", "right", "attribute", "name" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L902-L909
228,870
pear/Net_LDAP2
Net/LDAP2/Entry.php
Net_LDAP2_Entry.setLDAP
public function setLDAP($ldap) { if (!$ldap instanceof Net_LDAP2) { return PEAR::raiseError("LDAP is not a valid Net_LDAP2 object"); } else { $this->_ldap = $ldap; return true; } }
php
public function setLDAP($ldap) { if (!$ldap instanceof Net_LDAP2) { return PEAR::raiseError("LDAP is not a valid Net_LDAP2 object"); } else { $this->_ldap = $ldap; return true; } }
[ "public", "function", "setLDAP", "(", "$", "ldap", ")", "{", "if", "(", "!", "$", "ldap", "instanceof", "Net_LDAP2", ")", "{", "return", "PEAR", "::", "raiseError", "(", "\"LDAP is not a valid Net_LDAP2 object\"", ")", ";", "}", "else", "{", "$", "this", "->", "_ldap", "=", "$", "ldap", ";", "return", "true", ";", "}", "}" ]
Sets a reference to the LDAP-Object of this entry After setting a Net_LDAP2 object, calling update() will use that object for updating directory contents. Use this to dynamicly switch directorys. @param Net_LDAP2 $ldap Net_LDAP2 object that this entry should be connected to @access public @return true|Net_LDAP2_Error
[ "Sets", "a", "reference", "to", "the", "LDAP", "-", "Object", "of", "this", "entry" ]
38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8
https://github.com/pear/Net_LDAP2/blob/38f1b22a96dfbd7ec53852f0e1e7ec1a9a5eb0e8/Net/LDAP2/Entry.php#L938-L946
228,871
AOEpeople/StackFormation
src/AwsInspector/Ssh/Connection.php
Connection.closeMuxConnections
public static function closeMuxConnections() { $count = count(self::$multiplexedConnections); if ($count) { echo "Closing $count multiplexed connections...\n"; foreach (self::$multiplexedConnections as $key => $connection) { exec("ssh -O stop -o LogLevel=QUIET -S $connection > /dev/null 2>&1"); unset(self::$multiplexedConnections[$key]); } } }
php
public static function closeMuxConnections() { $count = count(self::$multiplexedConnections); if ($count) { echo "Closing $count multiplexed connections...\n"; foreach (self::$multiplexedConnections as $key => $connection) { exec("ssh -O stop -o LogLevel=QUIET -S $connection > /dev/null 2>&1"); unset(self::$multiplexedConnections[$key]); } } }
[ "public", "static", "function", "closeMuxConnections", "(", ")", "{", "$", "count", "=", "count", "(", "self", "::", "$", "multiplexedConnections", ")", ";", "if", "(", "$", "count", ")", "{", "echo", "\"Closing $count multiplexed connections...\\n\"", ";", "foreach", "(", "self", "::", "$", "multiplexedConnections", "as", "$", "key", "=>", "$", "connection", ")", "{", "exec", "(", "\"ssh -O stop -o LogLevel=QUIET -S $connection > /dev/null 2>&1\"", ")", ";", "unset", "(", "self", "::", "$", "multiplexedConnections", "[", "$", "key", "]", ")", ";", "}", "}", "}" ]
Close all multiplexed connections
[ "Close", "all", "multiplexed", "connections" ]
5332dbbe54653e50d610cbaf75fb865c68aa2f1e
https://github.com/AOEpeople/StackFormation/blob/5332dbbe54653e50d610cbaf75fb865c68aa2f1e/src/AwsInspector/Ssh/Connection.php#L106-L116
228,872
AOEpeople/StackFormation
src/AwsInspector/Ssh/Connection.php
Connection.exec
public function exec($command, $asUser=null) { $command = new Command($this, $command, $asUser); return $command->exec(); }
php
public function exec($command, $asUser=null) { $command = new Command($this, $command, $asUser); return $command->exec(); }
[ "public", "function", "exec", "(", "$", "command", ",", "$", "asUser", "=", "null", ")", "{", "$", "command", "=", "new", "Command", "(", "$", "this", ",", "$", "command", ",", "$", "asUser", ")", ";", "return", "$", "command", "->", "exec", "(", ")", ";", "}" ]
Execute command on this connection @param string $command @param string $asUser @return array
[ "Execute", "command", "on", "this", "connection" ]
5332dbbe54653e50d610cbaf75fb865c68aa2f1e
https://github.com/AOEpeople/StackFormation/blob/5332dbbe54653e50d610cbaf75fb865c68aa2f1e/src/AwsInspector/Ssh/Connection.php#L125-L129
228,873
chewett/php-uglifyjs
src/JSUglify.php
JSUglify.uglify
public function uglify(array $files, $outputFilename, array $options = [], $finalJsHeaderFilename=null) { foreach($files as $filename) { if(!is_readable($filename)) { throw new UglifyJSException("Filename " . $filename . " is not readable"); } } $optionsString = $this->validateOptions($options); $fileNames = implode(' ', array_map('escapeshellarg', $files)); $tmpUglifyJsOutput = tempnam(sys_get_temp_dir(), "uglify_js_intermediate_out_"); $safeShellTmpUglifyJsFilename = escapeshellarg($tmpUglifyJsOutput); $commandString = $this->uglifyBinaryPath . " {$fileNames} --output {$safeShellTmpUglifyJsFilename} {$optionsString}"; exec($commandString, $output, $returnCode); if($returnCode !== 0) { throw new UglifyJSException("Failed to run uglifyjs, something went wrong... command: " . $commandString); } if($finalJsHeaderFilename) { //If we have provided a header filename then we are going to get the uglified file then prepend the data $context = stream_context_create(); //Open both files in stream mode so we dont load the entire file into memory, streams are the best! $uglifyJsOutputFileHandler = fopen($tmpUglifyJsOutput, 'r', false, $context); $jsHeaderFileHandler = fopen($finalJsHeaderFilename, 'r',false, $context); $tmpFinalOutput = tempnam(sys_get_temp_dir(), 'php_uglify_js_out_'); file_put_contents($tmpFinalOutput, $jsHeaderFileHandler); file_put_contents($tmpFinalOutput, $uglifyJsOutputFileHandler, FILE_APPEND); //Close unlink and move the files we dont need fclose($uglifyJsOutputFileHandler); fclose($jsHeaderFileHandler); unlink($tmpUglifyJsOutput); rename($tmpFinalOutput, $outputFilename); }else{ //Dont try and add any files, just move the temporary file into the final location rename($tmpUglifyJsOutput, $outputFilename); } return $output; }
php
public function uglify(array $files, $outputFilename, array $options = [], $finalJsHeaderFilename=null) { foreach($files as $filename) { if(!is_readable($filename)) { throw new UglifyJSException("Filename " . $filename . " is not readable"); } } $optionsString = $this->validateOptions($options); $fileNames = implode(' ', array_map('escapeshellarg', $files)); $tmpUglifyJsOutput = tempnam(sys_get_temp_dir(), "uglify_js_intermediate_out_"); $safeShellTmpUglifyJsFilename = escapeshellarg($tmpUglifyJsOutput); $commandString = $this->uglifyBinaryPath . " {$fileNames} --output {$safeShellTmpUglifyJsFilename} {$optionsString}"; exec($commandString, $output, $returnCode); if($returnCode !== 0) { throw new UglifyJSException("Failed to run uglifyjs, something went wrong... command: " . $commandString); } if($finalJsHeaderFilename) { //If we have provided a header filename then we are going to get the uglified file then prepend the data $context = stream_context_create(); //Open both files in stream mode so we dont load the entire file into memory, streams are the best! $uglifyJsOutputFileHandler = fopen($tmpUglifyJsOutput, 'r', false, $context); $jsHeaderFileHandler = fopen($finalJsHeaderFilename, 'r',false, $context); $tmpFinalOutput = tempnam(sys_get_temp_dir(), 'php_uglify_js_out_'); file_put_contents($tmpFinalOutput, $jsHeaderFileHandler); file_put_contents($tmpFinalOutput, $uglifyJsOutputFileHandler, FILE_APPEND); //Close unlink and move the files we dont need fclose($uglifyJsOutputFileHandler); fclose($jsHeaderFileHandler); unlink($tmpUglifyJsOutput); rename($tmpFinalOutput, $outputFilename); }else{ //Dont try and add any files, just move the temporary file into the final location rename($tmpUglifyJsOutput, $outputFilename); } return $output; }
[ "public", "function", "uglify", "(", "array", "$", "files", ",", "$", "outputFilename", ",", "array", "$", "options", "=", "[", "]", ",", "$", "finalJsHeaderFilename", "=", "null", ")", "{", "foreach", "(", "$", "files", "as", "$", "filename", ")", "{", "if", "(", "!", "is_readable", "(", "$", "filename", ")", ")", "{", "throw", "new", "UglifyJSException", "(", "\"Filename \"", ".", "$", "filename", ".", "\" is not readable\"", ")", ";", "}", "}", "$", "optionsString", "=", "$", "this", "->", "validateOptions", "(", "$", "options", ")", ";", "$", "fileNames", "=", "implode", "(", "' '", ",", "array_map", "(", "'escapeshellarg'", ",", "$", "files", ")", ")", ";", "$", "tmpUglifyJsOutput", "=", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", "\"uglify_js_intermediate_out_\"", ")", ";", "$", "safeShellTmpUglifyJsFilename", "=", "escapeshellarg", "(", "$", "tmpUglifyJsOutput", ")", ";", "$", "commandString", "=", "$", "this", "->", "uglifyBinaryPath", ".", "\" {$fileNames} --output {$safeShellTmpUglifyJsFilename} {$optionsString}\"", ";", "exec", "(", "$", "commandString", ",", "$", "output", ",", "$", "returnCode", ")", ";", "if", "(", "$", "returnCode", "!==", "0", ")", "{", "throw", "new", "UglifyJSException", "(", "\"Failed to run uglifyjs, something went wrong... command: \"", ".", "$", "commandString", ")", ";", "}", "if", "(", "$", "finalJsHeaderFilename", ")", "{", "//If we have provided a header filename then we are going to get the uglified file then prepend the data", "$", "context", "=", "stream_context_create", "(", ")", ";", "//Open both files in stream mode so we dont load the entire file into memory, streams are the best!", "$", "uglifyJsOutputFileHandler", "=", "fopen", "(", "$", "tmpUglifyJsOutput", ",", "'r'", ",", "false", ",", "$", "context", ")", ";", "$", "jsHeaderFileHandler", "=", "fopen", "(", "$", "finalJsHeaderFilename", ",", "'r'", ",", "false", ",", "$", "context", ")", ";", "$", "tmpFinalOutput", "=", "tempnam", "(", "sys_get_temp_dir", "(", ")", ",", "'php_uglify_js_out_'", ")", ";", "file_put_contents", "(", "$", "tmpFinalOutput", ",", "$", "jsHeaderFileHandler", ")", ";", "file_put_contents", "(", "$", "tmpFinalOutput", ",", "$", "uglifyJsOutputFileHandler", ",", "FILE_APPEND", ")", ";", "//Close unlink and move the files we dont need", "fclose", "(", "$", "uglifyJsOutputFileHandler", ")", ";", "fclose", "(", "$", "jsHeaderFileHandler", ")", ";", "unlink", "(", "$", "tmpUglifyJsOutput", ")", ";", "rename", "(", "$", "tmpFinalOutput", ",", "$", "outputFilename", ")", ";", "}", "else", "{", "//Dont try and add any files, just move the temporary file into the final location", "rename", "(", "$", "tmpUglifyJsOutput", ",", "$", "outputFilename", ")", ";", "}", "return", "$", "output", ";", "}" ]
Calls the uglifyjs script and minifies the Javascript @param array $files List of filenames to minimise @param string $outputFilename Filename to output the javascript to @param array $options Options to pass to the script @param string|null $finalJsHeaderFilename Path to file of header to place at the top of the JS file @return string Full output of the executable @throws UglifyJSException Thrown when something goes wrong with running the script
[ "Calls", "the", "uglifyjs", "script", "and", "minifies", "the", "Javascript" ]
fad3be0056e96ff92def2c66bd1e413197fbfd10
https://github.com/chewett/php-uglifyjs/blob/fad3be0056e96ff92def2c66bd1e413197fbfd10/src/JSUglify.php#L84-L125
228,874
lekoala/silverstripe-form-extras
code/fields/BaseUploadField.php
BaseUploadField.createForClass
public static function createForClass( $class, $name, $title = null, \SS_List $items = null ) { $folderName = self::getFolderForClass($class, $name); $inst = new static($name, $title, $items); $inst->setFolderName($folderName . '/' . $name); return $inst; }
php
public static function createForClass( $class, $name, $title = null, \SS_List $items = null ) { $folderName = self::getFolderForClass($class, $name); $inst = new static($name, $title, $items); $inst->setFolderName($folderName . '/' . $name); return $inst; }
[ "public", "static", "function", "createForClass", "(", "$", "class", ",", "$", "name", ",", "$", "title", "=", "null", ",", "\\", "SS_List", "$", "items", "=", "null", ")", "{", "$", "folderName", "=", "self", "::", "getFolderForClass", "(", "$", "class", ",", "$", "name", ")", ";", "$", "inst", "=", "new", "static", "(", "$", "name", ",", "$", "title", ",", "$", "items", ")", ";", "$", "inst", "->", "setFolderName", "(", "$", "folderName", ".", "'/'", ".", "$", "name", ")", ";", "return", "$", "inst", ";", "}" ]
Return an instance of UploadField with the folder name already set up @param object|string $class @param string $name @param string $title @param \SS_List $items @return \static
[ "Return", "an", "instance", "of", "UploadField", "with", "the", "folder", "name", "already", "set", "up" ]
e0c1200792af8e6cea916e1999c73cf8408c6dd2
https://github.com/lekoala/silverstripe-form-extras/blob/e0c1200792af8e6cea916e1999c73cf8408c6dd2/code/fields/BaseUploadField.php#L25-L37
228,875
lekoala/silverstripe-form-extras
code/fields/BaseUploadField.php
BaseUploadField.getFolderForClass
public static function getFolderForClass($class) { $folderName = 'Uploads'; if (is_object($class)) { if (method_exists($class, 'hasMethod') && $class->hasMethod('BaseFolder')) { $folderName = $class->BaseFolder(); } elseif ($class instanceof Page) { $folderName = get_class($class); } elseif ($class instanceof DataObject) { $folderName = $class->baseTable(); } elseif ($class instanceof DataExtension) { $folderName = $class->getOwner()->baseTable(); } else { $folderName = get_class($class); } } elseif (is_string($class)) { $folderName = $class; } if (class_exists('Subsite') && Config::inst()->get( __CLASS__, 'use_subsite_integration' )) { $subsite = Subsite::currentSubsite(); if ($subsite) { // Subsite extras integration$ if ($subsite->hasField('BaseFolder')) { $baseFolder = $subsite->BaseFolder; } else { $filter = new URLSegmentFilter(); $baseFolder = $filter->filter($subsite->getTitle()); $baseFolder = str_replace( ' ', '', ucwords(str_replace('-', ' ', $baseFolder)) ); } if (!empty($baseFolder)) { $folderName = $baseFolder . '/' . $folderName; } } } return $folderName; }
php
public static function getFolderForClass($class) { $folderName = 'Uploads'; if (is_object($class)) { if (method_exists($class, 'hasMethod') && $class->hasMethod('BaseFolder')) { $folderName = $class->BaseFolder(); } elseif ($class instanceof Page) { $folderName = get_class($class); } elseif ($class instanceof DataObject) { $folderName = $class->baseTable(); } elseif ($class instanceof DataExtension) { $folderName = $class->getOwner()->baseTable(); } else { $folderName = get_class($class); } } elseif (is_string($class)) { $folderName = $class; } if (class_exists('Subsite') && Config::inst()->get( __CLASS__, 'use_subsite_integration' )) { $subsite = Subsite::currentSubsite(); if ($subsite) { // Subsite extras integration$ if ($subsite->hasField('BaseFolder')) { $baseFolder = $subsite->BaseFolder; } else { $filter = new URLSegmentFilter(); $baseFolder = $filter->filter($subsite->getTitle()); $baseFolder = str_replace( ' ', '', ucwords(str_replace('-', ' ', $baseFolder)) ); } if (!empty($baseFolder)) { $folderName = $baseFolder . '/' . $folderName; } } } return $folderName; }
[ "public", "static", "function", "getFolderForClass", "(", "$", "class", ")", "{", "$", "folderName", "=", "'Uploads'", ";", "if", "(", "is_object", "(", "$", "class", ")", ")", "{", "if", "(", "method_exists", "(", "$", "class", ",", "'hasMethod'", ")", "&&", "$", "class", "->", "hasMethod", "(", "'BaseFolder'", ")", ")", "{", "$", "folderName", "=", "$", "class", "->", "BaseFolder", "(", ")", ";", "}", "elseif", "(", "$", "class", "instanceof", "Page", ")", "{", "$", "folderName", "=", "get_class", "(", "$", "class", ")", ";", "}", "elseif", "(", "$", "class", "instanceof", "DataObject", ")", "{", "$", "folderName", "=", "$", "class", "->", "baseTable", "(", ")", ";", "}", "elseif", "(", "$", "class", "instanceof", "DataExtension", ")", "{", "$", "folderName", "=", "$", "class", "->", "getOwner", "(", ")", "->", "baseTable", "(", ")", ";", "}", "else", "{", "$", "folderName", "=", "get_class", "(", "$", "class", ")", ";", "}", "}", "elseif", "(", "is_string", "(", "$", "class", ")", ")", "{", "$", "folderName", "=", "$", "class", ";", "}", "if", "(", "class_exists", "(", "'Subsite'", ")", "&&", "Config", "::", "inst", "(", ")", "->", "get", "(", "__CLASS__", ",", "'use_subsite_integration'", ")", ")", "{", "$", "subsite", "=", "Subsite", "::", "currentSubsite", "(", ")", ";", "if", "(", "$", "subsite", ")", "{", "// Subsite extras integration$", "if", "(", "$", "subsite", "->", "hasField", "(", "'BaseFolder'", ")", ")", "{", "$", "baseFolder", "=", "$", "subsite", "->", "BaseFolder", ";", "}", "else", "{", "$", "filter", "=", "new", "URLSegmentFilter", "(", ")", ";", "$", "baseFolder", "=", "$", "filter", "->", "filter", "(", "$", "subsite", "->", "getTitle", "(", ")", ")", ";", "$", "baseFolder", "=", "str_replace", "(", "' '", ",", "''", ",", "ucwords", "(", "str_replace", "(", "'-'", ",", "' '", ",", "$", "baseFolder", ")", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "baseFolder", ")", ")", "{", "$", "folderName", "=", "$", "baseFolder", ".", "'/'", ".", "$", "folderName", ";", "}", "}", "}", "return", "$", "folderName", ";", "}" ]
Get folder for a given class @param mixed $class @return string
[ "Get", "folder", "for", "a", "given", "class" ]
e0c1200792af8e6cea916e1999c73cf8408c6dd2
https://github.com/lekoala/silverstripe-form-extras/blob/e0c1200792af8e6cea916e1999c73cf8408c6dd2/code/fields/BaseUploadField.php#L45-L96
228,876
slickframework/slick
src/Slick/Form/Factory.php
Factory.newForm
public function newForm($name, array $definition) { $container = ContainerBuilder::buildContainer([ $name => Definition::object('Slick\Form\Form') ->constructor([$name]) ]); $this->_form = $container->get($name); foreach ($definition as $name => $element) { $this->addElement($this->_form, $name, $element); } return $this->_form; }
php
public function newForm($name, array $definition) { $container = ContainerBuilder::buildContainer([ $name => Definition::object('Slick\Form\Form') ->constructor([$name]) ]); $this->_form = $container->get($name); foreach ($definition as $name => $element) { $this->addElement($this->_form, $name, $element); } return $this->_form; }
[ "public", "function", "newForm", "(", "$", "name", ",", "array", "$", "definition", ")", "{", "$", "container", "=", "ContainerBuilder", "::", "buildContainer", "(", "[", "$", "name", "=>", "Definition", "::", "object", "(", "'Slick\\Form\\Form'", ")", "->", "constructor", "(", "[", "$", "name", "]", ")", "]", ")", ";", "$", "this", "->", "_form", "=", "$", "container", "->", "get", "(", "$", "name", ")", ";", "foreach", "(", "$", "definition", "as", "$", "name", "=>", "$", "element", ")", "{", "$", "this", "->", "addElement", "(", "$", "this", "->", "_form", ",", "$", "name", ",", "$", "element", ")", ";", "}", "return", "$", "this", "->", "_form", ";", "}" ]
Creates a new form object @param string $name @param array $definition @return Form
[ "Creates", "a", "new", "form", "object" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Form/Factory.php#L83-L96
228,877
slickframework/slick
src/Slick/Form/Factory.php
Factory.addElement
public function addElement(FieldsetInterface &$form, $name, $data) { if ($data['type'] == 'fieldset') { $fieldset = new Fieldset(['name' => $name]); foreach ($data['elements'] as $key => $def) { $this->addElement($fieldset, $key, $def); } $form->add($fieldset); } else { if (array_key_exists($data['type'], static::$_elementAlias)) { $class = static::$_elementAlias[$data['type']]; } else if ( is_subclass_of($data['type'], 'Slick\Form\ElementInterface') ) { $class = $data['type']; } else { throw new Exception\UnknownElementException( "'{$data['type']}' is not a known alias or an implementation of " . "Slick\\Form\\ElementInterface interface" ); } /** @var Element $element */ $element = new $class(['name' => $name]); if (isset($data['input'])) { $element->input = InputFilterFactory::createInput( $data['input'], $element->getName() ); } if (!empty($data['validate'])) { $this->addValidation($element, $data['validate']); } foreach (array_keys($this->_elementProperties) as $key) { if (isset($data[$key])) { $element->$key = $data[$key]; } } $form->add($element); } }
php
public function addElement(FieldsetInterface &$form, $name, $data) { if ($data['type'] == 'fieldset') { $fieldset = new Fieldset(['name' => $name]); foreach ($data['elements'] as $key => $def) { $this->addElement($fieldset, $key, $def); } $form->add($fieldset); } else { if (array_key_exists($data['type'], static::$_elementAlias)) { $class = static::$_elementAlias[$data['type']]; } else if ( is_subclass_of($data['type'], 'Slick\Form\ElementInterface') ) { $class = $data['type']; } else { throw new Exception\UnknownElementException( "'{$data['type']}' is not a known alias or an implementation of " . "Slick\\Form\\ElementInterface interface" ); } /** @var Element $element */ $element = new $class(['name' => $name]); if (isset($data['input'])) { $element->input = InputFilterFactory::createInput( $data['input'], $element->getName() ); } if (!empty($data['validate'])) { $this->addValidation($element, $data['validate']); } foreach (array_keys($this->_elementProperties) as $key) { if (isset($data[$key])) { $element->$key = $data[$key]; } } $form->add($element); } }
[ "public", "function", "addElement", "(", "FieldsetInterface", "&", "$", "form", ",", "$", "name", ",", "$", "data", ")", "{", "if", "(", "$", "data", "[", "'type'", "]", "==", "'fieldset'", ")", "{", "$", "fieldset", "=", "new", "Fieldset", "(", "[", "'name'", "=>", "$", "name", "]", ")", ";", "foreach", "(", "$", "data", "[", "'elements'", "]", "as", "$", "key", "=>", "$", "def", ")", "{", "$", "this", "->", "addElement", "(", "$", "fieldset", ",", "$", "key", ",", "$", "def", ")", ";", "}", "$", "form", "->", "add", "(", "$", "fieldset", ")", ";", "}", "else", "{", "if", "(", "array_key_exists", "(", "$", "data", "[", "'type'", "]", ",", "static", "::", "$", "_elementAlias", ")", ")", "{", "$", "class", "=", "static", "::", "$", "_elementAlias", "[", "$", "data", "[", "'type'", "]", "]", ";", "}", "else", "if", "(", "is_subclass_of", "(", "$", "data", "[", "'type'", "]", ",", "'Slick\\Form\\ElementInterface'", ")", ")", "{", "$", "class", "=", "$", "data", "[", "'type'", "]", ";", "}", "else", "{", "throw", "new", "Exception", "\\", "UnknownElementException", "(", "\"'{$data['type']}' is not a known alias or an implementation of \"", ".", "\"Slick\\\\Form\\\\ElementInterface interface\"", ")", ";", "}", "/** @var Element $element */", "$", "element", "=", "new", "$", "class", "(", "[", "'name'", "=>", "$", "name", "]", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'input'", "]", ")", ")", "{", "$", "element", "->", "input", "=", "InputFilterFactory", "::", "createInput", "(", "$", "data", "[", "'input'", "]", ",", "$", "element", "->", "getName", "(", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "[", "'validate'", "]", ")", ")", "{", "$", "this", "->", "addValidation", "(", "$", "element", ",", "$", "data", "[", "'validate'", "]", ")", ";", "}", "foreach", "(", "array_keys", "(", "$", "this", "->", "_elementProperties", ")", "as", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "key", "]", ")", ")", "{", "$", "element", "->", "$", "key", "=", "$", "data", "[", "$", "key", "]", ";", "}", "}", "$", "form", "->", "add", "(", "$", "element", ")", ";", "}", "}" ]
Adds an element to the form @param FieldsetInterface $form @param string $name @param array $data @throws Exception\UnknownElementException
[ "Adds", "an", "element", "to", "the", "form" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Form/Factory.php#L107-L151
228,878
slickframework/slick
src/Slick/Form/Factory.php
Factory.addValidation
public function addValidation(Element &$element, array $data) { foreach ($data as $key => $value) { if (is_string($key)) { $element->getInput()->getValidatorChain()->add(StaticValidator::create($key, $value)); $this->checkRequired($key, $element); } else { $element->getInput()->getValidatorChain()->add(StaticValidator::create($value)); $this->checkRequired($value, $element); } } }
php
public function addValidation(Element &$element, array $data) { foreach ($data as $key => $value) { if (is_string($key)) { $element->getInput()->getValidatorChain()->add(StaticValidator::create($key, $value)); $this->checkRequired($key, $element); } else { $element->getInput()->getValidatorChain()->add(StaticValidator::create($value)); $this->checkRequired($value, $element); } } }
[ "public", "function", "addValidation", "(", "Element", "&", "$", "element", ",", "array", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_string", "(", "$", "key", ")", ")", "{", "$", "element", "->", "getInput", "(", ")", "->", "getValidatorChain", "(", ")", "->", "add", "(", "StaticValidator", "::", "create", "(", "$", "key", ",", "$", "value", ")", ")", ";", "$", "this", "->", "checkRequired", "(", "$", "key", ",", "$", "element", ")", ";", "}", "else", "{", "$", "element", "->", "getInput", "(", ")", "->", "getValidatorChain", "(", ")", "->", "add", "(", "StaticValidator", "::", "create", "(", "$", "value", ")", ")", ";", "$", "this", "->", "checkRequired", "(", "$", "value", ",", "$", "element", ")", ";", "}", "}", "}" ]
Add validator to the provided element @param Element $element @param array $data
[ "Add", "validator", "to", "the", "provided", "element" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Form/Factory.php#L159-L170
228,879
slickframework/slick
src/Slick/Form/Factory.php
Factory.checkRequired
public function checkRequired($validator, Element &$element) { if (in_array($validator, ['notEmpty'])) { $element->getInput()->required = true; $element->getInput()->allowEmpty = false; } }
php
public function checkRequired($validator, Element &$element) { if (in_array($validator, ['notEmpty'])) { $element->getInput()->required = true; $element->getInput()->allowEmpty = false; } }
[ "public", "function", "checkRequired", "(", "$", "validator", ",", "Element", "&", "$", "element", ")", "{", "if", "(", "in_array", "(", "$", "validator", ",", "[", "'notEmpty'", "]", ")", ")", "{", "$", "element", "->", "getInput", "(", ")", "->", "required", "=", "true", ";", "$", "element", "->", "getInput", "(", ")", "->", "allowEmpty", "=", "false", ";", "}", "}" ]
Check required flag based on validator name @param $validator @param Element $element
[ "Check", "required", "flag", "based", "on", "validator", "name" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Form/Factory.php#L178-L184
228,880
inc2734/wp-breadcrumbs
src/Controller/Single.php
Single.set_post_type_archive
protected function set_post_type_archive( $post_type_object ) { $label = $post_type_object->label; $this->set( $label, $this->get_post_type_archive_link( $post_type_object->name ) ); }
php
protected function set_post_type_archive( $post_type_object ) { $label = $post_type_object->label; $this->set( $label, $this->get_post_type_archive_link( $post_type_object->name ) ); }
[ "protected", "function", "set_post_type_archive", "(", "$", "post_type_object", ")", "{", "$", "label", "=", "$", "post_type_object", "->", "label", ";", "$", "this", "->", "set", "(", "$", "label", ",", "$", "this", "->", "get_post_type_archive_link", "(", "$", "post_type_object", "->", "name", ")", ")", ";", "}" ]
Sets Breadcrumbs items of post type archive @param object $post_type_object @return void
[ "Sets", "Breadcrumbs", "items", "of", "post", "type", "archive" ]
fb904467f5ab3ec18c17c7420d1cbd98248367d8
https://github.com/inc2734/wp-breadcrumbs/blob/fb904467f5ab3ec18c17c7420d1cbd98248367d8/src/Controller/Single.php#L44-L47
228,881
inc2734/wp-breadcrumbs
src/Controller/Single.php
Single.set_terms
protected function set_terms( $post_type_object ) { $taxonomies = get_object_taxonomies( $post_type_object->name ); if ( ! $taxonomies ) { return; } $taxonomy = apply_filters( 'inc2734_wp_breadcrumbs_main_taxonomy', array_shift( $taxonomies ), $taxonomies, $post_type_object ); $terms = get_the_terms( get_the_ID(), $taxonomy ); if ( ! $terms ) { return; } $term = array_shift( $terms ); $this->set_ancestors( $term->term_id, $taxonomy ); $this->set( $term->name, get_term_link( $term ) ); }
php
protected function set_terms( $post_type_object ) { $taxonomies = get_object_taxonomies( $post_type_object->name ); if ( ! $taxonomies ) { return; } $taxonomy = apply_filters( 'inc2734_wp_breadcrumbs_main_taxonomy', array_shift( $taxonomies ), $taxonomies, $post_type_object ); $terms = get_the_terms( get_the_ID(), $taxonomy ); if ( ! $terms ) { return; } $term = array_shift( $terms ); $this->set_ancestors( $term->term_id, $taxonomy ); $this->set( $term->name, get_term_link( $term ) ); }
[ "protected", "function", "set_terms", "(", "$", "post_type_object", ")", "{", "$", "taxonomies", "=", "get_object_taxonomies", "(", "$", "post_type_object", "->", "name", ")", ";", "if", "(", "!", "$", "taxonomies", ")", "{", "return", ";", "}", "$", "taxonomy", "=", "apply_filters", "(", "'inc2734_wp_breadcrumbs_main_taxonomy'", ",", "array_shift", "(", "$", "taxonomies", ")", ",", "$", "taxonomies", ",", "$", "post_type_object", ")", ";", "$", "terms", "=", "get_the_terms", "(", "get_the_ID", "(", ")", ",", "$", "taxonomy", ")", ";", "if", "(", "!", "$", "terms", ")", "{", "return", ";", "}", "$", "term", "=", "array_shift", "(", "$", "terms", ")", ";", "$", "this", "->", "set_ancestors", "(", "$", "term", "->", "term_id", ",", "$", "taxonomy", ")", ";", "$", "this", "->", "set", "(", "$", "term", "->", "name", ",", "get_term_link", "(", "$", "term", ")", ")", ";", "}" ]
Sets Breadcrumbs items of terms @param object $post_type_object @return void
[ "Sets", "Breadcrumbs", "items", "of", "terms" ]
fb904467f5ab3ec18c17c7420d1cbd98248367d8
https://github.com/inc2734/wp-breadcrumbs/blob/fb904467f5ab3ec18c17c7420d1cbd98248367d8/src/Controller/Single.php#L55-L71
228,882
inc2734/wp-breadcrumbs
src/Controller/Single.php
Single.set_categories
protected function set_categories() { $categories = get_the_category( get_the_ID() ); if ( $categories ) { $category = array_shift( $categories ); $this->set_ancestors( $category->term_id, 'category' ); $this->set( $category->name, get_term_link( $category ) ); } }
php
protected function set_categories() { $categories = get_the_category( get_the_ID() ); if ( $categories ) { $category = array_shift( $categories ); $this->set_ancestors( $category->term_id, 'category' ); $this->set( $category->name, get_term_link( $category ) ); } }
[ "protected", "function", "set_categories", "(", ")", "{", "$", "categories", "=", "get_the_category", "(", "get_the_ID", "(", ")", ")", ";", "if", "(", "$", "categories", ")", "{", "$", "category", "=", "array_shift", "(", "$", "categories", ")", ";", "$", "this", "->", "set_ancestors", "(", "$", "category", "->", "term_id", ",", "'category'", ")", ";", "$", "this", "->", "set", "(", "$", "category", "->", "name", ",", "get_term_link", "(", "$", "category", ")", ")", ";", "}", "}" ]
Sets Breadcrumbs items of categories @return void
[ "Sets", "Breadcrumbs", "items", "of", "categories" ]
fb904467f5ab3ec18c17c7420d1cbd98248367d8
https://github.com/inc2734/wp-breadcrumbs/blob/fb904467f5ab3ec18c17c7420d1cbd98248367d8/src/Controller/Single.php#L78-L85
228,883
slickframework/slick
src/Slick/Utility/WeightList.php
WeightList.insert
public function insert($data, $weight = 0) { if ($this->isEmpty()) { $this->_nodes[] = ['data' => $data, 'weight' => $weight]; return $this; } $inserted = false; $new = []; while(count($this->_nodes) > 0) { $element = array_shift($this->_nodes); if ( !$inserted && $this->compare((int) $weight, $element['weight']) <= 0 ) { $new[] = ['data' => $data, 'weight' => (int) $weight]; $new[] = ['data' => $element['data'], 'weight' => $element['weight']]; $inserted = true; } else { $new[] = ['data' => $element['data'], 'weight' => $element['weight']]; } } if (!$inserted) { $new[] = ['data' => $data, 'weight' => $weight]; } $this->_nodes = $new; return $this; }
php
public function insert($data, $weight = 0) { if ($this->isEmpty()) { $this->_nodes[] = ['data' => $data, 'weight' => $weight]; return $this; } $inserted = false; $new = []; while(count($this->_nodes) > 0) { $element = array_shift($this->_nodes); if ( !$inserted && $this->compare((int) $weight, $element['weight']) <= 0 ) { $new[] = ['data' => $data, 'weight' => (int) $weight]; $new[] = ['data' => $element['data'], 'weight' => $element['weight']]; $inserted = true; } else { $new[] = ['data' => $element['data'], 'weight' => $element['weight']]; } } if (!$inserted) { $new[] = ['data' => $data, 'weight' => $weight]; } $this->_nodes = $new; return $this; }
[ "public", "function", "insert", "(", "$", "data", ",", "$", "weight", "=", "0", ")", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "$", "this", "->", "_nodes", "[", "]", "=", "[", "'data'", "=>", "$", "data", ",", "'weight'", "=>", "$", "weight", "]", ";", "return", "$", "this", ";", "}", "$", "inserted", "=", "false", ";", "$", "new", "=", "[", "]", ";", "while", "(", "count", "(", "$", "this", "->", "_nodes", ")", ">", "0", ")", "{", "$", "element", "=", "array_shift", "(", "$", "this", "->", "_nodes", ")", ";", "if", "(", "!", "$", "inserted", "&&", "$", "this", "->", "compare", "(", "(", "int", ")", "$", "weight", ",", "$", "element", "[", "'weight'", "]", ")", "<=", "0", ")", "{", "$", "new", "[", "]", "=", "[", "'data'", "=>", "$", "data", ",", "'weight'", "=>", "(", "int", ")", "$", "weight", "]", ";", "$", "new", "[", "]", "=", "[", "'data'", "=>", "$", "element", "[", "'data'", "]", ",", "'weight'", "=>", "$", "element", "[", "'weight'", "]", "]", ";", "$", "inserted", "=", "true", ";", "}", "else", "{", "$", "new", "[", "]", "=", "[", "'data'", "=>", "$", "element", "[", "'data'", "]", ",", "'weight'", "=>", "$", "element", "[", "'weight'", "]", "]", ";", "}", "}", "if", "(", "!", "$", "inserted", ")", "{", "$", "new", "[", "]", "=", "[", "'data'", "=>", "$", "data", ",", "'weight'", "=>", "$", "weight", "]", ";", "}", "$", "this", "->", "_nodes", "=", "$", "new", ";", "return", "$", "this", ";", "}" ]
Inserts a new object in the list @param $data @param int $weight @return WeightList
[ "Inserts", "a", "new", "object", "in", "the", "list" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Utility/WeightList.php#L47-L74
228,884
slickframework/slick
src/Slick/Utility/WeightList.php
WeightList.remove
public function remove() { unset($this->_nodes[$this->_pointer]); $this->_nodes = array_values($this->_nodes); return $this; }
php
public function remove() { unset($this->_nodes[$this->_pointer]); $this->_nodes = array_values($this->_nodes); return $this; }
[ "public", "function", "remove", "(", ")", "{", "unset", "(", "$", "this", "->", "_nodes", "[", "$", "this", "->", "_pointer", "]", ")", ";", "$", "this", "->", "_nodes", "=", "array_values", "(", "$", "this", "->", "_nodes", ")", ";", "return", "$", "this", ";", "}" ]
Removes current object from the list @return WeightList
[ "Removes", "current", "object", "from", "the", "list" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Utility/WeightList.php#L81-L86
228,885
mjacobus/php-query-builder
lib/PO/QueryBuilder/Clauses/SetClause.php
SetClause.addSets
public function addSets(array $values = array()) { foreach ($values as $column => $value) { $this->addSet($column, $value); } return $this; }
php
public function addSets(array $values = array()) { foreach ($values as $column => $value) { $this->addSet($column, $value); } return $this; }
[ "public", "function", "addSets", "(", "array", "$", "values", "=", "array", "(", ")", ")", "{", "foreach", "(", "$", "values", "as", "$", "column", "=>", "$", "value", ")", "{", "$", "this", "->", "addSet", "(", "$", "column", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add the values to be set @param array $values @return PO\QueryBuilder\SetClause
[ "Add", "the", "values", "to", "be", "set" ]
eb7a90ae3bc433659306807535b39f12ce4dfd9f
https://github.com/mjacobus/php-query-builder/blob/eb7a90ae3bc433659306807535b39f12ce4dfd9f/lib/PO/QueryBuilder/Clauses/SetClause.php#L30-L37
228,886
mjacobus/php-query-builder
lib/PO/QueryBuilder/Clauses/SetClause.php
SetClause.toSql
public function toSql() { if ($this->isEmpty()) { return ''; } $params = $this->getParams(); $sql = array('SET'); $set = array(); foreach ($params as $column => $value) { $set[] = implode(' = ', array( $column, $this->getBuilder()->getHelper()->toDbValue($value) )); } $sql[] = implode(', ', $set); return implode(' ', $sql); }
php
public function toSql() { if ($this->isEmpty()) { return ''; } $params = $this->getParams(); $sql = array('SET'); $set = array(); foreach ($params as $column => $value) { $set[] = implode(' = ', array( $column, $this->getBuilder()->getHelper()->toDbValue($value) )); } $sql[] = implode(', ', $set); return implode(' ', $sql); }
[ "public", "function", "toSql", "(", ")", "{", "if", "(", "$", "this", "->", "isEmpty", "(", ")", ")", "{", "return", "''", ";", "}", "$", "params", "=", "$", "this", "->", "getParams", "(", ")", ";", "$", "sql", "=", "array", "(", "'SET'", ")", ";", "$", "set", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "as", "$", "column", "=>", "$", "value", ")", "{", "$", "set", "[", "]", "=", "implode", "(", "' = '", ",", "array", "(", "$", "column", ",", "$", "this", "->", "getBuilder", "(", ")", "->", "getHelper", "(", ")", "->", "toDbValue", "(", "$", "value", ")", ")", ")", ";", "}", "$", "sql", "[", "]", "=", "implode", "(", "', '", ",", "$", "set", ")", ";", "return", "implode", "(", "' '", ",", "$", "sql", ")", ";", "}" ]
The SET query part @return string
[ "The", "SET", "query", "part" ]
eb7a90ae3bc433659306807535b39f12ce4dfd9f
https://github.com/mjacobus/php-query-builder/blob/eb7a90ae3bc433659306807535b39f12ce4dfd9f/lib/PO/QueryBuilder/Clauses/SetClause.php#L58-L78
228,887
gauravojha/shoppingcart-eloquent
src/ShoppingCartImpl.php
ShoppingCartImpl.addToCart
public function addToCart($productid, $price, $quantity) { // check if the product already exists in the cart. // if it does, add the quantities together $productAlreadyExists = 0; $olderProduct = ShoppingCartItem::where('product_id', '=', $productid)->where('user_id', '=', Auth::user()->id)->first(); if($olderProduct != null) { $productAlreadyExists = $olderProduct->qty; $olderProduct->qty += $quantity; $olderProduct->save(); } else { $item = new ShoppingCartItem; $item->user_id = Auth::user()->id; $item->product_id = $productid; $item->price = $price; $item->qty = $quantity; $item->save(); } }
php
public function addToCart($productid, $price, $quantity) { // check if the product already exists in the cart. // if it does, add the quantities together $productAlreadyExists = 0; $olderProduct = ShoppingCartItem::where('product_id', '=', $productid)->where('user_id', '=', Auth::user()->id)->first(); if($olderProduct != null) { $productAlreadyExists = $olderProduct->qty; $olderProduct->qty += $quantity; $olderProduct->save(); } else { $item = new ShoppingCartItem; $item->user_id = Auth::user()->id; $item->product_id = $productid; $item->price = $price; $item->qty = $quantity; $item->save(); } }
[ "public", "function", "addToCart", "(", "$", "productid", ",", "$", "price", ",", "$", "quantity", ")", "{", "// check if the product already exists in the cart.", "// if it does, add the quantities together", "$", "productAlreadyExists", "=", "0", ";", "$", "olderProduct", "=", "ShoppingCartItem", "::", "where", "(", "'product_id'", ",", "'='", ",", "$", "productid", ")", "->", "where", "(", "'user_id'", ",", "'='", ",", "Auth", "::", "user", "(", ")", "->", "id", ")", "->", "first", "(", ")", ";", "if", "(", "$", "olderProduct", "!=", "null", ")", "{", "$", "productAlreadyExists", "=", "$", "olderProduct", "->", "qty", ";", "$", "olderProduct", "->", "qty", "+=", "$", "quantity", ";", "$", "olderProduct", "->", "save", "(", ")", ";", "}", "else", "{", "$", "item", "=", "new", "ShoppingCartItem", ";", "$", "item", "->", "user_id", "=", "Auth", "::", "user", "(", ")", "->", "id", ";", "$", "item", "->", "product_id", "=", "$", "productid", ";", "$", "item", "->", "price", "=", "$", "price", ";", "$", "item", "->", "qty", "=", "$", "quantity", ";", "$", "item", "->", "save", "(", ")", ";", "}", "}" ]
Function to add items to a cart
[ "Function", "to", "add", "items", "to", "a", "cart" ]
7d0f9f51e393abc36b771d2919ddf1c1cd14057f
https://github.com/gauravojha/shoppingcart-eloquent/blob/7d0f9f51e393abc36b771d2919ddf1c1cd14057f/src/ShoppingCartImpl.php#L31-L49
228,888
gauravojha/shoppingcart-eloquent
src/ShoppingCartImpl.php
ShoppingCartImpl.removeFromCart
public function removeFromCart($productid) { ShoppingCartItem::where('product_id', '=', $productid)->where('user_id', '=', Auth::user()->id)->delete(); }
php
public function removeFromCart($productid) { ShoppingCartItem::where('product_id', '=', $productid)->where('user_id', '=', Auth::user()->id)->delete(); }
[ "public", "function", "removeFromCart", "(", "$", "productid", ")", "{", "ShoppingCartItem", "::", "where", "(", "'product_id'", ",", "'='", ",", "$", "productid", ")", "->", "where", "(", "'user_id'", ",", "'='", ",", "Auth", "::", "user", "(", ")", "->", "id", ")", "->", "delete", "(", ")", ";", "}" ]
Function to delete an item from a cart
[ "Function", "to", "delete", "an", "item", "from", "a", "cart" ]
7d0f9f51e393abc36b771d2919ddf1c1cd14057f
https://github.com/gauravojha/shoppingcart-eloquent/blob/7d0f9f51e393abc36b771d2919ddf1c1cd14057f/src/ShoppingCartImpl.php#L62-L65
228,889
gauravojha/shoppingcart-eloquent
src/ShoppingCartImpl.php
ShoppingCartImpl.updateItemInCart
public function updateItemInCart($productid, $quantity) { $olderProduct = ShoppingCartItem::where('product_id', '=', $productid)->where('user_id', '=', Auth::user()->id)->first(); if($olderProduct != null) { $olderProduct->qty = $quantity; $olderProduct->save(); } }
php
public function updateItemInCart($productid, $quantity) { $olderProduct = ShoppingCartItem::where('product_id', '=', $productid)->where('user_id', '=', Auth::user()->id)->first(); if($olderProduct != null) { $olderProduct->qty = $quantity; $olderProduct->save(); } }
[ "public", "function", "updateItemInCart", "(", "$", "productid", ",", "$", "quantity", ")", "{", "$", "olderProduct", "=", "ShoppingCartItem", "::", "where", "(", "'product_id'", ",", "'='", ",", "$", "productid", ")", "->", "where", "(", "'user_id'", ",", "'='", ",", "Auth", "::", "user", "(", ")", "->", "id", ")", "->", "first", "(", ")", ";", "if", "(", "$", "olderProduct", "!=", "null", ")", "{", "$", "olderProduct", "->", "qty", "=", "$", "quantity", ";", "$", "olderProduct", "->", "save", "(", ")", ";", "}", "}" ]
Function to update an item in the cart
[ "Function", "to", "update", "an", "item", "in", "the", "cart" ]
7d0f9f51e393abc36b771d2919ddf1c1cd14057f
https://github.com/gauravojha/shoppingcart-eloquent/blob/7d0f9f51e393abc36b771d2919ddf1c1cd14057f/src/ShoppingCartImpl.php#L78-L85
228,890
gauravojha/shoppingcart-eloquent
src/ShoppingCartImpl.php
ShoppingCartImpl.totalPrice
public function totalPrice() { $total = 0; $products = $this->content(); foreach ($products as $product) { $total += ($product->qty * $product->price); } $total = ($total + ($total * ($this->taxRate/100))); $total += $this->deliveryCharges; return $total; }
php
public function totalPrice() { $total = 0; $products = $this->content(); foreach ($products as $product) { $total += ($product->qty * $product->price); } $total = ($total + ($total * ($this->taxRate/100))); $total += $this->deliveryCharges; return $total; }
[ "public", "function", "totalPrice", "(", ")", "{", "$", "total", "=", "0", ";", "$", "products", "=", "$", "this", "->", "content", "(", ")", ";", "foreach", "(", "$", "products", "as", "$", "product", ")", "{", "$", "total", "+=", "(", "$", "product", "->", "qty", "*", "$", "product", "->", "price", ")", ";", "}", "$", "total", "=", "(", "$", "total", "+", "(", "$", "total", "*", "(", "$", "this", "->", "taxRate", "/", "100", ")", ")", ")", ";", "$", "total", "+=", "$", "this", "->", "deliveryCharges", ";", "return", "$", "total", ";", "}" ]
Function to calculate the total price of products in the cart
[ "Function", "to", "calculate", "the", "total", "price", "of", "products", "in", "the", "cart" ]
7d0f9f51e393abc36b771d2919ddf1c1cd14057f
https://github.com/gauravojha/shoppingcart-eloquent/blob/7d0f9f51e393abc36b771d2919ddf1c1cd14057f/src/ShoppingCartImpl.php#L90-L100
228,891
slickframework/slick
src/Slick/Mvc/Dispatcher.php
Dispatcher.dispatch
public function dispatch(RouteInfo $routeInfo) { $this->setRouteInfo($routeInfo); $method = $this->_routeInfo->getAction(); $controller = $this->getController($method); $inspector = new Inspector($controller); $methodExists = $inspector->hasMethod($method); if ( !$methodExists || $inspector->getMethodAnnotations($method) ->hasAnnotation('@private') || $inspector->getMethodAnnotations($method) ->hasAnnotation('@protected') ) { throw new Exception\ActionNotFoundException( "Action '{$method}' not found" ); } $methodMeta = $inspector->getMethodAnnotations($method); /** * @param Inspector\AnnotationsList $meta * @param string $type */ $hooks = function ($meta, $type) use ($inspector, $controller) { static $run; if (is_null($run)) { $run = array(); } if ($meta->hasAnnotation($type)) { $methods = $meta->getAnnotation($type)->getValue(); if (is_string($methods)) { $methods = explode( ', ', $meta->getAnnotation($type)->getParameter('_raw') ); } foreach ($methods as $method) { $hookMeta = $inspector->getMethodAnnotations($method); if ( in_array($method, $run) && $hookMeta->hasAnnotation('@once') ) { continue; } $run[] = $method; $controller->$method(); } } }; $hooks($methodMeta, "@before"); $arguments = is_array($this->_routeInfo->getArguments()) ? $this->_routeInfo->getArguments() : []; $controller->arguments = $arguments; $filterEvent = new Filter( [ 'controller' => $controller, 'routeInfo' => $this->_routeInfo ], 'FilterEvent' ); $this->_application->getEventManager() ->trigger(Filter::BEFORE_FILTER, $this, $filterEvent); call_user_func_array( array( $filterEvent->controller, $method ), $arguments ); $hooks($methodMeta, "@after"); $this->_application->getEventManager() ->trigger(Filter::AFTER_FILTER, $this, $filterEvent); $this->_controller = $controller; return $this->_render(); }
php
public function dispatch(RouteInfo $routeInfo) { $this->setRouteInfo($routeInfo); $method = $this->_routeInfo->getAction(); $controller = $this->getController($method); $inspector = new Inspector($controller); $methodExists = $inspector->hasMethod($method); if ( !$methodExists || $inspector->getMethodAnnotations($method) ->hasAnnotation('@private') || $inspector->getMethodAnnotations($method) ->hasAnnotation('@protected') ) { throw new Exception\ActionNotFoundException( "Action '{$method}' not found" ); } $methodMeta = $inspector->getMethodAnnotations($method); /** * @param Inspector\AnnotationsList $meta * @param string $type */ $hooks = function ($meta, $type) use ($inspector, $controller) { static $run; if (is_null($run)) { $run = array(); } if ($meta->hasAnnotation($type)) { $methods = $meta->getAnnotation($type)->getValue(); if (is_string($methods)) { $methods = explode( ', ', $meta->getAnnotation($type)->getParameter('_raw') ); } foreach ($methods as $method) { $hookMeta = $inspector->getMethodAnnotations($method); if ( in_array($method, $run) && $hookMeta->hasAnnotation('@once') ) { continue; } $run[] = $method; $controller->$method(); } } }; $hooks($methodMeta, "@before"); $arguments = is_array($this->_routeInfo->getArguments()) ? $this->_routeInfo->getArguments() : []; $controller->arguments = $arguments; $filterEvent = new Filter( [ 'controller' => $controller, 'routeInfo' => $this->_routeInfo ], 'FilterEvent' ); $this->_application->getEventManager() ->trigger(Filter::BEFORE_FILTER, $this, $filterEvent); call_user_func_array( array( $filterEvent->controller, $method ), $arguments ); $hooks($methodMeta, "@after"); $this->_application->getEventManager() ->trigger(Filter::AFTER_FILTER, $this, $filterEvent); $this->_controller = $controller; return $this->_render(); }
[ "public", "function", "dispatch", "(", "RouteInfo", "$", "routeInfo", ")", "{", "$", "this", "->", "setRouteInfo", "(", "$", "routeInfo", ")", ";", "$", "method", "=", "$", "this", "->", "_routeInfo", "->", "getAction", "(", ")", ";", "$", "controller", "=", "$", "this", "->", "getController", "(", "$", "method", ")", ";", "$", "inspector", "=", "new", "Inspector", "(", "$", "controller", ")", ";", "$", "methodExists", "=", "$", "inspector", "->", "hasMethod", "(", "$", "method", ")", ";", "if", "(", "!", "$", "methodExists", "||", "$", "inspector", "->", "getMethodAnnotations", "(", "$", "method", ")", "->", "hasAnnotation", "(", "'@private'", ")", "||", "$", "inspector", "->", "getMethodAnnotations", "(", "$", "method", ")", "->", "hasAnnotation", "(", "'@protected'", ")", ")", "{", "throw", "new", "Exception", "\\", "ActionNotFoundException", "(", "\"Action '{$method}' not found\"", ")", ";", "}", "$", "methodMeta", "=", "$", "inspector", "->", "getMethodAnnotations", "(", "$", "method", ")", ";", "/**\n * @param Inspector\\AnnotationsList $meta\n * @param string $type\n */", "$", "hooks", "=", "function", "(", "$", "meta", ",", "$", "type", ")", "use", "(", "$", "inspector", ",", "$", "controller", ")", "{", "static", "$", "run", ";", "if", "(", "is_null", "(", "$", "run", ")", ")", "{", "$", "run", "=", "array", "(", ")", ";", "}", "if", "(", "$", "meta", "->", "hasAnnotation", "(", "$", "type", ")", ")", "{", "$", "methods", "=", "$", "meta", "->", "getAnnotation", "(", "$", "type", ")", "->", "getValue", "(", ")", ";", "if", "(", "is_string", "(", "$", "methods", ")", ")", "{", "$", "methods", "=", "explode", "(", "', '", ",", "$", "meta", "->", "getAnnotation", "(", "$", "type", ")", "->", "getParameter", "(", "'_raw'", ")", ")", ";", "}", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "$", "hookMeta", "=", "$", "inspector", "->", "getMethodAnnotations", "(", "$", "method", ")", ";", "if", "(", "in_array", "(", "$", "method", ",", "$", "run", ")", "&&", "$", "hookMeta", "->", "hasAnnotation", "(", "'@once'", ")", ")", "{", "continue", ";", "}", "$", "run", "[", "]", "=", "$", "method", ";", "$", "controller", "->", "$", "method", "(", ")", ";", "}", "}", "}", ";", "$", "hooks", "(", "$", "methodMeta", ",", "\"@before\"", ")", ";", "$", "arguments", "=", "is_array", "(", "$", "this", "->", "_routeInfo", "->", "getArguments", "(", ")", ")", "?", "$", "this", "->", "_routeInfo", "->", "getArguments", "(", ")", ":", "[", "]", ";", "$", "controller", "->", "arguments", "=", "$", "arguments", ";", "$", "filterEvent", "=", "new", "Filter", "(", "[", "'controller'", "=>", "$", "controller", ",", "'routeInfo'", "=>", "$", "this", "->", "_routeInfo", "]", ",", "'FilterEvent'", ")", ";", "$", "this", "->", "_application", "->", "getEventManager", "(", ")", "->", "trigger", "(", "Filter", "::", "BEFORE_FILTER", ",", "$", "this", ",", "$", "filterEvent", ")", ";", "call_user_func_array", "(", "array", "(", "$", "filterEvent", "->", "controller", ",", "$", "method", ")", ",", "$", "arguments", ")", ";", "$", "hooks", "(", "$", "methodMeta", ",", "\"@after\"", ")", ";", "$", "this", "->", "_application", "->", "getEventManager", "(", ")", "->", "trigger", "(", "Filter", "::", "AFTER_FILTER", ",", "$", "this", ",", "$", "filterEvent", ")", ";", "$", "this", "->", "_controller", "=", "$", "controller", ";", "return", "$", "this", "->", "_render", "(", ")", ";", "}" ]
Dispatches the routed request @param RouteInfo $routeInfo @return Response
[ "Dispatches", "the", "routed", "request" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Dispatcher.php#L71-L157
228,892
slickframework/slick
src/Slick/Mvc/Dispatcher.php
Dispatcher.getController
public function getController($method) { if (is_null($this->_controller)) { $className = $this->_routeInfo->getController(); if (!class_exists($className)) { throw new Exception\ControllerNotFoundException( "Controller '{$className}' not found" ); } $options = array( 'request' => $this->_application->getRequest(), 'response' => $this->_application->getResponse(), ); /** @var Controller $instance */ $instance = new $className($options); $methodExists = method_exists($instance,$method); $this->_controller = $instance; if (!$methodExists && $instance->isScaffold()) { $this->_controller = Scaffold::getScaffoldController( $instance ); } } return $this->_controller; }
php
public function getController($method) { if (is_null($this->_controller)) { $className = $this->_routeInfo->getController(); if (!class_exists($className)) { throw new Exception\ControllerNotFoundException( "Controller '{$className}' not found" ); } $options = array( 'request' => $this->_application->getRequest(), 'response' => $this->_application->getResponse(), ); /** @var Controller $instance */ $instance = new $className($options); $methodExists = method_exists($instance,$method); $this->_controller = $instance; if (!$methodExists && $instance->isScaffold()) { $this->_controller = Scaffold::getScaffoldController( $instance ); } } return $this->_controller; }
[ "public", "function", "getController", "(", "$", "method", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_controller", ")", ")", "{", "$", "className", "=", "$", "this", "->", "_routeInfo", "->", "getController", "(", ")", ";", "if", "(", "!", "class_exists", "(", "$", "className", ")", ")", "{", "throw", "new", "Exception", "\\", "ControllerNotFoundException", "(", "\"Controller '{$className}' not found\"", ")", ";", "}", "$", "options", "=", "array", "(", "'request'", "=>", "$", "this", "->", "_application", "->", "getRequest", "(", ")", ",", "'response'", "=>", "$", "this", "->", "_application", "->", "getResponse", "(", ")", ",", ")", ";", "/** @var Controller $instance */", "$", "instance", "=", "new", "$", "className", "(", "$", "options", ")", ";", "$", "methodExists", "=", "method_exists", "(", "$", "instance", ",", "$", "method", ")", ";", "$", "this", "->", "_controller", "=", "$", "instance", ";", "if", "(", "!", "$", "methodExists", "&&", "$", "instance", "->", "isScaffold", "(", ")", ")", "{", "$", "this", "->", "_controller", "=", "Scaffold", "::", "getScaffoldController", "(", "$", "instance", ")", ";", "}", "}", "return", "$", "this", "->", "_controller", ";", "}" ]
Loads the controller @param string $method @return Controller
[ "Loads", "the", "controller" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Dispatcher.php#L165-L191
228,893
slickframework/slick
src/Slick/Mvc/Dispatcher.php
Dispatcher._render
protected function _render() { $response = $this->_application->response; $body = $response->getBody(); $this->_controller->set( 'flashMessages', $this->_controller->flashMessages ); $data = $this->_controller->getViewVars(); $doLayout = $this->_controller->renderLayout && $this->getLayout(); $doView = $this->_controller->renderView && $this->getView(); try { if ($doView) { $body = $this->getView() ->set($data) ->render(); } if ($doLayout) { $body = $this->getLayout() ->set('layoutData', $body) ->set($data) ->render(); } } catch (\Exception $exp) { throw new Exception\RenderingErrorException( "Error while rendering view: " . $exp->getMessage() ); } return $response->setContent($body); }
php
protected function _render() { $response = $this->_application->response; $body = $response->getBody(); $this->_controller->set( 'flashMessages', $this->_controller->flashMessages ); $data = $this->_controller->getViewVars(); $doLayout = $this->_controller->renderLayout && $this->getLayout(); $doView = $this->_controller->renderView && $this->getView(); try { if ($doView) { $body = $this->getView() ->set($data) ->render(); } if ($doLayout) { $body = $this->getLayout() ->set('layoutData', $body) ->set($data) ->render(); } } catch (\Exception $exp) { throw new Exception\RenderingErrorException( "Error while rendering view: " . $exp->getMessage() ); } return $response->setContent($body); }
[ "protected", "function", "_render", "(", ")", "{", "$", "response", "=", "$", "this", "->", "_application", "->", "response", ";", "$", "body", "=", "$", "response", "->", "getBody", "(", ")", ";", "$", "this", "->", "_controller", "->", "set", "(", "'flashMessages'", ",", "$", "this", "->", "_controller", "->", "flashMessages", ")", ";", "$", "data", "=", "$", "this", "->", "_controller", "->", "getViewVars", "(", ")", ";", "$", "doLayout", "=", "$", "this", "->", "_controller", "->", "renderLayout", "&&", "$", "this", "->", "getLayout", "(", ")", ";", "$", "doView", "=", "$", "this", "->", "_controller", "->", "renderView", "&&", "$", "this", "->", "getView", "(", ")", ";", "try", "{", "if", "(", "$", "doView", ")", "{", "$", "body", "=", "$", "this", "->", "getView", "(", ")", "->", "set", "(", "$", "data", ")", "->", "render", "(", ")", ";", "}", "if", "(", "$", "doLayout", ")", "{", "$", "body", "=", "$", "this", "->", "getLayout", "(", ")", "->", "set", "(", "'layoutData'", ",", "$", "body", ")", "->", "set", "(", "$", "data", ")", "->", "render", "(", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "exp", ")", "{", "throw", "new", "Exception", "\\", "RenderingErrorException", "(", "\"Error while rendering view: \"", ".", "$", "exp", "->", "getMessage", "(", ")", ")", ";", "}", "return", "$", "response", "->", "setContent", "(", "$", "body", ")", ";", "}" ]
Render the view and layout templates with controller data @return Response
[ "Render", "the", "view", "and", "layout", "templates", "with", "controller", "data" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Dispatcher.php#L198-L232
228,894
slickframework/slick
src/Slick/Mvc/Dispatcher.php
Dispatcher.getView
public function getView() { if (is_null($this->_view)) { $controller = $this->_routeInfo->controllerName; $name = $this->_routeInfo->action; $ext = $this->_routeInfo->getExtension(); $template = "{$controller}/{$name}.{$ext}.twig"; if (!is_null($this->_controller->view)) { $template = "{$this->_controller->view}.{$ext}.twig"; } $this->_view = new View(['file' => $template]); } return $this->_view; }
php
public function getView() { if (is_null($this->_view)) { $controller = $this->_routeInfo->controllerName; $name = $this->_routeInfo->action; $ext = $this->_routeInfo->getExtension(); $template = "{$controller}/{$name}.{$ext}.twig"; if (!is_null($this->_controller->view)) { $template = "{$this->_controller->view}.{$ext}.twig"; } $this->_view = new View(['file' => $template]); } return $this->_view; }
[ "public", "function", "getView", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_view", ")", ")", "{", "$", "controller", "=", "$", "this", "->", "_routeInfo", "->", "controllerName", ";", "$", "name", "=", "$", "this", "->", "_routeInfo", "->", "action", ";", "$", "ext", "=", "$", "this", "->", "_routeInfo", "->", "getExtension", "(", ")", ";", "$", "template", "=", "\"{$controller}/{$name}.{$ext}.twig\"", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "_controller", "->", "view", ")", ")", "{", "$", "template", "=", "\"{$this->_controller->view}.{$ext}.twig\"", ";", "}", "$", "this", "->", "_view", "=", "new", "View", "(", "[", "'file'", "=>", "$", "template", "]", ")", ";", "}", "return", "$", "this", "->", "_view", ";", "}" ]
Returns the view for current request @return View
[ "Returns", "the", "view", "for", "current", "request" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Dispatcher.php#L239-L252
228,895
slickframework/slick
src/Slick/Mvc/Dispatcher.php
Dispatcher.getLayout
public function getLayout() { if (is_null($this->_layout)) { $default = 'layouts/default'; $ext = $this->_routeInfo->getExtension(); $file = "{$default}.{$ext}.twig"; if (!is_null($this->_controller->layout)) { $file = "{$this->_controller->layout}.{$ext}.twig"; } $this->_layout = new View(['file' => $file]); } return $this->_layout; }
php
public function getLayout() { if (is_null($this->_layout)) { $default = 'layouts/default'; $ext = $this->_routeInfo->getExtension(); $file = "{$default}.{$ext}.twig"; if (!is_null($this->_controller->layout)) { $file = "{$this->_controller->layout}.{$ext}.twig"; } $this->_layout = new View(['file' => $file]); } return $this->_layout; }
[ "public", "function", "getLayout", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_layout", ")", ")", "{", "$", "default", "=", "'layouts/default'", ";", "$", "ext", "=", "$", "this", "->", "_routeInfo", "->", "getExtension", "(", ")", ";", "$", "file", "=", "\"{$default}.{$ext}.twig\"", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "_controller", "->", "layout", ")", ")", "{", "$", "file", "=", "\"{$this->_controller->layout}.{$ext}.twig\"", ";", "}", "$", "this", "->", "_layout", "=", "new", "View", "(", "[", "'file'", "=>", "$", "file", "]", ")", ";", "}", "return", "$", "this", "->", "_layout", ";", "}" ]
Returns the layout for current request @return View
[ "Returns", "the", "layout", "for", "current", "request" ]
77f56b81020ce8c10f25f7d918661ccd9a918a37
https://github.com/slickframework/slick/blob/77f56b81020ce8c10f25f7d918661ccd9a918a37/src/Slick/Mvc/Dispatcher.php#L260-L272
228,896
AOEpeople/StackFormation
src/StackFormation/Command/Stack/TreeCommand.php
TreeCommand.prepareTree
protected function prepareTree(array $arr) { $tree = []; foreach ($arr as $a) { $name = $a->getName(); $cur = &$tree; foreach (explode("-", $name) as $e) { if (empty($cur[$e])) $cur[$e] = []; $cur = &$cur[$e]; } } return $tree; }
php
protected function prepareTree(array $arr) { $tree = []; foreach ($arr as $a) { $name = $a->getName(); $cur = &$tree; foreach (explode("-", $name) as $e) { if (empty($cur[$e])) $cur[$e] = []; $cur = &$cur[$e]; } } return $tree; }
[ "protected", "function", "prepareTree", "(", "array", "$", "arr", ")", "{", "$", "tree", "=", "[", "]", ";", "foreach", "(", "$", "arr", "as", "$", "a", ")", "{", "$", "name", "=", "$", "a", "->", "getName", "(", ")", ";", "$", "cur", "=", "&", "$", "tree", ";", "foreach", "(", "explode", "(", "\"-\"", ",", "$", "name", ")", "as", "$", "e", ")", "{", "if", "(", "empty", "(", "$", "cur", "[", "$", "e", "]", ")", ")", "$", "cur", "[", "$", "e", "]", "=", "[", "]", ";", "$", "cur", "=", "&", "$", "cur", "[", "$", "e", "]", ";", "}", "}", "return", "$", "tree", ";", "}" ]
prepare stack list @param StackFormation\Stack[] @return array
[ "prepare", "stack", "list" ]
5332dbbe54653e50d610cbaf75fb865c68aa2f1e
https://github.com/AOEpeople/StackFormation/blob/5332dbbe54653e50d610cbaf75fb865c68aa2f1e/src/StackFormation/Command/Stack/TreeCommand.php#L51-L62
228,897
AOEpeople/StackFormation
src/StackFormation/Command/Stack/TreeCommand.php
TreeCommand.flatternTree
protected function flatternTree(array $treeIn) { $treeOut = []; foreach ($treeIn as $name => $children) { if (count($children) === 0) { $treeOut[$name] = []; } elseif (count($children) === 1) { $name = sprintf('%s-%s', $name, key($children)); if (count($children[key($children)]) > 0) { $treeOut[$name] = $this->flatternTree($children[key($children)]); }else{ $treeOut[$name] = []; } } else { $treeOut[$name] = $this->flatternTree($children); } } return $treeOut; }
php
protected function flatternTree(array $treeIn) { $treeOut = []; foreach ($treeIn as $name => $children) { if (count($children) === 0) { $treeOut[$name] = []; } elseif (count($children) === 1) { $name = sprintf('%s-%s', $name, key($children)); if (count($children[key($children)]) > 0) { $treeOut[$name] = $this->flatternTree($children[key($children)]); }else{ $treeOut[$name] = []; } } else { $treeOut[$name] = $this->flatternTree($children); } } return $treeOut; }
[ "protected", "function", "flatternTree", "(", "array", "$", "treeIn", ")", "{", "$", "treeOut", "=", "[", "]", ";", "foreach", "(", "$", "treeIn", "as", "$", "name", "=>", "$", "children", ")", "{", "if", "(", "count", "(", "$", "children", ")", "===", "0", ")", "{", "$", "treeOut", "[", "$", "name", "]", "=", "[", "]", ";", "}", "elseif", "(", "count", "(", "$", "children", ")", "===", "1", ")", "{", "$", "name", "=", "sprintf", "(", "'%s-%s'", ",", "$", "name", ",", "key", "(", "$", "children", ")", ")", ";", "if", "(", "count", "(", "$", "children", "[", "key", "(", "$", "children", ")", "]", ")", ">", "0", ")", "{", "$", "treeOut", "[", "$", "name", "]", "=", "$", "this", "->", "flatternTree", "(", "$", "children", "[", "key", "(", "$", "children", ")", "]", ")", ";", "}", "else", "{", "$", "treeOut", "[", "$", "name", "]", "=", "[", "]", ";", "}", "}", "else", "{", "$", "treeOut", "[", "$", "name", "]", "=", "$", "this", "->", "flatternTree", "(", "$", "children", ")", ";", "}", "}", "return", "$", "treeOut", ";", "}" ]
flattern tree to gain a better overview @param array $treeIn @return array
[ "flattern", "tree", "to", "gain", "a", "better", "overview" ]
5332dbbe54653e50d610cbaf75fb865c68aa2f1e
https://github.com/AOEpeople/StackFormation/blob/5332dbbe54653e50d610cbaf75fb865c68aa2f1e/src/StackFormation/Command/Stack/TreeCommand.php#L70-L89
228,898
Ardakilic/laravel-mutlucell-sms
src/Ardakilic/Mutlucell/Mutlucell.php
Mutlucell.setConfig
public function setConfig(array $config) { $this->config = $config; $this->senderID = $this->config['default_sender']; // The user may have called setConfig() manually, // and the array may have missing arguments. // So, we're checking whether they are set, and filling them if not set // Critical ones will throw exceptions, non-critical ones will set default values if (!isset($this->config['auth'])) { throw new \Exception($this->lang['exceptions']['0']); } else { if (!isset($this->config['auth']['username']) || !isset($this->config['auth']['password'])) { throw new \Exception($this->lang['exceptions']['1']); } } if (!isset($this->config['default_sender'])) { throw new \Exception($this->lang['exceptions']['2']); } if (!isset($this->config['queue'])) { $this->config['queue'] = false; } if (!isset($this->config['charset'])) { $this->config['charset'] = 'default'; } if (!isset($this->config['append_unsubscribe_link'])) { $this->config['append_unsubscribe_link'] = false; } return $this; }
php
public function setConfig(array $config) { $this->config = $config; $this->senderID = $this->config['default_sender']; // The user may have called setConfig() manually, // and the array may have missing arguments. // So, we're checking whether they are set, and filling them if not set // Critical ones will throw exceptions, non-critical ones will set default values if (!isset($this->config['auth'])) { throw new \Exception($this->lang['exceptions']['0']); } else { if (!isset($this->config['auth']['username']) || !isset($this->config['auth']['password'])) { throw new \Exception($this->lang['exceptions']['1']); } } if (!isset($this->config['default_sender'])) { throw new \Exception($this->lang['exceptions']['2']); } if (!isset($this->config['queue'])) { $this->config['queue'] = false; } if (!isset($this->config['charset'])) { $this->config['charset'] = 'default'; } if (!isset($this->config['append_unsubscribe_link'])) { $this->config['append_unsubscribe_link'] = false; } return $this; }
[ "public", "function", "setConfig", "(", "array", "$", "config", ")", "{", "$", "this", "->", "config", "=", "$", "config", ";", "$", "this", "->", "senderID", "=", "$", "this", "->", "config", "[", "'default_sender'", "]", ";", "// The user may have called setConfig() manually,", "// and the array may have missing arguments.", "// So, we're checking whether they are set, and filling them if not set", "// Critical ones will throw exceptions, non-critical ones will set default values", "if", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "'auth'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "$", "this", "->", "lang", "[", "'exceptions'", "]", "[", "'0'", "]", ")", ";", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "'auth'", "]", "[", "'username'", "]", ")", "||", "!", "isset", "(", "$", "this", "->", "config", "[", "'auth'", "]", "[", "'password'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "$", "this", "->", "lang", "[", "'exceptions'", "]", "[", "'1'", "]", ")", ";", "}", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "'default_sender'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "$", "this", "->", "lang", "[", "'exceptions'", "]", "[", "'2'", "]", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "'queue'", "]", ")", ")", "{", "$", "this", "->", "config", "[", "'queue'", "]", "=", "false", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "'charset'", "]", ")", ")", "{", "$", "this", "->", "config", "[", "'charset'", "]", "=", "'default'", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "'append_unsubscribe_link'", "]", ")", ")", "{", "$", "this", "->", "config", "[", "'append_unsubscribe_link'", "]", "=", "false", ";", "}", "return", "$", "this", ";", "}" ]
This method allows user to change configuration on-the-fly @param array $config @throws \Exception if auth parameter or originator is not set @return $this
[ "This", "method", "allows", "user", "to", "change", "configuration", "on", "-", "the", "-", "fly" ]
a6b5208b6cffe7c33b1fe9fb670e8e16a86b4b11
https://github.com/Ardakilic/laravel-mutlucell-sms/blob/a6b5208b6cffe7c33b1fe9fb670e8e16a86b4b11/src/Ardakilic/Mutlucell/Mutlucell.php#L41-L70
228,899
Ardakilic/laravel-mutlucell-sms
src/Ardakilic/Mutlucell/Mutlucell.php
Mutlucell.sendBulk
public function sendBulk($recipents, $message = '', $date = '', $senderID = '') { //Checks the $message and $senderID, and initializes it $this->preChecks($message, $senderID); //Sending for future date $dateStr = ''; if (strlen($date)) { $dateStr = ' tarih="' . $date . '"'; } //Recipents check + XML initialise if (is_array($recipents)) { $recipents = implode(', ', $recipents); } $xml = '<?xml version="1.0" encoding="UTF-8"?>' . '<smspack ka="' . $this->config['auth']['username'] . '" pwd="' . $this->config['auth']['password'] . '"' . $dateStr . ' org="' . $this->senderID . '" charset="' . $this->config['charset'] . '"' . ($this->config['append_unsubscribe_link'] ? ' addLinkToEnd="true"' : '') . '>'; $xml .= '<mesaj>' . '<metin>' . $this->message . '</metin>' . '<nums>' . $recipents . '</nums>' . '</mesaj>'; $xml .= '</smspack>'; return $this->postXML($xml, 'https://smsgw.mutlucell.com/smsgw-ws/sndblkex'); }
php
public function sendBulk($recipents, $message = '', $date = '', $senderID = '') { //Checks the $message and $senderID, and initializes it $this->preChecks($message, $senderID); //Sending for future date $dateStr = ''; if (strlen($date)) { $dateStr = ' tarih="' . $date . '"'; } //Recipents check + XML initialise if (is_array($recipents)) { $recipents = implode(', ', $recipents); } $xml = '<?xml version="1.0" encoding="UTF-8"?>' . '<smspack ka="' . $this->config['auth']['username'] . '" pwd="' . $this->config['auth']['password'] . '"' . $dateStr . ' org="' . $this->senderID . '" charset="' . $this->config['charset'] . '"' . ($this->config['append_unsubscribe_link'] ? ' addLinkToEnd="true"' : '') . '>'; $xml .= '<mesaj>' . '<metin>' . $this->message . '</metin>' . '<nums>' . $recipents . '</nums>' . '</mesaj>'; $xml .= '</smspack>'; return $this->postXML($xml, 'https://smsgw.mutlucell.com/smsgw-ws/sndblkex'); }
[ "public", "function", "sendBulk", "(", "$", "recipents", ",", "$", "message", "=", "''", ",", "$", "date", "=", "''", ",", "$", "senderID", "=", "''", ")", "{", "//Checks the $message and $senderID, and initializes it", "$", "this", "->", "preChecks", "(", "$", "message", ",", "$", "senderID", ")", ";", "//Sending for future date", "$", "dateStr", "=", "''", ";", "if", "(", "strlen", "(", "$", "date", ")", ")", "{", "$", "dateStr", "=", "' tarih=\"'", ".", "$", "date", ".", "'\"'", ";", "}", "//Recipents check + XML initialise", "if", "(", "is_array", "(", "$", "recipents", ")", ")", "{", "$", "recipents", "=", "implode", "(", "', '", ",", "$", "recipents", ")", ";", "}", "$", "xml", "=", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'", ".", "'<smspack ka=\"'", ".", "$", "this", "->", "config", "[", "'auth'", "]", "[", "'username'", "]", ".", "'\" pwd=\"'", ".", "$", "this", "->", "config", "[", "'auth'", "]", "[", "'password'", "]", ".", "'\"'", ".", "$", "dateStr", ".", "' org=\"'", ".", "$", "this", "->", "senderID", ".", "'\" charset=\"'", ".", "$", "this", "->", "config", "[", "'charset'", "]", ".", "'\"'", ".", "(", "$", "this", "->", "config", "[", "'append_unsubscribe_link'", "]", "?", "' addLinkToEnd=\"true\"'", ":", "''", ")", ".", "'>'", ";", "$", "xml", ".=", "'<mesaj>'", ".", "'<metin>'", ".", "$", "this", "->", "message", ".", "'</metin>'", ".", "'<nums>'", ".", "$", "recipents", ".", "'</nums>'", ".", "'</mesaj>'", ";", "$", "xml", ".=", "'</smspack>'", ";", "return", "$", "this", "->", "postXML", "(", "$", "xml", ",", "'https://smsgw.mutlucell.com/smsgw-ws/sndblkex'", ")", ";", "}" ]
Send same bulk message to many people @param $recipents array recipents @param $message string message to be sent @param $date string when will the message be sent? @param $senderID string originator/sender id (may be a text or number) @return string status API response
[ "Send", "same", "bulk", "message", "to", "many", "people" ]
a6b5208b6cffe7c33b1fe9fb670e8e16a86b4b11
https://github.com/Ardakilic/laravel-mutlucell-sms/blob/a6b5208b6cffe7c33b1fe9fb670e8e16a86b4b11/src/Ardakilic/Mutlucell/Mutlucell.php#L80-L104