本文整理汇总了PHP中StringHelper::toLowerCase方法的典型用法代码示例。如果您正苦于以下问题:PHP StringHelper::toLowerCase方法的具体用法?PHP StringHelper::toLowerCase怎么用?PHP StringHelper::toLowerCase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringHelper
的用法示例。
在下文中一共展示了StringHelper::toLowerCase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
/**
* Initializes the console app by creating the command runner.
*
* @return null
*/
public function init()
{
// Set default timezone to UTC
date_default_timezone_set('UTC');
// Import all the built-in components
foreach ($this->componentAliases as $alias) {
Craft::import($alias);
}
// Attach our Craft app behavior.
$this->attachBehavior('AppBehavior', new AppBehavior());
// Initialize Cache and LogRouter right away (order is important)
$this->getComponent('cache');
$this->getComponent('log');
// So we can try to translate Yii framework strings
$this->coreMessages->attachEventHandler('onMissingTranslation', array('Craft\\LocalizationHelper', 'findMissingTranslation'));
// Set our own custom runtime path.
$this->setRuntimePath(craft()->path->getRuntimePath());
// Attach our own custom Logger
Craft::setLogger(new Logger());
// No need for these.
craft()->log->removeRoute('WebLogRoute');
craft()->log->removeRoute('ProfileLogRoute');
// Load the plugins
craft()->plugins->loadPlugins();
// Validate some basics on the database configuration file.
craft()->validateDbConfigFile();
// Call parent::init before the plugin console command logic so craft()->commandRunner will be available to us.
parent::init();
foreach (craft()->plugins->getPlugins() as $plugin) {
$commandsPath = craft()->path->getPluginsPath() . StringHelper::toLowerCase($plugin->getClassHandle()) . '/consolecommands/';
if (IOHelper::folderExists($commandsPath)) {
craft()->commandRunner->addCommands(rtrim($commandsPath, '/'));
}
}
}
示例2: _makeHandle
/**
* Make handle from source name.
*
* @param $name
*
* @return string
*/
private function _makeHandle($name, $sourceId)
{
// Remove HTML tags
$handle = preg_replace('/<(.*?)>/', '', $name);
$handle = preg_replace('/<[\'"‘’“”\\[\\]\\(\\)\\{\\}:]>/', '', $handle);
$handle = StringHelper::toLowerCase($handle);
$handle = StringHelper::asciiString($handle);
$handle = preg_replace('/^[^a-z]+/', '', $handle);
// In case it was an all non-ASCII handle, have a default.
if (!$handle) {
$handle = 'source' . $sourceId;
}
$handleParts = preg_split('/[^a-z0-9]+/', $handle);
$handle = '';
foreach ($handleParts as $index => &$part) {
if ($index) {
$part = ucfirst($part);
}
$handle .= $part;
}
$appendix = '';
while (true) {
$taken = craft()->db->createCommand()->select('handle')->from('assetsources')->where('handle = :handle', array(':handle' => $handle . $appendix))->queryScalar();
if ($taken) {
$appendix = (int) $appendix + 1;
} else {
break;
}
}
return $handle . $appendix;
}
示例3: counter
public function counter($requestData)
{
$period = isset($requestData['period']) ? $requestData['period'] : null;
$dimension = isset($requestData['options']['dimension']) ? $requestData['options']['dimension'] : null;
$metric = isset($requestData['options']['metric']) ? $requestData['options']['metric'] : null;
$start = date('Y-m-d', strtotime('-1 ' . $period));
$end = date('Y-m-d');
// Counter
$criteria = new Analytics_RequestCriteriaModel();
$criteria->startDate = $start;
$criteria->endDate = $end;
$criteria->metrics = $metric;
if ($dimension) {
$optParams = array('filters' => $dimension . '!=(not set);' . $dimension . '!=(not provided)');
$criteria->optParams = $optParams;
}
$response = craft()->analytics->sendRequest($criteria);
if (!empty($response['rows'][0][0]['f'])) {
$count = $response['rows'][0][0]['f'];
} else {
$count = 0;
}
$counter = array('count' => $count, 'label' => StringHelper::toLowerCase(Craft::t(craft()->analytics_metadata->getDimMet($metric))));
// Return JSON
return ['type' => 'counter', 'counter' => $counter, 'response' => $response, 'metric' => Craft::t(craft()->analytics_metadata->getDimMet($metric)), 'period' => $period, 'periodLabel' => Craft::t('this ' . $period)];
}
示例4: processLogs
/**
* Saves log messages in files.
*
* @param array $logs The list of log messages
*
* @return null
*/
protected function processLogs($logs)
{
$types = array();
foreach ($logs as $log) {
$message = LoggingHelper::redact($log[0]);
$level = $log[1];
$category = $log[2];
$time = $log[3];
$force = isset($log[4]) && $log[4] == true ? true : false;
$plugin = isset($log[5]) ? StringHelper::toLowerCase($log[5]) : 'craft';
if (isset($types[$plugin])) {
$types[$plugin] .= $this->formatLogMessageWithForce($message, $level, $category, $time, $force, $plugin);
} else {
$types[$plugin] = $this->formatLogMessageWithForce($message, $level, $category, $time, $force, $plugin);
}
}
foreach ($types as $plugin => $text) {
$text .= PHP_EOL . '******************************************************************************************************' . PHP_EOL;
$this->setLogFile($plugin . '.log');
$logFile = IOHelper::normalizePathSeparators($this->getLogPath() . '/' . $this->getLogFile());
// Check the config setting first. Is it set to true?
if (craft()->config->get('useWriteFileLock') === true) {
$lock = true;
} else {
if (craft()->config->get('useWriteFileLock') === false) {
$lock = false;
} else {
if (craft()->cache->get('useWriteFileLock') === 'yes') {
$lock = true;
} else {
$lock = false;
}
}
}
$fp = @fopen($logFile, 'a');
if ($lock) {
@flock($fp, LOCK_EX);
}
if (IOHelper::getFileSize($logFile) > $this->getMaxFileSize() * 1024) {
$this->rotateFiles();
if ($lock) {
@flock($fp, LOCK_UN);
}
@fclose($fp);
if ($lock) {
IOHelper::writeToFile($logFile, $text, false, true, false);
} else {
IOHelper::writeToFile($logFile, $text, false, true, true);
}
} else {
@fwrite($fp, $text);
if ($lock) {
@flock($fp, LOCK_UN);
}
@fclose($fp);
}
}
}
示例5: isValidName
/**
* Checks to see if the given name is valid in the enum.
*
* @param $name The name to search for.
* @param bool $strict Defaults to false. If set to true, will do a case sensitive search for the name.
*
* @return bool true if it is a valid name, false otherwise.
*/
public static function isValidName($name, $strict = false)
{
$constants = static::_getConstants();
if ($strict) {
return array_key_exists($name, $constants);
}
$keys = array_map(array('Craft\\StringHelper', 'toLowerCase'), array_keys($constants));
return in_array(StringHelper::toLowerCase($name), $keys);
}
示例6: log
/**
* A wrapper for writing to the log files for plugins that will ultimately call {@link Craft::log()}. This allows
* plugins to be able to write to their own log files at `craft/storage/runtime/logs/pluginHandle.log` using
* `PluginHandle::log()` syntax.
*
* @param $msg The message to be logged.
* @param string $level The level of the message (e.g. LogLevel::Trace', LogLevel::Info, LogLevel::Warning or
* LogLevel::Error).
* @param bool $force Whether to force the message to be logged regardless of the level or category.
*
* @return mixed
*/
public static function log($msg, $level = LogLevel::Info, $force = false)
{
$plugin = get_called_class();
// Chunk off any namespaces
$parts = explode('\\', $plugin);
if (count($parts) > 0) {
$plugin = $parts[count($parts) - 1];
}
// Remove the trailing 'Plugin'.
$plugin = str_replace('Plugin', '', $plugin);
Craft::log($msg, $level, $force, 'plugin', StringHelper::toLowerCase($plugin));
}
示例7: __get
/**
* @param string $name
*
* @return mixed
*/
public function __get($name)
{
$plugin = craft()->plugins->getPlugin($name);
if ($plugin && $plugin->isEnabled) {
$pluginName = $plugin->getClassHandle();
$className = __NAMESPACE__ . '\\' . $pluginName . 'Variable';
// Variables should already be imported by the plugin service, but let's double check.
if (!class_exists($className)) {
Craft::import('plugins.' . StringHelper::toLowerCase($pluginName) . '.variables.' . $pluginName . 'Variable');
}
return new $className();
}
}
示例8: removeRoute
/**
* Removes a route from the LogRouter by class name.
*
* @param $class
*
* @return null
*/
public function removeRoute($class)
{
$match = false;
for ($counter = 0; $counter < sizeof($this->_routes); $counter++) {
if (StringHelper::toLowerCase(get_class($this->_routes[$counter])) == StringHelper::toLowerCase(__NAMESPACE__ . '\\' . $class)) {
$match = $counter;
break;
}
}
if (is_numeric($match)) {
array_splice($this->_routes, $match, 1);
}
}
示例9: nav
/**
* Get the sections of the CP.
*
* @return array
*/
public function nav()
{
$nav['dashboard'] = array('label' => Craft::t('Dashboard'));
if (craft()->sections->getTotalEditableSections()) {
$nav['entries'] = array('label' => Craft::t('Entries'));
}
$globals = craft()->globals->getEditableSets();
if ($globals) {
$nav['globals'] = array('label' => Craft::t('Globals'), 'url' => 'globals/' . $globals[0]->handle);
}
if (craft()->categories->getEditableGroupIds()) {
$nav['categories'] = array('label' => Craft::t('Categories'));
}
if (craft()->assetSources->getTotalViewableSources()) {
$nav['assets'] = array('label' => Craft::t('Assets'));
}
if (craft()->getEdition() == Craft::Pro && craft()->userSession->checkPermission('editUsers')) {
$nav['users'] = array('label' => Craft::t('Users'));
}
// Add any Plugin nav items
$plugins = craft()->plugins->getPlugins();
foreach ($plugins as $plugin) {
if ($plugin->hasCpSection()) {
if (craft()->userSession->checkPermission('accessPlugin-' . $plugin->getClassHandle())) {
$lcHandle = StringHelper::toLowerCase($plugin->getClassHandle());
$nav[$lcHandle] = array('label' => $plugin->getName());
}
}
}
// Allow plugins to modify the nav
craft()->plugins->call('modifyCpNav', array(&$nav));
// Figure out which item is selected, and normalize the items
$firstSegment = craft()->request->getSegment(1);
if ($firstSegment == 'myaccount') {
$firstSegment = 'users';
}
foreach ($nav as $handle => &$item) {
if (is_string($item)) {
$item = array('label' => $item);
}
$item['sel'] = $handle == $firstSegment;
if (isset($item['url'])) {
$item['url'] = UrlHelper::getUrl($item['url']);
} else {
$item['url'] = UrlHelper::getUrl($handle);
}
}
return $nav;
}
示例10: createSlug
/**
* Creates a slug based on a given string.
*
* @param string $str
*
* @return string
*/
public static function createSlug($str)
{
// Remove HTML tags
$slug = preg_replace('/<(.*?)>/u', '', $str);
// Remove inner-word punctuation.
$slug = preg_replace('/[\'"‘’“”\\[\\]\\(\\)\\{\\}:]/u', '', $slug);
if (craft()->config->get('allowUppercaseInSlug') === false) {
// Make it lowercase
$slug = StringHelper::toLowerCase($slug);
}
// Get the "words". Split on anything that is not alphanumeric, or a period, underscore, or hyphen.
preg_match_all('/[\\p{L}\\p{N}\\._-]+/u', $slug, $words);
$words = ArrayHelper::filterEmptyStringsFromArray($words[0]);
$slug = implode(craft()->config->get('slugWordSeparator'), $words);
return $slug;
}
示例11: __get
/**
* @param string $name
*
* @return mixed
*/
public function __get($name)
{
$plugin = craft()->plugins->getPlugin($name);
if ($plugin && $plugin->isEnabled) {
$pluginName = $plugin->getClassHandle();
$className = __NAMESPACE__ . '\\' . $pluginName . 'Variable';
// Variables should already be imported by the plugin service, but let's double check.
if (!class_exists($className)) {
Craft::import('plugins.' . StringHelper::toLowerCase($pluginName) . '.variables.' . $pluginName . 'Variable');
}
// If we haven't done this one yet, create it and save it for later.
if (!isset($this->_pluginVariableInstances[$className])) {
$this->_pluginVariableInstances[$className] = new $className();
}
return $this->_pluginVariableInstances[$className];
}
}
示例12: backupAllForms
/**
* Backup All Forms
*/
public function backupAllForms()
{
$forms = FormBuilder2_FormRecord::model()->ordered()->findAll();
$table = 'craft_formbuilder2_forms';
if ($forms) {
$this->_currentVersion = 'v' . craft()->getVersion() . '.' . craft()->getBuild();
$siteName = IOHelper::cleanFilename(StringHelper::asciiString(craft()->getSiteName()));
$fileName = ($siteName ? $siteName . '_' : '') . gmdate('ymd_His') . '_' . $this->_currentVersion . '.sql';
$this->_filePath = craft()->path->getDbBackupPath() . StringHelper::toLowerCase($fileName);
$this->_processHeader();
$results = $this->_processResult($table);
$this->_processConstraints();
$this->_processFooter();
$filepath = $this->_filePath;
$this->_processFile($fileName, $filepath);
} else {
return false;
}
}
示例13: run
/**
* Triggers the database backup including all DML and DDL and writes it out to a file.
*
* @return string The path to the database backup file.
*/
public function run()
{
// Normalize the ignored table names if there is a table prefix set.
if (($tablePrefix = craft()->config->get('tablePrefix', ConfigFile::Db)) !== '') {
foreach ($this->_ignoreDataTables as $key => $tableName) {
$this->_ignoreDataTables[$key] = $tablePrefix . '_' . $tableName;
}
}
$this->_currentVersion = 'v' . craft()->getVersion() . '.' . craft()->getBuild();
$fileName = IOHelper::cleanFilename(craft()->getSiteName()) . '_' . gmdate('ymd_His') . '_' . $this->_currentVersion . '.sql';
$this->_filePath = craft()->path->getDbBackupPath() . StringHelper::toLowerCase($fileName);
$this->_processHeader();
foreach (craft()->db->getSchema()->getTables() as $resultName => $val) {
$this->_processResult($resultName);
}
$this->_processConstraints();
$this->_processFooter();
return $this->_filePath;
}
示例14: validateAttribute
/**
* @param $object
* @param $attribute
*
* @return null
*/
protected function validateAttribute($object, $attribute)
{
$handle = $object->{$attribute};
// Handles are always required, so if it's blank, the required validator will catch this.
if ($handle) {
$reservedWords = array_merge($this->reservedWords, static::$baseReservedWords);
$reservedWords = array_map(array('Craft\\StringHelper', 'toLowerCase'), $reservedWords);
$lcHandle = StringHelper::toLowerCase($handle);
if (in_array($lcHandle, $reservedWords)) {
$message = Craft::t('“{handle}” is a reserved word.', array('handle' => $handle));
$this->addError($object, $attribute, $message);
} else {
if (!preg_match('/^' . static::$handlePattern . '$/', $handle)) {
$altMessage = Craft::t('“{handle}” isn’t a valid handle.', array('handle' => $handle));
$message = $this->message !== null ? $this->message : $altMessage;
$this->addError($object, $attribute, $message);
}
}
}
}
示例15: createCommand
/**
* @param string $name command name (case-insensitive)
*
* @return \CConsoleCommand The command object. Null if the name is invalid.
*/
public function createCommand($name)
{
$name = StringHelper::toLowerCase($name);
$command = null;
if (isset($this->commands[$name])) {
$command = $this->commands[$name];
} else {
$commands = array_change_key_case($this->commands);
if (isset($commands[$name])) {
$command = $commands[$name];
}
}
if ($command !== null) {
if (is_string($command)) {
if (strpos($command, '/') !== false || strpos($command, '\\') !== false) {
$className = IOHelper::getFileName($command, false);
// If it's a default framework command, don't namespace it.
if (strpos($command, 'framework') === false) {
$className = __NAMESPACE__ . '\\' . $className;
}
if (!class_exists($className, false)) {
require_once $command;
}
} else {
$className = Craft::import($command);
}
return new $className($name, $this);
} else {
return Craft::createComponent($command, $name, $this);
}
} else {
if ($name === 'help') {
return new \CHelpCommand('help', $this);
} else {
return null;
}
}
}