repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
concrete5/concrete5
concrete/controllers/single_page/dashboard/system/api/integrations.php
Integrations.create
public function create() { $this->add(); $this->validateIntegrationRequest(); if (!$this->token->validate('create')) { $this->error->add($this->token->getErrorMessage()); } if ($this->error->has()) { return; } $factory = $this->app->make(ClientFactory::class); $credentials = $factory->generateCredentials(); // Create a new client while hashing the new secret $client = $factory->createClient( $this->request->request->get('name'), $this->request->request->get('redirect'), [], $credentials->getKey(), password_hash($credentials->getSecret(), PASSWORD_DEFAULT) ); // Persist the new client to the database $this->entityManager->persist($client); $this->entityManager->flush(); $this->flash('success', t('Integration saved successfully.')); $this->flash('clientSecret', $credentials->getSecret()); return $this->redirect('/dashboard/system/api/integrations/', 'view_client', $client->getIdentifier()); }
php
public function create() { $this->add(); $this->validateIntegrationRequest(); if (!$this->token->validate('create')) { $this->error->add($this->token->getErrorMessage()); } if ($this->error->has()) { return; } $factory = $this->app->make(ClientFactory::class); $credentials = $factory->generateCredentials(); // Create a new client while hashing the new secret $client = $factory->createClient( $this->request->request->get('name'), $this->request->request->get('redirect'), [], $credentials->getKey(), password_hash($credentials->getSecret(), PASSWORD_DEFAULT) ); // Persist the new client to the database $this->entityManager->persist($client); $this->entityManager->flush(); $this->flash('success', t('Integration saved successfully.')); $this->flash('clientSecret', $credentials->getSecret()); return $this->redirect('/dashboard/system/api/integrations/', 'view_client', $client->getIdentifier()); }
[ "public", "function", "create", "(", ")", "{", "$", "this", "->", "add", "(", ")", ";", "$", "this", "->", "validateIntegrationRequest", "(", ")", ";", "if", "(", "!", "$", "this", "->", "token", "->", "validate", "(", "'create'", ")", ")", "{", "$", "this", "->", "error", "->", "add", "(", "$", "this", "->", "token", "->", "getErrorMessage", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "error", "->", "has", "(", ")", ")", "{", "return", ";", "}", "$", "factory", "=", "$", "this", "->", "app", "->", "make", "(", "ClientFactory", "::", "class", ")", ";", "$", "credentials", "=", "$", "factory", "->", "generateCredentials", "(", ")", ";", "// Create a new client while hashing the new secret", "$", "client", "=", "$", "factory", "->", "createClient", "(", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'name'", ")", ",", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'redirect'", ")", ",", "[", "]", ",", "$", "credentials", "->", "getKey", "(", ")", ",", "password_hash", "(", "$", "credentials", "->", "getSecret", "(", ")", ",", "PASSWORD_DEFAULT", ")", ")", ";", "// Persist the new client to the database", "$", "this", "->", "entityManager", "->", "persist", "(", "$", "client", ")", ";", "$", "this", "->", "entityManager", "->", "flush", "(", ")", ";", "$", "this", "->", "flash", "(", "'success'", ",", "t", "(", "'Integration saved successfully.'", ")", ")", ";", "$", "this", "->", "flash", "(", "'clientSecret'", ",", "$", "credentials", "->", "getSecret", "(", ")", ")", ";", "return", "$", "this", "->", "redirect", "(", "'/dashboard/system/api/integrations/'", ",", "'view_client'", ",", "$", "client", "->", "getIdentifier", "(", ")", ")", ";", "}" ]
Request handler to create new client objects This method: 1. Makes sure a name exists 2. Validates the request token `create` 3. Returns if any errors exist 4. Uses a ClientFactory to create a new client object 5. Uses password_hash on the client secret before storing to the database 6. Stores the secret to a session flash bag 7. Redirects to the view_client action
[ "Request", "handler", "to", "create", "new", "client", "objects" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/single_page/dashboard/system/api/integrations.php#L167-L198
train
concrete5/concrete5
concrete/src/Error/ErrorList/Formatter/StandardFormatter.php
StandardFormatter.getString
public function getString() { $html = ''; if ($this->error->has()) { $html .= '<ul class="ccm-error">'; foreach ($this->error->getList() as $error) { $html .= '<li>'; if ($error instanceof HtmlAwareErrorInterface && $error->messageContainsHtml()) { $html .= (string) $error; } else { $html .= nl2br(h((string) $error)); } $html .= '</li>'; } $html .= '</ul>'; } return $html; }
php
public function getString() { $html = ''; if ($this->error->has()) { $html .= '<ul class="ccm-error">'; foreach ($this->error->getList() as $error) { $html .= '<li>'; if ($error instanceof HtmlAwareErrorInterface && $error->messageContainsHtml()) { $html .= (string) $error; } else { $html .= nl2br(h((string) $error)); } $html .= '</li>'; } $html .= '</ul>'; } return $html; }
[ "public", "function", "getString", "(", ")", "{", "$", "html", "=", "''", ";", "if", "(", "$", "this", "->", "error", "->", "has", "(", ")", ")", "{", "$", "html", ".=", "'<ul class=\"ccm-error\">'", ";", "foreach", "(", "$", "this", "->", "error", "->", "getList", "(", ")", "as", "$", "error", ")", "{", "$", "html", ".=", "'<li>'", ";", "if", "(", "$", "error", "instanceof", "HtmlAwareErrorInterface", "&&", "$", "error", "->", "messageContainsHtml", "(", ")", ")", "{", "$", "html", ".=", "(", "string", ")", "$", "error", ";", "}", "else", "{", "$", "html", ".=", "nl2br", "(", "h", "(", "(", "string", ")", "$", "error", ")", ")", ";", "}", "$", "html", ".=", "'</li>'", ";", "}", "$", "html", ".=", "'</ul>'", ";", "}", "return", "$", "html", ";", "}" ]
Build an HTML-formatted string describing the errors. @return string
[ "Build", "an", "HTML", "-", "formatted", "string", "describing", "the", "errors", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Error/ErrorList/Formatter/StandardFormatter.php#L24-L42
train
concrete5/concrete5
concrete/controllers/single_page/dashboard/system/environment/logging.php
Logging.view
public function view($strStatus = false) { $config = $this->app->make('config'); $strStatus = (string) $strStatus; $intLogErrors = $config->get('concrete.log.errors') == 1 ? 1 : 0; $intLogEmails = $config->get('concrete.log.emails') == 1 ? 1 : 0; $this->set('fh', Loader::helper('form')); $this->set('intLogErrors', $intLogErrors); $this->set('intLogEmails', $intLogEmails); if ($strStatus == 'logging_saved') { $this->set('message', t('Logging configuration saved.')); } $levels = [ 'DEBUG' => t('Debug'), 'INFO' => t('Info'), 'NOTICE' => t('Notice'), 'WARNING' => t('Warning'), 'ERROR' => t('Error'), 'CRITICAL' => t('Critical'), 'ALERT' => t('Alert'), 'EMERGENCY' => t('Emergency'), ]; $handlers = [ 'database' => t('Database'), 'file' => t('File'), ]; $this->set('enableDashboardReport', !!$config->get('concrete.log.enable_dashboard_report')); $this->set('levels', $levels); $this->set('handlers', $handlers); $this->set('loggingMode', $config->get('concrete.log.configuration.mode')); $this->set('coreLoggingLevel', $config->get('concrete.log.configuration.simple.core_logging_level')); $this->set('handler', $config->get('concrete.log.configuration.simple.handler')); $this->set('logFile', $config->get('concrete.log.configuration.simple.file.file')); }
php
public function view($strStatus = false) { $config = $this->app->make('config'); $strStatus = (string) $strStatus; $intLogErrors = $config->get('concrete.log.errors') == 1 ? 1 : 0; $intLogEmails = $config->get('concrete.log.emails') == 1 ? 1 : 0; $this->set('fh', Loader::helper('form')); $this->set('intLogErrors', $intLogErrors); $this->set('intLogEmails', $intLogEmails); if ($strStatus == 'logging_saved') { $this->set('message', t('Logging configuration saved.')); } $levels = [ 'DEBUG' => t('Debug'), 'INFO' => t('Info'), 'NOTICE' => t('Notice'), 'WARNING' => t('Warning'), 'ERROR' => t('Error'), 'CRITICAL' => t('Critical'), 'ALERT' => t('Alert'), 'EMERGENCY' => t('Emergency'), ]; $handlers = [ 'database' => t('Database'), 'file' => t('File'), ]; $this->set('enableDashboardReport', !!$config->get('concrete.log.enable_dashboard_report')); $this->set('levels', $levels); $this->set('handlers', $handlers); $this->set('loggingMode', $config->get('concrete.log.configuration.mode')); $this->set('coreLoggingLevel', $config->get('concrete.log.configuration.simple.core_logging_level')); $this->set('handler', $config->get('concrete.log.configuration.simple.handler')); $this->set('logFile', $config->get('concrete.log.configuration.simple.file.file')); }
[ "public", "function", "view", "(", "$", "strStatus", "=", "false", ")", "{", "$", "config", "=", "$", "this", "->", "app", "->", "make", "(", "'config'", ")", ";", "$", "strStatus", "=", "(", "string", ")", "$", "strStatus", ";", "$", "intLogErrors", "=", "$", "config", "->", "get", "(", "'concrete.log.errors'", ")", "==", "1", "?", "1", ":", "0", ";", "$", "intLogEmails", "=", "$", "config", "->", "get", "(", "'concrete.log.emails'", ")", "==", "1", "?", "1", ":", "0", ";", "$", "this", "->", "set", "(", "'fh'", ",", "Loader", "::", "helper", "(", "'form'", ")", ")", ";", "$", "this", "->", "set", "(", "'intLogErrors'", ",", "$", "intLogErrors", ")", ";", "$", "this", "->", "set", "(", "'intLogEmails'", ",", "$", "intLogEmails", ")", ";", "if", "(", "$", "strStatus", "==", "'logging_saved'", ")", "{", "$", "this", "->", "set", "(", "'message'", ",", "t", "(", "'Logging configuration saved.'", ")", ")", ";", "}", "$", "levels", "=", "[", "'DEBUG'", "=>", "t", "(", "'Debug'", ")", ",", "'INFO'", "=>", "t", "(", "'Info'", ")", ",", "'NOTICE'", "=>", "t", "(", "'Notice'", ")", ",", "'WARNING'", "=>", "t", "(", "'Warning'", ")", ",", "'ERROR'", "=>", "t", "(", "'Error'", ")", ",", "'CRITICAL'", "=>", "t", "(", "'Critical'", ")", ",", "'ALERT'", "=>", "t", "(", "'Alert'", ")", ",", "'EMERGENCY'", "=>", "t", "(", "'Emergency'", ")", ",", "]", ";", "$", "handlers", "=", "[", "'database'", "=>", "t", "(", "'Database'", ")", ",", "'file'", "=>", "t", "(", "'File'", ")", ",", "]", ";", "$", "this", "->", "set", "(", "'enableDashboardReport'", ",", "!", "!", "$", "config", "->", "get", "(", "'concrete.log.enable_dashboard_report'", ")", ")", ";", "$", "this", "->", "set", "(", "'levels'", ",", "$", "levels", ")", ";", "$", "this", "->", "set", "(", "'handlers'", ",", "$", "handlers", ")", ";", "$", "this", "->", "set", "(", "'loggingMode'", ",", "$", "config", "->", "get", "(", "'concrete.log.configuration.mode'", ")", ")", ";", "$", "this", "->", "set", "(", "'coreLoggingLevel'", ",", "$", "config", "->", "get", "(", "'concrete.log.configuration.simple.core_logging_level'", ")", ")", ";", "$", "this", "->", "set", "(", "'handler'", ",", "$", "config", "->", "get", "(", "'concrete.log.configuration.simple.handler'", ")", ")", ";", "$", "this", "->", "set", "(", "'logFile'", ",", "$", "config", "->", "get", "(", "'concrete.log.configuration.simple.file.file'", ")", ")", ";", "}" ]
Dasboard page view. @param string $strStatus - Result of attempting to update logging settings
[ "Dasboard", "page", "view", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/single_page/dashboard/system/environment/logging.php#L16-L53
train
concrete5/concrete5
concrete/controllers/single_page/dashboard/system/environment/logging.php
Logging.update_logging
public function update_logging() { $config = $this->app->make('config'); if (!$this->token->validate('update_logging')) { $this->error->add($this->token->getErrorMessage()); } if ($this->request->request->get('handler') == 'file' && $this->request->request->get('logging_mode')) { $logFile = $this->request->request->get('logFile'); $filesystem = new Filesystem(); $directory = dirname($logFile); if ($filesystem->isFile($logFile) && !$filesystem->isWritable($logFile)) { $this->error->add(t('Log file exists but is not writable by the web server.')); } if (!$filesystem->isFile($logFile) && (!$filesystem->isDirectory($directory) || !$filesystem->isWritable($directory))) { $this->error->add(t('Log file does not exist on the server. The directory of the file provided must exist and be writable on the web server.')); } $filename = basename($logFile); if (!$filename || substr($filename, -4) != '.log') { $this->error->add(t('The filename provided must be a valid filename and end with .log')); } } if (!$this->error->has()) { $intLogErrorsPost = $this->post('ENABLE_LOG_ERRORS') == 1 ? 1 : 0; $intLogEmailsPost = $this->post('ENABLE_LOG_EMAILS') == 1 ? 1 : 0; $config->save('concrete.log.errors', $intLogErrorsPost); $config->save('concrete.log.emails', $intLogEmailsPost); $mode = $this->request->request->get('logging_mode'); if ($mode != 'advanced') { $mode = 'simple'; $config->save('concrete.log.configuration.simple.core_logging_level', $this->request->request->get('logging_level') ); $config->save('concrete.log.configuration.simple.handler', $this->request->request->get('handler') ); $config->save('concrete.log.configuration.simple.file.file', $this->request->request->get('logFile') ); } $config->save('concrete.log.enable_dashboard_report', $this->request->request->get('enable_dashboard_report') ? true : false); $config->save('concrete.log.configuration.mode', $mode); $this->redirect('/dashboard/system/environment/logging', 'logging_saved'); } $this->view(); }
php
public function update_logging() { $config = $this->app->make('config'); if (!$this->token->validate('update_logging')) { $this->error->add($this->token->getErrorMessage()); } if ($this->request->request->get('handler') == 'file' && $this->request->request->get('logging_mode')) { $logFile = $this->request->request->get('logFile'); $filesystem = new Filesystem(); $directory = dirname($logFile); if ($filesystem->isFile($logFile) && !$filesystem->isWritable($logFile)) { $this->error->add(t('Log file exists but is not writable by the web server.')); } if (!$filesystem->isFile($logFile) && (!$filesystem->isDirectory($directory) || !$filesystem->isWritable($directory))) { $this->error->add(t('Log file does not exist on the server. The directory of the file provided must exist and be writable on the web server.')); } $filename = basename($logFile); if (!$filename || substr($filename, -4) != '.log') { $this->error->add(t('The filename provided must be a valid filename and end with .log')); } } if (!$this->error->has()) { $intLogErrorsPost = $this->post('ENABLE_LOG_ERRORS') == 1 ? 1 : 0; $intLogEmailsPost = $this->post('ENABLE_LOG_EMAILS') == 1 ? 1 : 0; $config->save('concrete.log.errors', $intLogErrorsPost); $config->save('concrete.log.emails', $intLogEmailsPost); $mode = $this->request->request->get('logging_mode'); if ($mode != 'advanced') { $mode = 'simple'; $config->save('concrete.log.configuration.simple.core_logging_level', $this->request->request->get('logging_level') ); $config->save('concrete.log.configuration.simple.handler', $this->request->request->get('handler') ); $config->save('concrete.log.configuration.simple.file.file', $this->request->request->get('logFile') ); } $config->save('concrete.log.enable_dashboard_report', $this->request->request->get('enable_dashboard_report') ? true : false); $config->save('concrete.log.configuration.mode', $mode); $this->redirect('/dashboard/system/environment/logging', 'logging_saved'); } $this->view(); }
[ "public", "function", "update_logging", "(", ")", "{", "$", "config", "=", "$", "this", "->", "app", "->", "make", "(", "'config'", ")", ";", "if", "(", "!", "$", "this", "->", "token", "->", "validate", "(", "'update_logging'", ")", ")", "{", "$", "this", "->", "error", "->", "add", "(", "$", "this", "->", "token", "->", "getErrorMessage", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'handler'", ")", "==", "'file'", "&&", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'logging_mode'", ")", ")", "{", "$", "logFile", "=", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'logFile'", ")", ";", "$", "filesystem", "=", "new", "Filesystem", "(", ")", ";", "$", "directory", "=", "dirname", "(", "$", "logFile", ")", ";", "if", "(", "$", "filesystem", "->", "isFile", "(", "$", "logFile", ")", "&&", "!", "$", "filesystem", "->", "isWritable", "(", "$", "logFile", ")", ")", "{", "$", "this", "->", "error", "->", "add", "(", "t", "(", "'Log file exists but is not writable by the web server.'", ")", ")", ";", "}", "if", "(", "!", "$", "filesystem", "->", "isFile", "(", "$", "logFile", ")", "&&", "(", "!", "$", "filesystem", "->", "isDirectory", "(", "$", "directory", ")", "||", "!", "$", "filesystem", "->", "isWritable", "(", "$", "directory", ")", ")", ")", "{", "$", "this", "->", "error", "->", "add", "(", "t", "(", "'Log file does not exist on the server. The directory of the file provided must exist and be writable on the web server.'", ")", ")", ";", "}", "$", "filename", "=", "basename", "(", "$", "logFile", ")", ";", "if", "(", "!", "$", "filename", "||", "substr", "(", "$", "filename", ",", "-", "4", ")", "!=", "'.log'", ")", "{", "$", "this", "->", "error", "->", "add", "(", "t", "(", "'The filename provided must be a valid filename and end with .log'", ")", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "error", "->", "has", "(", ")", ")", "{", "$", "intLogErrorsPost", "=", "$", "this", "->", "post", "(", "'ENABLE_LOG_ERRORS'", ")", "==", "1", "?", "1", ":", "0", ";", "$", "intLogEmailsPost", "=", "$", "this", "->", "post", "(", "'ENABLE_LOG_EMAILS'", ")", "==", "1", "?", "1", ":", "0", ";", "$", "config", "->", "save", "(", "'concrete.log.errors'", ",", "$", "intLogErrorsPost", ")", ";", "$", "config", "->", "save", "(", "'concrete.log.emails'", ",", "$", "intLogEmailsPost", ")", ";", "$", "mode", "=", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'logging_mode'", ")", ";", "if", "(", "$", "mode", "!=", "'advanced'", ")", "{", "$", "mode", "=", "'simple'", ";", "$", "config", "->", "save", "(", "'concrete.log.configuration.simple.core_logging_level'", ",", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'logging_level'", ")", ")", ";", "$", "config", "->", "save", "(", "'concrete.log.configuration.simple.handler'", ",", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'handler'", ")", ")", ";", "$", "config", "->", "save", "(", "'concrete.log.configuration.simple.file.file'", ",", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'logFile'", ")", ")", ";", "}", "$", "config", "->", "save", "(", "'concrete.log.enable_dashboard_report'", ",", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'enable_dashboard_report'", ")", "?", "true", ":", "false", ")", ";", "$", "config", "->", "save", "(", "'concrete.log.configuration.mode'", ",", "$", "mode", ")", ";", "$", "this", "->", "redirect", "(", "'/dashboard/system/environment/logging'", ",", "'logging_saved'", ")", ";", "}", "$", "this", "->", "view", "(", ")", ";", "}" ]
Updates logging settings.
[ "Updates", "logging", "settings", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/single_page/dashboard/system/environment/logging.php#L58-L106
train
concrete5/concrete5
concrete/src/Install/Installer.php
Installer.createConnection
public function createConnection() { $pdoCheck = $this->application->make(PdoMysqlExtension::class)->performCheck(); if ($pdoCheck->getState() !== PreconditionResult::STATE_PASSED) { throw new UserMessageException($pdoCheck->getMessage()); } $databaseConfiguration = $this->getDefaultConnectionConfiguration(); if ($databaseConfiguration === null) { throw new UserMessageException(t('The configuration is missing the required database connection parameters.')); } $databaseManager = $this->application->make(DatabaseManager::class); try { $connection = $databaseManager->getFactory()->createConnection($databaseConfiguration); } catch (Exception $x) { throw new UserMessageException($x->getMessage(), $x->getCode(), $x); } catch (Throwable $x) { throw new UserMessageException($x->getMessage(), $x->getCode()); } $connection = $this->setPreferredCharsetCollation($connection); return $connection; }
php
public function createConnection() { $pdoCheck = $this->application->make(PdoMysqlExtension::class)->performCheck(); if ($pdoCheck->getState() !== PreconditionResult::STATE_PASSED) { throw new UserMessageException($pdoCheck->getMessage()); } $databaseConfiguration = $this->getDefaultConnectionConfiguration(); if ($databaseConfiguration === null) { throw new UserMessageException(t('The configuration is missing the required database connection parameters.')); } $databaseManager = $this->application->make(DatabaseManager::class); try { $connection = $databaseManager->getFactory()->createConnection($databaseConfiguration); } catch (Exception $x) { throw new UserMessageException($x->getMessage(), $x->getCode(), $x); } catch (Throwable $x) { throw new UserMessageException($x->getMessage(), $x->getCode()); } $connection = $this->setPreferredCharsetCollation($connection); return $connection; }
[ "public", "function", "createConnection", "(", ")", "{", "$", "pdoCheck", "=", "$", "this", "->", "application", "->", "make", "(", "PdoMysqlExtension", "::", "class", ")", "->", "performCheck", "(", ")", ";", "if", "(", "$", "pdoCheck", "->", "getState", "(", ")", "!==", "PreconditionResult", "::", "STATE_PASSED", ")", "{", "throw", "new", "UserMessageException", "(", "$", "pdoCheck", "->", "getMessage", "(", ")", ")", ";", "}", "$", "databaseConfiguration", "=", "$", "this", "->", "getDefaultConnectionConfiguration", "(", ")", ";", "if", "(", "$", "databaseConfiguration", "===", "null", ")", "{", "throw", "new", "UserMessageException", "(", "t", "(", "'The configuration is missing the required database connection parameters.'", ")", ")", ";", "}", "$", "databaseManager", "=", "$", "this", "->", "application", "->", "make", "(", "DatabaseManager", "::", "class", ")", ";", "try", "{", "$", "connection", "=", "$", "databaseManager", "->", "getFactory", "(", ")", "->", "createConnection", "(", "$", "databaseConfiguration", ")", ";", "}", "catch", "(", "Exception", "$", "x", ")", "{", "throw", "new", "UserMessageException", "(", "$", "x", "->", "getMessage", "(", ")", ",", "$", "x", "->", "getCode", "(", ")", ",", "$", "x", ")", ";", "}", "catch", "(", "Throwable", "$", "x", ")", "{", "throw", "new", "UserMessageException", "(", "$", "x", "->", "getMessage", "(", ")", ",", "$", "x", "->", "getCode", "(", ")", ")", ";", "}", "$", "connection", "=", "$", "this", "->", "setPreferredCharsetCollation", "(", "$", "connection", ")", ";", "return", "$", "connection", ";", "}" ]
Create a new Connection instance using the values specified in the options. @throws \Concrete\Core\Error\UserMessageException throws a UserMessageException in case of problems @return \Concrete\Core\Database\Connection\Connection
[ "Create", "a", "new", "Connection", "instance", "using", "the", "values", "specified", "in", "the", "options", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/Installer.php#L89-L111
train
concrete5/concrete5
concrete/src/Install/Installer.php
Installer.getStartingPoint
public function getStartingPoint($fallbackToDefault) { $handle = $this->getOptions()->getStartingPointHandle(); if ($handle === '') { if (!$fallbackToDefault) { throw new UserMessageException(t('The starting point has not been defined.')); } $handle = static::DEFAULT_STARTING_POINT; } $result = StartingPointPackage::getClass($handle); if ($result === null) { throw new UserMessageException(t('Invalid starting point: %s', $handle)); } $result->setInstallerOptions($this->getOptions()); return $result; }
php
public function getStartingPoint($fallbackToDefault) { $handle = $this->getOptions()->getStartingPointHandle(); if ($handle === '') { if (!$fallbackToDefault) { throw new UserMessageException(t('The starting point has not been defined.')); } $handle = static::DEFAULT_STARTING_POINT; } $result = StartingPointPackage::getClass($handle); if ($result === null) { throw new UserMessageException(t('Invalid starting point: %s', $handle)); } $result->setInstallerOptions($this->getOptions()); return $result; }
[ "public", "function", "getStartingPoint", "(", "$", "fallbackToDefault", ")", "{", "$", "handle", "=", "$", "this", "->", "getOptions", "(", ")", "->", "getStartingPointHandle", "(", ")", ";", "if", "(", "$", "handle", "===", "''", ")", "{", "if", "(", "!", "$", "fallbackToDefault", ")", "{", "throw", "new", "UserMessageException", "(", "t", "(", "'The starting point has not been defined.'", ")", ")", ";", "}", "$", "handle", "=", "static", "::", "DEFAULT_STARTING_POINT", ";", "}", "$", "result", "=", "StartingPointPackage", "::", "getClass", "(", "$", "handle", ")", ";", "if", "(", "$", "result", "===", "null", ")", "{", "throw", "new", "UserMessageException", "(", "t", "(", "'Invalid starting point: %s'", ",", "$", "handle", ")", ")", ";", "}", "$", "result", "->", "setInstallerOptions", "(", "$", "this", "->", "getOptions", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
Get the StartingPointPackage instance. @param bool $fallbackToDefault Fallback to the default one if the starting point handle is not defined? @throws UserMessageException @return StartingPointPackage
[ "Get", "the", "StartingPointPackage", "instance", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/Installer.php#L122-L138
train
concrete5/concrete5
concrete/src/Localization/Translation/Local/Factory.php
Factory.getTranslationsStats
protected function getTranslationsStats(Translations $translations, DateTime $defaultUpdatedOn) { $result = null; foreach ($translations as $translation) { if ($translation->hasTranslation()) { $result = [ 'version' => '', 'updatedOn' => $defaultUpdatedOn, ]; break; } } if ($result !== null) { $h = $translations->getHeader('Project-Id-Version'); if ($h && preg_match('/\s([\S]*\d[\S]*)$/', $h, $m)) { $result['version'] = $m[1]; } $h = $translations->getHeader('PO-Revision-Date'); if ($h) { try { $result['updatedOn'] = new DateTime($h); } catch (Exception $x) { } catch (Throwable $x) { } } } return $result; }
php
protected function getTranslationsStats(Translations $translations, DateTime $defaultUpdatedOn) { $result = null; foreach ($translations as $translation) { if ($translation->hasTranslation()) { $result = [ 'version' => '', 'updatedOn' => $defaultUpdatedOn, ]; break; } } if ($result !== null) { $h = $translations->getHeader('Project-Id-Version'); if ($h && preg_match('/\s([\S]*\d[\S]*)$/', $h, $m)) { $result['version'] = $m[1]; } $h = $translations->getHeader('PO-Revision-Date'); if ($h) { try { $result['updatedOn'] = new DateTime($h); } catch (Exception $x) { } catch (Throwable $x) { } } } return $result; }
[ "protected", "function", "getTranslationsStats", "(", "Translations", "$", "translations", ",", "DateTime", "$", "defaultUpdatedOn", ")", "{", "$", "result", "=", "null", ";", "foreach", "(", "$", "translations", "as", "$", "translation", ")", "{", "if", "(", "$", "translation", "->", "hasTranslation", "(", ")", ")", "{", "$", "result", "=", "[", "'version'", "=>", "''", ",", "'updatedOn'", "=>", "$", "defaultUpdatedOn", ",", "]", ";", "break", ";", "}", "}", "if", "(", "$", "result", "!==", "null", ")", "{", "$", "h", "=", "$", "translations", "->", "getHeader", "(", "'Project-Id-Version'", ")", ";", "if", "(", "$", "h", "&&", "preg_match", "(", "'/\\s([\\S]*\\d[\\S]*)$/'", ",", "$", "h", ",", "$", "m", ")", ")", "{", "$", "result", "[", "'version'", "]", "=", "$", "m", "[", "1", "]", ";", "}", "$", "h", "=", "$", "translations", "->", "getHeader", "(", "'PO-Revision-Date'", ")", ";", "if", "(", "$", "h", ")", "{", "try", "{", "$", "result", "[", "'updatedOn'", "]", "=", "new", "DateTime", "(", "$", "h", ")", ";", "}", "catch", "(", "Exception", "$", "x", ")", "{", "}", "catch", "(", "Throwable", "$", "x", ")", "{", "}", "}", "}", "return", "$", "result", ";", "}" ]
Get stats for a \Gettext\Translations instance. @param Translations $translations @param DateTime $defaultUpdatedOn @return null|array { @var string $version @var DateTime $updatedOn }
[ "Get", "stats", "for", "a", "\\", "Gettext", "\\", "Translations", "instance", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Translation/Local/Factory.php#L132-L160
train
concrete5/concrete5
concrete/src/Localization/Translation/Local/Factory.php
Factory.getMoFileStats
protected function getMoFileStats($moFile) { if ($this->fs->isFile($moFile)) { $lastModifiedTimestamp = $this->fs->lastModified($moFile); if ($this->cache->isEnabled()) { $cacheItem = $this->cache->getItem(self::CACHE_PREFIX . '/' . md5($moFile) . '_' . $lastModifiedTimestamp); } else { $cacheItem = null; } if ($cacheItem === null || $cacheItem->isMiss()) { $stats = $this->getTranslationsStats(Translations::fromMoFile($moFile), new DateTime('@' . $lastModifiedTimestamp)); if ($cacheItem !== null) { $cacheItem->set($stats)->expiresAfter(self::CACHE_DURATION)->save(); } } else { $stats = $cacheItem->get(); } } else { $stats = null; } return new Stats('mo', $moFile, ($stats === null) ? '' : $stats['version'], ($stats === null) ? null : $stats['updatedOn']); }
php
protected function getMoFileStats($moFile) { if ($this->fs->isFile($moFile)) { $lastModifiedTimestamp = $this->fs->lastModified($moFile); if ($this->cache->isEnabled()) { $cacheItem = $this->cache->getItem(self::CACHE_PREFIX . '/' . md5($moFile) . '_' . $lastModifiedTimestamp); } else { $cacheItem = null; } if ($cacheItem === null || $cacheItem->isMiss()) { $stats = $this->getTranslationsStats(Translations::fromMoFile($moFile), new DateTime('@' . $lastModifiedTimestamp)); if ($cacheItem !== null) { $cacheItem->set($stats)->expiresAfter(self::CACHE_DURATION)->save(); } } else { $stats = $cacheItem->get(); } } else { $stats = null; } return new Stats('mo', $moFile, ($stats === null) ? '' : $stats['version'], ($stats === null) ? null : $stats['updatedOn']); }
[ "protected", "function", "getMoFileStats", "(", "$", "moFile", ")", "{", "if", "(", "$", "this", "->", "fs", "->", "isFile", "(", "$", "moFile", ")", ")", "{", "$", "lastModifiedTimestamp", "=", "$", "this", "->", "fs", "->", "lastModified", "(", "$", "moFile", ")", ";", "if", "(", "$", "this", "->", "cache", "->", "isEnabled", "(", ")", ")", "{", "$", "cacheItem", "=", "$", "this", "->", "cache", "->", "getItem", "(", "self", "::", "CACHE_PREFIX", ".", "'/'", ".", "md5", "(", "$", "moFile", ")", ".", "'_'", ".", "$", "lastModifiedTimestamp", ")", ";", "}", "else", "{", "$", "cacheItem", "=", "null", ";", "}", "if", "(", "$", "cacheItem", "===", "null", "||", "$", "cacheItem", "->", "isMiss", "(", ")", ")", "{", "$", "stats", "=", "$", "this", "->", "getTranslationsStats", "(", "Translations", "::", "fromMoFile", "(", "$", "moFile", ")", ",", "new", "DateTime", "(", "'@'", ".", "$", "lastModifiedTimestamp", ")", ")", ";", "if", "(", "$", "cacheItem", "!==", "null", ")", "{", "$", "cacheItem", "->", "set", "(", "$", "stats", ")", "->", "expiresAfter", "(", "self", "::", "CACHE_DURATION", ")", "->", "save", "(", ")", ";", "}", "}", "else", "{", "$", "stats", "=", "$", "cacheItem", "->", "get", "(", ")", ";", "}", "}", "else", "{", "$", "stats", "=", "null", ";", "}", "return", "new", "Stats", "(", "'mo'", ",", "$", "moFile", ",", "(", "$", "stats", "===", "null", ")", "?", "''", ":", "$", "stats", "[", "'version'", "]", ",", "(", "$", "stats", "===", "null", ")", "?", "null", ":", "$", "stats", "[", "'updatedOn'", "]", ")", ";", "}" ]
Get stats for a gettext .mo file. @param string $moFile The full path to a gettext .mo file (it may not exist) @return Stats
[ "Get", "stats", "for", "a", "gettext", ".", "mo", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Translation/Local/Factory.php#L169-L191
train
concrete5/concrete5
concrete/src/Legacy/UserList.php
UserList.get
public function get($itemsToGet = 100, $offset = 0) { $userInfos = array(); $this->createQuery(); $r = parent::get($itemsToGet, intval($offset)); foreach ($r as $row) { $ui = UserInfo::getByID($row['uID']); $userInfos[] = $ui; } return $userInfos; }
php
public function get($itemsToGet = 100, $offset = 0) { $userInfos = array(); $this->createQuery(); $r = parent::get($itemsToGet, intval($offset)); foreach ($r as $row) { $ui = UserInfo::getByID($row['uID']); $userInfos[] = $ui; } return $userInfos; }
[ "public", "function", "get", "(", "$", "itemsToGet", "=", "100", ",", "$", "offset", "=", "0", ")", "{", "$", "userInfos", "=", "array", "(", ")", ";", "$", "this", "->", "createQuery", "(", ")", ";", "$", "r", "=", "parent", "::", "get", "(", "$", "itemsToGet", ",", "intval", "(", "$", "offset", ")", ")", ";", "foreach", "(", "$", "r", "as", "$", "row", ")", "{", "$", "ui", "=", "UserInfo", "::", "getByID", "(", "$", "row", "[", "'uID'", "]", ")", ";", "$", "userInfos", "[", "]", "=", "$", "ui", ";", "}", "return", "$", "userInfos", ";", "}" ]
Returns an array of userInfo objects based on current filter settings. @return UserInfo[]
[ "Returns", "an", "array", "of", "userInfo", "objects", "based", "on", "current", "filter", "settings", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Legacy/UserList.php#L103-L114
train
concrete5/concrete5
concrete/src/Legacy/UserList.php
UserList.getUserIDs
public function getUserIDs($itemsToGet = 100, $offset = 0) { $this->createQuery(); $userIDs = array(); $r = parent::get($itemsToGet, intval($offset)); foreach ($r as $row) { $userIDs[] = $row['uID']; } return $userIDs; }
php
public function getUserIDs($itemsToGet = 100, $offset = 0) { $this->createQuery(); $userIDs = array(); $r = parent::get($itemsToGet, intval($offset)); foreach ($r as $row) { $userIDs[] = $row['uID']; } return $userIDs; }
[ "public", "function", "getUserIDs", "(", "$", "itemsToGet", "=", "100", ",", "$", "offset", "=", "0", ")", "{", "$", "this", "->", "createQuery", "(", ")", ";", "$", "userIDs", "=", "array", "(", ")", ";", "$", "r", "=", "parent", "::", "get", "(", "$", "itemsToGet", ",", "intval", "(", "$", "offset", ")", ")", ";", "foreach", "(", "$", "r", "as", "$", "row", ")", "{", "$", "userIDs", "[", "]", "=", "$", "row", "[", "'uID'", "]", ";", "}", "return", "$", "userIDs", ";", "}" ]
Similar to get except it returns an array of userIDs. Much faster than getting a UserInfo object for each result if all you need is the user's id. @return array $userIDs
[ "Similar", "to", "get", "except", "it", "returns", "an", "array", "of", "userIDs", ".", "Much", "faster", "than", "getting", "a", "UserInfo", "object", "for", "each", "result", "if", "all", "you", "need", "is", "the", "user", "s", "id", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Legacy/UserList.php#L122-L132
train
concrete5/concrete5
concrete/src/Utility/IPAddress.php
IPAddress.setIp
public function setIp($ipAddress, $isHex = false) { if ($isHex) { $this->ipHex = $ipAddress; } else { //discard any IPv6 port $ipAddress = preg_replace('/\[(.*?)\].*/', '$1', $ipAddress); //discard any IPv4 port if (strpos($ipAddress, '.') !== false) { $ipAddress = preg_replace('/(.*?(?:\d{1,3}\.?){4}).*/', "$1", $ipAddress); } $this->ipHex = bin2hex(inet_pton($ipAddress)); } return $this; }
php
public function setIp($ipAddress, $isHex = false) { if ($isHex) { $this->ipHex = $ipAddress; } else { //discard any IPv6 port $ipAddress = preg_replace('/\[(.*?)\].*/', '$1', $ipAddress); //discard any IPv4 port if (strpos($ipAddress, '.') !== false) { $ipAddress = preg_replace('/(.*?(?:\d{1,3}\.?){4}).*/', "$1", $ipAddress); } $this->ipHex = bin2hex(inet_pton($ipAddress)); } return $this; }
[ "public", "function", "setIp", "(", "$", "ipAddress", ",", "$", "isHex", "=", "false", ")", "{", "if", "(", "$", "isHex", ")", "{", "$", "this", "->", "ipHex", "=", "$", "ipAddress", ";", "}", "else", "{", "//discard any IPv6 port", "$", "ipAddress", "=", "preg_replace", "(", "'/\\[(.*?)\\].*/'", ",", "'$1'", ",", "$", "ipAddress", ")", ";", "//discard any IPv4 port", "if", "(", "strpos", "(", "$", "ipAddress", ",", "'.'", ")", "!==", "false", ")", "{", "$", "ipAddress", "=", "preg_replace", "(", "'/(.*?(?:\\d{1,3}\\.?){4}).*/'", ",", "\"$1\"", ",", "$", "ipAddress", ")", ";", "}", "$", "this", "->", "ipHex", "=", "bin2hex", "(", "inet_pton", "(", "$", "ipAddress", ")", ")", ";", "}", "return", "$", "this", ";", "}" ]
Sets the current IP Address. @param string $ipAddress @param bool $isHex @return $this
[ "Sets", "the", "current", "IP", "Address", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/IPAddress.php#L33-L48
train
concrete5/concrete5
concrete/src/Utility/IPAddress.php
IPAddress.getIp
public function getIp($format = self::FORMAT_HEX) { if ($this->ipHex === null) { return null; } elseif ($format === self::FORMAT_HEX) { return $this->ipHex; } elseif ($format === self::FORMAT_IP_STRING) { return inet_ntop($this->hex2bin($this->ipHex)); } throw new \Exception('Invalid IP format'); }
php
public function getIp($format = self::FORMAT_HEX) { if ($this->ipHex === null) { return null; } elseif ($format === self::FORMAT_HEX) { return $this->ipHex; } elseif ($format === self::FORMAT_IP_STRING) { return inet_ntop($this->hex2bin($this->ipHex)); } throw new \Exception('Invalid IP format'); }
[ "public", "function", "getIp", "(", "$", "format", "=", "self", "::", "FORMAT_HEX", ")", "{", "if", "(", "$", "this", "->", "ipHex", "===", "null", ")", "{", "return", "null", ";", "}", "elseif", "(", "$", "format", "===", "self", "::", "FORMAT_HEX", ")", "{", "return", "$", "this", "->", "ipHex", ";", "}", "elseif", "(", "$", "format", "===", "self", "::", "FORMAT_IP_STRING", ")", "{", "return", "inet_ntop", "(", "$", "this", "->", "hex2bin", "(", "$", "this", "->", "ipHex", ")", ")", ";", "}", "throw", "new", "\\", "Exception", "(", "'Invalid IP format'", ")", ";", "}" ]
Returns the IPAddress string, null if no ip address has been set. @param int $format Uses the IPAddress::FORMAT_* constants @throws \Exception Throws an exception if the value is not null and no valid format constant is given @return string|null
[ "Returns", "the", "IPAddress", "string", "null", "if", "no", "ip", "address", "has", "been", "set", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/IPAddress.php#L59-L69
train
concrete5/concrete5
concrete/src/Utility/IPAddress.php
IPAddress.isLoopBack
public function isLoopBack() { if (!$this->isIpSet()) { throw new \Exception('No IP Set'); } if ($this->isIPv4() && strpos($this->ipHex, '7f') === 0) { return true; //IPv4 loopback 127.0.0.0/8 } elseif ($this->ipHex === '00000000000000000000000000000001' || $this->ipHex === '00000000000000000000ffff7f000001' ) { return true; //IPv6 loopback ::1 or ::ffff:127.0.0.1 } return false; }
php
public function isLoopBack() { if (!$this->isIpSet()) { throw new \Exception('No IP Set'); } if ($this->isIPv4() && strpos($this->ipHex, '7f') === 0) { return true; //IPv4 loopback 127.0.0.0/8 } elseif ($this->ipHex === '00000000000000000000000000000001' || $this->ipHex === '00000000000000000000ffff7f000001' ) { return true; //IPv6 loopback ::1 or ::ffff:127.0.0.1 } return false; }
[ "public", "function", "isLoopBack", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isIpSet", "(", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'No IP Set'", ")", ";", "}", "if", "(", "$", "this", "->", "isIPv4", "(", ")", "&&", "strpos", "(", "$", "this", "->", "ipHex", ",", "'7f'", ")", "===", "0", ")", "{", "return", "true", ";", "//IPv4 loopback 127.0.0.0/8", "}", "elseif", "(", "$", "this", "->", "ipHex", "===", "'00000000000000000000000000000001'", "||", "$", "this", "->", "ipHex", "===", "'00000000000000000000ffff7f000001'", ")", "{", "return", "true", ";", "//IPv6 loopback ::1 or ::ffff:127.0.0.1", "}", "return", "false", ";", "}" ]
Used to check of the current IP is a loopback IP address. @throws \Exception if no IP is set @return bool returns true for loopback IP's, returns false if it is not a loopback IP
[ "Used", "to", "check", "of", "the", "current", "IP", "is", "a", "loopback", "IP", "address", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/IPAddress.php#L103-L117
train
concrete5/concrete5
concrete/src/Utility/IPAddress.php
IPAddress.isPrivate
public function isPrivate() { if (!$this->isIpSet()) { throw new \Exception('No IP Set'); } if ( ($this->isIPv4() && (strpos($this->ipHex, '0a') === 0 //10.0.0.0/8 || strpos($this->ipHex, 'ac1') === 0 //172.16.0.0/12 || strpos($this->ipHex, 'c0a8') === 0 //192.168.0.0/16 ) ) || ($this->isIPv6() && (strpos($this->ipHex, 'fc') === 0 //fc00::/7 || strpos($this->ipHex, 'fd') === 0 //fd00::/7 || strpos($this->ipHex, 'ffff0a') === 20 //::ffff:10.0.0.0/8 || strpos($this->ipHex, 'ffffac1') === 20 //::ffff:172.16.0.0/12 || strpos($this->ipHex, 'ffffc0a8') === 20 //::ffff:192.168.0.0/16 ) ) ) { return true; } return false; }
php
public function isPrivate() { if (!$this->isIpSet()) { throw new \Exception('No IP Set'); } if ( ($this->isIPv4() && (strpos($this->ipHex, '0a') === 0 //10.0.0.0/8 || strpos($this->ipHex, 'ac1') === 0 //172.16.0.0/12 || strpos($this->ipHex, 'c0a8') === 0 //192.168.0.0/16 ) ) || ($this->isIPv6() && (strpos($this->ipHex, 'fc') === 0 //fc00::/7 || strpos($this->ipHex, 'fd') === 0 //fd00::/7 || strpos($this->ipHex, 'ffff0a') === 20 //::ffff:10.0.0.0/8 || strpos($this->ipHex, 'ffffac1') === 20 //::ffff:172.16.0.0/12 || strpos($this->ipHex, 'ffffc0a8') === 20 //::ffff:192.168.0.0/16 ) ) ) { return true; } return false; }
[ "public", "function", "isPrivate", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isIpSet", "(", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'No IP Set'", ")", ";", "}", "if", "(", "(", "$", "this", "->", "isIPv4", "(", ")", "&&", "(", "strpos", "(", "$", "this", "->", "ipHex", ",", "'0a'", ")", "===", "0", "//10.0.0.0/8", "||", "strpos", "(", "$", "this", "->", "ipHex", ",", "'ac1'", ")", "===", "0", "//172.16.0.0/12", "||", "strpos", "(", "$", "this", "->", "ipHex", ",", "'c0a8'", ")", "===", "0", "//192.168.0.0/16", ")", ")", "||", "(", "$", "this", "->", "isIPv6", "(", ")", "&&", "(", "strpos", "(", "$", "this", "->", "ipHex", ",", "'fc'", ")", "===", "0", "//fc00::/7", "||", "strpos", "(", "$", "this", "->", "ipHex", ",", "'fd'", ")", "===", "0", "//fd00::/7", "||", "strpos", "(", "$", "this", "->", "ipHex", ",", "'ffff0a'", ")", "===", "20", "//::ffff:10.0.0.0/8", "||", "strpos", "(", "$", "this", "->", "ipHex", ",", "'ffffac1'", ")", "===", "20", "//::ffff:172.16.0.0/12", "||", "strpos", "(", "$", "this", "->", "ipHex", ",", "'ffffc0a8'", ")", "===", "20", "//::ffff:192.168.0.0/16", ")", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Returns true if the IP address belongs to a private network, false if it is not. @return bool @throws \Exception
[ "Returns", "true", "if", "the", "IP", "address", "belongs", "to", "a", "private", "network", "false", "if", "it", "is", "not", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/IPAddress.php#L126-L152
train
concrete5/concrete5
concrete/src/Workflow/Workflow.php
Workflow.getWorkflowProgressCurrentStatusNum
public function getWorkflowProgressCurrentStatusNum(WorkflowProgress $wp) { $req = $wp->getWorkflowRequestObject(); if (is_object($req)) { return $req->getWorkflowRequestStatusNum(); } }
php
public function getWorkflowProgressCurrentStatusNum(WorkflowProgress $wp) { $req = $wp->getWorkflowRequestObject(); if (is_object($req)) { return $req->getWorkflowRequestStatusNum(); } }
[ "public", "function", "getWorkflowProgressCurrentStatusNum", "(", "WorkflowProgress", "$", "wp", ")", "{", "$", "req", "=", "$", "wp", "->", "getWorkflowRequestObject", "(", ")", ";", "if", "(", "is_object", "(", "$", "req", ")", ")", "{", "return", "$", "req", "->", "getWorkflowRequestStatusNum", "(", ")", ";", "}", "}" ]
we do this so that we can order things by most important, etc...
[ "we", "do", "this", "so", "that", "we", "can", "order", "things", "by", "most", "important", "etc", "..." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Workflow/Workflow.php#L111-L117
train
concrete5/concrete5
concrete/src/Entity/User/LoginAttemptRepository.php
LoginAttemptRepository.before
public function before(DateTime $before, $user = null, $count = false) { // Validate and normalize input $before = $this->validateTimezone($before); $user = $this->validateUser($user); // Build the query builder $qb = $this->createQueryBuilder('a'); if ($count) { $qb->select('count(a)'); } else { $qb->select(); } $qb->where('a.utcDate < :before')->setParameter('before', $before); // Pivot on user id if needed if ($user) { $qb->andWhere('a.userId=:user')->setParameter('user', $user); } if ($count) { try { return $qb->getQuery()->getSingleScalarResult(); } catch (UnexpectedResultException $e) { return 0; } } else { // Return an iterator that contains all login attempts before a given date return $qb->getQuery()->iterate(); } }
php
public function before(DateTime $before, $user = null, $count = false) { // Validate and normalize input $before = $this->validateTimezone($before); $user = $this->validateUser($user); // Build the query builder $qb = $this->createQueryBuilder('a'); if ($count) { $qb->select('count(a)'); } else { $qb->select(); } $qb->where('a.utcDate < :before')->setParameter('before', $before); // Pivot on user id if needed if ($user) { $qb->andWhere('a.userId=:user')->setParameter('user', $user); } if ($count) { try { return $qb->getQuery()->getSingleScalarResult(); } catch (UnexpectedResultException $e) { return 0; } } else { // Return an iterator that contains all login attempts before a given date return $qb->getQuery()->iterate(); } }
[ "public", "function", "before", "(", "DateTime", "$", "before", ",", "$", "user", "=", "null", ",", "$", "count", "=", "false", ")", "{", "// Validate and normalize input", "$", "before", "=", "$", "this", "->", "validateTimezone", "(", "$", "before", ")", ";", "$", "user", "=", "$", "this", "->", "validateUser", "(", "$", "user", ")", ";", "// Build the query builder", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'a'", ")", ";", "if", "(", "$", "count", ")", "{", "$", "qb", "->", "select", "(", "'count(a)'", ")", ";", "}", "else", "{", "$", "qb", "->", "select", "(", ")", ";", "}", "$", "qb", "->", "where", "(", "'a.utcDate < :before'", ")", "->", "setParameter", "(", "'before'", ",", "$", "before", ")", ";", "// Pivot on user id if needed", "if", "(", "$", "user", ")", "{", "$", "qb", "->", "andWhere", "(", "'a.userId=:user'", ")", "->", "setParameter", "(", "'user'", ",", "$", "user", ")", ";", "}", "if", "(", "$", "count", ")", "{", "try", "{", "return", "$", "qb", "->", "getQuery", "(", ")", "->", "getSingleScalarResult", "(", ")", ";", "}", "catch", "(", "UnexpectedResultException", "$", "e", ")", "{", "return", "0", ";", "}", "}", "else", "{", "// Return an iterator that contains all login attempts before a given date", "return", "$", "qb", "->", "getQuery", "(", ")", "->", "iterate", "(", ")", ";", "}", "}" ]
Get a list of login attempts prior to a date @param \DateTime $before Must be in UTC @param \Concrete\Core\Entity\User\User|int $user @param bool $count Whether we return an integer count, or an iterator of matches @return \Iterator|\Concrete\Core\Entity\User\LoginAttempt[]|int
[ "Get", "a", "list", "of", "login", "attempts", "prior", "to", "a", "date" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/User/LoginAttemptRepository.php#L23-L55
train
concrete5/concrete5
concrete/src/Entity/User/LoginAttemptRepository.php
LoginAttemptRepository.validateUser
private function validateUser($user, $requireValue = false) { // If we're passed something falsy, just return null if (!$user && !$requireValue) { return null; } // If we have a known supported type, resolve the id and return it if ($user instanceof User || $user instanceof UserInfo) { return (int) $user->getUserID(); } // If what we're left with is numeric, return it as an int if (is_numeric($user)) { return (int) $user; } throw new \InvalidArgumentException('Invalid user value passed, must be User instance or int'); }
php
private function validateUser($user, $requireValue = false) { // If we're passed something falsy, just return null if (!$user && !$requireValue) { return null; } // If we have a known supported type, resolve the id and return it if ($user instanceof User || $user instanceof UserInfo) { return (int) $user->getUserID(); } // If what we're left with is numeric, return it as an int if (is_numeric($user)) { return (int) $user; } throw new \InvalidArgumentException('Invalid user value passed, must be User instance or int'); }
[ "private", "function", "validateUser", "(", "$", "user", ",", "$", "requireValue", "=", "false", ")", "{", "// If we're passed something falsy, just return null", "if", "(", "!", "$", "user", "&&", "!", "$", "requireValue", ")", "{", "return", "null", ";", "}", "// If we have a known supported type, resolve the id and return it", "if", "(", "$", "user", "instanceof", "User", "||", "$", "user", "instanceof", "UserInfo", ")", "{", "return", "(", "int", ")", "$", "user", "->", "getUserID", "(", ")", ";", "}", "// If what we're left with is numeric, return it as an int", "if", "(", "is_numeric", "(", "$", "user", ")", ")", "{", "return", "(", "int", ")", "$", "user", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid user value passed, must be User instance or int'", ")", ";", "}" ]
Validate a passed user value and resolve the ID @param mixed $user @param bool $requireValue Whether a user value is required @return int|null @throws \InvalidArgumentException
[ "Validate", "a", "passed", "user", "value", "and", "resolve", "the", "ID" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/User/LoginAttemptRepository.php#L130-L148
train
concrete5/concrete5
concrete/src/Entity/OAuth/AuthCodeRepository.php
AuthCodeRepository.persistNewAuthCode
public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity) { $this->getEntityManager()->transactional(function(EntityManagerInterface $entityManager) use ($authCodeEntity) { $entityManager->persist($authCodeEntity); }); }
php
public function persistNewAuthCode(AuthCodeEntityInterface $authCodeEntity) { $this->getEntityManager()->transactional(function(EntityManagerInterface $entityManager) use ($authCodeEntity) { $entityManager->persist($authCodeEntity); }); }
[ "public", "function", "persistNewAuthCode", "(", "AuthCodeEntityInterface", "$", "authCodeEntity", ")", "{", "$", "this", "->", "getEntityManager", "(", ")", "->", "transactional", "(", "function", "(", "EntityManagerInterface", "$", "entityManager", ")", "use", "(", "$", "authCodeEntity", ")", "{", "$", "entityManager", "->", "persist", "(", "$", "authCodeEntity", ")", ";", "}", ")", ";", "}" ]
Persists a new auth code to permanent storage. @param AuthCodeEntityInterface $authCodeEntity @throws \Exception
[ "Persists", "a", "new", "auth", "code", "to", "permanent", "storage", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/OAuth/AuthCodeRepository.php#L30-L35
train
concrete5/concrete5
concrete/src/Entity/OAuth/AuthCodeRepository.php
AuthCodeRepository.revokeAuthCode
public function revokeAuthCode($codeId) { $code = $this->find($codeId); if (!$code) { throw new \InvalidArgumentException('Invalid auth token code'); } $this->getEntityManager()->transactional(function(EntityManagerInterface $em) use ($code) { $code = $em->merge($code); if ($code) { $em->remove($code); } }); }
php
public function revokeAuthCode($codeId) { $code = $this->find($codeId); if (!$code) { throw new \InvalidArgumentException('Invalid auth token code'); } $this->getEntityManager()->transactional(function(EntityManagerInterface $em) use ($code) { $code = $em->merge($code); if ($code) { $em->remove($code); } }); }
[ "public", "function", "revokeAuthCode", "(", "$", "codeId", ")", "{", "$", "code", "=", "$", "this", "->", "find", "(", "$", "codeId", ")", ";", "if", "(", "!", "$", "code", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid auth token code'", ")", ";", "}", "$", "this", "->", "getEntityManager", "(", ")", "->", "transactional", "(", "function", "(", "EntityManagerInterface", "$", "em", ")", "use", "(", "$", "code", ")", "{", "$", "code", "=", "$", "em", "->", "merge", "(", "$", "code", ")", ";", "if", "(", "$", "code", ")", "{", "$", "em", "->", "remove", "(", "$", "code", ")", ";", "}", "}", ")", ";", "}" ]
Revoke an auth code. @param string $codeId @throws \Exception
[ "Revoke", "an", "auth", "code", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Entity/OAuth/AuthCodeRepository.php#L43-L57
train
concrete5/concrete5
concrete/src/Express/Search/SearchProvider.php
SearchProvider.getItemsPerPage
public function getItemsPerPage() { $query = $this->getSessionCurrentQuery(); if ($query) { return $query->getItemsPerPage(); } else { return $this->entity->getItemsPerPage(); } }
php
public function getItemsPerPage() { $query = $this->getSessionCurrentQuery(); if ($query) { return $query->getItemsPerPage(); } else { return $this->entity->getItemsPerPage(); } }
[ "public", "function", "getItemsPerPage", "(", ")", "{", "$", "query", "=", "$", "this", "->", "getSessionCurrentQuery", "(", ")", ";", "if", "(", "$", "query", ")", "{", "return", "$", "query", "->", "getItemsPerPage", "(", ")", ";", "}", "else", "{", "return", "$", "this", "->", "entity", "->", "getItemsPerPage", "(", ")", ";", "}", "}" ]
Returns the number of items per page. @return int
[ "Returns", "the", "number", "of", "items", "per", "page", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Express/Search/SearchProvider.php#L101-L109
train
concrete5/concrete5
concrete/src/Foundation/Queue/DatabaseQueueAdapter.php
DatabaseQueueAdapter.getQueueId
protected function getQueueId($name) { $r = $this->db->fetchColumn('select queue_id from Queues where queue_name = ? limit 1', [$name]); if ($r === false) { throw new RuntimeException(t('Queue does not exist: %s', $name)); } $count = (int) $r; return $count; }
php
protected function getQueueId($name) { $r = $this->db->fetchColumn('select queue_id from Queues where queue_name = ? limit 1', [$name]); if ($r === false) { throw new RuntimeException(t('Queue does not exist: %s', $name)); } $count = (int) $r; return $count; }
[ "protected", "function", "getQueueId", "(", "$", "name", ")", "{", "$", "r", "=", "$", "this", "->", "db", "->", "fetchColumn", "(", "'select queue_id from Queues where queue_name = ? limit 1'", ",", "[", "$", "name", "]", ")", ";", "if", "(", "$", "r", "===", "false", ")", "{", "throw", "new", "RuntimeException", "(", "t", "(", "'Queue does not exist: %s'", ",", "$", "name", ")", ")", ";", "}", "$", "count", "=", "(", "int", ")", "$", "r", ";", "return", "$", "count", ";", "}" ]
Get the identifier of a queue given its name. @param string $name The name of a queue @throws RuntimeException Throws a RuntimeException if the queue does not exist @return int
[ "Get", "the", "identifier", "of", "a", "queue", "given", "its", "name", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Queue/DatabaseQueueAdapter.php#L281-L292
train
concrete5/concrete5
concrete/src/Utility/Service/Text.php
Text.encodePath
public static function encodePath($path) { if (mb_strpos($path, '/') !== false) { $path = explode('/', $path); $path = array_map('rawurlencode', $path); $newPath = implode('/', $path); } else { if (is_null($path)) { $newPath = null; } else { $newPath = rawurlencode($path); } } $path = str_replace('%21', '!', $newPath); return $path; }
php
public static function encodePath($path) { if (mb_strpos($path, '/') !== false) { $path = explode('/', $path); $path = array_map('rawurlencode', $path); $newPath = implode('/', $path); } else { if (is_null($path)) { $newPath = null; } else { $newPath = rawurlencode($path); } } $path = str_replace('%21', '!', $newPath); return $path; }
[ "public", "static", "function", "encodePath", "(", "$", "path", ")", "{", "if", "(", "mb_strpos", "(", "$", "path", ",", "'/'", ")", "!==", "false", ")", "{", "$", "path", "=", "explode", "(", "'/'", ",", "$", "path", ")", ";", "$", "path", "=", "array_map", "(", "'rawurlencode'", ",", "$", "path", ")", ";", "$", "newPath", "=", "implode", "(", "'/'", ",", "$", "path", ")", ";", "}", "else", "{", "if", "(", "is_null", "(", "$", "path", ")", ")", "{", "$", "newPath", "=", "null", ";", "}", "else", "{", "$", "newPath", "=", "rawurlencode", "(", "$", "path", ")", ";", "}", "}", "$", "path", "=", "str_replace", "(", "'%21'", ",", "'!'", ",", "$", "newPath", ")", ";", "return", "$", "path", ";", "}" ]
URL-encodes collection path. @param string $path @return string $path
[ "URL", "-", "encodes", "collection", "path", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Text.php#L29-L45
train
concrete5/concrete5
concrete/src/Utility/Service/Text.php
Text.slugSafeString
public function slugSafeString($handle, $maxlength = 128) { $handle = preg_replace('/[^\\p{L}\\p{Nd}\-_]+/u', ' ', $handle); // remove unneeded chars $handle = preg_replace('/[-\s]+/', '-', $handle); // convert spaces to hyphens return trim(Utf8::substr($handle, 0, $maxlength), '-'); // trim to first $max_length chars }
php
public function slugSafeString($handle, $maxlength = 128) { $handle = preg_replace('/[^\\p{L}\\p{Nd}\-_]+/u', ' ', $handle); // remove unneeded chars $handle = preg_replace('/[-\s]+/', '-', $handle); // convert spaces to hyphens return trim(Utf8::substr($handle, 0, $maxlength), '-'); // trim to first $max_length chars }
[ "public", "function", "slugSafeString", "(", "$", "handle", ",", "$", "maxlength", "=", "128", ")", "{", "$", "handle", "=", "preg_replace", "(", "'/[^\\\\p{L}\\\\p{Nd}\\-_]+/u'", ",", "' '", ",", "$", "handle", ")", ";", "// remove unneeded chars", "$", "handle", "=", "preg_replace", "(", "'/[-\\s]+/'", ",", "'-'", ",", "$", "handle", ")", ";", "// convert spaces to hyphens", "return", "trim", "(", "Utf8", "::", "substr", "(", "$", "handle", ",", "0", ",", "$", "maxlength", ")", ",", "'-'", ")", ";", "// trim to first $max_length chars", "}" ]
Remove unsafe characters for URL slug. @param string $handle @param int $maxlength = Max number of characters of the return value @return string $handle
[ "Remove", "unsafe", "characters", "for", "URL", "slug", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Text.php#L79-L84
train
concrete5/concrete5
concrete/src/Utility/Service/Text.php
Text.sanitize
public function sanitize($string, $max_length = 0, $allowed = '') { $text = trim(strip_tags($string, $allowed)); if ($max_length > 0) { if (function_exists('mb_substr')) { $text = mb_substr($text, 0, $max_length, APP_CHARSET); } else { $text = substr($text, 0, $max_length); } } if ($text == null) { return ""; // we need to explicitly return a string otherwise some DB functions might insert this as a ZERO. } return $text; }
php
public function sanitize($string, $max_length = 0, $allowed = '') { $text = trim(strip_tags($string, $allowed)); if ($max_length > 0) { if (function_exists('mb_substr')) { $text = mb_substr($text, 0, $max_length, APP_CHARSET); } else { $text = substr($text, 0, $max_length); } } if ($text == null) { return ""; // we need to explicitly return a string otherwise some DB functions might insert this as a ZERO. } return $text; }
[ "public", "function", "sanitize", "(", "$", "string", ",", "$", "max_length", "=", "0", ",", "$", "allowed", "=", "''", ")", "{", "$", "text", "=", "trim", "(", "strip_tags", "(", "$", "string", ",", "$", "allowed", ")", ")", ";", "if", "(", "$", "max_length", ">", "0", ")", "{", "if", "(", "function_exists", "(", "'mb_substr'", ")", ")", "{", "$", "text", "=", "mb_substr", "(", "$", "text", ",", "0", ",", "$", "max_length", ",", "APP_CHARSET", ")", ";", "}", "else", "{", "$", "text", "=", "substr", "(", "$", "text", ",", "0", ",", "$", "max_length", ")", ";", "}", "}", "if", "(", "$", "text", "==", "null", ")", "{", "return", "\"\"", ";", "// we need to explicitly return a string otherwise some DB functions might insert this as a ZERO.", "}", "return", "$", "text", ";", "}" ]
Strips tags and optionally reduces string to specified length. @param string $string @param int $max_length @param string $allowed @return string
[ "Strips", "tags", "and", "optionally", "reduces", "string", "to", "specified", "length", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Text.php#L95-L110
train
concrete5/concrete5
concrete/src/Utility/Service/Text.php
Text.makenice
public function makenice($input) { $output = strip_tags($input); $output = $this->autolink($output); $output = nl2br($output); return $output; }
php
public function makenice($input) { $output = strip_tags($input); $output = $this->autolink($output); $output = nl2br($output); return $output; }
[ "public", "function", "makenice", "(", "$", "input", ")", "{", "$", "output", "=", "strip_tags", "(", "$", "input", ")", ";", "$", "output", "=", "$", "this", "->", "autolink", "(", "$", "output", ")", ";", "$", "output", "=", "nl2br", "(", "$", "output", ")", ";", "return", "$", "output", ";", "}" ]
Runs a number of text functions, including autolink, nl2br, strip_tags. Assumes that you want simple text comments but with a few niceties. @param string $input @return string $output
[ "Runs", "a", "number", "of", "text", "functions", "including", "autolink", "nl2br", "strip_tags", ".", "Assumes", "that", "you", "want", "simple", "text", "comments", "but", "with", "a", "few", "niceties", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Text.php#L262-L269
train
concrete5/concrete5
concrete/src/Utility/Service/Text.php
Text.autolink
public function autolink($input, $newWindow = false, $defaultProtocol = 'http://') { $target = $newWindow ? ' target="_blank"' : ''; $output = preg_replace_callback( '/(http:\/\/|https:\/\/|(www\.))(([^\s<]{4,80})[^\s<]*)/', function (array $matches) use ($target, $defaultProtocol) { $protocol = strpos($matches[1], ':') ? $matches[1] : $defaultProtocol; return "<a href=\"{$protocol}{$matches[2]}{$matches[3]}\"{$target} rel=\"nofollow\">{$matches[2]}{$matches[4]}</a>"; }, $input); return $output; }
php
public function autolink($input, $newWindow = false, $defaultProtocol = 'http://') { $target = $newWindow ? ' target="_blank"' : ''; $output = preg_replace_callback( '/(http:\/\/|https:\/\/|(www\.))(([^\s<]{4,80})[^\s<]*)/', function (array $matches) use ($target, $defaultProtocol) { $protocol = strpos($matches[1], ':') ? $matches[1] : $defaultProtocol; return "<a href=\"{$protocol}{$matches[2]}{$matches[3]}\"{$target} rel=\"nofollow\">{$matches[2]}{$matches[4]}</a>"; }, $input); return $output; }
[ "public", "function", "autolink", "(", "$", "input", ",", "$", "newWindow", "=", "false", ",", "$", "defaultProtocol", "=", "'http://'", ")", "{", "$", "target", "=", "$", "newWindow", "?", "' target=\"_blank\"'", ":", "''", ";", "$", "output", "=", "preg_replace_callback", "(", "'/(http:\\/\\/|https:\\/\\/|(www\\.))(([^\\s<]{4,80})[^\\s<]*)/'", ",", "function", "(", "array", "$", "matches", ")", "use", "(", "$", "target", ",", "$", "defaultProtocol", ")", "{", "$", "protocol", "=", "strpos", "(", "$", "matches", "[", "1", "]", ",", "':'", ")", "?", "$", "matches", "[", "1", "]", ":", "$", "defaultProtocol", ";", "return", "\"<a href=\\\"{$protocol}{$matches[2]}{$matches[3]}\\\"{$target} rel=\\\"nofollow\\\">{$matches[2]}{$matches[4]}</a>\"", ";", "}", ",", "$", "input", ")", ";", "return", "$", "output", ";", "}" ]
Scans passed text and automatically hyperlinks any URL inside it. @param string $input @param bool $newWindow @param string $defaultProtocol @return string $output
[ "Scans", "passed", "text", "and", "automatically", "hyperlinks", "any", "URL", "inside", "it", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Text.php#L291-L303
train
concrete5/concrete5
concrete/src/Utility/Service/Text.php
Text.handle
public function handle($handle, $leaveSlashes = false) { $handle = $this->sanitizeFileSystem($handle, $leaveSlashes); return str_replace('-', '_', $handle); }
php
public function handle($handle, $leaveSlashes = false) { $handle = $this->sanitizeFileSystem($handle, $leaveSlashes); return str_replace('-', '_', $handle); }
[ "public", "function", "handle", "(", "$", "handle", ",", "$", "leaveSlashes", "=", "false", ")", "{", "$", "handle", "=", "$", "this", "->", "sanitizeFileSystem", "(", "$", "handle", ",", "$", "leaveSlashes", ")", ";", "return", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "handle", ")", ";", "}" ]
Takes a string and turns it into a handle. @param $handle @param bool $leaveSlashes @return string
[ "Takes", "a", "string", "and", "turns", "it", "into", "a", "handle", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Text.php#L360-L364
train
concrete5/concrete5
concrete/src/Utility/Service/Text.php
Text.urlify
public function urlify($handle, $max_length = null, $locale = '', $removeExcludedWords = true) { if ($max_length === null) { $max_length = Config::get('concrete.seo.segment_max_length'); } $text = strtolower(str_replace(array("\r", "\n", "\t"), ' ', $this->asciify($handle, $locale))); if ($removeExcludedWords) { $excludeSeoWords = Config::get('concrete.seo.exclude_words'); if (is_string($excludeSeoWords)) { if (strlen($excludeSeoWords)) { $remove_list = explode(',', $excludeSeoWords); $remove_list = array_map('trim', $remove_list); $remove_list = array_filter($remove_list, 'strlen'); } else { $remove_list = array(); } } else { $remove_list = URLify::$remove_list; } if (count($remove_list)) { $text = preg_replace('/\b(' . implode('|', $remove_list) . ')\b/i', '', $text); } } $text = preg_replace('/[^-\w\s]/', '', $text); // remove unneeded chars $text = str_replace('_', ' ', $text); // treat underscores as spaces $text = preg_replace('/^\s+|\s+$/', '', $text); // trim leading/trailing spaces $text = preg_replace('/[-\s]+/', '-', $text); // convert spaces to hyphens $text = strtolower($text); // convert to lowercase return trim(substr($text, 0, $max_length), '-'); // trim to first $maxlength chars }
php
public function urlify($handle, $max_length = null, $locale = '', $removeExcludedWords = true) { if ($max_length === null) { $max_length = Config::get('concrete.seo.segment_max_length'); } $text = strtolower(str_replace(array("\r", "\n", "\t"), ' ', $this->asciify($handle, $locale))); if ($removeExcludedWords) { $excludeSeoWords = Config::get('concrete.seo.exclude_words'); if (is_string($excludeSeoWords)) { if (strlen($excludeSeoWords)) { $remove_list = explode(',', $excludeSeoWords); $remove_list = array_map('trim', $remove_list); $remove_list = array_filter($remove_list, 'strlen'); } else { $remove_list = array(); } } else { $remove_list = URLify::$remove_list; } if (count($remove_list)) { $text = preg_replace('/\b(' . implode('|', $remove_list) . ')\b/i', '', $text); } } $text = preg_replace('/[^-\w\s]/', '', $text); // remove unneeded chars $text = str_replace('_', ' ', $text); // treat underscores as spaces $text = preg_replace('/^\s+|\s+$/', '', $text); // trim leading/trailing spaces $text = preg_replace('/[-\s]+/', '-', $text); // convert spaces to hyphens $text = strtolower($text); // convert to lowercase return trim(substr($text, 0, $max_length), '-'); // trim to first $maxlength chars }
[ "public", "function", "urlify", "(", "$", "handle", ",", "$", "max_length", "=", "null", ",", "$", "locale", "=", "''", ",", "$", "removeExcludedWords", "=", "true", ")", "{", "if", "(", "$", "max_length", "===", "null", ")", "{", "$", "max_length", "=", "Config", "::", "get", "(", "'concrete.seo.segment_max_length'", ")", ";", "}", "$", "text", "=", "strtolower", "(", "str_replace", "(", "array", "(", "\"\\r\"", ",", "\"\\n\"", ",", "\"\\t\"", ")", ",", "' '", ",", "$", "this", "->", "asciify", "(", "$", "handle", ",", "$", "locale", ")", ")", ")", ";", "if", "(", "$", "removeExcludedWords", ")", "{", "$", "excludeSeoWords", "=", "Config", "::", "get", "(", "'concrete.seo.exclude_words'", ")", ";", "if", "(", "is_string", "(", "$", "excludeSeoWords", ")", ")", "{", "if", "(", "strlen", "(", "$", "excludeSeoWords", ")", ")", "{", "$", "remove_list", "=", "explode", "(", "','", ",", "$", "excludeSeoWords", ")", ";", "$", "remove_list", "=", "array_map", "(", "'trim'", ",", "$", "remove_list", ")", ";", "$", "remove_list", "=", "array_filter", "(", "$", "remove_list", ",", "'strlen'", ")", ";", "}", "else", "{", "$", "remove_list", "=", "array", "(", ")", ";", "}", "}", "else", "{", "$", "remove_list", "=", "URLify", "::", "$", "remove_list", ";", "}", "if", "(", "count", "(", "$", "remove_list", ")", ")", "{", "$", "text", "=", "preg_replace", "(", "'/\\b('", ".", "implode", "(", "'|'", ",", "$", "remove_list", ")", ".", "')\\b/i'", ",", "''", ",", "$", "text", ")", ";", "}", "}", "$", "text", "=", "preg_replace", "(", "'/[^-\\w\\s]/'", ",", "''", ",", "$", "text", ")", ";", "// remove unneeded chars", "$", "text", "=", "str_replace", "(", "'_'", ",", "' '", ",", "$", "text", ")", ";", "// treat underscores as spaces", "$", "text", "=", "preg_replace", "(", "'/^\\s+|\\s+$/'", ",", "''", ",", "$", "text", ")", ";", "// trim leading/trailing spaces", "$", "text", "=", "preg_replace", "(", "'/[-\\s]+/'", ",", "'-'", ",", "$", "text", ")", ";", "// convert spaces to hyphens", "$", "text", "=", "strtolower", "(", "$", "text", ")", ";", "// convert to lowercase", "return", "trim", "(", "substr", "(", "$", "text", ",", "0", ",", "$", "max_length", ")", ",", "'-'", ")", ";", "// trim to first $maxlength chars", "}" ]
Takes text and returns it in the "lowercase-and-dashed-with-no-punctuation" format. @param string $handle @param int $max_length Max number of characters of the return value @param string $locale Language code of the language rules that should be priorized @param bool $removeExcludedWords Set to true to remove excluded words, false to allow them. @return string
[ "Takes", "text", "and", "returns", "it", "in", "the", "lowercase", "-", "and", "-", "dashed", "-", "with", "-", "no", "-", "punctuation", "format", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Text.php#L392-L421
train
concrete5/concrete5
concrete/src/Utility/Service/Text.php
Text.highlightSearch
public function highlightSearch($value, $searchString) { if (strlen($value) < 1 || strlen($searchString) < 1) { return $value; } preg_match_all("/$searchString+/i", $value, $matches); if (is_array($matches[0]) && count($matches[0]) > 0) { return str_replace($matches[0][0], '<em class="ccm-highlight-search">' . $matches[0][0] . '</em>', $value); } return $value; }
php
public function highlightSearch($value, $searchString) { if (strlen($value) < 1 || strlen($searchString) < 1) { return $value; } preg_match_all("/$searchString+/i", $value, $matches); if (is_array($matches[0]) && count($matches[0]) > 0) { return str_replace($matches[0][0], '<em class="ccm-highlight-search">' . $matches[0][0] . '</em>', $value); } return $value; }
[ "public", "function", "highlightSearch", "(", "$", "value", ",", "$", "searchString", ")", "{", "if", "(", "strlen", "(", "$", "value", ")", "<", "1", "||", "strlen", "(", "$", "searchString", ")", "<", "1", ")", "{", "return", "$", "value", ";", "}", "preg_match_all", "(", "\"/$searchString+/i\"", ",", "$", "value", ",", "$", "matches", ")", ";", "if", "(", "is_array", "(", "$", "matches", "[", "0", "]", ")", "&&", "count", "(", "$", "matches", "[", "0", "]", ")", ">", "0", ")", "{", "return", "str_replace", "(", "$", "matches", "[", "0", "]", "[", "0", "]", ",", "'<em class=\"ccm-highlight-search\">'", ".", "$", "matches", "[", "0", "]", "[", "0", "]", ".", "'</em>'", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Highlights a string within a string with the class ccm-highlight-search. @param string $value @param string $searchString @return string
[ "Highlights", "a", "string", "within", "a", "string", "with", "the", "class", "ccm", "-", "highlight", "-", "search", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Text.php#L516-L527
train
concrete5/concrete5
concrete/src/Utility/Service/Text.php
Text.appendXML
public function appendXML(\SimpleXMLElement $root, \SimpleXMLElement $new) { $node = $root->addChild($new->getName(), (string) $new); foreach ($new->attributes() as $attr => $value) { $node->addAttribute($attr, $value); } foreach ($new->children() as $ch) { $this->appendXML($node, $ch); } }
php
public function appendXML(\SimpleXMLElement $root, \SimpleXMLElement $new) { $node = $root->addChild($new->getName(), (string) $new); foreach ($new->attributes() as $attr => $value) { $node->addAttribute($attr, $value); } foreach ($new->children() as $ch) { $this->appendXML($node, $ch); } }
[ "public", "function", "appendXML", "(", "\\", "SimpleXMLElement", "$", "root", ",", "\\", "SimpleXMLElement", "$", "new", ")", "{", "$", "node", "=", "$", "root", "->", "addChild", "(", "$", "new", "->", "getName", "(", ")", ",", "(", "string", ")", "$", "new", ")", ";", "foreach", "(", "$", "new", "->", "attributes", "(", ")", "as", "$", "attr", "=>", "$", "value", ")", "{", "$", "node", "->", "addAttribute", "(", "$", "attr", ",", "$", "value", ")", ";", "}", "foreach", "(", "$", "new", "->", "children", "(", ")", "as", "$", "ch", ")", "{", "$", "this", "->", "appendXML", "(", "$", "node", ",", "$", "ch", ")", ";", "}", "}" ]
Appends a SimpleXMLElement to a SimpleXMLElement. @param \SimpleXMLElement $root @param \SimpleXMLElement $new
[ "Appends", "a", "SimpleXMLElement", "to", "a", "SimpleXMLElement", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Utility/Service/Text.php#L552-L561
train
concrete5/concrete5
concrete/src/Application/Service/UserInterface.php
UserInterface.submit
public function submit($text, $formID = false, $buttonAlign = 'right', $innerClass = null, $args = []) { if ('right' == $buttonAlign) { $innerClass .= ' pull-right'; } elseif ('left' == $buttonAlign) { $innerClass .= ' pull-left'; } if (!$formID) { $formID = 'button'; } $argsstr = ''; foreach ($args as $k => $v) { $argsstr .= $k . '="' . $v . '" '; } return '<input type="submit" class="btn ' . $innerClass . '" value="' . $text . '" id="ccm-submit-' . $formID . '" name="ccm-submit-' . $formID . '" ' . $argsstr . ' />'; }
php
public function submit($text, $formID = false, $buttonAlign = 'right', $innerClass = null, $args = []) { if ('right' == $buttonAlign) { $innerClass .= ' pull-right'; } elseif ('left' == $buttonAlign) { $innerClass .= ' pull-left'; } if (!$formID) { $formID = 'button'; } $argsstr = ''; foreach ($args as $k => $v) { $argsstr .= $k . '="' . $v . '" '; } return '<input type="submit" class="btn ' . $innerClass . '" value="' . $text . '" id="ccm-submit-' . $formID . '" name="ccm-submit-' . $formID . '" ' . $argsstr . ' />'; }
[ "public", "function", "submit", "(", "$", "text", ",", "$", "formID", "=", "false", ",", "$", "buttonAlign", "=", "'right'", ",", "$", "innerClass", "=", "null", ",", "$", "args", "=", "[", "]", ")", "{", "if", "(", "'right'", "==", "$", "buttonAlign", ")", "{", "$", "innerClass", ".=", "' pull-right'", ";", "}", "elseif", "(", "'left'", "==", "$", "buttonAlign", ")", "{", "$", "innerClass", ".=", "' pull-left'", ";", "}", "if", "(", "!", "$", "formID", ")", "{", "$", "formID", "=", "'button'", ";", "}", "$", "argsstr", "=", "''", ";", "foreach", "(", "$", "args", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "argsstr", ".=", "$", "k", ".", "'=\"'", ".", "$", "v", ".", "'\" '", ";", "}", "return", "'<input type=\"submit\" class=\"btn '", ".", "$", "innerClass", ".", "'\" value=\"'", ".", "$", "text", ".", "'\" id=\"ccm-submit-'", ".", "$", "formID", ".", "'\" name=\"ccm-submit-'", ".", "$", "formID", ".", "'\" '", ".", "$", "argsstr", ".", "' />'", ";", "}" ]
Generates a submit button in the Concrete style. @param string $text The text of the button @param bool|string $formID The form this button will submit @param string $buttonAlign @param string $innerClass @param array $args Extra args passed to the link @return string
[ "Generates", "a", "submit", "button", "in", "the", "Concrete", "style", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/UserInterface.php#L41-L58
train
concrete5/concrete5
concrete/src/Application/Service/UserInterface.php
UserInterface.button
public function button($text, $href, $buttonAlign = 'right', $innerClass = null, $args = []) { if ('right' == $buttonAlign) { $innerClass .= ' pull-right'; } elseif ('left' == $buttonAlign) { $innerClass .= ' pull-left'; } $argsstr = ''; foreach ($args as $k => $v) { $argsstr .= $k . '="' . $v . '" '; } return '<a href="' . $href . '" class="btn btn-default ' . $innerClass . '" ' . $argsstr . '>' . $text . '</a>'; }
php
public function button($text, $href, $buttonAlign = 'right', $innerClass = null, $args = []) { if ('right' == $buttonAlign) { $innerClass .= ' pull-right'; } elseif ('left' == $buttonAlign) { $innerClass .= ' pull-left'; } $argsstr = ''; foreach ($args as $k => $v) { $argsstr .= $k . '="' . $v . '" '; } return '<a href="' . $href . '" class="btn btn-default ' . $innerClass . '" ' . $argsstr . '>' . $text . '</a>'; }
[ "public", "function", "button", "(", "$", "text", ",", "$", "href", ",", "$", "buttonAlign", "=", "'right'", ",", "$", "innerClass", "=", "null", ",", "$", "args", "=", "[", "]", ")", "{", "if", "(", "'right'", "==", "$", "buttonAlign", ")", "{", "$", "innerClass", ".=", "' pull-right'", ";", "}", "elseif", "(", "'left'", "==", "$", "buttonAlign", ")", "{", "$", "innerClass", ".=", "' pull-left'", ";", "}", "$", "argsstr", "=", "''", ";", "foreach", "(", "$", "args", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "argsstr", ".=", "$", "k", ".", "'=\"'", ".", "$", "v", ".", "'\" '", ";", "}", "return", "'<a href=\"'", ".", "$", "href", ".", "'\" class=\"btn btn-default '", ".", "$", "innerClass", ".", "'\" '", ".", "$", "argsstr", ".", "'>'", ".", "$", "text", ".", "'</a>'", ";", "}" ]
Generates a simple link button in the Concrete style. @param string $text The text of the button @param string $href @param string $buttonAlign @param string $innerClass @param array $args Extra args passed to the link @return string
[ "Generates", "a", "simple", "link", "button", "in", "the", "Concrete", "style", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/UserInterface.php#L71-L84
train
concrete5/concrete5
concrete/src/Application/Service/UserInterface.php
UserInterface.buttonJs
public function buttonJs($text, $onclick, $buttonAlign = 'right', $innerClass = null, $args = []) { if ('right' == $buttonAlign) { $innerClass .= ' pull-right'; } elseif ('left' == $buttonAlign) { $innerClass .= ' pull-left'; } $argsstr = ''; foreach ($args as $k => $v) { $argsstr .= $k . '="' . $v . '" '; } return '<input type="button" class="btn btn-default ' . $innerClass . '" value="' . $text . '" onclick="' . $onclick . '" ' . $buttonAlign . ' ' . $argsstr . ' />'; }
php
public function buttonJs($text, $onclick, $buttonAlign = 'right', $innerClass = null, $args = []) { if ('right' == $buttonAlign) { $innerClass .= ' pull-right'; } elseif ('left' == $buttonAlign) { $innerClass .= ' pull-left'; } $argsstr = ''; foreach ($args as $k => $v) { $argsstr .= $k . '="' . $v . '" '; } return '<input type="button" class="btn btn-default ' . $innerClass . '" value="' . $text . '" onclick="' . $onclick . '" ' . $buttonAlign . ' ' . $argsstr . ' />'; }
[ "public", "function", "buttonJs", "(", "$", "text", ",", "$", "onclick", ",", "$", "buttonAlign", "=", "'right'", ",", "$", "innerClass", "=", "null", ",", "$", "args", "=", "[", "]", ")", "{", "if", "(", "'right'", "==", "$", "buttonAlign", ")", "{", "$", "innerClass", ".=", "' pull-right'", ";", "}", "elseif", "(", "'left'", "==", "$", "buttonAlign", ")", "{", "$", "innerClass", ".=", "' pull-left'", ";", "}", "$", "argsstr", "=", "''", ";", "foreach", "(", "$", "args", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "argsstr", ".=", "$", "k", ".", "'=\"'", ".", "$", "v", ".", "'\" '", ";", "}", "return", "'<input type=\"button\" class=\"btn btn-default '", ".", "$", "innerClass", ".", "'\" value=\"'", ".", "$", "text", ".", "'\" onclick=\"'", ".", "$", "onclick", ".", "'\" '", ".", "$", "buttonAlign", ".", "' '", ".", "$", "argsstr", ".", "' />'", ";", "}" ]
Generates a JavaScript function button in the Concrete style. @param string $text The text of the button @param string $onclick @param string $buttonAlign @param string $innerClass - no longer used @param array $args Extra args passed to the link @return string
[ "Generates", "a", "JavaScript", "function", "button", "in", "the", "Concrete", "style", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/UserInterface.php#L97-L110
train
concrete5/concrete5
concrete/src/Application/Service/UserInterface.php
UserInterface.showHelpOverlay
public function showHelpOverlay() { $result = false; if (Config::get('concrete.misc.help_overlay')) { $u = new ConcreteUser(); $timestamp = $u->config('MAIN_HELP_LAST_VIEWED'); if (!$timestamp) { $result = true; } } return $result; }
php
public function showHelpOverlay() { $result = false; if (Config::get('concrete.misc.help_overlay')) { $u = new ConcreteUser(); $timestamp = $u->config('MAIN_HELP_LAST_VIEWED'); if (!$timestamp) { $result = true; } } return $result; }
[ "public", "function", "showHelpOverlay", "(", ")", "{", "$", "result", "=", "false", ";", "if", "(", "Config", "::", "get", "(", "'concrete.misc.help_overlay'", ")", ")", "{", "$", "u", "=", "new", "ConcreteUser", "(", ")", ";", "$", "timestamp", "=", "$", "u", "->", "config", "(", "'MAIN_HELP_LAST_VIEWED'", ")", ";", "if", "(", "!", "$", "timestamp", ")", "{", "$", "result", "=", "true", ";", "}", "}", "return", "$", "result", ";", "}" ]
Shall we show the introductive help overlay? @return bool
[ "Shall", "we", "show", "the", "introductive", "help", "overlay?" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/UserInterface.php#L212-L224
train
concrete5/concrete5
concrete/src/Mail/Importer/MailImporter.php
MailImportedMessage.getProcessedBody
public function getProcessedBody() { $r = preg_split(MailImporter::getMessageBodyHashRegularExpression(), $this->body); $message = $r[0]; $r = preg_replace(array( '/^On (.*) at (.*), (.*) wrote:/sm', '/[\n\r\s\>]*\Z/i', ), '', $message); return $r; }
php
public function getProcessedBody() { $r = preg_split(MailImporter::getMessageBodyHashRegularExpression(), $this->body); $message = $r[0]; $r = preg_replace(array( '/^On (.*) at (.*), (.*) wrote:/sm', '/[\n\r\s\>]*\Z/i', ), '', $message); return $r; }
[ "public", "function", "getProcessedBody", "(", ")", "{", "$", "r", "=", "preg_split", "(", "MailImporter", "::", "getMessageBodyHashRegularExpression", "(", ")", ",", "$", "this", "->", "body", ")", ";", "$", "message", "=", "$", "r", "[", "0", "]", ";", "$", "r", "=", "preg_replace", "(", "array", "(", "'/^On (.*) at (.*), (.*) wrote:/sm'", ",", "'/[\\n\\r\\s\\>]*\\Z/i'", ",", ")", ",", "''", ",", "$", "message", ")", ";", "return", "$", "r", ";", "}" ]
Returns the relevant content of the email message, minus any quotations, and the line that includes the validation hash.
[ "Returns", "the", "relevant", "content", "of", "the", "email", "message", "minus", "any", "quotations", "and", "the", "line", "that", "includes", "the", "validation", "hash", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Mail/Importer/MailImporter.php#L396-L406
train
concrete5/concrete5
concrete/src/Mail/Importer/MailImporter.php
MailImportedMessage.validate
public function validate() { if (!$this->validationHash) { return false; } $db = Database::connection(); $row = $db->GetRow("select * from MailValidationHashes where mHash = ? order by mDateGenerated desc limit 1", $this->validationHash); if ($row['mvhID'] > 0) { // Can't do this even though it's a good idea //if ($row['email'] != $this->sender) { // return false; //} else { return $row['mDateRedeemed'] == 0; //} } }
php
public function validate() { if (!$this->validationHash) { return false; } $db = Database::connection(); $row = $db->GetRow("select * from MailValidationHashes where mHash = ? order by mDateGenerated desc limit 1", $this->validationHash); if ($row['mvhID'] > 0) { // Can't do this even though it's a good idea //if ($row['email'] != $this->sender) { // return false; //} else { return $row['mDateRedeemed'] == 0; //} } }
[ "public", "function", "validate", "(", ")", "{", "if", "(", "!", "$", "this", "->", "validationHash", ")", "{", "return", "false", ";", "}", "$", "db", "=", "Database", "::", "connection", "(", ")", ";", "$", "row", "=", "$", "db", "->", "GetRow", "(", "\"select * from MailValidationHashes where mHash = ? order by mDateGenerated desc limit 1\"", ",", "$", "this", "->", "validationHash", ")", ";", "if", "(", "$", "row", "[", "'mvhID'", "]", ">", "0", ")", "{", "// Can't do this even though it's a good idea", "//if ($row['email'] != $this->sender) {", "//\treturn false;", "//} else {", "return", "$", "row", "[", "'mDateRedeemed'", "]", "==", "0", ";", "//}", "}", "}" ]
Validates the email message - checks the validation hash found in the body with one in the database. Checks the from address as well.
[ "Validates", "the", "email", "message", "-", "checks", "the", "validation", "hash", "found", "in", "the", "body", "with", "one", "in", "the", "database", ".", "Checks", "the", "from", "address", "as", "well", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Mail/Importer/MailImporter.php#L416-L431
train
concrete5/concrete5
concrete/src/Mail/Importer/MailImporter.php
MailImportedMessage.isSendError
public function isSendError() { $message = $this->getOriginalMessageObject(); $headers = $message->getHeaders(); $isSendError = false; if (is_array($headers) && count($headers)) { foreach (array_keys($headers) as $key) { if (strstr($key, 'x-fail') !== false) { $isSendError = true; break; } } } return $isSendError; }
php
public function isSendError() { $message = $this->getOriginalMessageObject(); $headers = $message->getHeaders(); $isSendError = false; if (is_array($headers) && count($headers)) { foreach (array_keys($headers) as $key) { if (strstr($key, 'x-fail') !== false) { $isSendError = true; break; } } } return $isSendError; }
[ "public", "function", "isSendError", "(", ")", "{", "$", "message", "=", "$", "this", "->", "getOriginalMessageObject", "(", ")", ";", "$", "headers", "=", "$", "message", "->", "getHeaders", "(", ")", ";", "$", "isSendError", "=", "false", ";", "if", "(", "is_array", "(", "$", "headers", ")", "&&", "count", "(", "$", "headers", ")", ")", "{", "foreach", "(", "array_keys", "(", "$", "headers", ")", "as", "$", "key", ")", "{", "if", "(", "strstr", "(", "$", "key", ",", "'x-fail'", ")", "!==", "false", ")", "{", "$", "isSendError", "=", "true", ";", "break", ";", "}", "}", "}", "return", "$", "isSendError", ";", "}" ]
checks to see if the message is a bounce or delivery failure. @return bool
[ "checks", "to", "see", "if", "the", "message", "is", "a", "bounce", "or", "delivery", "failure", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Mail/Importer/MailImporter.php#L443-L458
train
concrete5/concrete5
concrete/src/Logging/Processor/Concrete5UserProcessor.php
Concrete5UserProcessor.getLoggedInUser
protected function getLoggedInUser() { if (!$this->user) { $this->user = $this->app->make(User::class); } return $this->user; }
php
protected function getLoggedInUser() { if (!$this->user) { $this->user = $this->app->make(User::class); } return $this->user; }
[ "protected", "function", "getLoggedInUser", "(", ")", "{", "if", "(", "!", "$", "this", "->", "user", ")", "{", "$", "this", "->", "user", "=", "$", "this", "->", "app", "->", "make", "(", "User", "::", "class", ")", ";", "}", "return", "$", "this", "->", "user", ";", "}" ]
Resolve a user intance from the IOC container and cache it @return User|mixed
[ "Resolve", "a", "user", "intance", "from", "the", "IOC", "container", "and", "cache", "it" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Logging/Processor/Concrete5UserProcessor.php#L54-L61
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.loadAll
public static function loadAll() { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $permissionkeys = []; $txt = $app->make('helper/text'); $e = $db->executeQuery(<<<'EOT' select pkID, pkName, pkDescription, pkHandle, pkCategoryHandle, pkCanTriggerWorkflow, pkHasCustomClass, PermissionKeys.pkCategoryID, PermissionKeyCategories.pkgID from PermissionKeys inner join PermissionKeyCategories on PermissionKeyCategories.pkCategoryID = PermissionKeys.pkCategoryID EOT ); while (($r = $e->fetch(PDO::FETCH_ASSOC)) !== false) { if ($r['pkHasCustomClass']) { $class = '\\Core\\Permission\\Key\\' . $txt->camelcase($r['pkHandle'] . '_' . $r['pkCategoryHandle']) . 'Key'; } else { $class = '\\Core\\Permission\\Key\\' . $txt->camelcase($r['pkCategoryHandle']) . 'Key'; } $pkgHandle = $r['pkgID'] ? PackageList::getHandle($r['pkgID']) : null; $class = core_class($class, $pkgHandle); $pk = $app->make($class); $pk->setPropertiesFromArray($r); $permissionkeys[$r['pkHandle']] = $pk; $permissionkeys[$r['pkID']] = $pk; } $cache = $app->make('cache/request'); if ($cache->isEnabled()) { $cache->getItem('permission_keys')->set($permissionkeys)->save(); } return $permissionkeys; }
php
public static function loadAll() { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $permissionkeys = []; $txt = $app->make('helper/text'); $e = $db->executeQuery(<<<'EOT' select pkID, pkName, pkDescription, pkHandle, pkCategoryHandle, pkCanTriggerWorkflow, pkHasCustomClass, PermissionKeys.pkCategoryID, PermissionKeyCategories.pkgID from PermissionKeys inner join PermissionKeyCategories on PermissionKeyCategories.pkCategoryID = PermissionKeys.pkCategoryID EOT ); while (($r = $e->fetch(PDO::FETCH_ASSOC)) !== false) { if ($r['pkHasCustomClass']) { $class = '\\Core\\Permission\\Key\\' . $txt->camelcase($r['pkHandle'] . '_' . $r['pkCategoryHandle']) . 'Key'; } else { $class = '\\Core\\Permission\\Key\\' . $txt->camelcase($r['pkCategoryHandle']) . 'Key'; } $pkgHandle = $r['pkgID'] ? PackageList::getHandle($r['pkgID']) : null; $class = core_class($class, $pkgHandle); $pk = $app->make($class); $pk->setPropertiesFromArray($r); $permissionkeys[$r['pkHandle']] = $pk; $permissionkeys[$r['pkID']] = $pk; } $cache = $app->make('cache/request'); if ($cache->isEnabled()) { $cache->getItem('permission_keys')->set($permissionkeys)->save(); } return $permissionkeys; }
[ "public", "static", "function", "loadAll", "(", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "permissionkeys", "=", "[", "]", ";", "$", "txt", "=", "$", "app", "->", "make", "(", "'helper/text'", ")", ";", "$", "e", "=", "$", "db", "->", "executeQuery", "(", "<<<'EOT'\nselect pkID, pkName, pkDescription, pkHandle, pkCategoryHandle, pkCanTriggerWorkflow, pkHasCustomClass, PermissionKeys.pkCategoryID, PermissionKeyCategories.pkgID\nfrom PermissionKeys\ninner join PermissionKeyCategories on PermissionKeyCategories.pkCategoryID = PermissionKeys.pkCategoryID\nEOT", ")", ";", "while", "(", "(", "$", "r", "=", "$", "e", "->", "fetch", "(", "PDO", "::", "FETCH_ASSOC", ")", ")", "!==", "false", ")", "{", "if", "(", "$", "r", "[", "'pkHasCustomClass'", "]", ")", "{", "$", "class", "=", "'\\\\Core\\\\Permission\\\\Key\\\\'", ".", "$", "txt", "->", "camelcase", "(", "$", "r", "[", "'pkHandle'", "]", ".", "'_'", ".", "$", "r", "[", "'pkCategoryHandle'", "]", ")", ".", "'Key'", ";", "}", "else", "{", "$", "class", "=", "'\\\\Core\\\\Permission\\\\Key\\\\'", ".", "$", "txt", "->", "camelcase", "(", "$", "r", "[", "'pkCategoryHandle'", "]", ")", ".", "'Key'", ";", "}", "$", "pkgHandle", "=", "$", "r", "[", "'pkgID'", "]", "?", "PackageList", "::", "getHandle", "(", "$", "r", "[", "'pkgID'", "]", ")", ":", "null", ";", "$", "class", "=", "core_class", "(", "$", "class", ",", "$", "pkgHandle", ")", ";", "$", "pk", "=", "$", "app", "->", "make", "(", "$", "class", ")", ";", "$", "pk", "->", "setPropertiesFromArray", "(", "$", "r", ")", ";", "$", "permissionkeys", "[", "$", "r", "[", "'pkHandle'", "]", "]", "=", "$", "pk", ";", "$", "permissionkeys", "[", "$", "r", "[", "'pkID'", "]", "]", "=", "$", "pk", ";", "}", "$", "cache", "=", "$", "app", "->", "make", "(", "'cache/request'", ")", ";", "if", "(", "$", "cache", "->", "isEnabled", "(", ")", ")", "{", "$", "cache", "->", "getItem", "(", "'permission_keys'", ")", "->", "set", "(", "$", "permissionkeys", ")", "->", "save", "(", ")", ";", "}", "return", "$", "permissionkeys", ";", "}" ]
Get the list of all the defined permission keys. @return \Concrete\Core\Permission\Key\Key[]
[ "Get", "the", "list", "of", "all", "the", "defined", "permission", "keys", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L236-L268
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.getPackageHandle
public function getPackageHandle() { $pkgID = $this->getPackageID(); return $pkgID ? PackageList::getHandle($this->pkgID) : null; }
php
public function getPackageHandle() { $pkgID = $this->getPackageID(); return $pkgID ? PackageList::getHandle($this->pkgID) : null; }
[ "public", "function", "getPackageHandle", "(", ")", "{", "$", "pkgID", "=", "$", "this", "->", "getPackageID", "(", ")", ";", "return", "$", "pkgID", "?", "PackageList", "::", "getHandle", "(", "$", "this", "->", "pkgID", ")", ":", "null", ";", "}" ]
Get the handle of the package that defines this permission key. @return string|null
[ "Get", "the", "handle", "of", "the", "package", "that", "defines", "this", "permission", "key", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L303-L308
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.getList
public static function getList($pkCategoryHandle, $filters = []) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $q = 'select pkID from PermissionKeys inner join PermissionKeyCategories on PermissionKeys.pkCategoryID = PermissionKeyCategories.pkCategoryID where pkCategoryHandle = ?'; foreach ($filters as $key => $value) { $q .= ' and ' . $key . ' = ' . $value . ' '; } $r = $db->executeQuery($q, [$pkCategoryHandle]); $list = []; while (($pkID = $r->fetchColumn()) !== false) { $pk = self::load($pkID); if ($pk) { $list[] = $pk; } } return $list; }
php
public static function getList($pkCategoryHandle, $filters = []) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $q = 'select pkID from PermissionKeys inner join PermissionKeyCategories on PermissionKeys.pkCategoryID = PermissionKeyCategories.pkCategoryID where pkCategoryHandle = ?'; foreach ($filters as $key => $value) { $q .= ' and ' . $key . ' = ' . $value . ' '; } $r = $db->executeQuery($q, [$pkCategoryHandle]); $list = []; while (($pkID = $r->fetchColumn()) !== false) { $pk = self::load($pkID); if ($pk) { $list[] = $pk; } } return $list; }
[ "public", "static", "function", "getList", "(", "$", "pkCategoryHandle", ",", "$", "filters", "=", "[", "]", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "q", "=", "'select pkID from PermissionKeys inner join PermissionKeyCategories on PermissionKeys.pkCategoryID = PermissionKeyCategories.pkCategoryID where pkCategoryHandle = ?'", ";", "foreach", "(", "$", "filters", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "q", ".=", "' and '", ".", "$", "key", ".", "' = '", ".", "$", "value", ".", "' '", ";", "}", "$", "r", "=", "$", "db", "->", "executeQuery", "(", "$", "q", ",", "[", "$", "pkCategoryHandle", "]", ")", ";", "$", "list", "=", "[", "]", ";", "while", "(", "(", "$", "pkID", "=", "$", "r", "->", "fetchColumn", "(", ")", ")", "!==", "false", ")", "{", "$", "pk", "=", "self", "::", "load", "(", "$", "pkID", ")", ";", "if", "(", "$", "pk", ")", "{", "$", "list", "[", "]", "=", "$", "pk", ";", "}", "}", "return", "$", "list", ";", "}" ]
Returns the list of all permissions of this category. @param string $pkCategoryHandle @param array $filters An array containing of field name => value (to be used directly in the SQL query) @return \Concrete\Core\Permission\Key\Key[]
[ "Returns", "the", "list", "of", "all", "permissions", "of", "this", "category", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L318-L336
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.export
public function export($axml) { $category = PermissionKeyCategory::getByID($this->pkCategoryID)->getPermissionKeyCategoryHandle(); $pkey = $axml->addChild('permissionkey'); $pkey->addAttribute('handle', $this->getPermissionKeyHandle()); $pkey->addAttribute('name', $this->getPermissionKeyName()); $pkey->addAttribute('description', $this->getPermissionKeyDescription()); $pkey->addAttribute('package', $this->getPackageHandle()); $pkey->addAttribute('category', $category); $this->exportAccess($pkey); return $pkey; }
php
public function export($axml) { $category = PermissionKeyCategory::getByID($this->pkCategoryID)->getPermissionKeyCategoryHandle(); $pkey = $axml->addChild('permissionkey'); $pkey->addAttribute('handle', $this->getPermissionKeyHandle()); $pkey->addAttribute('name', $this->getPermissionKeyName()); $pkey->addAttribute('description', $this->getPermissionKeyDescription()); $pkey->addAttribute('package', $this->getPackageHandle()); $pkey->addAttribute('category', $category); $this->exportAccess($pkey); return $pkey; }
[ "public", "function", "export", "(", "$", "axml", ")", "{", "$", "category", "=", "PermissionKeyCategory", "::", "getByID", "(", "$", "this", "->", "pkCategoryID", ")", "->", "getPermissionKeyCategoryHandle", "(", ")", ";", "$", "pkey", "=", "$", "axml", "->", "addChild", "(", "'permissionkey'", ")", ";", "$", "pkey", "->", "addAttribute", "(", "'handle'", ",", "$", "this", "->", "getPermissionKeyHandle", "(", ")", ")", ";", "$", "pkey", "->", "addAttribute", "(", "'name'", ",", "$", "this", "->", "getPermissionKeyName", "(", ")", ")", ";", "$", "pkey", "->", "addAttribute", "(", "'description'", ",", "$", "this", "->", "getPermissionKeyDescription", "(", ")", ")", ";", "$", "pkey", "->", "addAttribute", "(", "'package'", ",", "$", "this", "->", "getPackageHandle", "(", ")", ")", ";", "$", "pkey", "->", "addAttribute", "(", "'category'", ",", "$", "category", ")", ";", "$", "this", "->", "exportAccess", "(", "$", "pkey", ")", ";", "return", "$", "pkey", ";", "}" ]
Export this permission key to a SimpleXMLElement instance. @param \SimpleXMLElement $axml @return \SimpleXMLElement
[ "Export", "this", "permission", "key", "to", "a", "SimpleXMLElement", "instance", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L345-L357
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.exportList
public static function exportList($xml) { $categories = PermissionKeyCategory::getList(); $pxml = $xml->addChild('permissionkeys'); foreach ($categories as $cat) { $permissions = static::getList($cat->getPermissionKeyCategoryHandle()); foreach ($permissions as $p) { $p->export($pxml); } } }
php
public static function exportList($xml) { $categories = PermissionKeyCategory::getList(); $pxml = $xml->addChild('permissionkeys'); foreach ($categories as $cat) { $permissions = static::getList($cat->getPermissionKeyCategoryHandle()); foreach ($permissions as $p) { $p->export($pxml); } } }
[ "public", "static", "function", "exportList", "(", "$", "xml", ")", "{", "$", "categories", "=", "PermissionKeyCategory", "::", "getList", "(", ")", ";", "$", "pxml", "=", "$", "xml", "->", "addChild", "(", "'permissionkeys'", ")", ";", "foreach", "(", "$", "categories", "as", "$", "cat", ")", "{", "$", "permissions", "=", "static", "::", "getList", "(", "$", "cat", "->", "getPermissionKeyCategoryHandle", "(", ")", ")", ";", "foreach", "(", "$", "permissions", "as", "$", "p", ")", "{", "$", "p", "->", "export", "(", "$", "pxml", ")", ";", "}", "}", "}" ]
Export the list of all permissions of this category to a SimpleXMLElement instance. @param \SimpleXMLElement $xml
[ "Export", "the", "list", "of", "all", "permissions", "of", "this", "category", "to", "a", "SimpleXMLElement", "instance", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L364-L374
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.getListByPackage
public static function getListByPackage($pkg) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $kina = ['-1']; $rs = $db->executeQuery('select pkCategoryID from PermissionKeyCategories where pkgID = ?', [$pkg->getPackageID()]); while (($pkCategoryID = $rs->fetchColumn()) !== false) { $kina[] = $pkCategoryID; } $kinstr = implode(',', $kina); $categories = []; /* @var \Concrete\Core\Permission\Category[] $categories */ $list = []; $r = $db->executeQuery('select pkID, pkCategoryID from PermissionKeys where (pkgID = ? or pkCategoryID in (' . $kinstr . ')) order by pkID asc', [$pkg->getPackageID()]); while (($row = $r->fetch(PDO::FETCH_ASSOC)) !== false) { if (!isset($categories[$row['pkCategoryID']])) { $categories[$row['pkCategoryID']] = PermissionKeyCategory::getByID($row['pkCategoryID']); } $pkc = $categories[$row['pkCategoryID']]; $pk = $pkc->getPermissionKeyByID($row['pkID']); $list[] = $pk; } return $list; }
php
public static function getListByPackage($pkg) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $kina = ['-1']; $rs = $db->executeQuery('select pkCategoryID from PermissionKeyCategories where pkgID = ?', [$pkg->getPackageID()]); while (($pkCategoryID = $rs->fetchColumn()) !== false) { $kina[] = $pkCategoryID; } $kinstr = implode(',', $kina); $categories = []; /* @var \Concrete\Core\Permission\Category[] $categories */ $list = []; $r = $db->executeQuery('select pkID, pkCategoryID from PermissionKeys where (pkgID = ? or pkCategoryID in (' . $kinstr . ')) order by pkID asc', [$pkg->getPackageID()]); while (($row = $r->fetch(PDO::FETCH_ASSOC)) !== false) { if (!isset($categories[$row['pkCategoryID']])) { $categories[$row['pkCategoryID']] = PermissionKeyCategory::getByID($row['pkCategoryID']); } $pkc = $categories[$row['pkCategoryID']]; $pk = $pkc->getPermissionKeyByID($row['pkID']); $list[] = $pk; } return $list; }
[ "public", "static", "function", "getListByPackage", "(", "$", "pkg", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "kina", "=", "[", "'-1'", "]", ";", "$", "rs", "=", "$", "db", "->", "executeQuery", "(", "'select pkCategoryID from PermissionKeyCategories where pkgID = ?'", ",", "[", "$", "pkg", "->", "getPackageID", "(", ")", "]", ")", ";", "while", "(", "(", "$", "pkCategoryID", "=", "$", "rs", "->", "fetchColumn", "(", ")", ")", "!==", "false", ")", "{", "$", "kina", "[", "]", "=", "$", "pkCategoryID", ";", "}", "$", "kinstr", "=", "implode", "(", "','", ",", "$", "kina", ")", ";", "$", "categories", "=", "[", "]", ";", "/* @var \\Concrete\\Core\\Permission\\Category[] $categories */", "$", "list", "=", "[", "]", ";", "$", "r", "=", "$", "db", "->", "executeQuery", "(", "'select pkID, pkCategoryID from PermissionKeys where (pkgID = ? or pkCategoryID in ('", ".", "$", "kinstr", ".", "')) order by pkID asc'", ",", "[", "$", "pkg", "->", "getPackageID", "(", ")", "]", ")", ";", "while", "(", "(", "$", "row", "=", "$", "r", "->", "fetch", "(", "PDO", "::", "FETCH_ASSOC", ")", ")", "!==", "false", ")", "{", "if", "(", "!", "isset", "(", "$", "categories", "[", "$", "row", "[", "'pkCategoryID'", "]", "]", ")", ")", "{", "$", "categories", "[", "$", "row", "[", "'pkCategoryID'", "]", "]", "=", "PermissionKeyCategory", "::", "getByID", "(", "$", "row", "[", "'pkCategoryID'", "]", ")", ";", "}", "$", "pkc", "=", "$", "categories", "[", "$", "row", "[", "'pkCategoryID'", "]", "]", ";", "$", "pk", "=", "$", "pkc", "->", "getPermissionKeyByID", "(", "$", "row", "[", "'pkID'", "]", ")", ";", "$", "list", "[", "]", "=", "$", "pk", ";", "}", "return", "$", "list", ";", "}" ]
Get the list of permission keys defined by a package. Note, this queries both the pkgID found on the PermissionKeys table AND any permission keys of a special type installed by that package, and any in categories by that package. @param \Concrete\Core\Entity\Package|\Concrete\Core\Package\Package $pkg @return \Concrete\Core\Permission\Key\Key[]
[ "Get", "the", "list", "of", "permission", "keys", "defined", "by", "a", "package", ".", "Note", "this", "queries", "both", "the", "pkgID", "found", "on", "the", "PermissionKeys", "table", "AND", "any", "permission", "keys", "of", "a", "special", "type", "installed", "by", "that", "package", "and", "any", "in", "categories", "by", "that", "package", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L385-L411
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.import
public static function import(SimpleXMLElement $pk) { if ($pk['package']) { $app = Application::getFacadeApplication(); $pkg = $app->make(PackageService::class)->getByHandle($pk['package']); } else { $pkg = null; } return self::add( $pk['category'], $pk['handle'], $pk['name'], $pk['description'], $pk['can-trigger-workflow'] ? 1 : 0, $pk['has-custom-class'] ? 1 : 0, $pkg ); }
php
public static function import(SimpleXMLElement $pk) { if ($pk['package']) { $app = Application::getFacadeApplication(); $pkg = $app->make(PackageService::class)->getByHandle($pk['package']); } else { $pkg = null; } return self::add( $pk['category'], $pk['handle'], $pk['name'], $pk['description'], $pk['can-trigger-workflow'] ? 1 : 0, $pk['has-custom-class'] ? 1 : 0, $pkg ); }
[ "public", "static", "function", "import", "(", "SimpleXMLElement", "$", "pk", ")", "{", "if", "(", "$", "pk", "[", "'package'", "]", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "pkg", "=", "$", "app", "->", "make", "(", "PackageService", "::", "class", ")", "->", "getByHandle", "(", "$", "pk", "[", "'package'", "]", ")", ";", "}", "else", "{", "$", "pkg", "=", "null", ";", "}", "return", "self", "::", "add", "(", "$", "pk", "[", "'category'", "]", ",", "$", "pk", "[", "'handle'", "]", ",", "$", "pk", "[", "'name'", "]", ",", "$", "pk", "[", "'description'", "]", ",", "$", "pk", "[", "'can-trigger-workflow'", "]", "?", "1", ":", "0", ",", "$", "pk", "[", "'has-custom-class'", "]", "?", "1", ":", "0", ",", "$", "pkg", ")", ";", "}" ]
Import a permission key from a SimpleXMLElement element. @param \SimpleXMLElement $pk @return \Concrete\Core\Permission\Key\Key
[ "Import", "a", "permission", "key", "from", "a", "SimpleXMLElement", "element", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L420-L438
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.getByID
public static function getByID($pkID) { $keys = null; $app = Application::getFacadeApplication(); $cache = $app->make('cache/request'); if ($cache->isEnabled()) { $item = $cache->getItem('permission_keys'); if (!$item->isMiss()) { $keys = $item->get(); } } if ($keys === null) { $keys = self::loadAll(); } return isset($keys[$pkID]) ? $keys[$pkID] : null; }
php
public static function getByID($pkID) { $keys = null; $app = Application::getFacadeApplication(); $cache = $app->make('cache/request'); if ($cache->isEnabled()) { $item = $cache->getItem('permission_keys'); if (!$item->isMiss()) { $keys = $item->get(); } } if ($keys === null) { $keys = self::loadAll(); } return isset($keys[$pkID]) ? $keys[$pkID] : null; }
[ "public", "static", "function", "getByID", "(", "$", "pkID", ")", "{", "$", "keys", "=", "null", ";", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "cache", "=", "$", "app", "->", "make", "(", "'cache/request'", ")", ";", "if", "(", "$", "cache", "->", "isEnabled", "(", ")", ")", "{", "$", "item", "=", "$", "cache", "->", "getItem", "(", "'permission_keys'", ")", ";", "if", "(", "!", "$", "item", "->", "isMiss", "(", ")", ")", "{", "$", "keys", "=", "$", "item", "->", "get", "(", ")", ";", "}", "}", "if", "(", "$", "keys", "===", "null", ")", "{", "$", "keys", "=", "self", "::", "loadAll", "(", ")", ";", "}", "return", "isset", "(", "$", "keys", "[", "$", "pkID", "]", ")", "?", "$", "keys", "[", "$", "pkID", "]", ":", "null", ";", "}" ]
Get a permission key given its ID. @param int $pkID @return \Concrete\Core\Permission\Key\Key|null
[ "Get", "a", "permission", "key", "given", "its", "ID", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L447-L463
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.getByHandle
public static function getByHandle($pkHandle) { $keys = null; $app = Application::getFacadeApplication(); $cache = $app->make('cache/request'); if ($cache->isEnabled()) { $item = $cache->getItem('permission_keys'); if (!$item->isMiss()) { $keys = $item->get(); } } if ($keys === null) { $keys = self::loadAll(); } return isset($keys[$pkHandle]) ? $keys[$pkHandle] : null; }
php
public static function getByHandle($pkHandle) { $keys = null; $app = Application::getFacadeApplication(); $cache = $app->make('cache/request'); if ($cache->isEnabled()) { $item = $cache->getItem('permission_keys'); if (!$item->isMiss()) { $keys = $item->get(); } } if ($keys === null) { $keys = self::loadAll(); } return isset($keys[$pkHandle]) ? $keys[$pkHandle] : null; }
[ "public", "static", "function", "getByHandle", "(", "$", "pkHandle", ")", "{", "$", "keys", "=", "null", ";", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "cache", "=", "$", "app", "->", "make", "(", "'cache/request'", ")", ";", "if", "(", "$", "cache", "->", "isEnabled", "(", ")", ")", "{", "$", "item", "=", "$", "cache", "->", "getItem", "(", "'permission_keys'", ")", ";", "if", "(", "!", "$", "item", "->", "isMiss", "(", ")", ")", "{", "$", "keys", "=", "$", "item", "->", "get", "(", ")", ";", "}", "}", "if", "(", "$", "keys", "===", "null", ")", "{", "$", "keys", "=", "self", "::", "loadAll", "(", ")", ";", "}", "return", "isset", "(", "$", "keys", "[", "$", "pkHandle", "]", ")", "?", "$", "keys", "[", "$", "pkHandle", "]", ":", "null", ";", "}" ]
Get a permission key given its handle. @param string $pkHandle @return \Concrete\Core\Permission\Key\Key|null
[ "Get", "a", "permission", "key", "given", "its", "handle", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L472-L488
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.add
public static function add($pkCategoryHandle, $pkHandle, $pkName, $pkDescription, $pkCanTriggerWorkflow, $pkHasCustomClass, $pkg = false) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $pkCategoryID = $db->fetchColumn('select pkCategoryID from PermissionKeyCategories where pkCategoryHandle = ?', [$pkCategoryHandle]); $db->insert('PermissionKeys', [ 'pkHandle' => $pkHandle, 'pkName' => $pkName, 'pkDescription' => $pkDescription, 'pkCategoryID' => $pkCategoryID, 'pkCanTriggerWorkflow' => $pkCanTriggerWorkflow ? 1 : 0, 'pkHasCustomClass' => $pkHasCustomClass ? 1 : 0, 'pkgID' => is_object($pkg) ? $pkg->getPackageID() : 0, ]); $pkID = $db->lastInsertId(); $keys = self::loadAll(); return $keys[$pkID]; }
php
public static function add($pkCategoryHandle, $pkHandle, $pkName, $pkDescription, $pkCanTriggerWorkflow, $pkHasCustomClass, $pkg = false) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $pkCategoryID = $db->fetchColumn('select pkCategoryID from PermissionKeyCategories where pkCategoryHandle = ?', [$pkCategoryHandle]); $db->insert('PermissionKeys', [ 'pkHandle' => $pkHandle, 'pkName' => $pkName, 'pkDescription' => $pkDescription, 'pkCategoryID' => $pkCategoryID, 'pkCanTriggerWorkflow' => $pkCanTriggerWorkflow ? 1 : 0, 'pkHasCustomClass' => $pkHasCustomClass ? 1 : 0, 'pkgID' => is_object($pkg) ? $pkg->getPackageID() : 0, ]); $pkID = $db->lastInsertId(); $keys = self::loadAll(); return $keys[$pkID]; }
[ "public", "static", "function", "add", "(", "$", "pkCategoryHandle", ",", "$", "pkHandle", ",", "$", "pkName", ",", "$", "pkDescription", ",", "$", "pkCanTriggerWorkflow", ",", "$", "pkHasCustomClass", ",", "$", "pkg", "=", "false", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "pkCategoryID", "=", "$", "db", "->", "fetchColumn", "(", "'select pkCategoryID from PermissionKeyCategories where pkCategoryHandle = ?'", ",", "[", "$", "pkCategoryHandle", "]", ")", ";", "$", "db", "->", "insert", "(", "'PermissionKeys'", ",", "[", "'pkHandle'", "=>", "$", "pkHandle", ",", "'pkName'", "=>", "$", "pkName", ",", "'pkDescription'", "=>", "$", "pkDescription", ",", "'pkCategoryID'", "=>", "$", "pkCategoryID", ",", "'pkCanTriggerWorkflow'", "=>", "$", "pkCanTriggerWorkflow", "?", "1", ":", "0", ",", "'pkHasCustomClass'", "=>", "$", "pkHasCustomClass", "?", "1", ":", "0", ",", "'pkgID'", "=>", "is_object", "(", "$", "pkg", ")", "?", "$", "pkg", "->", "getPackageID", "(", ")", ":", "0", ",", "]", ")", ";", "$", "pkID", "=", "$", "db", "->", "lastInsertId", "(", ")", ";", "$", "keys", "=", "self", "::", "loadAll", "(", ")", ";", "return", "$", "keys", "[", "$", "pkID", "]", ";", "}" ]
Adds an permission key. @param string $pkCategoryHandle @param string $pkHandle @param string $pkName @param string $pkDescription @param bool $pkCanTriggerWorkflow @param bool $pkHasCustomClass @param \Concrete\Core\Entity\Package|\Concrete\Core\Package\Package|null $pkg
[ "Adds", "an", "permission", "key", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L501-L520
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.delete
public function delete() { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $db->executeQuery('delete from PermissionKeys where pkID = ?', [$this->getPermissionKeyID()]); self::loadAll(); }
php
public function delete() { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $db->executeQuery('delete from PermissionKeys where pkID = ?', [$this->getPermissionKeyID()]); self::loadAll(); }
[ "public", "function", "delete", "(", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "db", "->", "executeQuery", "(", "'delete from PermissionKeys where pkID = ?'", ",", "[", "$", "this", "->", "getPermissionKeyID", "(", ")", "]", ")", ";", "self", "::", "loadAll", "(", ")", ";", "}" ]
Delete this permission key.
[ "Delete", "this", "permission", "key", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L581-L587
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.getAccessListItems
public function getAccessListItems() { $obj = $this->getPermissionAccessObject(); if (!$obj) { return []; } $args = func_get_args(); switch (count($args)) { case 0: return $obj->getAccessListItems(); case 1: return $obj->getAccessListItems($args[0]); case 2: return $obj->getAccessListItems($args[0], $args[1]); case 3: return $obj->getAccessListItems($args[0], $args[1], $args[2]); default: return call_user_func_array([$obj, 'getAccessListItems'], $args); } }
php
public function getAccessListItems() { $obj = $this->getPermissionAccessObject(); if (!$obj) { return []; } $args = func_get_args(); switch (count($args)) { case 0: return $obj->getAccessListItems(); case 1: return $obj->getAccessListItems($args[0]); case 2: return $obj->getAccessListItems($args[0], $args[1]); case 3: return $obj->getAccessListItems($args[0], $args[1], $args[2]); default: return call_user_func_array([$obj, 'getAccessListItems'], $args); } }
[ "public", "function", "getAccessListItems", "(", ")", "{", "$", "obj", "=", "$", "this", "->", "getPermissionAccessObject", "(", ")", ";", "if", "(", "!", "$", "obj", ")", "{", "return", "[", "]", ";", "}", "$", "args", "=", "func_get_args", "(", ")", ";", "switch", "(", "count", "(", "$", "args", ")", ")", "{", "case", "0", ":", "return", "$", "obj", "->", "getAccessListItems", "(", ")", ";", "case", "1", ":", "return", "$", "obj", "->", "getAccessListItems", "(", "$", "args", "[", "0", "]", ")", ";", "case", "2", ":", "return", "$", "obj", "->", "getAccessListItems", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ")", ";", "case", "3", ":", "return", "$", "obj", "->", "getAccessListItems", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ",", "$", "args", "[", "2", "]", ")", ";", "default", ":", "return", "call_user_func_array", "(", "[", "$", "obj", ",", "'getAccessListItems'", "]", ",", "$", "args", ")", ";", "}", "}" ]
A shortcut for grabbing the current assignment and passing into that object. @return \Concrete\Core\Permission\Access\ListItem\ListItem[]
[ "A", "shortcut", "for", "grabbing", "the", "current", "assignment", "and", "passing", "into", "that", "object", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L594-L613
train
concrete5/concrete5
concrete/src/Permission/Key/Key.php
Key.exportTranslations
public static function exportTranslations() { $translations = new Translations(); $categories = PermissionKeyCategory::getList(); foreach ($categories as $cat) { $permissions = static::getList($cat->getPermissionKeyCategoryHandle()); foreach ($permissions as $p) { $translations->insert('PermissionKeyName', $p->getPermissionKeyName()); if ($p->getPermissionKeyDescription()) { $translations->insert('PermissionKeyDescription', $p->getPermissionKeyDescription()); } } } return $translations; }
php
public static function exportTranslations() { $translations = new Translations(); $categories = PermissionKeyCategory::getList(); foreach ($categories as $cat) { $permissions = static::getList($cat->getPermissionKeyCategoryHandle()); foreach ($permissions as $p) { $translations->insert('PermissionKeyName', $p->getPermissionKeyName()); if ($p->getPermissionKeyDescription()) { $translations->insert('PermissionKeyDescription', $p->getPermissionKeyDescription()); } } } return $translations; }
[ "public", "static", "function", "exportTranslations", "(", ")", "{", "$", "translations", "=", "new", "Translations", "(", ")", ";", "$", "categories", "=", "PermissionKeyCategory", "::", "getList", "(", ")", ";", "foreach", "(", "$", "categories", "as", "$", "cat", ")", "{", "$", "permissions", "=", "static", "::", "getList", "(", "$", "cat", "->", "getPermissionKeyCategoryHandle", "(", ")", ")", ";", "foreach", "(", "$", "permissions", "as", "$", "p", ")", "{", "$", "translations", "->", "insert", "(", "'PermissionKeyName'", ",", "$", "p", "->", "getPermissionKeyName", "(", ")", ")", ";", "if", "(", "$", "p", "->", "getPermissionKeyDescription", "(", ")", ")", "{", "$", "translations", "->", "insert", "(", "'PermissionKeyDescription'", ",", "$", "p", "->", "getPermissionKeyDescription", "(", ")", ")", ";", "}", "}", "}", "return", "$", "translations", ";", "}" ]
Export the strings that should be translated. @return \Gettext\Translations
[ "Export", "the", "strings", "that", "should", "be", "translated", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Permission/Key/Key.php#L667-L682
train
concrete5/concrete5
concrete/src/Foundation/Runtime/DefaultRuntime.php
DefaultRuntime.boot
public function boot() { $booter = $this->getBooter(); if ($response = $booter->boot()) { $this->sendResponse($response); } else { $this->status = self::STATUS_ACTIVE; } }
php
public function boot() { $booter = $this->getBooter(); if ($response = $booter->boot()) { $this->sendResponse($response); } else { $this->status = self::STATUS_ACTIVE; } }
[ "public", "function", "boot", "(", ")", "{", "$", "booter", "=", "$", "this", "->", "getBooter", "(", ")", ";", "if", "(", "$", "response", "=", "$", "booter", "->", "boot", "(", ")", ")", "{", "$", "this", "->", "sendResponse", "(", "$", "response", ")", ";", "}", "else", "{", "$", "this", "->", "status", "=", "self", "::", "STATUS_ACTIVE", ";", "}", "}" ]
Initialize the environment and prepare for running.
[ "Initialize", "the", "environment", "and", "prepare", "for", "running", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Runtime/DefaultRuntime.php#L76-L85
train
concrete5/concrete5
concrete/src/Service/Manager/ServiceManager.php
ServiceManager.getService
public function getService($handle, $version = '') { $result = null; if ($this->has($handle)) { $key = $handle; $version = (string) $version; if ($version !== '') { $key .= "@$version"; } if (!isset($this->services[$key])) { $abstract = $this->extensions[$handle]; $service = $this->buildService($abstract, $version); if ($service === null) { throw new \RuntimeException('Invalid service binding.'); } $this->services[$key] = $service; } $result = $this->services[$key]; } return $result; }
php
public function getService($handle, $version = '') { $result = null; if ($this->has($handle)) { $key = $handle; $version = (string) $version; if ($version !== '') { $key .= "@$version"; } if (!isset($this->services[$key])) { $abstract = $this->extensions[$handle]; $service = $this->buildService($abstract, $version); if ($service === null) { throw new \RuntimeException('Invalid service binding.'); } $this->services[$key] = $service; } $result = $this->services[$key]; } return $result; }
[ "public", "function", "getService", "(", "$", "handle", ",", "$", "version", "=", "''", ")", "{", "$", "result", "=", "null", ";", "if", "(", "$", "this", "->", "has", "(", "$", "handle", ")", ")", "{", "$", "key", "=", "$", "handle", ";", "$", "version", "=", "(", "string", ")", "$", "version", ";", "if", "(", "$", "version", "!==", "''", ")", "{", "$", "key", ".=", "\"@$version\"", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "services", "[", "$", "key", "]", ")", ")", "{", "$", "abstract", "=", "$", "this", "->", "extensions", "[", "$", "handle", "]", ";", "$", "service", "=", "$", "this", "->", "buildService", "(", "$", "abstract", ",", "$", "version", ")", ";", "if", "(", "$", "service", "===", "null", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Invalid service binding.'", ")", ";", "}", "$", "this", "->", "services", "[", "$", "key", "]", "=", "$", "service", ";", "}", "$", "result", "=", "$", "this", "->", "services", "[", "$", "key", "]", ";", "}", "return", "$", "result", ";", "}" ]
Get the driver for this handle. @param string $handle @param string $version @return ServiceInterface|null
[ "Get", "the", "driver", "for", "this", "handle", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Service/Manager/ServiceManager.php#L76-L97
train
concrete5/concrete5
concrete/src/Service/Manager/ServiceManager.php
ServiceManager.buildService
private function buildService($abstract, $version = '') { $resolved = null; if (is_string($abstract)) { // If it's a string, throw it at the IoC container $resolved = $this->app->make($abstract, array($version)); } elseif (is_callable($abstract)) { // If it's a callable, lets call it with the application and $this $resolved = $abstract($version, $this->app, $this); } return $resolved; }
php
private function buildService($abstract, $version = '') { $resolved = null; if (is_string($abstract)) { // If it's a string, throw it at the IoC container $resolved = $this->app->make($abstract, array($version)); } elseif (is_callable($abstract)) { // If it's a callable, lets call it with the application and $this $resolved = $abstract($version, $this->app, $this); } return $resolved; }
[ "private", "function", "buildService", "(", "$", "abstract", ",", "$", "version", "=", "''", ")", "{", "$", "resolved", "=", "null", ";", "if", "(", "is_string", "(", "$", "abstract", ")", ")", "{", "// If it's a string, throw it at the IoC container", "$", "resolved", "=", "$", "this", "->", "app", "->", "make", "(", "$", "abstract", ",", "array", "(", "$", "version", ")", ")", ";", "}", "elseif", "(", "is_callable", "(", "$", "abstract", ")", ")", "{", "// If it's a callable, lets call it with the application and $this", "$", "resolved", "=", "$", "abstract", "(", "$", "version", ",", "$", "this", "->", "app", ",", "$", "this", ")", ";", "}", "return", "$", "resolved", ";", "}" ]
Build a service from an abstract. @param string|callable $abstract @param string $version @return ServiceInterface|null
[ "Build", "a", "service", "from", "an", "abstract", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Service/Manager/ServiceManager.php#L107-L120
train
concrete5/concrete5
concrete/src/Service/Manager/ServiceManager.php
ServiceManager.getAllServices
public function getAllServices() { $result = array(); foreach ($this->getExtensions() as $handle) { $result[$handle] = $this->getService($handle); } return $result; }
php
public function getAllServices() { $result = array(); foreach ($this->getExtensions() as $handle) { $result[$handle] = $this->getService($handle); } return $result; }
[ "public", "function", "getAllServices", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getExtensions", "(", ")", "as", "$", "handle", ")", "{", "$", "result", "[", "$", "handle", "]", "=", "$", "this", "->", "getService", "(", "$", "handle", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns all the available services. @return ServiceInterface[]
[ "Returns", "all", "the", "available", "services", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Service/Manager/ServiceManager.php#L127-L135
train
concrete5/concrete5
concrete/src/Service/Manager/ServiceManager.php
ServiceManager.getActiveServices
public function getActiveServices() { $active = array(); foreach ($this->getExtensions() as $handle) { $service = $this->getService($handle); $version = $service->getDetector()->detect(); if ($version !== null) { $active[] = $this->getService($handle, $version); } } return $active; }
php
public function getActiveServices() { $active = array(); foreach ($this->getExtensions() as $handle) { $service = $this->getService($handle); $version = $service->getDetector()->detect(); if ($version !== null) { $active[] = $this->getService($handle, $version); } } return $active; }
[ "public", "function", "getActiveServices", "(", ")", "{", "$", "active", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "getExtensions", "(", ")", "as", "$", "handle", ")", "{", "$", "service", "=", "$", "this", "->", "getService", "(", "$", "handle", ")", ";", "$", "version", "=", "$", "service", "->", "getDetector", "(", ")", "->", "detect", "(", ")", ";", "if", "(", "$", "version", "!==", "null", ")", "{", "$", "active", "[", "]", "=", "$", "this", "->", "getService", "(", "$", "handle", ",", "$", "version", ")", ";", "}", "}", "return", "$", "active", ";", "}" ]
Loops through the bound services and returns the ones that are active. @return ServiceInterface[]
[ "Loops", "through", "the", "bound", "services", "and", "returns", "the", "ones", "that", "are", "active", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Service/Manager/ServiceManager.php#L142-L154
train
concrete5/concrete5
concrete/src/Database/Query/LikeBuilder.php
LikeBuilder.getEscapeMap
protected function getEscapeMap() { if ($this->escapeMap === null) { $escapeMap = [ $this->anyCharacterWildcard => $this->escapeCharacter . $this->anyCharacterWildcard, $this->oneCharacterWildcard => $this->escapeCharacter . $this->oneCharacterWildcard, $this->escapeCharacter => $this->escapeCharacter . $this->escapeCharacter, ]; foreach ($this->otherWildcards as $otherWildcard) { $escapeMap[$otherWildcard] = $this->escapeCharacter . $otherWildcard; } $this->escapeMap = $escapeMap; } return $this->escapeMap; }
php
protected function getEscapeMap() { if ($this->escapeMap === null) { $escapeMap = [ $this->anyCharacterWildcard => $this->escapeCharacter . $this->anyCharacterWildcard, $this->oneCharacterWildcard => $this->escapeCharacter . $this->oneCharacterWildcard, $this->escapeCharacter => $this->escapeCharacter . $this->escapeCharacter, ]; foreach ($this->otherWildcards as $otherWildcard) { $escapeMap[$otherWildcard] = $this->escapeCharacter . $otherWildcard; } $this->escapeMap = $escapeMap; } return $this->escapeMap; }
[ "protected", "function", "getEscapeMap", "(", ")", "{", "if", "(", "$", "this", "->", "escapeMap", "===", "null", ")", "{", "$", "escapeMap", "=", "[", "$", "this", "->", "anyCharacterWildcard", "=>", "$", "this", "->", "escapeCharacter", ".", "$", "this", "->", "anyCharacterWildcard", ",", "$", "this", "->", "oneCharacterWildcard", "=>", "$", "this", "->", "escapeCharacter", ".", "$", "this", "->", "oneCharacterWildcard", ",", "$", "this", "->", "escapeCharacter", "=>", "$", "this", "->", "escapeCharacter", ".", "$", "this", "->", "escapeCharacter", ",", "]", ";", "foreach", "(", "$", "this", "->", "otherWildcards", "as", "$", "otherWildcard", ")", "{", "$", "escapeMap", "[", "$", "otherWildcard", "]", "=", "$", "this", "->", "escapeCharacter", ".", "$", "otherWildcard", ";", "}", "$", "this", "->", "escapeMap", "=", "$", "escapeMap", ";", "}", "return", "$", "this", "->", "escapeMap", ";", "}" ]
Get the string mapping used to escape special characters. @return array
[ "Get", "the", "string", "mapping", "used", "to", "escape", "special", "characters", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/Query/LikeBuilder.php#L102-L117
train
concrete5/concrete5
concrete/src/Database/Query/LikeBuilder.php
LikeBuilder.escapeForLike
public function escapeForLike($string, $wildcardAtStart = true, $wildcardAtEnd = true) { if ($wildcardAtStart) { $result = $this->anyCharacterWildcard; } else { $result = ''; } $result .= strtr((string) $string, $this->getEscapeMap()); if ($wildcardAtEnd && $result !== $this->anyCharacterWildcard) { $result .= $this->anyCharacterWildcard; } return $result; }
php
public function escapeForLike($string, $wildcardAtStart = true, $wildcardAtEnd = true) { if ($wildcardAtStart) { $result = $this->anyCharacterWildcard; } else { $result = ''; } $result .= strtr((string) $string, $this->getEscapeMap()); if ($wildcardAtEnd && $result !== $this->anyCharacterWildcard) { $result .= $this->anyCharacterWildcard; } return $result; }
[ "public", "function", "escapeForLike", "(", "$", "string", ",", "$", "wildcardAtStart", "=", "true", ",", "$", "wildcardAtEnd", "=", "true", ")", "{", "if", "(", "$", "wildcardAtStart", ")", "{", "$", "result", "=", "$", "this", "->", "anyCharacterWildcard", ";", "}", "else", "{", "$", "result", "=", "''", ";", "}", "$", "result", ".=", "strtr", "(", "(", "string", ")", "$", "string", ",", "$", "this", "->", "getEscapeMap", "(", ")", ")", ";", "if", "(", "$", "wildcardAtEnd", "&&", "$", "result", "!==", "$", "this", "->", "anyCharacterWildcard", ")", "{", "$", "result", ".=", "$", "this", "->", "anyCharacterWildcard", ";", "}", "return", "$", "result", ";", "}" ]
Escape a string to be safely used as a parameter for a LIKE query. @param string $string The string to be escaped @param bool $wildcardAtStart whether to add the any-character wildcard as a prefix @param bool $wildcardAtEnd whether to add the any-character wildcard as a suffix @return string @example escapeForLike('Hi% there', false, true) will return 'Hi\% there%'
[ "Escape", "a", "string", "to", "be", "safely", "used", "as", "a", "parameter", "for", "a", "LIKE", "query", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/Query/LikeBuilder.php#L130-L143
train
concrete5/concrete5
concrete/src/Database/Query/LikeBuilder.php
LikeBuilder.splitKeywordsForLike
public function splitKeywordsForLike($string, $wordSeparators = '\s', $addWildcards = true) { $result = null; if (is_string($string)) { $words = preg_split('/[' . $wordSeparators . ']+/ms', $string); foreach ($words as $word) { if ($word !== '') { $result[] = $this->escapeForLike($word, $addWildcards, $addWildcards); } } } return $result; }
php
public function splitKeywordsForLike($string, $wordSeparators = '\s', $addWildcards = true) { $result = null; if (is_string($string)) { $words = preg_split('/[' . $wordSeparators . ']+/ms', $string); foreach ($words as $word) { if ($word !== '') { $result[] = $this->escapeForLike($word, $addWildcards, $addWildcards); } } } return $result; }
[ "public", "function", "splitKeywordsForLike", "(", "$", "string", ",", "$", "wordSeparators", "=", "'\\s'", ",", "$", "addWildcards", "=", "true", ")", "{", "$", "result", "=", "null", ";", "if", "(", "is_string", "(", "$", "string", ")", ")", "{", "$", "words", "=", "preg_split", "(", "'/['", ".", "$", "wordSeparators", ".", "']+/ms'", ",", "$", "string", ")", ";", "foreach", "(", "$", "words", "as", "$", "word", ")", "{", "if", "(", "$", "word", "!==", "''", ")", "{", "$", "result", "[", "]", "=", "$", "this", "->", "escapeForLike", "(", "$", "word", ",", "$", "addWildcards", ",", "$", "addWildcards", ")", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Split a string into words and format them to be used in LIKE queries. @param string|mixed $string The string to be splitted @param string $wordSeparators The regular expression pattern that represents potential word delimiters (eg '\s' for any whitespace character) @param bool $addWildcards whether to add any-character wildcard at start and end of every resulting word @return string[]|null Returns null if no word has been found, an array of escaped words otherwise
[ "Split", "a", "string", "into", "words", "and", "format", "them", "to", "be", "used", "in", "LIKE", "queries", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Database/Query/LikeBuilder.php#L154-L167
train
concrete5/concrete5
concrete/src/File/Image/BasicThumbnailer.php
BasicThumbnailer.returnThumbnailObjectFromResolver
private function returnThumbnailObjectFromResolver($obj, $maxWidth, $maxHeight, $crop = false) { return $this->processThumbnail(true, $obj, $maxWidth, $maxHeight, $crop); }
php
private function returnThumbnailObjectFromResolver($obj, $maxWidth, $maxHeight, $crop = false) { return $this->processThumbnail(true, $obj, $maxWidth, $maxHeight, $crop); }
[ "private", "function", "returnThumbnailObjectFromResolver", "(", "$", "obj", ",", "$", "maxWidth", ",", "$", "maxHeight", ",", "$", "crop", "=", "false", ")", "{", "return", "$", "this", "->", "processThumbnail", "(", "true", ",", "$", "obj", ",", "$", "maxWidth", ",", "$", "maxHeight", ",", "$", "crop", ")", ";", "}" ]
Checks thumbnail resolver for filename, schedule for creation via ajax if necessary. @param File|string $obj file instance of path to a file @param int|null $maxWidth @param int|null $maxHeight @param bool $crop @return \stdClass
[ "Checks", "thumbnail", "resolver", "for", "filename", "schedule", "for", "creation", "via", "ajax", "if", "necessary", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BasicThumbnailer.php#L231-L234
train
concrete5/concrete5
concrete/src/File/Image/BasicThumbnailer.php
BasicThumbnailer.checkForThumbnailAndCreateIfNecessary
private function checkForThumbnailAndCreateIfNecessary($obj, $maxWidth, $maxHeight, $crop = false) { return $this->processThumbnail(false, $obj, $maxWidth, $maxHeight, $crop); }
php
private function checkForThumbnailAndCreateIfNecessary($obj, $maxWidth, $maxHeight, $crop = false) { return $this->processThumbnail(false, $obj, $maxWidth, $maxHeight, $crop); }
[ "private", "function", "checkForThumbnailAndCreateIfNecessary", "(", "$", "obj", ",", "$", "maxWidth", ",", "$", "maxHeight", ",", "$", "crop", "=", "false", ")", "{", "return", "$", "this", "->", "processThumbnail", "(", "false", ",", "$", "obj", ",", "$", "maxWidth", ",", "$", "maxHeight", ",", "$", "crop", ")", ";", "}" ]
Checks filesystem for thumbnail and if file doesn't exist will create it immediately. concrete5's default behavior from the beginning up to 8.1. @param File|string $obj file instance of path to a file @param int|null $maxWidth @param int|null $maxHeight @param bool $crop @return \stdClass
[ "Checks", "filesystem", "for", "thumbnail", "and", "if", "file", "doesn", "t", "exist", "will", "create", "it", "immediately", ".", "concrete5", "s", "default", "behavior", "from", "the", "beginning", "up", "to", "8", ".", "1", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/BasicThumbnailer.php#L247-L250
train
concrete5/concrete5
concrete/src/Search/ItemList/ItemList.php
ItemList.getResults
public function getResults() { $results = array(); $this->debugStart(); $executeResults = $this->executeGetResults(); $this->debugStop(); foreach ($executeResults as $result) { $r = $this->getResult($result); if ($r != null) { $results[] = $r; } } return $results; }
php
public function getResults() { $results = array(); $this->debugStart(); $executeResults = $this->executeGetResults(); $this->debugStop(); foreach ($executeResults as $result) { $r = $this->getResult($result); if ($r != null) { $results[] = $r; } } return $results; }
[ "public", "function", "getResults", "(", ")", "{", "$", "results", "=", "array", "(", ")", ";", "$", "this", "->", "debugStart", "(", ")", ";", "$", "executeResults", "=", "$", "this", "->", "executeGetResults", "(", ")", ";", "$", "this", "->", "debugStop", "(", ")", ";", "foreach", "(", "$", "executeResults", "as", "$", "result", ")", "{", "$", "r", "=", "$", "this", "->", "getResult", "(", "$", "result", ")", ";", "if", "(", "$", "r", "!=", "null", ")", "{", "$", "results", "[", "]", "=", "$", "r", ";", "}", "}", "return", "$", "results", ";", "}" ]
Returns a full array of results.
[ "Returns", "a", "full", "array", "of", "results", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Search/ItemList/ItemList.php#L78-L96
train
concrete5/concrete5
concrete/src/Search/ItemList/ItemList.php
ItemList.setNameSpace
public function setNameSpace($nameSpace) { $this->paginationPageParameter .= '_' . $nameSpace; $this->sortColumnParameter .= '_' . $nameSpace; $this->sortDirectionParameter .= '_' . $nameSpace; }
php
public function setNameSpace($nameSpace) { $this->paginationPageParameter .= '_' . $nameSpace; $this->sortColumnParameter .= '_' . $nameSpace; $this->sortDirectionParameter .= '_' . $nameSpace; }
[ "public", "function", "setNameSpace", "(", "$", "nameSpace", ")", "{", "$", "this", "->", "paginationPageParameter", ".=", "'_'", ".", "$", "nameSpace", ";", "$", "this", "->", "sortColumnParameter", ".=", "'_'", ".", "$", "nameSpace", ";", "$", "this", "->", "sortDirectionParameter", ".=", "'_'", ".", "$", "nameSpace", ";", "}" ]
Allow to modify the auto-pagination parameters and the auto-sorting parameters @param mixed $nameSpace Content that will be added to the parameters
[ "Allow", "to", "modify", "the", "auto", "-", "pagination", "parameters", "and", "the", "auto", "-", "sorting", "parameters" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Search/ItemList/ItemList.php#L243-L248
train
concrete5/concrete5
concrete/src/Support/Symbol/PhpDocGenerator.php
PhpDocGenerator.describeVar
public function describeVar($name, $value) { return $this->indentation . '/** @var ' . $this->getVarType($value) . ' ' . ($name[0] === '$' ? '' : '$') . $name . " */\n"; }
php
public function describeVar($name, $value) { return $this->indentation . '/** @var ' . $this->getVarType($value) . ' ' . ($name[0] === '$' ? '' : '$') . $name . " */\n"; }
[ "public", "function", "describeVar", "(", "$", "name", ",", "$", "value", ")", "{", "return", "$", "this", "->", "indentation", ".", "'/** @var '", ".", "$", "this", "->", "getVarType", "(", "$", "value", ")", ".", "' '", ".", "(", "$", "name", "[", "0", "]", "===", "'$'", "?", "''", ":", "'$'", ")", ".", "$", "name", ".", "\" */\\n\"", ";", "}" ]
Generate the PHPDoc to describe a variable. @param string $name The variable name @param mixed $value The variable value @return string
[ "Generate", "the", "PHPDoc", "to", "describe", "a", "variable", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Support/Symbol/PhpDocGenerator.php#L81-L84
train
concrete5/concrete5
concrete/src/Support/Symbol/PhpDocGenerator.php
PhpDocGenerator.describeVars
public function describeVars(array $vars, $sortByName = true) { $result = ''; if ($sortByName) { ksort($vars, SORT_NATURAL); } foreach ($vars as $name => $value) { $result .= $this->describeVar($name, $value); } return $result; }
php
public function describeVars(array $vars, $sortByName = true) { $result = ''; if ($sortByName) { ksort($vars, SORT_NATURAL); } foreach ($vars as $name => $value) { $result .= $this->describeVar($name, $value); } return $result; }
[ "public", "function", "describeVars", "(", "array", "$", "vars", ",", "$", "sortByName", "=", "true", ")", "{", "$", "result", "=", "''", ";", "if", "(", "$", "sortByName", ")", "{", "ksort", "(", "$", "vars", ",", "SORT_NATURAL", ")", ";", "}", "foreach", "(", "$", "vars", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "result", ".=", "$", "this", "->", "describeVar", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "result", ";", "}" ]
Generate the PHPDoc to describe a list of variables. @param array $vars @param bool $sortByName @return string
[ "Generate", "the", "PHPDoc", "to", "describe", "a", "list", "of", "variables", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Support/Symbol/PhpDocGenerator.php#L94-L105
train
concrete5/concrete5
concrete/src/Support/Symbol/PhpDocGenerator.php
PhpDocGenerator.getVarType
protected function getVarType($var, $arrayLevel = 0) { $phpType = gettype($var); switch ($phpType) { case 'boolean': $result = 'bool'; break; case 'integer': $result = 'int'; break; case 'double': $result = 'float'; break; case 'string': $result = 'string'; break; case 'array': if ($arrayLevel > 1) { $result = 'array'; } else { $result = null; $first = true; foreach ($var as $item) { $itemType = $this->getVarType($item, $arrayLevel + 1); if ($first) { $result = $itemType; $commonObjectDescriptors = $this->getObjectDescriptors($item); $first = false; } else { if ($result !== $itemType) { $result = null; if (empty($commonObjectDescriptors)) { break; } if (!empty($commonObjectDescriptors)) { $commonObjectDescriptors = array_intersect($commonObjectDescriptors, $this->getObjectDescriptors($item)); } } } } if ($result !== null) { $result .= '[]'; } elseif (!empty($commonObjectDescriptors)) { $result = array_shift($commonObjectDescriptors) . '[]'; } else { $result = 'array'; } } break; case 'object': $result = get_class($var); if ($result === false) { $result = 'mixed'; } else { if ($this->insideNamespace) { $result = '\\' . $result; } } break; case 'resource': $result = 'resource'; break; case 'NULL': $result = 'null'; break; case 'unknown type': default: $result = 'mixed'; break; } return $result; }
php
protected function getVarType($var, $arrayLevel = 0) { $phpType = gettype($var); switch ($phpType) { case 'boolean': $result = 'bool'; break; case 'integer': $result = 'int'; break; case 'double': $result = 'float'; break; case 'string': $result = 'string'; break; case 'array': if ($arrayLevel > 1) { $result = 'array'; } else { $result = null; $first = true; foreach ($var as $item) { $itemType = $this->getVarType($item, $arrayLevel + 1); if ($first) { $result = $itemType; $commonObjectDescriptors = $this->getObjectDescriptors($item); $first = false; } else { if ($result !== $itemType) { $result = null; if (empty($commonObjectDescriptors)) { break; } if (!empty($commonObjectDescriptors)) { $commonObjectDescriptors = array_intersect($commonObjectDescriptors, $this->getObjectDescriptors($item)); } } } } if ($result !== null) { $result .= '[]'; } elseif (!empty($commonObjectDescriptors)) { $result = array_shift($commonObjectDescriptors) . '[]'; } else { $result = 'array'; } } break; case 'object': $result = get_class($var); if ($result === false) { $result = 'mixed'; } else { if ($this->insideNamespace) { $result = '\\' . $result; } } break; case 'resource': $result = 'resource'; break; case 'NULL': $result = 'null'; break; case 'unknown type': default: $result = 'mixed'; break; } return $result; }
[ "protected", "function", "getVarType", "(", "$", "var", ",", "$", "arrayLevel", "=", "0", ")", "{", "$", "phpType", "=", "gettype", "(", "$", "var", ")", ";", "switch", "(", "$", "phpType", ")", "{", "case", "'boolean'", ":", "$", "result", "=", "'bool'", ";", "break", ";", "case", "'integer'", ":", "$", "result", "=", "'int'", ";", "break", ";", "case", "'double'", ":", "$", "result", "=", "'float'", ";", "break", ";", "case", "'string'", ":", "$", "result", "=", "'string'", ";", "break", ";", "case", "'array'", ":", "if", "(", "$", "arrayLevel", ">", "1", ")", "{", "$", "result", "=", "'array'", ";", "}", "else", "{", "$", "result", "=", "null", ";", "$", "first", "=", "true", ";", "foreach", "(", "$", "var", "as", "$", "item", ")", "{", "$", "itemType", "=", "$", "this", "->", "getVarType", "(", "$", "item", ",", "$", "arrayLevel", "+", "1", ")", ";", "if", "(", "$", "first", ")", "{", "$", "result", "=", "$", "itemType", ";", "$", "commonObjectDescriptors", "=", "$", "this", "->", "getObjectDescriptors", "(", "$", "item", ")", ";", "$", "first", "=", "false", ";", "}", "else", "{", "if", "(", "$", "result", "!==", "$", "itemType", ")", "{", "$", "result", "=", "null", ";", "if", "(", "empty", "(", "$", "commonObjectDescriptors", ")", ")", "{", "break", ";", "}", "if", "(", "!", "empty", "(", "$", "commonObjectDescriptors", ")", ")", "{", "$", "commonObjectDescriptors", "=", "array_intersect", "(", "$", "commonObjectDescriptors", ",", "$", "this", "->", "getObjectDescriptors", "(", "$", "item", ")", ")", ";", "}", "}", "}", "}", "if", "(", "$", "result", "!==", "null", ")", "{", "$", "result", ".=", "'[]'", ";", "}", "elseif", "(", "!", "empty", "(", "$", "commonObjectDescriptors", ")", ")", "{", "$", "result", "=", "array_shift", "(", "$", "commonObjectDescriptors", ")", ".", "'[]'", ";", "}", "else", "{", "$", "result", "=", "'array'", ";", "}", "}", "break", ";", "case", "'object'", ":", "$", "result", "=", "get_class", "(", "$", "var", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "$", "result", "=", "'mixed'", ";", "}", "else", "{", "if", "(", "$", "this", "->", "insideNamespace", ")", "{", "$", "result", "=", "'\\\\'", ".", "$", "result", ";", "}", "}", "break", ";", "case", "'resource'", ":", "$", "result", "=", "'resource'", ";", "break", ";", "case", "'NULL'", ":", "$", "result", "=", "'null'", ";", "break", ";", "case", "'unknown type'", ":", "default", ":", "$", "result", "=", "'mixed'", ";", "break", ";", "}", "return", "$", "result", ";", "}" ]
Get the PHPDoc type name of a variable. @param mixed $var @param int $arrayLevel @return string
[ "Get", "the", "PHPDoc", "type", "name", "of", "a", "variable", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Support/Symbol/PhpDocGenerator.php#L115-L187
train
concrete5/concrete5
concrete/src/File/Image/Thumbnail/Type/Version.php
Version.getByHandle
public static function getByHandle($handle) { $list = Type::getVersionList(); foreach ($list as $version) { if ($version->getHandle() == $handle) { return $version; } } }
php
public static function getByHandle($handle) { $list = Type::getVersionList(); foreach ($list as $version) { if ($version->getHandle() == $handle) { return $version; } } }
[ "public", "static", "function", "getByHandle", "(", "$", "handle", ")", "{", "$", "list", "=", "Type", "::", "getVersionList", "(", ")", ";", "foreach", "(", "$", "list", "as", "$", "version", ")", "{", "if", "(", "$", "version", "->", "getHandle", "(", ")", "==", "$", "handle", ")", "{", "return", "$", "version", ";", "}", "}", "}" ]
Get a thumbnail type version given its handle. @param string $handle @return \Concrete\Core\File\Image\Thumbnail\Type\Version|null
[ "Get", "a", "thumbnail", "type", "version", "given", "its", "handle", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/Type/Version.php#L133-L141
train
concrete5/concrete5
concrete/src/File/Image/Thumbnail/Type/Version.php
Version.shouldExistFor
public function shouldExistFor($imageWidth, $imageHeight, File $file = null) { $result = false; $imageWidth = (int) $imageWidth; $imageHeight = (int) $imageHeight; if ($imageWidth > 0 && $imageHeight > 0) { // We have both image dimensions $thumbnailWidth = (int) $this->getWidth() ?: 0; $thumbnailHeight = (int) $this->getHeight() ?: 0; switch ($this->getSizingMode()) { case ThumbnailType::RESIZE_EXACT: // Both the thumbnail width and height must be set if ($thumbnailWidth > 0 && $thumbnailHeight > 0) { // None of the thumbnail dimensions can be greater that image ones if ($this->isUpscalingEnabled()) { $result = true; } else { if ($thumbnailWidth <= $imageWidth && $thumbnailHeight <= $imageHeight) { // Thumbnail must not be the same size as the image if ($thumbnailWidth !== $imageWidth || $thumbnailHeight !== $imageHeight) { $result = true; } } } } break; case ThumbnailType::RESIZE_PROPORTIONAL: default: if ($thumbnailWidth > 0 || $thumbnailHeight > 0) { if ($this->isUpscalingEnabled()) { $result = true; } else { if ($thumbnailWidth > 0 && $thumbnailHeight > 0) { // Both the thumbnail width and height are set // At least one thumbnail dimension must be smaller that the corresponding image dimension if ($thumbnailWidth < $imageWidth || $thumbnailHeight < $imageHeight) { $result = true; } } elseif ($thumbnailWidth > 0) { // Only the thumbnail width is set: the thumbnail must be narrower than the image. if ($thumbnailWidth < $imageWidth) { $result = true; } } elseif ($thumbnailHeight > 0) { // Only the thumbnail height is set: the thumbnail must be shorter than the image. if ($thumbnailHeight < $imageHeight) { $result = true; } } } } break; } if ($result === true && $file !== null) { $fileSetIDs = $this->getAssociatedFileSetIDs(); if ($this->isLimitedToFileSets()) { // Thumbnail only if the file is in the specified file sets if (empty($fileSetIDs)) { $result = false; } else { $valid = array_intersect($fileSetIDs, $file->getFileSetIDs()); if (empty($valid)) { $result = false; } } } else { // Thumbnail only if the file is NOT in the specified file sets if (!empty($fileSetIDs)) { $blocking = array_intersect($fileSetIDs, $file->getFileSetIDs()); if (!empty($blocking)) { $result = false; } } } } } return $result; }
php
public function shouldExistFor($imageWidth, $imageHeight, File $file = null) { $result = false; $imageWidth = (int) $imageWidth; $imageHeight = (int) $imageHeight; if ($imageWidth > 0 && $imageHeight > 0) { // We have both image dimensions $thumbnailWidth = (int) $this->getWidth() ?: 0; $thumbnailHeight = (int) $this->getHeight() ?: 0; switch ($this->getSizingMode()) { case ThumbnailType::RESIZE_EXACT: // Both the thumbnail width and height must be set if ($thumbnailWidth > 0 && $thumbnailHeight > 0) { // None of the thumbnail dimensions can be greater that image ones if ($this->isUpscalingEnabled()) { $result = true; } else { if ($thumbnailWidth <= $imageWidth && $thumbnailHeight <= $imageHeight) { // Thumbnail must not be the same size as the image if ($thumbnailWidth !== $imageWidth || $thumbnailHeight !== $imageHeight) { $result = true; } } } } break; case ThumbnailType::RESIZE_PROPORTIONAL: default: if ($thumbnailWidth > 0 || $thumbnailHeight > 0) { if ($this->isUpscalingEnabled()) { $result = true; } else { if ($thumbnailWidth > 0 && $thumbnailHeight > 0) { // Both the thumbnail width and height are set // At least one thumbnail dimension must be smaller that the corresponding image dimension if ($thumbnailWidth < $imageWidth || $thumbnailHeight < $imageHeight) { $result = true; } } elseif ($thumbnailWidth > 0) { // Only the thumbnail width is set: the thumbnail must be narrower than the image. if ($thumbnailWidth < $imageWidth) { $result = true; } } elseif ($thumbnailHeight > 0) { // Only the thumbnail height is set: the thumbnail must be shorter than the image. if ($thumbnailHeight < $imageHeight) { $result = true; } } } } break; } if ($result === true && $file !== null) { $fileSetIDs = $this->getAssociatedFileSetIDs(); if ($this->isLimitedToFileSets()) { // Thumbnail only if the file is in the specified file sets if (empty($fileSetIDs)) { $result = false; } else { $valid = array_intersect($fileSetIDs, $file->getFileSetIDs()); if (empty($valid)) { $result = false; } } } else { // Thumbnail only if the file is NOT in the specified file sets if (!empty($fileSetIDs)) { $blocking = array_intersect($fileSetIDs, $file->getFileSetIDs()); if (!empty($blocking)) { $result = false; } } } } } return $result; }
[ "public", "function", "shouldExistFor", "(", "$", "imageWidth", ",", "$", "imageHeight", ",", "File", "$", "file", "=", "null", ")", "{", "$", "result", "=", "false", ";", "$", "imageWidth", "=", "(", "int", ")", "$", "imageWidth", ";", "$", "imageHeight", "=", "(", "int", ")", "$", "imageHeight", ";", "if", "(", "$", "imageWidth", ">", "0", "&&", "$", "imageHeight", ">", "0", ")", "{", "// We have both image dimensions", "$", "thumbnailWidth", "=", "(", "int", ")", "$", "this", "->", "getWidth", "(", ")", "?", ":", "0", ";", "$", "thumbnailHeight", "=", "(", "int", ")", "$", "this", "->", "getHeight", "(", ")", "?", ":", "0", ";", "switch", "(", "$", "this", "->", "getSizingMode", "(", ")", ")", "{", "case", "ThumbnailType", "::", "RESIZE_EXACT", ":", "// Both the thumbnail width and height must be set", "if", "(", "$", "thumbnailWidth", ">", "0", "&&", "$", "thumbnailHeight", ">", "0", ")", "{", "// None of the thumbnail dimensions can be greater that image ones", "if", "(", "$", "this", "->", "isUpscalingEnabled", "(", ")", ")", "{", "$", "result", "=", "true", ";", "}", "else", "{", "if", "(", "$", "thumbnailWidth", "<=", "$", "imageWidth", "&&", "$", "thumbnailHeight", "<=", "$", "imageHeight", ")", "{", "// Thumbnail must not be the same size as the image", "if", "(", "$", "thumbnailWidth", "!==", "$", "imageWidth", "||", "$", "thumbnailHeight", "!==", "$", "imageHeight", ")", "{", "$", "result", "=", "true", ";", "}", "}", "}", "}", "break", ";", "case", "ThumbnailType", "::", "RESIZE_PROPORTIONAL", ":", "default", ":", "if", "(", "$", "thumbnailWidth", ">", "0", "||", "$", "thumbnailHeight", ">", "0", ")", "{", "if", "(", "$", "this", "->", "isUpscalingEnabled", "(", ")", ")", "{", "$", "result", "=", "true", ";", "}", "else", "{", "if", "(", "$", "thumbnailWidth", ">", "0", "&&", "$", "thumbnailHeight", ">", "0", ")", "{", "// Both the thumbnail width and height are set", "// At least one thumbnail dimension must be smaller that the corresponding image dimension", "if", "(", "$", "thumbnailWidth", "<", "$", "imageWidth", "||", "$", "thumbnailHeight", "<", "$", "imageHeight", ")", "{", "$", "result", "=", "true", ";", "}", "}", "elseif", "(", "$", "thumbnailWidth", ">", "0", ")", "{", "// Only the thumbnail width is set: the thumbnail must be narrower than the image.", "if", "(", "$", "thumbnailWidth", "<", "$", "imageWidth", ")", "{", "$", "result", "=", "true", ";", "}", "}", "elseif", "(", "$", "thumbnailHeight", ">", "0", ")", "{", "// Only the thumbnail height is set: the thumbnail must be shorter than the image.", "if", "(", "$", "thumbnailHeight", "<", "$", "imageHeight", ")", "{", "$", "result", "=", "true", ";", "}", "}", "}", "}", "break", ";", "}", "if", "(", "$", "result", "===", "true", "&&", "$", "file", "!==", "null", ")", "{", "$", "fileSetIDs", "=", "$", "this", "->", "getAssociatedFileSetIDs", "(", ")", ";", "if", "(", "$", "this", "->", "isLimitedToFileSets", "(", ")", ")", "{", "// Thumbnail only if the file is in the specified file sets", "if", "(", "empty", "(", "$", "fileSetIDs", ")", ")", "{", "$", "result", "=", "false", ";", "}", "else", "{", "$", "valid", "=", "array_intersect", "(", "$", "fileSetIDs", ",", "$", "file", "->", "getFileSetIDs", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "valid", ")", ")", "{", "$", "result", "=", "false", ";", "}", "}", "}", "else", "{", "// Thumbnail only if the file is NOT in the specified file sets", "if", "(", "!", "empty", "(", "$", "fileSetIDs", ")", ")", "{", "$", "blocking", "=", "array_intersect", "(", "$", "fileSetIDs", ",", "$", "file", "->", "getFileSetIDs", "(", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "blocking", ")", ")", "{", "$", "result", "=", "false", ";", "}", "}", "}", "}", "}", "return", "$", "result", ";", "}" ]
Check if this thumbnail type version should exist for an image with the specified dimensions. @param int $imageWidth The original image width @param int $imageHeight The original image height @param File|null $file The File instance to check file sets against @return bool
[ "Check", "if", "this", "thumbnail", "type", "version", "should", "exist", "for", "an", "image", "with", "the", "specified", "dimensions", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/Type/Version.php#L448-L526
train
concrete5/concrete5
concrete/src/Localization/Service/CountryList.php
CountryList.getCountries
public function getCountries() { if (!array_key_exists(Localization::activeLocale(), $this->countries)) { $this->loadCountries(); } return $this->countries[Localization::activeLocale()]; }
php
public function getCountries() { if (!array_key_exists(Localization::activeLocale(), $this->countries)) { $this->loadCountries(); } return $this->countries[Localization::activeLocale()]; }
[ "public", "function", "getCountries", "(", ")", "{", "if", "(", "!", "array_key_exists", "(", "Localization", "::", "activeLocale", "(", ")", ",", "$", "this", "->", "countries", ")", ")", "{", "$", "this", "->", "loadCountries", "(", ")", ";", "}", "return", "$", "this", "->", "countries", "[", "Localization", "::", "activeLocale", "(", ")", "]", ";", "}" ]
Returns an array of countries with their short name as the key and their full name as the value @return array Keys are the country codes, values are the county names
[ "Returns", "an", "array", "of", "countries", "with", "their", "short", "name", "as", "the", "key", "and", "their", "full", "name", "as", "the", "value" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/CountryList.php#L36-L43
train
concrete5/concrete5
concrete/src/Localization/Service/CountryList.php
CountryList.getCountriesForLanguage
public function getCountriesForLanguage($languageCode, $languageStatuses = 'orfm') { $territories = []; foreach (\Punic\Territory::getTerritoriesForLanguage($languageCode) as $territory) { $territoryLanguages = \Punic\Territory::getLanguages($territory, $languageStatuses, true); if (in_array($languageCode, $territoryLanguages)) { $territories[] = $territory; } } $validCountryCodes = array_keys($this->getCountries()); $result = array_intersect($territories, $validCountryCodes); return array_values($result); }
php
public function getCountriesForLanguage($languageCode, $languageStatuses = 'orfm') { $territories = []; foreach (\Punic\Territory::getTerritoriesForLanguage($languageCode) as $territory) { $territoryLanguages = \Punic\Territory::getLanguages($territory, $languageStatuses, true); if (in_array($languageCode, $territoryLanguages)) { $territories[] = $territory; } } $validCountryCodes = array_keys($this->getCountries()); $result = array_intersect($territories, $validCountryCodes); return array_values($result); }
[ "public", "function", "getCountriesForLanguage", "(", "$", "languageCode", ",", "$", "languageStatuses", "=", "'orfm'", ")", "{", "$", "territories", "=", "[", "]", ";", "foreach", "(", "\\", "Punic", "\\", "Territory", "::", "getTerritoriesForLanguage", "(", "$", "languageCode", ")", "as", "$", "territory", ")", "{", "$", "territoryLanguages", "=", "\\", "Punic", "\\", "Territory", "::", "getLanguages", "(", "$", "territory", ",", "$", "languageStatuses", ",", "true", ")", ";", "if", "(", "in_array", "(", "$", "languageCode", ",", "$", "territoryLanguages", ")", ")", "{", "$", "territories", "[", "]", "=", "$", "territory", ";", "}", "}", "$", "validCountryCodes", "=", "array_keys", "(", "$", "this", "->", "getCountries", "(", ")", ")", ";", "$", "result", "=", "array_intersect", "(", "$", "territories", ",", "$", "validCountryCodes", ")", ";", "return", "array_values", "(", "$", "result", ")", ";", "}" ]
Return a list of territory codes where a specific language is spoken, sorted by the total number of people speaking that language. @param string $languageCode The language code (eg. 'en') @param string $languageStatuses The allowed statuses of the languages, whose codes are 'o' (official), 'r' (official regional), 'f' (de facto official), 'm' (official minority), 'u' (unofficial or unknown) @return array Returns a list of country codes
[ "Return", "a", "list", "of", "territory", "codes", "where", "a", "specific", "language", "is", "spoken", "sorted", "by", "the", "total", "number", "of", "people", "speaking", "that", "language", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Service/CountryList.php#L65-L79
train
concrete5/concrete5
concrete/controllers/backend/user_interface.php
UserInterface.validateAction
protected function validateAction() { $token = (isset($this->validationToken)) ? $this->validationToken : get_class($this); if (!$this->app->make('token')->validate($token)) { $this->error->add($this->app->make('token')->getErrorMessage()); return false; } if (!$this->canAccess()) { return false; } return true; }
php
protected function validateAction() { $token = (isset($this->validationToken)) ? $this->validationToken : get_class($this); if (!$this->app->make('token')->validate($token)) { $this->error->add($this->app->make('token')->getErrorMessage()); return false; } if (!$this->canAccess()) { return false; } return true; }
[ "protected", "function", "validateAction", "(", ")", "{", "$", "token", "=", "(", "isset", "(", "$", "this", "->", "validationToken", ")", ")", "?", "$", "this", "->", "validationToken", ":", "get_class", "(", "$", "this", ")", ";", "if", "(", "!", "$", "this", "->", "app", "->", "make", "(", "'token'", ")", "->", "validate", "(", "$", "token", ")", ")", "{", "$", "this", "->", "error", "->", "add", "(", "$", "this", "->", "app", "->", "make", "(", "'token'", ")", "->", "getErrorMessage", "(", ")", ")", ";", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "canAccess", "(", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check whether the token is valid and if the current page be accessed. @return bool
[ "Check", "whether", "the", "token", "is", "valid", "and", "if", "the", "current", "page", "be", "accessed", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/backend/user_interface.php#L89-L102
train
concrete5/concrete5
concrete/src/Url/Resolver/RouterUrlResolver.php
RouterUrlResolver.resolveRoute
private function resolveRoute($route_handle, $route_parameters) { $list = $this->getRouteList(); $generator = $this->getGenerator(); if ($route = $list->get($route_handle)) { if ($path = $generator->generate($route_handle, $route_parameters, UrlGeneratorInterface::ABSOLUTE_PATH)) { return $this->pathUrlResolver->resolve(array($path)); } } }
php
private function resolveRoute($route_handle, $route_parameters) { $list = $this->getRouteList(); $generator = $this->getGenerator(); if ($route = $list->get($route_handle)) { if ($path = $generator->generate($route_handle, $route_parameters, UrlGeneratorInterface::ABSOLUTE_PATH)) { return $this->pathUrlResolver->resolve(array($path)); } } }
[ "private", "function", "resolveRoute", "(", "$", "route_handle", ",", "$", "route_parameters", ")", "{", "$", "list", "=", "$", "this", "->", "getRouteList", "(", ")", ";", "$", "generator", "=", "$", "this", "->", "getGenerator", "(", ")", ";", "if", "(", "$", "route", "=", "$", "list", "->", "get", "(", "$", "route_handle", ")", ")", "{", "if", "(", "$", "path", "=", "$", "generator", "->", "generate", "(", "$", "route_handle", ",", "$", "route_parameters", ",", "UrlGeneratorInterface", "::", "ABSOLUTE_PATH", ")", ")", "{", "return", "$", "this", "->", "pathUrlResolver", "->", "resolve", "(", "array", "(", "$", "path", ")", ")", ";", "}", "}", "}" ]
Resolve the route. @param $route_handle @param $route_parameters @return $this|\League\URL\URLInterface|mixed|null
[ "Resolve", "the", "route", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Url/Resolver/RouterUrlResolver.php#L93-L103
train
concrete5/concrete5
concrete/src/Geolocator/GeolocationResult.php
GeolocationResult.setError
public function setError($code, $message = '', Exception $innerException = null) { if ($code == static::ERR_NONE && !$message && $innerException === null) { $this->errorCode = static::ERR_NONE; $this->errorMessage = ''; $this->innerException = null; } else { $code = (int) $code; $this->errorCode = $code === static::ERR_NONE ? static::ERR_OTHER : $code; $message = trim((string) $message); if ($message === '') { switch ($this->errorCode) { case static::ERR_NOCURRENTLIBRARY: $this->errorMessage = t("There's no current geolocation library"); break; case static::ERR_NOCURRENTIPADDRESS: $this->errorMessage = t('The IP address of the current client is not available'); break; case static::ERR_IPNOTPUBLIC: $this->errorMessage = t('The IP address is not in the public IP address ranges'); break; case static::ERR_MISCONFIGURED: $this->errorMessage = t('The geolocation library is misconfigured'); break; case static::ERR_NETWORK: $this->errorMessage = t('A network error occurred during the geolocalization'); break; case static::ERR_LIBRARYSPECIFIC: $this->errorMessage = t('An unspecified error occurred in the geolocation library'); break; default: $this->errorMessage = t('An unexpected error occurred in the geolocation library'); } } else { $this->errorMessage = $message; } $this->innerException = $innerException; } }
php
public function setError($code, $message = '', Exception $innerException = null) { if ($code == static::ERR_NONE && !$message && $innerException === null) { $this->errorCode = static::ERR_NONE; $this->errorMessage = ''; $this->innerException = null; } else { $code = (int) $code; $this->errorCode = $code === static::ERR_NONE ? static::ERR_OTHER : $code; $message = trim((string) $message); if ($message === '') { switch ($this->errorCode) { case static::ERR_NOCURRENTLIBRARY: $this->errorMessage = t("There's no current geolocation library"); break; case static::ERR_NOCURRENTIPADDRESS: $this->errorMessage = t('The IP address of the current client is not available'); break; case static::ERR_IPNOTPUBLIC: $this->errorMessage = t('The IP address is not in the public IP address ranges'); break; case static::ERR_MISCONFIGURED: $this->errorMessage = t('The geolocation library is misconfigured'); break; case static::ERR_NETWORK: $this->errorMessage = t('A network error occurred during the geolocalization'); break; case static::ERR_LIBRARYSPECIFIC: $this->errorMessage = t('An unspecified error occurred in the geolocation library'); break; default: $this->errorMessage = t('An unexpected error occurred in the geolocation library'); } } else { $this->errorMessage = $message; } $this->innerException = $innerException; } }
[ "public", "function", "setError", "(", "$", "code", ",", "$", "message", "=", "''", ",", "Exception", "$", "innerException", "=", "null", ")", "{", "if", "(", "$", "code", "==", "static", "::", "ERR_NONE", "&&", "!", "$", "message", "&&", "$", "innerException", "===", "null", ")", "{", "$", "this", "->", "errorCode", "=", "static", "::", "ERR_NONE", ";", "$", "this", "->", "errorMessage", "=", "''", ";", "$", "this", "->", "innerException", "=", "null", ";", "}", "else", "{", "$", "code", "=", "(", "int", ")", "$", "code", ";", "$", "this", "->", "errorCode", "=", "$", "code", "===", "static", "::", "ERR_NONE", "?", "static", "::", "ERR_OTHER", ":", "$", "code", ";", "$", "message", "=", "trim", "(", "(", "string", ")", "$", "message", ")", ";", "if", "(", "$", "message", "===", "''", ")", "{", "switch", "(", "$", "this", "->", "errorCode", ")", "{", "case", "static", "::", "ERR_NOCURRENTLIBRARY", ":", "$", "this", "->", "errorMessage", "=", "t", "(", "\"There's no current geolocation library\"", ")", ";", "break", ";", "case", "static", "::", "ERR_NOCURRENTIPADDRESS", ":", "$", "this", "->", "errorMessage", "=", "t", "(", "'The IP address of the current client is not available'", ")", ";", "break", ";", "case", "static", "::", "ERR_IPNOTPUBLIC", ":", "$", "this", "->", "errorMessage", "=", "t", "(", "'The IP address is not in the public IP address ranges'", ")", ";", "break", ";", "case", "static", "::", "ERR_MISCONFIGURED", ":", "$", "this", "->", "errorMessage", "=", "t", "(", "'The geolocation library is misconfigured'", ")", ";", "break", ";", "case", "static", "::", "ERR_NETWORK", ":", "$", "this", "->", "errorMessage", "=", "t", "(", "'A network error occurred during the geolocalization'", ")", ";", "break", ";", "case", "static", "::", "ERR_LIBRARYSPECIFIC", ":", "$", "this", "->", "errorMessage", "=", "t", "(", "'An unspecified error occurred in the geolocation library'", ")", ";", "break", ";", "default", ":", "$", "this", "->", "errorMessage", "=", "t", "(", "'An unexpected error occurred in the geolocation library'", ")", ";", "}", "}", "else", "{", "$", "this", "->", "errorMessage", "=", "$", "message", ";", "}", "$", "this", "->", "innerException", "=", "$", "innerException", ";", "}", "}" ]
Set the error state. @param int $code one of the GeolocationResult::ERR_... constants @param string $message the error message @param Exception|null $innerException the underlying exception causing the error (if available)
[ "Set", "the", "error", "state", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Geolocator/GeolocationResult.php#L150-L188
train
concrete5/concrete5
concrete/src/Geolocator/GeolocationResult.php
GeolocationResult.setLatitude
public function setLatitude($value) { if (is_float($value) || is_int($value) || (is_string($value) && is_numeric($value))) { $this->latitude = (float) $value; } else { $this->latitude = null; } return $this; }
php
public function setLatitude($value) { if (is_float($value) || is_int($value) || (is_string($value) && is_numeric($value))) { $this->latitude = (float) $value; } else { $this->latitude = null; } return $this; }
[ "public", "function", "setLatitude", "(", "$", "value", ")", "{", "if", "(", "is_float", "(", "$", "value", ")", "||", "is_int", "(", "$", "value", ")", "||", "(", "is_string", "(", "$", "value", ")", "&&", "is_numeric", "(", "$", "value", ")", ")", ")", "{", "$", "this", "->", "latitude", "=", "(", "float", ")", "$", "value", ";", "}", "else", "{", "$", "this", "->", "latitude", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
Set the latitude. @param float|null $value @return $this
[ "Set", "the", "latitude", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Geolocator/GeolocationResult.php#L422-L431
train
concrete5/concrete5
concrete/src/Geolocator/GeolocationResult.php
GeolocationResult.setLongitude
public function setLongitude($value) { if (is_float($value) || is_int($value) || (is_string($value) && is_numeric($value))) { $this->longitude = (float) $value; } else { $this->longitude = null; } return $this; }
php
public function setLongitude($value) { if (is_float($value) || is_int($value) || (is_string($value) && is_numeric($value))) { $this->longitude = (float) $value; } else { $this->longitude = null; } return $this; }
[ "public", "function", "setLongitude", "(", "$", "value", ")", "{", "if", "(", "is_float", "(", "$", "value", ")", "||", "is_int", "(", "$", "value", ")", "||", "(", "is_string", "(", "$", "value", ")", "&&", "is_numeric", "(", "$", "value", ")", ")", ")", "{", "$", "this", "->", "longitude", "=", "(", "float", ")", "$", "value", ";", "}", "else", "{", "$", "this", "->", "longitude", "=", "null", ";", "}", "return", "$", "this", ";", "}" ]
Set the longitude. @param float|null $value @return $this
[ "Set", "the", "longitude", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Geolocator/GeolocationResult.php#L450-L459
train
concrete5/concrete5
concrete/src/Geolocator/GeolocationResult.php
GeolocationResult.hasData
public function hasData() { return $this->countryCode !== '' || $this->countryName !== '' || $this->stateProvinceCode !== '' || $this->stateProvinceName !== '' || $this->cityName !== '' || $this->postalCode !== '' || $this->latitude !== null || $this->longitude !== null ; }
php
public function hasData() { return $this->countryCode !== '' || $this->countryName !== '' || $this->stateProvinceCode !== '' || $this->stateProvinceName !== '' || $this->cityName !== '' || $this->postalCode !== '' || $this->latitude !== null || $this->longitude !== null ; }
[ "public", "function", "hasData", "(", ")", "{", "return", "$", "this", "->", "countryCode", "!==", "''", "||", "$", "this", "->", "countryName", "!==", "''", "||", "$", "this", "->", "stateProvinceCode", "!==", "''", "||", "$", "this", "->", "stateProvinceName", "!==", "''", "||", "$", "this", "->", "cityName", "!==", "''", "||", "$", "this", "->", "postalCode", "!==", "''", "||", "$", "this", "->", "latitude", "!==", "null", "||", "$", "this", "->", "longitude", "!==", "null", ";", "}" ]
Does this instance contain some geolocalized data? @return bool
[ "Does", "this", "instance", "contain", "some", "geolocalized", "data?" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Geolocator/GeolocationResult.php#L466-L485
train
concrete5/concrete5
concrete/controllers/backend/file.php
File.getDestinationFolder
protected function getDestinationFolder() { if ($this->destinationFolder === false) { $replacingFile = $this->getFileToBeReplaced(); if ($replacingFile !== null) { $folder = $replacingFile->getFileFolderObject(); } else { $treeNodeID = $this->request->request->get('currentFolder'); if ($treeNodeID) { $treeNodeID = is_scalar($treeNodeID) ? (int) $treeNodeID : 0; $folder = $treeNodeID === 0 ? null : Node::getByID($treeNodeID); } else { $filesystem = new Filesystem(); $folder = $filesystem->getRootFolder(); } } if (!$folder instanceof FileFolder) { throw new UserMessageException(t('Unable to find the specified folder.')); } if ($replacingFile === null) { $fp = new Checker($folder); if (!$fp->canAddFiles()) { throw new UserMessageException(t('Unable to add files.'), 400); } } $this->destinationFolder = $folder; } return $this->destinationFolder; }
php
protected function getDestinationFolder() { if ($this->destinationFolder === false) { $replacingFile = $this->getFileToBeReplaced(); if ($replacingFile !== null) { $folder = $replacingFile->getFileFolderObject(); } else { $treeNodeID = $this->request->request->get('currentFolder'); if ($treeNodeID) { $treeNodeID = is_scalar($treeNodeID) ? (int) $treeNodeID : 0; $folder = $treeNodeID === 0 ? null : Node::getByID($treeNodeID); } else { $filesystem = new Filesystem(); $folder = $filesystem->getRootFolder(); } } if (!$folder instanceof FileFolder) { throw new UserMessageException(t('Unable to find the specified folder.')); } if ($replacingFile === null) { $fp = new Checker($folder); if (!$fp->canAddFiles()) { throw new UserMessageException(t('Unable to add files.'), 400); } } $this->destinationFolder = $folder; } return $this->destinationFolder; }
[ "protected", "function", "getDestinationFolder", "(", ")", "{", "if", "(", "$", "this", "->", "destinationFolder", "===", "false", ")", "{", "$", "replacingFile", "=", "$", "this", "->", "getFileToBeReplaced", "(", ")", ";", "if", "(", "$", "replacingFile", "!==", "null", ")", "{", "$", "folder", "=", "$", "replacingFile", "->", "getFileFolderObject", "(", ")", ";", "}", "else", "{", "$", "treeNodeID", "=", "$", "this", "->", "request", "->", "request", "->", "get", "(", "'currentFolder'", ")", ";", "if", "(", "$", "treeNodeID", ")", "{", "$", "treeNodeID", "=", "is_scalar", "(", "$", "treeNodeID", ")", "?", "(", "int", ")", "$", "treeNodeID", ":", "0", ";", "$", "folder", "=", "$", "treeNodeID", "===", "0", "?", "null", ":", "Node", "::", "getByID", "(", "$", "treeNodeID", ")", ";", "}", "else", "{", "$", "filesystem", "=", "new", "Filesystem", "(", ")", ";", "$", "folder", "=", "$", "filesystem", "->", "getRootFolder", "(", ")", ";", "}", "}", "if", "(", "!", "$", "folder", "instanceof", "FileFolder", ")", "{", "throw", "new", "UserMessageException", "(", "t", "(", "'Unable to find the specified folder.'", ")", ")", ";", "}", "if", "(", "$", "replacingFile", "===", "null", ")", "{", "$", "fp", "=", "new", "Checker", "(", "$", "folder", ")", ";", "if", "(", "!", "$", "fp", "->", "canAddFiles", "(", ")", ")", "{", "throw", "new", "UserMessageException", "(", "t", "(", "'Unable to add files.'", ")", ",", "400", ")", ";", "}", "}", "$", "this", "->", "destinationFolder", "=", "$", "folder", ";", "}", "return", "$", "this", "->", "destinationFolder", ";", "}" ]
Get the destination folder where the uploaded files should be placed. @throws \Concrete\Core\Error\UserMessageException in case the folder couldn't be found or it's not accessible @return \Concrete\Core\Tree\Node\Type\FileFolder @since 8.5.0a3
[ "Get", "the", "destination", "folder", "where", "the", "uploaded", "files", "should", "be", "placed", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/backend/file.php#L568-L597
train
concrete5/concrete5
concrete/controllers/backend/file.php
File.downloadRemoteURL
protected function downloadRemoteURL($url, $temporaryDirectory) { $client = $this->app->make('http/client'); $request = $client->getRequest()->setUri($url); $response = $client->send(); if (!$response->isSuccess()) { throw new UserMessageException(t(/*i18n: %1$s is an URL, %2$s is an error message*/'There was an error downloading "%1$s": %2$s', $url, $response->getReasonPhrase() . ' (' . $response->getStatusCode() . ')')); } $headers = $response->getHeaders(); // figure out a filename based on filename, mimetype, ??? $matches = null; if (preg_match('/^[^#\?]+[\\/]([-\w%]+\.[-\w%]+)($|\?|#)/', $request->getUri(), $matches)) { // got a filename (with extension)... use it $filename = $matches[1]; } else { $contentType = $headers->get('ContentType')->getFieldValue(); if ($contentType) { list($mimeType) = explode(';', $contentType, 2); $mimeType = trim($mimeType); // use mimetype from http response $extension = $this->app->make('helper/mime')->mimeToExtension($mimeType); if ($extension === false) { throw new UserMessageException(t('Unknown mime-type: %s', h($mimeType))); } $filename = date('Y-m-d_H-i_') . mt_rand(100, 999) . '.' . $extension; } else { throw new UserMessageException(t(/*i18n: %s is an URL*/'Could not determine the name of the file at %s', $url)); } } $fullFilename = $temporaryDirectory . '/' . $filename; // write the downloaded file to a temporary location on disk $handle = fopen($fullFilename, 'wb'); fwrite($handle, $response->getBody()); fclose($handle); return $fullFilename; }
php
protected function downloadRemoteURL($url, $temporaryDirectory) { $client = $this->app->make('http/client'); $request = $client->getRequest()->setUri($url); $response = $client->send(); if (!$response->isSuccess()) { throw new UserMessageException(t(/*i18n: %1$s is an URL, %2$s is an error message*/'There was an error downloading "%1$s": %2$s', $url, $response->getReasonPhrase() . ' (' . $response->getStatusCode() . ')')); } $headers = $response->getHeaders(); // figure out a filename based on filename, mimetype, ??? $matches = null; if (preg_match('/^[^#\?]+[\\/]([-\w%]+\.[-\w%]+)($|\?|#)/', $request->getUri(), $matches)) { // got a filename (with extension)... use it $filename = $matches[1]; } else { $contentType = $headers->get('ContentType')->getFieldValue(); if ($contentType) { list($mimeType) = explode(';', $contentType, 2); $mimeType = trim($mimeType); // use mimetype from http response $extension = $this->app->make('helper/mime')->mimeToExtension($mimeType); if ($extension === false) { throw new UserMessageException(t('Unknown mime-type: %s', h($mimeType))); } $filename = date('Y-m-d_H-i_') . mt_rand(100, 999) . '.' . $extension; } else { throw new UserMessageException(t(/*i18n: %s is an URL*/'Could not determine the name of the file at %s', $url)); } } $fullFilename = $temporaryDirectory . '/' . $filename; // write the downloaded file to a temporary location on disk $handle = fopen($fullFilename, 'wb'); fwrite($handle, $response->getBody()); fclose($handle); return $fullFilename; }
[ "protected", "function", "downloadRemoteURL", "(", "$", "url", ",", "$", "temporaryDirectory", ")", "{", "$", "client", "=", "$", "this", "->", "app", "->", "make", "(", "'http/client'", ")", ";", "$", "request", "=", "$", "client", "->", "getRequest", "(", ")", "->", "setUri", "(", "$", "url", ")", ";", "$", "response", "=", "$", "client", "->", "send", "(", ")", ";", "if", "(", "!", "$", "response", "->", "isSuccess", "(", ")", ")", "{", "throw", "new", "UserMessageException", "(", "t", "(", "/*i18n: %1$s is an URL, %2$s is an error message*/", "'There was an error downloading \"%1$s\": %2$s'", ",", "$", "url", ",", "$", "response", "->", "getReasonPhrase", "(", ")", ".", "' ('", ".", "$", "response", "->", "getStatusCode", "(", ")", ".", "')'", ")", ")", ";", "}", "$", "headers", "=", "$", "response", "->", "getHeaders", "(", ")", ";", "// figure out a filename based on filename, mimetype, ???", "$", "matches", "=", "null", ";", "if", "(", "preg_match", "(", "'/^[^#\\?]+[\\\\/]([-\\w%]+\\.[-\\w%]+)($|\\?|#)/'", ",", "$", "request", "->", "getUri", "(", ")", ",", "$", "matches", ")", ")", "{", "// got a filename (with extension)... use it", "$", "filename", "=", "$", "matches", "[", "1", "]", ";", "}", "else", "{", "$", "contentType", "=", "$", "headers", "->", "get", "(", "'ContentType'", ")", "->", "getFieldValue", "(", ")", ";", "if", "(", "$", "contentType", ")", "{", "list", "(", "$", "mimeType", ")", "=", "explode", "(", "';'", ",", "$", "contentType", ",", "2", ")", ";", "$", "mimeType", "=", "trim", "(", "$", "mimeType", ")", ";", "// use mimetype from http response", "$", "extension", "=", "$", "this", "->", "app", "->", "make", "(", "'helper/mime'", ")", "->", "mimeToExtension", "(", "$", "mimeType", ")", ";", "if", "(", "$", "extension", "===", "false", ")", "{", "throw", "new", "UserMessageException", "(", "t", "(", "'Unknown mime-type: %s'", ",", "h", "(", "$", "mimeType", ")", ")", ")", ";", "}", "$", "filename", "=", "date", "(", "'Y-m-d_H-i_'", ")", ".", "mt_rand", "(", "100", ",", "999", ")", ".", "'.'", ".", "$", "extension", ";", "}", "else", "{", "throw", "new", "UserMessageException", "(", "t", "(", "/*i18n: %s is an URL*/", "'Could not determine the name of the file at %s'", ",", "$", "url", ")", ")", ";", "}", "}", "$", "fullFilename", "=", "$", "temporaryDirectory", ".", "'/'", ".", "$", "filename", ";", "// write the downloaded file to a temporary location on disk", "$", "handle", "=", "fopen", "(", "$", "fullFilename", ",", "'wb'", ")", ";", "fwrite", "(", "$", "handle", ",", "$", "response", "->", "getBody", "(", ")", ")", ";", "fclose", "(", "$", "handle", ")", ";", "return", "$", "fullFilename", ";", "}" ]
Download an URL to the temporary directory. @param string $url @param string $temporaryDirectory @throws \Concrete\Core\Error\UserMessageException in case of errors @return string the local filename
[ "Download", "an", "URL", "to", "the", "temporary", "directory", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/backend/file.php#L704-L740
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.shouldEnableLegacyNamespace
public function shouldEnableLegacyNamespace() { if (isset($this->pkgAutoloaderMapCoreExtensions) && $this->pkgAutoloaderMapCoreExtensions) { // We're no longer using this to denote non-legacy applications, but if a package uses this // that means it's NOT using the legacy namespace. return false; } $concrete5 = '7.9.9'; $package = $this->getApplicationVersionRequired(); if (version_compare($package, $concrete5, '>')) { return false; } return $this->pkgEnableLegacyNamespace; }
php
public function shouldEnableLegacyNamespace() { if (isset($this->pkgAutoloaderMapCoreExtensions) && $this->pkgAutoloaderMapCoreExtensions) { // We're no longer using this to denote non-legacy applications, but if a package uses this // that means it's NOT using the legacy namespace. return false; } $concrete5 = '7.9.9'; $package = $this->getApplicationVersionRequired(); if (version_compare($package, $concrete5, '>')) { return false; } return $this->pkgEnableLegacyNamespace; }
[ "public", "function", "shouldEnableLegacyNamespace", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "pkgAutoloaderMapCoreExtensions", ")", "&&", "$", "this", "->", "pkgAutoloaderMapCoreExtensions", ")", "{", "// We're no longer using this to denote non-legacy applications, but if a package uses this", "// that means it's NOT using the legacy namespace.", "return", "false", ";", "}", "$", "concrete5", "=", "'7.9.9'", ";", "$", "package", "=", "$", "this", "->", "getApplicationVersionRequired", "(", ")", ";", "if", "(", "version_compare", "(", "$", "package", ",", "$", "concrete5", ",", "'>'", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "pkgEnableLegacyNamespace", ";", "}" ]
Should this package enable legacy namespaces? This returns true IF: 1. $this->pkgAutoloaderMapCoreExtensions is false or unset 2. The required package version > 7.9.9 meaning version 8 or newer 3. $this->pkgEnableLegacyNamespace is true @return bool
[ "Should", "this", "package", "enable", "legacy", "namespaces?" ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L306-L321
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.getDatabaseConfig
public function getDatabaseConfig() { if (!$this->config) { $this->config = new Liaison($this->app->make('config/database'), $this->getPackageHandle()); } return $this->config; }
php
public function getDatabaseConfig() { if (!$this->config) { $this->config = new Liaison($this->app->make('config/database'), $this->getPackageHandle()); } return $this->config; }
[ "public", "function", "getDatabaseConfig", "(", ")", "{", "if", "(", "!", "$", "this", "->", "config", ")", "{", "$", "this", "->", "config", "=", "new", "Liaison", "(", "$", "this", "->", "app", "->", "make", "(", "'config/database'", ")", ",", "$", "this", "->", "getPackageHandle", "(", ")", ")", ";", "}", "return", "$", "this", "->", "config", ";", "}" ]
Get the database configuration liaison. @return Liaison
[ "Get", "the", "database", "configuration", "liaison", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L338-L345
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.getFileConfig
public function getFileConfig() { if (!$this->fileConfig) { $this->fileConfig = new Liaison($this->app->make('config'), $this->getPackageHandle()); } return $this->fileConfig; }
php
public function getFileConfig() { if (!$this->fileConfig) { $this->fileConfig = new Liaison($this->app->make('config'), $this->getPackageHandle()); } return $this->fileConfig; }
[ "public", "function", "getFileConfig", "(", ")", "{", "if", "(", "!", "$", "this", "->", "fileConfig", ")", "{", "$", "this", "->", "fileConfig", "=", "new", "Liaison", "(", "$", "this", "->", "app", "->", "make", "(", "'config'", ")", ",", "$", "this", "->", "getPackageHandle", "(", ")", ")", ";", "}", "return", "$", "this", "->", "fileConfig", ";", "}" ]
Get the filesystem configuration liaison. @return Liaison
[ "Get", "the", "filesystem", "configuration", "liaison", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L352-L359
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.getPackagePath
public function getPackagePath() { $packageHandle = $this->getPackageHandle(); $result = $this->DIR_PACKAGES . '/' . $packageHandle; if (!is_dir($result)) { $result = $this->DIR_PACKAGES_CORE . '/' . $packageHandle; } return $result; }
php
public function getPackagePath() { $packageHandle = $this->getPackageHandle(); $result = $this->DIR_PACKAGES . '/' . $packageHandle; if (!is_dir($result)) { $result = $this->DIR_PACKAGES_CORE . '/' . $packageHandle; } return $result; }
[ "public", "function", "getPackagePath", "(", ")", "{", "$", "packageHandle", "=", "$", "this", "->", "getPackageHandle", "(", ")", ";", "$", "result", "=", "$", "this", "->", "DIR_PACKAGES", ".", "'/'", ".", "$", "packageHandle", ";", "if", "(", "!", "is_dir", "(", "$", "result", ")", ")", "{", "$", "result", "=", "$", "this", "->", "DIR_PACKAGES_CORE", ".", "'/'", ".", "$", "packageHandle", ";", "}", "return", "$", "result", ";", "}" ]
Get the absolute path to the package. @return string
[ "Get", "the", "absolute", "path", "to", "the", "package", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L481-L490
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.getRelativePath
public function getRelativePath() { $packageHandle = $this->getPackageHandle(); if (is_dir($this->DIR_PACKAGES . '/' . $packageHandle)) { $result = $this->REL_DIR_PACKAGES . '/' . $packageHandle; } else { $result = $this->REL_DIR_PACKAGES_CORE . '/' . $packageHandle; } return $result; }
php
public function getRelativePath() { $packageHandle = $this->getPackageHandle(); if (is_dir($this->DIR_PACKAGES . '/' . $packageHandle)) { $result = $this->REL_DIR_PACKAGES . '/' . $packageHandle; } else { $result = $this->REL_DIR_PACKAGES_CORE . '/' . $packageHandle; } return $result; }
[ "public", "function", "getRelativePath", "(", ")", "{", "$", "packageHandle", "=", "$", "this", "->", "getPackageHandle", "(", ")", ";", "if", "(", "is_dir", "(", "$", "this", "->", "DIR_PACKAGES", ".", "'/'", ".", "$", "packageHandle", ")", ")", "{", "$", "result", "=", "$", "this", "->", "REL_DIR_PACKAGES", ".", "'/'", ".", "$", "packageHandle", ";", "}", "else", "{", "$", "result", "=", "$", "this", "->", "REL_DIR_PACKAGES_CORE", ".", "'/'", ".", "$", "packageHandle", ";", "}", "return", "$", "result", ";", "}" ]
Get the path to the package relative to the web root. @return string
[ "Get", "the", "path", "to", "the", "package", "relative", "to", "the", "web", "root", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L497-L507
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.getChangelogContents
public function getChangelogContents() { $prefix = $this->getPackagePath() . '/'; foreach (['CHANGELOG', 'CHANGELOG.txt', 'CHANGELOG.md'] as $name) { $file = $prefix . $name; if (is_file($file)) { $contents = $this->app->make('helper/file')->getContents($file); return nl2br(h($contents)); } } return ''; }
php
public function getChangelogContents() { $prefix = $this->getPackagePath() . '/'; foreach (['CHANGELOG', 'CHANGELOG.txt', 'CHANGELOG.md'] as $name) { $file = $prefix . $name; if (is_file($file)) { $contents = $this->app->make('helper/file')->getContents($file); return nl2br(h($contents)); } } return ''; }
[ "public", "function", "getChangelogContents", "(", ")", "{", "$", "prefix", "=", "$", "this", "->", "getPackagePath", "(", ")", ".", "'/'", ";", "foreach", "(", "[", "'CHANGELOG'", ",", "'CHANGELOG.txt'", ",", "'CHANGELOG.md'", "]", "as", "$", "name", ")", "{", "$", "file", "=", "$", "prefix", ".", "$", "name", ";", "if", "(", "is_file", "(", "$", "file", ")", ")", "{", "$", "contents", "=", "$", "this", "->", "app", "->", "make", "(", "'helper/file'", ")", "->", "getContents", "(", "$", "file", ")", ";", "return", "nl2br", "(", "h", "(", "$", "contents", ")", ")", ";", "}", "}", "return", "''", ";", "}" ]
Get the contents of the package's CHANGELOG file. @return string if no changelog is available an empty string is returned
[ "Get", "the", "contents", "of", "the", "package", "s", "CHANGELOG", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L604-L616
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.backup
public function backup() { $packageHandle = $this->getPackageHandle(); $errors = $this->app->make('error'); if ($packageHandle === '' || !is_dir(DIR_PACKAGES . '/' . $packageHandle)) { $errors->add($this->getErrorText(self::E_PACKAGE_NOT_FOUND)); } else { $config = $this->app->make('config'); $trash = $config->get('concrete.misc.package_backup_directory'); if (!is_dir($trash)) { @mkdir($trash, $config->get('concrete.filesystem.permissions.directory')); } if (!is_dir($trash)) { $errors->add($this->getErrorText(self::E_PACKAGE_MIGRATE_BACKUP)); } else { $trashName = $trash . '/' . $packageHandle . '_' . date('YmdHis'); if (!@rename(DIR_PACKAGES . '/' . $this->getPackageHandle(), $trashName)) { $errors->add($this->getErrorText(self::E_PACKAGE_MIGRATE_BACKUP)); } else { $this->backedUpFname = $trashName; } } } return $errors->has() ? $errors : $this; }
php
public function backup() { $packageHandle = $this->getPackageHandle(); $errors = $this->app->make('error'); if ($packageHandle === '' || !is_dir(DIR_PACKAGES . '/' . $packageHandle)) { $errors->add($this->getErrorText(self::E_PACKAGE_NOT_FOUND)); } else { $config = $this->app->make('config'); $trash = $config->get('concrete.misc.package_backup_directory'); if (!is_dir($trash)) { @mkdir($trash, $config->get('concrete.filesystem.permissions.directory')); } if (!is_dir($trash)) { $errors->add($this->getErrorText(self::E_PACKAGE_MIGRATE_BACKUP)); } else { $trashName = $trash . '/' . $packageHandle . '_' . date('YmdHis'); if (!@rename(DIR_PACKAGES . '/' . $this->getPackageHandle(), $trashName)) { $errors->add($this->getErrorText(self::E_PACKAGE_MIGRATE_BACKUP)); } else { $this->backedUpFname = $trashName; } } } return $errors->has() ? $errors : $this; }
[ "public", "function", "backup", "(", ")", "{", "$", "packageHandle", "=", "$", "this", "->", "getPackageHandle", "(", ")", ";", "$", "errors", "=", "$", "this", "->", "app", "->", "make", "(", "'error'", ")", ";", "if", "(", "$", "packageHandle", "===", "''", "||", "!", "is_dir", "(", "DIR_PACKAGES", ".", "'/'", ".", "$", "packageHandle", ")", ")", "{", "$", "errors", "->", "add", "(", "$", "this", "->", "getErrorText", "(", "self", "::", "E_PACKAGE_NOT_FOUND", ")", ")", ";", "}", "else", "{", "$", "config", "=", "$", "this", "->", "app", "->", "make", "(", "'config'", ")", ";", "$", "trash", "=", "$", "config", "->", "get", "(", "'concrete.misc.package_backup_directory'", ")", ";", "if", "(", "!", "is_dir", "(", "$", "trash", ")", ")", "{", "@", "mkdir", "(", "$", "trash", ",", "$", "config", "->", "get", "(", "'concrete.filesystem.permissions.directory'", ")", ")", ";", "}", "if", "(", "!", "is_dir", "(", "$", "trash", ")", ")", "{", "$", "errors", "->", "add", "(", "$", "this", "->", "getErrorText", "(", "self", "::", "E_PACKAGE_MIGRATE_BACKUP", ")", ")", ";", "}", "else", "{", "$", "trashName", "=", "$", "trash", ".", "'/'", ".", "$", "packageHandle", ".", "'_'", ".", "date", "(", "'YmdHis'", ")", ";", "if", "(", "!", "@", "rename", "(", "DIR_PACKAGES", ".", "'/'", ".", "$", "this", "->", "getPackageHandle", "(", ")", ",", "$", "trashName", ")", ")", "{", "$", "errors", "->", "add", "(", "$", "this", "->", "getErrorText", "(", "self", "::", "E_PACKAGE_MIGRATE_BACKUP", ")", ")", ";", "}", "else", "{", "$", "this", "->", "backedUpFname", "=", "$", "trashName", ";", "}", "}", "}", "return", "$", "errors", "->", "has", "(", ")", "?", "$", "errors", ":", "$", "this", ";", "}" ]
Move the current package directory to the trash directory, and rename it with the package handle and a date code. @return \Concrete\Core\Error\ErrorList\ErrorList|static return the Package instance if the package has been moved, an ErrorList instance otherwise
[ "Move", "the", "current", "package", "directory", "to", "the", "trash", "directory", "and", "rename", "it", "with", "the", "package", "handle", "and", "a", "date", "code", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L817-L842
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.installDB
public static function installDB($xmlFile) { if (file_exists($xmlFile)) { $app = ApplicationFacade::getFacadeApplication(); $db = $app->make(Connection::class); /* @var Connection $db */ $db->beginTransaction(); $parser = Schema::getSchemaParser(simplexml_load_file($xmlFile)); $parser->setIgnoreExistingTables(false); $toSchema = $parser->parse($db); $fromSchema = $db->getSchemaManager()->createSchema(); $comparator = new SchemaComparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $saveQueries = $schemaDiff->toSaveSql($db->getDatabasePlatform()); foreach ($saveQueries as $query) { $db->query($query); } $db->commit(); $result = new stdClass(); $result->result = false; } else { $result = false; } return $result; }
php
public static function installDB($xmlFile) { if (file_exists($xmlFile)) { $app = ApplicationFacade::getFacadeApplication(); $db = $app->make(Connection::class); /* @var Connection $db */ $db->beginTransaction(); $parser = Schema::getSchemaParser(simplexml_load_file($xmlFile)); $parser->setIgnoreExistingTables(false); $toSchema = $parser->parse($db); $fromSchema = $db->getSchemaManager()->createSchema(); $comparator = new SchemaComparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $saveQueries = $schemaDiff->toSaveSql($db->getDatabasePlatform()); foreach ($saveQueries as $query) { $db->query($query); } $db->commit(); $result = new stdClass(); $result->result = false; } else { $result = false; } return $result; }
[ "public", "static", "function", "installDB", "(", "$", "xmlFile", ")", "{", "if", "(", "file_exists", "(", "$", "xmlFile", ")", ")", "{", "$", "app", "=", "ApplicationFacade", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "/* @var Connection $db */", "$", "db", "->", "beginTransaction", "(", ")", ";", "$", "parser", "=", "Schema", "::", "getSchemaParser", "(", "simplexml_load_file", "(", "$", "xmlFile", ")", ")", ";", "$", "parser", "->", "setIgnoreExistingTables", "(", "false", ")", ";", "$", "toSchema", "=", "$", "parser", "->", "parse", "(", "$", "db", ")", ";", "$", "fromSchema", "=", "$", "db", "->", "getSchemaManager", "(", ")", "->", "createSchema", "(", ")", ";", "$", "comparator", "=", "new", "SchemaComparator", "(", ")", ";", "$", "schemaDiff", "=", "$", "comparator", "->", "compare", "(", "$", "fromSchema", ",", "$", "toSchema", ")", ";", "$", "saveQueries", "=", "$", "schemaDiff", "->", "toSaveSql", "(", "$", "db", "->", "getDatabasePlatform", "(", ")", ")", ";", "foreach", "(", "$", "saveQueries", "as", "$", "query", ")", "{", "$", "db", "->", "query", "(", "$", "query", ")", ";", "}", "$", "db", "->", "commit", "(", ")", ";", "$", "result", "=", "new", "stdClass", "(", ")", ";", "$", "result", "->", "result", "=", "false", ";", "}", "else", "{", "$", "result", "=", "false", ";", "}", "return", "$", "result", ";", "}" ]
Installs a package database from an XML file. @param string $xmlFile Path to the database XML file @throws \Doctrine\DBAL\ConnectionException @return bool|stdClass Returns false if the XML file could not be found
[ "Installs", "a", "package", "database", "from", "an", "XML", "file", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L920-L950
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.upgradeCoreData
public function upgradeCoreData() { $entity = $this->getPackageEntity(); if ($entity !== null) { $em = $this->app->make(EntityManagerInterface::class); $entity->setPackageName($this->getPackageName()); $entity->setPackageDescription($this->getPackageDescription()); $entity->setPackageVersion($this->getPackageVersion()); $em->persist($entity); $em->flush(); } }
php
public function upgradeCoreData() { $entity = $this->getPackageEntity(); if ($entity !== null) { $em = $this->app->make(EntityManagerInterface::class); $entity->setPackageName($this->getPackageName()); $entity->setPackageDescription($this->getPackageDescription()); $entity->setPackageVersion($this->getPackageVersion()); $em->persist($entity); $em->flush(); } }
[ "public", "function", "upgradeCoreData", "(", ")", "{", "$", "entity", "=", "$", "this", "->", "getPackageEntity", "(", ")", ";", "if", "(", "$", "entity", "!==", "null", ")", "{", "$", "em", "=", "$", "this", "->", "app", "->", "make", "(", "EntityManagerInterface", "::", "class", ")", ";", "$", "entity", "->", "setPackageName", "(", "$", "this", "->", "getPackageName", "(", ")", ")", ";", "$", "entity", "->", "setPackageDescription", "(", "$", "this", "->", "getPackageDescription", "(", ")", ")", ";", "$", "entity", "->", "setPackageVersion", "(", "$", "this", "->", "getPackageVersion", "(", ")", ")", ";", "$", "em", "->", "persist", "(", "$", "entity", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "}", "}" ]
Updates the package entity name, description and version using the current class properties.
[ "Updates", "the", "package", "entity", "name", "description", "and", "version", "using", "the", "current", "class", "properties", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L955-L966
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.upgrade
public function upgrade() { $this->upgradeDatabase(); // now we refresh all blocks $manager = new Manager($this->app); $items = $manager->driver('block_type')->getItems($this->getPackageEntity()); foreach ($items as $item) { $item->refresh(); } Localization::clearCache(); }
php
public function upgrade() { $this->upgradeDatabase(); // now we refresh all blocks $manager = new Manager($this->app); $items = $manager->driver('block_type')->getItems($this->getPackageEntity()); foreach ($items as $item) { $item->refresh(); } Localization::clearCache(); }
[ "public", "function", "upgrade", "(", ")", "{", "$", "this", "->", "upgradeDatabase", "(", ")", ";", "// now we refresh all blocks", "$", "manager", "=", "new", "Manager", "(", "$", "this", "->", "app", ")", ";", "$", "items", "=", "$", "manager", "->", "driver", "(", "'block_type'", ")", "->", "getItems", "(", "$", "this", "->", "getPackageEntity", "(", ")", ")", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "$", "item", "->", "refresh", "(", ")", ";", "}", "Localization", "::", "clearCache", "(", ")", ";", "}" ]
Upgrades a package's database and refreshes all blocks.
[ "Upgrades", "a", "package", "s", "database", "and", "refreshes", "all", "blocks", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L971-L983
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.upgradeDatabase
public function upgradeDatabase() { $em = $this->getPackageEntityManager(); if ($em !== null) { $this->destroyProxyClasses($em); $this->installEntitiesDatabase(); } static::installDB($this->getPackagePath() . '/' . FILENAME_PACKAGE_DB); }
php
public function upgradeDatabase() { $em = $this->getPackageEntityManager(); if ($em !== null) { $this->destroyProxyClasses($em); $this->installEntitiesDatabase(); } static::installDB($this->getPackagePath() . '/' . FILENAME_PACKAGE_DB); }
[ "public", "function", "upgradeDatabase", "(", ")", "{", "$", "em", "=", "$", "this", "->", "getPackageEntityManager", "(", ")", ";", "if", "(", "$", "em", "!==", "null", ")", "{", "$", "this", "->", "destroyProxyClasses", "(", "$", "em", ")", ";", "$", "this", "->", "installEntitiesDatabase", "(", ")", ";", "}", "static", "::", "installDB", "(", "$", "this", "->", "getPackagePath", "(", ")", ".", "'/'", ".", "FILENAME_PACKAGE_DB", ")", ";", "}" ]
Updates a package's database using entities and a db.xml. @throws \Doctrine\DBAL\ConnectionException @throws \Exception
[ "Updates", "a", "package", "s", "database", "using", "entities", "and", "a", "db", ".", "xml", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L991-L999
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.getPackageEntityManager
public function getPackageEntityManager() { $providerFactory = new PackageProviderFactory($this->app, $this); $provider = $providerFactory->getEntityManagerProvider(); $drivers = $provider->getDrivers(); if (empty($drivers)) { $result = null; } else { $config = Setup::createConfiguration(true, $this->app->make('config')->get('database.proxy_classes')); $driverImpl = new MappingDriverChain(); $coreDriver = new CoreDriver($this->app); // Add all the installed packages so that the new package could potentially extend packages that are already / installed $packages = $this->app->make(PackageService::class)->getInstalledList(); foreach($packages as $package) { $existingProviderFactory = new PackageProviderFactory($this->app, $package->getController()); $existingProvider = $existingProviderFactory->getEntityManagerProvider(); $existingDrivers = $existingProvider->getDrivers(); if (!empty($existingDrivers)) { foreach($existingDrivers as $existingDriver) { $driverImpl->addDriver($existingDriver->getDriver(), $existingDriver->getNamespace()); } } } // Add the core driver to it so packages can extend the core and not break. $driverImpl->addDriver($coreDriver->getDriver(), $coreDriver->getNamespace()); foreach ($drivers as $driver) { $driverImpl->addDriver($driver->getDriver(), $driver->getNamespace()); } $config->setMetadataDriverImpl($driverImpl); $db = $this->app->make(Connection::class); $result = EntityManager::create($db, $config); } return $result; }
php
public function getPackageEntityManager() { $providerFactory = new PackageProviderFactory($this->app, $this); $provider = $providerFactory->getEntityManagerProvider(); $drivers = $provider->getDrivers(); if (empty($drivers)) { $result = null; } else { $config = Setup::createConfiguration(true, $this->app->make('config')->get('database.proxy_classes')); $driverImpl = new MappingDriverChain(); $coreDriver = new CoreDriver($this->app); // Add all the installed packages so that the new package could potentially extend packages that are already / installed $packages = $this->app->make(PackageService::class)->getInstalledList(); foreach($packages as $package) { $existingProviderFactory = new PackageProviderFactory($this->app, $package->getController()); $existingProvider = $existingProviderFactory->getEntityManagerProvider(); $existingDrivers = $existingProvider->getDrivers(); if (!empty($existingDrivers)) { foreach($existingDrivers as $existingDriver) { $driverImpl->addDriver($existingDriver->getDriver(), $existingDriver->getNamespace()); } } } // Add the core driver to it so packages can extend the core and not break. $driverImpl->addDriver($coreDriver->getDriver(), $coreDriver->getNamespace()); foreach ($drivers as $driver) { $driverImpl->addDriver($driver->getDriver(), $driver->getNamespace()); } $config->setMetadataDriverImpl($driverImpl); $db = $this->app->make(Connection::class); $result = EntityManager::create($db, $config); } return $result; }
[ "public", "function", "getPackageEntityManager", "(", ")", "{", "$", "providerFactory", "=", "new", "PackageProviderFactory", "(", "$", "this", "->", "app", ",", "$", "this", ")", ";", "$", "provider", "=", "$", "providerFactory", "->", "getEntityManagerProvider", "(", ")", ";", "$", "drivers", "=", "$", "provider", "->", "getDrivers", "(", ")", ";", "if", "(", "empty", "(", "$", "drivers", ")", ")", "{", "$", "result", "=", "null", ";", "}", "else", "{", "$", "config", "=", "Setup", "::", "createConfiguration", "(", "true", ",", "$", "this", "->", "app", "->", "make", "(", "'config'", ")", "->", "get", "(", "'database.proxy_classes'", ")", ")", ";", "$", "driverImpl", "=", "new", "MappingDriverChain", "(", ")", ";", "$", "coreDriver", "=", "new", "CoreDriver", "(", "$", "this", "->", "app", ")", ";", "// Add all the installed packages so that the new package could potentially extend packages that are already / installed", "$", "packages", "=", "$", "this", "->", "app", "->", "make", "(", "PackageService", "::", "class", ")", "->", "getInstalledList", "(", ")", ";", "foreach", "(", "$", "packages", "as", "$", "package", ")", "{", "$", "existingProviderFactory", "=", "new", "PackageProviderFactory", "(", "$", "this", "->", "app", ",", "$", "package", "->", "getController", "(", ")", ")", ";", "$", "existingProvider", "=", "$", "existingProviderFactory", "->", "getEntityManagerProvider", "(", ")", ";", "$", "existingDrivers", "=", "$", "existingProvider", "->", "getDrivers", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "existingDrivers", ")", ")", "{", "foreach", "(", "$", "existingDrivers", "as", "$", "existingDriver", ")", "{", "$", "driverImpl", "->", "addDriver", "(", "$", "existingDriver", "->", "getDriver", "(", ")", ",", "$", "existingDriver", "->", "getNamespace", "(", ")", ")", ";", "}", "}", "}", "// Add the core driver to it so packages can extend the core and not break.", "$", "driverImpl", "->", "addDriver", "(", "$", "coreDriver", "->", "getDriver", "(", ")", ",", "$", "coreDriver", "->", "getNamespace", "(", ")", ")", ";", "foreach", "(", "$", "drivers", "as", "$", "driver", ")", "{", "$", "driverImpl", "->", "addDriver", "(", "$", "driver", "->", "getDriver", "(", ")", ",", "$", "driver", "->", "getNamespace", "(", ")", ")", ";", "}", "$", "config", "->", "setMetadataDriverImpl", "(", "$", "driverImpl", ")", ";", "$", "db", "=", "$", "this", "->", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "result", "=", "EntityManager", "::", "create", "(", "$", "db", ",", "$", "config", ")", ";", "}", "return", "$", "result", ";", "}" ]
Create an entity manager used for the package install, upgrade and unistall process. @return EntityManager|null
[ "Create", "an", "entity", "manager", "used", "for", "the", "package", "install", "upgrade", "and", "unistall", "process", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L1020-L1057
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.getErrorText
protected function getErrorText($errorCode) { if (is_array($errorCode)) { $code = array_shift($errorCode); $result = vsprintf($this->getErrorText($code), $errorCode); } else { $config = $this->app->make('config'); $dictionary = [ self::E_PACKAGE_INSTALLED => t("You've already installed that package."), self::E_PACKAGE_NOT_FOUND => t('Invalid Package.'), self::E_PACKAGE_VERSION => t('This package requires concrete5 version %s or greater.'), self::E_PACKAGE_DOWNLOAD => t('An error occurred while downloading the package.'), self::E_PACKAGE_SAVE => t('concrete5 was not able to save the package after download.'), self::E_PACKAGE_UNZIP => t('An error occurred while trying to unzip the package.'), self::E_PACKAGE_INSTALL => t('An error occurred while trying to install the package.'), self::E_PACKAGE_MIGRATE_BACKUP => t('Unable to backup old package directory to %s', $config->get('concrete.misc.package_backup_directory')), self::E_PACKAGE_INVALID_APP_VERSION => t('This package isn\'t currently available for this version of concrete5. Please contact the maintainer of this package for assistance.'), self::E_PACKAGE_THEME_ACTIVE => t('This package contains the active site theme, please change the theme before uninstalling.'), ]; if (isset($dictionary[$errorCode])) { $result = $dictionary[$errorCode]; } else { $result = (string) $errorCode; } } return $result; }
php
protected function getErrorText($errorCode) { if (is_array($errorCode)) { $code = array_shift($errorCode); $result = vsprintf($this->getErrorText($code), $errorCode); } else { $config = $this->app->make('config'); $dictionary = [ self::E_PACKAGE_INSTALLED => t("You've already installed that package."), self::E_PACKAGE_NOT_FOUND => t('Invalid Package.'), self::E_PACKAGE_VERSION => t('This package requires concrete5 version %s or greater.'), self::E_PACKAGE_DOWNLOAD => t('An error occurred while downloading the package.'), self::E_PACKAGE_SAVE => t('concrete5 was not able to save the package after download.'), self::E_PACKAGE_UNZIP => t('An error occurred while trying to unzip the package.'), self::E_PACKAGE_INSTALL => t('An error occurred while trying to install the package.'), self::E_PACKAGE_MIGRATE_BACKUP => t('Unable to backup old package directory to %s', $config->get('concrete.misc.package_backup_directory')), self::E_PACKAGE_INVALID_APP_VERSION => t('This package isn\'t currently available for this version of concrete5. Please contact the maintainer of this package for assistance.'), self::E_PACKAGE_THEME_ACTIVE => t('This package contains the active site theme, please change the theme before uninstalling.'), ]; if (isset($dictionary[$errorCode])) { $result = $dictionary[$errorCode]; } else { $result = (string) $errorCode; } } return $result; }
[ "protected", "function", "getErrorText", "(", "$", "errorCode", ")", "{", "if", "(", "is_array", "(", "$", "errorCode", ")", ")", "{", "$", "code", "=", "array_shift", "(", "$", "errorCode", ")", ";", "$", "result", "=", "vsprintf", "(", "$", "this", "->", "getErrorText", "(", "$", "code", ")", ",", "$", "errorCode", ")", ";", "}", "else", "{", "$", "config", "=", "$", "this", "->", "app", "->", "make", "(", "'config'", ")", ";", "$", "dictionary", "=", "[", "self", "::", "E_PACKAGE_INSTALLED", "=>", "t", "(", "\"You've already installed that package.\"", ")", ",", "self", "::", "E_PACKAGE_NOT_FOUND", "=>", "t", "(", "'Invalid Package.'", ")", ",", "self", "::", "E_PACKAGE_VERSION", "=>", "t", "(", "'This package requires concrete5 version %s or greater.'", ")", ",", "self", "::", "E_PACKAGE_DOWNLOAD", "=>", "t", "(", "'An error occurred while downloading the package.'", ")", ",", "self", "::", "E_PACKAGE_SAVE", "=>", "t", "(", "'concrete5 was not able to save the package after download.'", ")", ",", "self", "::", "E_PACKAGE_UNZIP", "=>", "t", "(", "'An error occurred while trying to unzip the package.'", ")", ",", "self", "::", "E_PACKAGE_INSTALL", "=>", "t", "(", "'An error occurred while trying to install the package.'", ")", ",", "self", "::", "E_PACKAGE_MIGRATE_BACKUP", "=>", "t", "(", "'Unable to backup old package directory to %s'", ",", "$", "config", "->", "get", "(", "'concrete.misc.package_backup_directory'", ")", ")", ",", "self", "::", "E_PACKAGE_INVALID_APP_VERSION", "=>", "t", "(", "'This package isn\\'t currently available for this version of concrete5. Please contact the maintainer of this package for assistance.'", ")", ",", "self", "::", "E_PACKAGE_THEME_ACTIVE", "=>", "t", "(", "'This package contains the active site theme, please change the theme before uninstalling.'", ")", ",", "]", ";", "if", "(", "isset", "(", "$", "dictionary", "[", "$", "errorCode", "]", ")", ")", "{", "$", "result", "=", "$", "dictionary", "[", "$", "errorCode", "]", ";", "}", "else", "{", "$", "result", "=", "(", "string", ")", "$", "errorCode", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get the error text corresponsing to an error code. @param array|int $errorCode one of the Package::E_PACKAGE_ constants, or an array with the first value is one of the Package::E_PACKAGE_ constants and the other values are used to fill in fields @return string
[ "Get", "the", "error", "text", "corresponsing", "to", "an", "error", "code", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L1126-L1153
train
concrete5/concrete5
concrete/src/Package/Package.php
Package.destroyProxyClasses
protected function destroyProxyClasses(EntityManagerInterface $em) { $config = $em->getConfiguration(); $proxyGenerator = new ProxyGenerator($config->getProxyDir(), $config->getProxyNamespace()); $classes = $em->getMetadataFactory()->getAllMetadata(); foreach ($classes as $class) { // We have to do this check because we include core entities in this list because without it packages that extend // the core will complain. if (strpos($class->getName(), 'Concrete\Core\Entity') === 0) { continue; } $proxyFileName = $proxyGenerator->getProxyFileName($class->getName(), $config->getProxyDir()); if (file_exists($proxyFileName)) { @unlink($proxyFileName); } } }
php
protected function destroyProxyClasses(EntityManagerInterface $em) { $config = $em->getConfiguration(); $proxyGenerator = new ProxyGenerator($config->getProxyDir(), $config->getProxyNamespace()); $classes = $em->getMetadataFactory()->getAllMetadata(); foreach ($classes as $class) { // We have to do this check because we include core entities in this list because without it packages that extend // the core will complain. if (strpos($class->getName(), 'Concrete\Core\Entity') === 0) { continue; } $proxyFileName = $proxyGenerator->getProxyFileName($class->getName(), $config->getProxyDir()); if (file_exists($proxyFileName)) { @unlink($proxyFileName); } } }
[ "protected", "function", "destroyProxyClasses", "(", "EntityManagerInterface", "$", "em", ")", "{", "$", "config", "=", "$", "em", "->", "getConfiguration", "(", ")", ";", "$", "proxyGenerator", "=", "new", "ProxyGenerator", "(", "$", "config", "->", "getProxyDir", "(", ")", ",", "$", "config", "->", "getProxyNamespace", "(", ")", ")", ";", "$", "classes", "=", "$", "em", "->", "getMetadataFactory", "(", ")", "->", "getAllMetadata", "(", ")", ";", "foreach", "(", "$", "classes", "as", "$", "class", ")", "{", "// We have to do this check because we include core entities in this list because without it packages that extend", "// the core will complain.", "if", "(", "strpos", "(", "$", "class", "->", "getName", "(", ")", ",", "'Concrete\\Core\\Entity'", ")", "===", "0", ")", "{", "continue", ";", "}", "$", "proxyFileName", "=", "$", "proxyGenerator", "->", "getProxyFileName", "(", "$", "class", "->", "getName", "(", ")", ",", "$", "config", "->", "getProxyDir", "(", ")", ")", ";", "if", "(", "file_exists", "(", "$", "proxyFileName", ")", ")", "{", "@", "unlink", "(", "$", "proxyFileName", ")", ";", "}", "}", "}" ]
Destroys all proxies related to a package. @param EntityManagerInterface $em
[ "Destroys", "all", "proxies", "related", "to", "a", "package", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/Package.php#L1160-L1177
train
concrete5/concrete5
concrete/src/Attribute/Category/CategoryService.php
CategoryService.getByHandle
public function getByHandle($akCategoryHandle) { $r = $this->entityManager->getRepository(Category::class); return $r->findOneBy(['akCategoryHandle' => $akCategoryHandle]); }
php
public function getByHandle($akCategoryHandle) { $r = $this->entityManager->getRepository(Category::class); return $r->findOneBy(['akCategoryHandle' => $akCategoryHandle]); }
[ "public", "function", "getByHandle", "(", "$", "akCategoryHandle", ")", "{", "$", "r", "=", "$", "this", "->", "entityManager", "->", "getRepository", "(", "Category", "::", "class", ")", ";", "return", "$", "r", "->", "findOneBy", "(", "[", "'akCategoryHandle'", "=>", "$", "akCategoryHandle", "]", ")", ";", "}" ]
Get a attribute category given its handle. @param string $akCategoryHandle @return Category|null
[ "Get", "a", "attribute", "category", "given", "its", "handle", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Attribute/Category/CategoryService.php#L28-L33
train
concrete5/concrete5
concrete/src/Attribute/Category/CategoryService.php
CategoryService.getByID
public function getByID($akCategoryID) { $r = $this->entityManager->getRepository(Category::class); return $r->findOneBy(['akCategoryID' => $akCategoryID]); }
php
public function getByID($akCategoryID) { $r = $this->entityManager->getRepository(Category::class); return $r->findOneBy(['akCategoryID' => $akCategoryID]); }
[ "public", "function", "getByID", "(", "$", "akCategoryID", ")", "{", "$", "r", "=", "$", "this", "->", "entityManager", "->", "getRepository", "(", "Category", "::", "class", ")", ";", "return", "$", "r", "->", "findOneBy", "(", "[", "'akCategoryID'", "=>", "$", "akCategoryID", "]", ")", ";", "}" ]
Get a attribute category given its ID. @param int $akCategoryID @return Category|null
[ "Get", "a", "attribute", "category", "given", "its", "ID", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Attribute/Category/CategoryService.php#L42-L47
train
concrete5/concrete5
concrete/src/Attribute/Category/CategoryService.php
CategoryService.getListByPackage
public function getListByPackage(Package $pkg) { $r = $this->entityManager->getRepository(Category::class); return $r->findByPackage($pkg); }
php
public function getListByPackage(Package $pkg) { $r = $this->entityManager->getRepository(Category::class); return $r->findByPackage($pkg); }
[ "public", "function", "getListByPackage", "(", "Package", "$", "pkg", ")", "{", "$", "r", "=", "$", "this", "->", "entityManager", "->", "getRepository", "(", "Category", "::", "class", ")", ";", "return", "$", "r", "->", "findByPackage", "(", "$", "pkg", ")", ";", "}" ]
Get all the available attribute categories created by a package. @param Package $pkg @return Category[]
[ "Get", "all", "the", "available", "attribute", "categories", "created", "by", "a", "package", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Attribute/Category/CategoryService.php#L68-L73
train
concrete5/concrete5
concrete/src/Attribute/Category/CategoryService.php
CategoryService.add
public function add($akCategoryHandle, $allowSets = StandardSetManager::ASET_ALLOW_SINGLE, $pkg = null) { $category = new Category(); $category->setAttributeKeyCategoryHandle($akCategoryHandle); $category->setAllowAttributeSets($allowSets); if ($pkg) { $category->setPackage($pkg); } $this->entityManager->persist($category); $this->entityManager->flush(); $indexer = $category->getController()->getSearchIndexer(); if (is_object($indexer)) { $indexer->createRepository($category->getController()); } return $category->getController(); }
php
public function add($akCategoryHandle, $allowSets = StandardSetManager::ASET_ALLOW_SINGLE, $pkg = null) { $category = new Category(); $category->setAttributeKeyCategoryHandle($akCategoryHandle); $category->setAllowAttributeSets($allowSets); if ($pkg) { $category->setPackage($pkg); } $this->entityManager->persist($category); $this->entityManager->flush(); $indexer = $category->getController()->getSearchIndexer(); if (is_object($indexer)) { $indexer->createRepository($category->getController()); } return $category->getController(); }
[ "public", "function", "add", "(", "$", "akCategoryHandle", ",", "$", "allowSets", "=", "StandardSetManager", "::", "ASET_ALLOW_SINGLE", ",", "$", "pkg", "=", "null", ")", "{", "$", "category", "=", "new", "Category", "(", ")", ";", "$", "category", "->", "setAttributeKeyCategoryHandle", "(", "$", "akCategoryHandle", ")", ";", "$", "category", "->", "setAllowAttributeSets", "(", "$", "allowSets", ")", ";", "if", "(", "$", "pkg", ")", "{", "$", "category", "->", "setPackage", "(", "$", "pkg", ")", ";", "}", "$", "this", "->", "entityManager", "->", "persist", "(", "$", "category", ")", ";", "$", "this", "->", "entityManager", "->", "flush", "(", ")", ";", "$", "indexer", "=", "$", "category", "->", "getController", "(", ")", "->", "getSearchIndexer", "(", ")", ";", "if", "(", "is_object", "(", "$", "indexer", ")", ")", "{", "$", "indexer", "->", "createRepository", "(", "$", "category", "->", "getController", "(", ")", ")", ";", "}", "return", "$", "category", "->", "getController", "(", ")", ";", "}" ]
Create a new attribute category. @param string $akCategoryHandle the category handle @param int $allowSets One of the StandardSetManager::ASET_ALLOW_... constants @param Package|null $pkg the package that is creating this category @return CategoryInterface
[ "Create", "a", "new", "attribute", "category", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Attribute/Category/CategoryService.php#L84-L101
train
concrete5/concrete5
concrete/src/Block/BlockType/Set.php
Set.getByID
public static function getByID($btsID) { $result = null; $btsID = (int) $btsID; if ($btsID !== 0) { $app = Application::getFacadeApplication(); $cache = $app->make('cache/request'); $identifier = sprintf('block/type/set/%s', $btsID); $item = $cache->getItem($identifier); if ($item->isMiss()) { $item->lock(); $db = $app->make(Connection::class); $row = $db->fetchAssoc('select btsID, btsHandle, pkgID, btsName from BlockTypeSets where btsID = ?', [$btsID]); if ($row !== false) { $result = new static(); $result->setPropertiesFromArray($row); } $item->set($result)->save(); } else { $result = $item->get(); } } return $result; }
php
public static function getByID($btsID) { $result = null; $btsID = (int) $btsID; if ($btsID !== 0) { $app = Application::getFacadeApplication(); $cache = $app->make('cache/request'); $identifier = sprintf('block/type/set/%s', $btsID); $item = $cache->getItem($identifier); if ($item->isMiss()) { $item->lock(); $db = $app->make(Connection::class); $row = $db->fetchAssoc('select btsID, btsHandle, pkgID, btsName from BlockTypeSets where btsID = ?', [$btsID]); if ($row !== false) { $result = new static(); $result->setPropertiesFromArray($row); } $item->set($result)->save(); } else { $result = $item->get(); } } return $result; }
[ "public", "static", "function", "getByID", "(", "$", "btsID", ")", "{", "$", "result", "=", "null", ";", "$", "btsID", "=", "(", "int", ")", "$", "btsID", ";", "if", "(", "$", "btsID", "!==", "0", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "cache", "=", "$", "app", "->", "make", "(", "'cache/request'", ")", ";", "$", "identifier", "=", "sprintf", "(", "'block/type/set/%s'", ",", "$", "btsID", ")", ";", "$", "item", "=", "$", "cache", "->", "getItem", "(", "$", "identifier", ")", ";", "if", "(", "$", "item", "->", "isMiss", "(", ")", ")", "{", "$", "item", "->", "lock", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "row", "=", "$", "db", "->", "fetchAssoc", "(", "'select btsID, btsHandle, pkgID, btsName from BlockTypeSets where btsID = ?'", ",", "[", "$", "btsID", "]", ")", ";", "if", "(", "$", "row", "!==", "false", ")", "{", "$", "result", "=", "new", "static", "(", ")", ";", "$", "result", "->", "setPropertiesFromArray", "(", "$", "row", ")", ";", "}", "$", "item", "->", "set", "(", "$", "result", ")", "->", "save", "(", ")", ";", "}", "else", "{", "$", "result", "=", "$", "item", "->", "get", "(", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get a block type set given its ID. @param int $btsID @return static|null
[ "Get", "a", "block", "type", "set", "given", "its", "ID", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockType/Set.php#L20-L44
train
concrete5/concrete5
concrete/src/Block/BlockType/Set.php
Set.getByHandle
public static function getByHandle($btsHandle) { $result = null; $btsHandle = (string) $btsHandle; if ($btsHandle !== '') { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $row = $db->fetchAssoc('select btsID, btsHandle, pkgID, btsName from BlockTypeSets where btsHandle = ?', [$btsHandle]); if ($row !== false) { $result = new static(); $result->setPropertiesFromArray($row); } } return $result; }
php
public static function getByHandle($btsHandle) { $result = null; $btsHandle = (string) $btsHandle; if ($btsHandle !== '') { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $row = $db->fetchAssoc('select btsID, btsHandle, pkgID, btsName from BlockTypeSets where btsHandle = ?', [$btsHandle]); if ($row !== false) { $result = new static(); $result->setPropertiesFromArray($row); } } return $result; }
[ "public", "static", "function", "getByHandle", "(", "$", "btsHandle", ")", "{", "$", "result", "=", "null", ";", "$", "btsHandle", "=", "(", "string", ")", "$", "btsHandle", ";", "if", "(", "$", "btsHandle", "!==", "''", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "row", "=", "$", "db", "->", "fetchAssoc", "(", "'select btsID, btsHandle, pkgID, btsName from BlockTypeSets where btsHandle = ?'", ",", "[", "$", "btsHandle", "]", ")", ";", "if", "(", "$", "row", "!==", "false", ")", "{", "$", "result", "=", "new", "static", "(", ")", ";", "$", "result", "->", "setPropertiesFromArray", "(", "$", "row", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get a block type set given its handle. @param string $btsHandle @return static|null
[ "Get", "a", "block", "type", "set", "given", "its", "handle", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockType/Set.php#L53-L68
train
concrete5/concrete5
concrete/src/Block/BlockType/Set.php
Set.getListByPackage
public static function getListByPackage($pkg) { $result = []; $pkgID = (int) (is_object($pkg) ? $pkg->getPackageID() : $pkg); if ($pkgID !== 0) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $rs = $db->executeQuery('select btsID from BlockTypeSets where pkgID = ? order by btsID asc', [$pkgID]); while (($btsID = $rs->fetchColumn()) !== false) { $result[] = static::getByID($btsID); } } return $result; }
php
public static function getListByPackage($pkg) { $result = []; $pkgID = (int) (is_object($pkg) ? $pkg->getPackageID() : $pkg); if ($pkgID !== 0) { $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); $rs = $db->executeQuery('select btsID from BlockTypeSets where pkgID = ? order by btsID asc', [$pkgID]); while (($btsID = $rs->fetchColumn()) !== false) { $result[] = static::getByID($btsID); } } return $result; }
[ "public", "static", "function", "getListByPackage", "(", "$", "pkg", ")", "{", "$", "result", "=", "[", "]", ";", "$", "pkgID", "=", "(", "int", ")", "(", "is_object", "(", "$", "pkg", ")", "?", "$", "pkg", "->", "getPackageID", "(", ")", ":", "$", "pkg", ")", ";", "if", "(", "$", "pkgID", "!==", "0", ")", "{", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "$", "rs", "=", "$", "db", "->", "executeQuery", "(", "'select btsID from BlockTypeSets where pkgID = ? order by btsID asc'", ",", "[", "$", "pkgID", "]", ")", ";", "while", "(", "(", "$", "btsID", "=", "$", "rs", "->", "fetchColumn", "(", ")", ")", "!==", "false", ")", "{", "$", "result", "[", "]", "=", "static", "::", "getByID", "(", "$", "btsID", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Get the list of block type sets defined by a package. @param \Concrete\Core\Entity\Package|\Concrete\Core\Package\Package|int $pkg @return static[]
[ "Get", "the", "list", "of", "block", "type", "sets", "defined", "by", "a", "package", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockType/Set.php#L77-L91
train
concrete5/concrete5
concrete/src/Block/BlockType/Set.php
Set.getList
public static function getList($excluded = ['core_desktop']) { $result = []; $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); if (empty($excluded)) { $rs = $db->executeQuery('select btsID from BlockTypeSets order by btsDisplayOrder asc'); } else { $rs = $db->executeQuery('select btsID from BlockTypeSets where btsHandle not in (?) order by btsDisplayOrder asc', [$excluded], [Connection::PARAM_STR_ARRAY] ); } while (($btsID = $rs->fetchColumn()) !== false) { $result[] = static::getByID($btsID); } return $result; }
php
public static function getList($excluded = ['core_desktop']) { $result = []; $app = Application::getFacadeApplication(); $db = $app->make(Connection::class); if (empty($excluded)) { $rs = $db->executeQuery('select btsID from BlockTypeSets order by btsDisplayOrder asc'); } else { $rs = $db->executeQuery('select btsID from BlockTypeSets where btsHandle not in (?) order by btsDisplayOrder asc', [$excluded], [Connection::PARAM_STR_ARRAY] ); } while (($btsID = $rs->fetchColumn()) !== false) { $result[] = static::getByID($btsID); } return $result; }
[ "public", "static", "function", "getList", "(", "$", "excluded", "=", "[", "'core_desktop'", "]", ")", "{", "$", "result", "=", "[", "]", ";", "$", "app", "=", "Application", "::", "getFacadeApplication", "(", ")", ";", "$", "db", "=", "$", "app", "->", "make", "(", "Connection", "::", "class", ")", ";", "if", "(", "empty", "(", "$", "excluded", ")", ")", "{", "$", "rs", "=", "$", "db", "->", "executeQuery", "(", "'select btsID from BlockTypeSets order by btsDisplayOrder asc'", ")", ";", "}", "else", "{", "$", "rs", "=", "$", "db", "->", "executeQuery", "(", "'select btsID from BlockTypeSets where btsHandle not in (?) order by btsDisplayOrder asc'", ",", "[", "$", "excluded", "]", ",", "[", "Connection", "::", "PARAM_STR_ARRAY", "]", ")", ";", "}", "while", "(", "(", "$", "btsID", "=", "$", "rs", "->", "fetchColumn", "(", ")", ")", "!==", "false", ")", "{", "$", "result", "[", "]", "=", "static", "::", "getByID", "(", "$", "btsID", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get the list of block type sets. @param string[] $excluded a list of block type set handles to be exluded @return static[]
[ "Get", "the", "list", "of", "block", "type", "sets", "." ]
c54c94e4eb6d45696fed85a5b8b415f70ea677b8
https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Block/BlockType/Set.php#L100-L118
train