当前位置: 首页>>代码示例>>PHP>>正文


PHP Unicode::substr方法代码示例

本文整理汇总了PHP中Drupal\Component\Utility\Unicode::substr方法的典型用法代码示例。如果您正苦于以下问题:PHP Unicode::substr方法的具体用法?PHP Unicode::substr怎么用?PHP Unicode::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Component\Utility\Unicode的用法示例。


在下文中一共展示了Unicode::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: log

 /**
  * {@inheritdoc}
  */
 public function log($level, $message, array $context = array())
 {
     // Remove any backtraces since they may contain an unserializable variable.
     unset($context['backtrace']);
     // Convert PSR3-style messages to SafeMarkup::format() style, so they can be
     // translated too in runtime.
     $message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
     try {
         $this->connection->insert('watchdog')->fields(array('uid' => $context['uid'], 'type' => Unicode::substr($context['channel'], 0, 64), 'message' => $message, 'variables' => serialize($message_placeholders), 'severity' => $level, 'link' => $context['link'], 'location' => $context['request_uri'], 'referer' => $context['referer'], 'hostname' => Unicode::substr($context['ip'], 0, 128), 'timestamp' => $context['timestamp']))->execute();
     } catch (\Exception $e) {
         // When running Drupal on MySQL or MariaDB you can run into several errors
         // that corrupt the database connection. Some examples for these kind of
         // errors on the database layer are "1100 - Table 'xyz' was not locked
         // with LOCK TABLES" and "1153 - Got a packet bigger than
         // 'max_allowed_packet' bytes". If such an error happens, the MySQL server
         // invalidates the connection and answers all further requests in this
         // connection with "2006 - MySQL server had gone away". In that case the
         // insert statement above results in a database exception. To ensure that
         // the causal error is written to the log we try once to open a dedicated
         // connection and write again.
         if (($e instanceof DatabaseException || $e instanceof \PDOException) && $this->connection->getTarget() != self::DEDICATED_DBLOG_CONNECTION_TARGET) {
             // Open a dedicated connection for logging.
             $key = $this->connection->getKey();
             $info = Database::getConnectionInfo($key);
             Database::addConnectionInfo($key, self::DEDICATED_DBLOG_CONNECTION_TARGET, $info['default']);
             $this->connection = Database::getConnection(self::DEDICATED_DBLOG_CONNECTION_TARGET, $key);
             // Now try once to log the error again.
             $this->log($level, $message, $context);
         } else {
             throw $e;
         }
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:36,代码来源:DbLog.php

示例2: prepareValue

 /**
  * {@inheritdoc}
  */
 protected function prepareValue($delta, array &$values)
 {
     // Trim the value if it's too long.
     if (!empty($this->settings['max_length'])) {
         $values['value'] = Unicode::substr($values['value'], 0, $this->settings['max_length']);
     }
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:10,代码来源:StringTarget.php

示例3: at_core_submit_layouts

/**
 * Form submit handler for the theme settings form.
 */
function at_core_submit_layouts(&$form, &$form_state) {
  $build_info = $form_state->getBuildInfo();
  $values = $form_state->getValues();
  $theme = $build_info['args'][0];

  // Generate and save a new layout.
  if (isset($values['settings_layouts_enable']) && $values['settings_layouts_enable'] == 1) {

    $generateLayout = new LayoutSubmit($theme, $values);

    // Update the themes info file with new regions.
    $generateLayout->saveLayoutRegions();

    // Build and save the suggestions layout css files.
    $generateLayout->saveLayoutSuggestionsCSS();

    // Build and save the suggestions twig templates.
    $generateLayout->saveLayoutSuggestionsMarkup();

    // Add a new suggestion to the page suggestions array in config.
    if (!empty($values['ts_name'])) {
      $suggestion = trim($values['ts_name']);
      $clean_suggestion = str_replace('-', '_', $suggestion);
      $values["settings_suggestion_page__$clean_suggestion"] = $clean_suggestion;
    }

    // Delete suggestion files
    $templates_directory = drupal_get_path('theme', $theme) . '/templates/page';
    $css_directory = $values['settings_generated_files_path'];

    foreach ($values as $values_key => $values_value) {
      if (substr($values_key, 0, 18) === 'delete_suggestion_') {
        if ($values_value === 1) {
          $delete_suggestion_keys[] = Unicode::substr($values_key, 18);
        }
      }
    }

    if (isset($delete_suggestion_keys)) {
      foreach ($delete_suggestion_keys as $suggestion_to_remove) {
        $formatted_suggestion = str_replace('_', '-', $suggestion_to_remove);
        $template_file_path = $templates_directory . '/' . $formatted_suggestion . '.html.twig';
        $css_file_path = $css_directory . '/' . $theme . '--layout__' . $formatted_suggestion . '.css';
        if (file_exists($template_file_path)) {unlink($template_file_path);}
        if (file_exists($css_file_path)) {unlink($css_file_path);}
      }
    }
  }

  // Flush all caches. This is the only realy reliable way I have found to ensure
  // new templates and layouts work correctly.
  drupal_flush_all_caches();

  // Manage settings and configuration.
  // Must get mutable config otherwise bad things happen.
  $config = \Drupal::configFactory()->getEditable($theme . '.settings');
  $convertToConfig = new ThemeSettingsConfig();
  $convertToConfig->settingsConvertToConfig($values, $config);
}
开发者ID:jno84,项目名称:drupal8,代码行数:62,代码来源:layouts_submit.php

示例4: generateSampleValue

 /**
  * {@inheritdoc}
  */
 public static function generateSampleValue(FieldDefinitionInterface $field_definition)
 {
     $values = parent::generateSampleValue($field_definition);
     $suffix_length = $field_definition->getSetting('max_length') - 7;
     foreach ($values as $key => $value) {
         $values[$key] = 'http://' . Unicode::substr($value, 0, $suffix_length);
     }
     return $values;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:12,代码来源:UriItem.php

示例5: log

 /**
  * {@inheritdoc}
  */
 public function log($level, $message, array $context = array())
 {
     // Remove any backtraces since they may contain an unserializable variable.
     unset($context['backtrace']);
     // Convert PSR3-style messages to SafeMarkup::format() style, so they can be
     // translated too in runtime.
     $message_placeholders = $this->parser->parseMessagePlaceholders($message, $context);
     $this->database->insert('watchdog')->fields(array('uid' => $context['uid'], 'type' => Unicode::substr($context['channel'], 0, 64), 'message' => $message, 'variables' => serialize($message_placeholders), 'severity' => $level, 'link' => $context['link'], 'location' => $context['request_uri'], 'referer' => $context['referer'], 'hostname' => Unicode::substr($context['ip'], 0, 128), 'timestamp' => $context['timestamp']))->execute();
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:12,代码来源:DbLog.php

示例6: hexToRgba

 /**
  * Convert a RGBA hex to its RGBA integer GD components.
  *
  * GD expects a value between 0 and 127 for alpha, where 0 indicates
  * completely opaque while 127 indicates completely transparent.
  * RGBA hexadecimal notation has #00 for transparent and #FF for
  * fully opaque.
  *
  * @param string $rgba_hex
  *   A string specifing an RGBA color in the format '#RRGGBBAA'.
  *
  * @return array
  *   An array with four elements for red, green, blue, and alpha.
  */
 protected function hexToRgba($rgba_hex)
 {
     $rgbHex = Unicode::substr($rgba_hex, 0, 7);
     try {
         $rgb = Color::hexToRgb($rgbHex);
         $opacity = ColorUtility::rgbaToOpacity($rgba_hex);
         $alpha = 127 - floor($opacity / 100 * 127);
         $rgb['alpha'] = $alpha;
         return $rgb;
     } catch (\InvalidArgumentException $e) {
         return FALSE;
     }
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:27,代码来源:GDOperationTrait.php

示例7: decrypt

 /**
  * @return mixed
  */
 public function decrypt($text, $key, $options = array())
 {
     $processed_text = '';
     // Key cannot be too long for this encryption.
     $key = \Drupal\Component\Utility\Unicode::substr($key, 0, 32);
     // Define iv cipher.
     $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
     $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
     $disable_base64 = array_key_exists('base64', $options) && $options['base64'] == FALSE;
     // Check if we are disabling base64 encoding
     if (!$disable_base64) {
         $text = base64_decode($text);
     }
     // Decrypt text.
     return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv));
 }
开发者ID:nerdstein,项目名称:encrypt,代码行数:19,代码来源:McryptAES256Encryption.php

示例8: testDedupe

 /**
  * Tests entity based deduplication based on providerTestDedupe() values.
  *
  * @dataProvider providerTestDedupe
  */
 public function testDedupe($count, $postfix = '', $start = NULL, $length = NULL)
 {
     $configuration = array('entity_type' => 'test_entity_type', 'field' => 'test_field');
     if ($postfix) {
         $configuration['postfix'] = $postfix;
     }
     $configuration['start'] = isset($start) ? $start : NULL;
     $configuration['length'] = isset($length) ? $length : NULL;
     $plugin = new DedupeEntity($configuration, 'dedupe_entity', array(), $this->getMigration(), $this->entityQueryFactory);
     $this->entityQueryExpects($count);
     $value = $this->randomMachineName(32);
     $actual = $plugin->transform($value, $this->migrateExecutable, $this->row, 'testproperty');
     $expected = Unicode::substr($value, $start, $length);
     $expected .= $count ? $postfix . $count : '';
     $this->assertSame($expected, $actual);
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:21,代码来源:DedupeEntityTest.php

示例9: testSearchSimplifyUnicode

 /**
  * Tests that all Unicode characters simplify correctly.
  */
 function testSearchSimplifyUnicode()
 {
     // This test uses a file that was constructed so that the even lines are
     // boundary characters, and the odd lines are valid word characters. (It
     // was generated as a sequence of all the Unicode characters, and then the
     // boundary characters (punctuation, spaces, etc.) were split off into
     // their own lines).  So the even-numbered lines should simplify to nothing,
     // and the odd-numbered lines we need to split into shorter chunks and
     // verify that simplification doesn't lose any characters.
     $input = file_get_contents(\Drupal::root() . '/core/modules/search/tests/UnicodeTest.txt');
     $basestrings = explode(chr(10), $input);
     $strings = array();
     foreach ($basestrings as $key => $string) {
         if ($key % 2) {
             // Even line - should simplify down to a space.
             $simplified = search_simplify($string);
             $this->assertIdentical($simplified, ' ', "Line {$key} is excluded from the index");
         } else {
             // Odd line, should be word characters.
             // Split this into 30-character chunks, so we don't run into limits
             // of truncation in search_simplify().
             $start = 0;
             while ($start < Unicode::strlen($string)) {
                 $newstr = Unicode::substr($string, $start, 30);
                 // Special case: leading zeros are removed from numeric strings,
                 // and there's one string in this file that is numbers starting with
                 // zero, so prepend a 1 on that string.
                 if (preg_match('/^[0-9]+$/', $newstr)) {
                     $newstr = '1' . $newstr;
                 }
                 $strings[] = $newstr;
                 $start += 30;
             }
         }
     }
     foreach ($strings as $key => $string) {
         $simplified = search_simplify($string);
         $this->assertTrue(Unicode::strlen($simplified) >= Unicode::strlen($string), "Nothing is removed from string {$key}.");
     }
     // Test the low-numbered ASCII control characters separately. They are not
     // in the text file because they are problematic for diff, especially \0.
     $string = '';
     for ($i = 0; $i < 32; $i++) {
         $string .= chr($i);
     }
     $this->assertIdentical(' ', search_simplify($string), 'Search simplify works for ASCII control characters.');
 }
开发者ID:318io,项目名称:318-io,代码行数:50,代码来源:SearchSimplifyTest.php

示例10: prepareValue

 /**
  * {@inheritdoc}
  */
 protected function prepareValue($delta, array &$values)
 {
     $values['value'] = (string) $values['value'];
     // At todo. Maybe break these up into separate classes.
     if (!empty($this->settings['settings']['allowed_values'])) {
         if ($key = array_search($values['value'], $this->settings['settings']['allowed_values']) !== FALSE) {
             $values['value'] = $key;
         } else {
             $values['value'] = '';
         }
     }
     // Trim the value if it's too long.
     if (!empty($this->settings['settings']['max_length'])) {
         $values['value'] = Unicode::substr($values['value'], 0, $this->settings['settings']['max_length']);
     }
     $values['format'] = $this->configuration['format'];
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:20,代码来源:Text.php

示例11: transform

 /**
  * {@inheritdoc}
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $start = isset($this->configuration['start']) ? $this->configuration['start'] : 0;
     if (!is_int($start)) {
         throw new MigrateException('The start position configuration value should be an integer. Omit this key to capture from the beginning of the string.');
     }
     $length = isset($this->configuration['length']) ? $this->configuration['length'] : NULL;
     if (!is_null($length) && !is_int($length)) {
         throw new MigrateException('The character length configuration value should be an integer. Omit this key to capture from the start position to the end of the string.');
     }
     if (!is_string($value)) {
         throw new MigrateException('The input value must be a string.');
     }
     // Use optional start or length to return a portion of $value.
     $new_value = Unicode::substr($value, $start, $length);
     return $new_value;
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:20,代码来源:Substr.php

示例12: prepareValue

 /**
  * {@inheritdoc}
  */
 protected function prepareValue($delta, array &$values)
 {
     $values['value'] = (string) $values['value'];
     // @todo We need to generalize this big time. We might be able to get rid of
     // some target classes if property_constraints get used across the board.
     if (!empty($this->settings['property_constraints'])) {
         foreach ($this->settings['property_constraints'] as $key => $constraint) {
             foreach ($constraint as $name => $condition) {
                 switch ($name) {
                     case 'Length':
                         $values[$key] = Unicode::substr($values[$key], 0, $condition['max']);
                         break;
                 }
             }
         }
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:20,代码来源:String.php

示例13: settingsConvertToConfig

 /**
  * Set config for theme settings, core seems to have forgotten themes can
  * have custom settings that you probably very much need in config.
  */
 public function settingsConvertToConfig(array $values, Config $config) {
   foreach ($values as $key => $value) {
     // Save settings as config
     if (substr($key, 0, 9) == 'settings_') {
       $config_key = Unicode::substr($key, 9);
       $config->set('settings.' . $config_key, $value)->save();
     }
     // Delete suggestions config settings. We do not remove all the suggestions settings
     // because later on if the suggestion is recreated there will be settings for it already,
     // which is kind of nice for the user should they accidentally delete a suggestion.
     if (substr($key, 0, 18) == 'delete_suggestion_') {
       $delete_suggestion_key = 'settings.suggestion_' . Unicode::substr($key, 18);
       if ($value == 1) {
         $config->clear($delete_suggestion_key, $value)->save();
       }
     }
   }
 }
开发者ID:jno84,项目名称:drupal8,代码行数:22,代码来源:ThemeSettingsConfig.php

示例14: addWords

 public function addWords($words, $tag = '')
 {
     if ($tag != $this->tag) {
         $this->_flushGroup($tag);
     }
     foreach ($words as $word) {
         // new-line should only come as first char of word.
         if ($word == '') {
             continue;
         }
         if ($word[0] == "\n") {
             $this->_flushLine($tag);
             $word = Unicode::substr($word, 1);
         }
         assert(!strstr($word, "\n"));
         $this->group .= $word;
     }
 }
开发者ID:penguinclub,项目名称:penguinweb_drupal8,代码行数:18,代码来源:HWLDFWordAccumulator.php

示例15: optimize

 /**
  * {@inheritdoc}
  */
 public function optimize(array $js_asset)
 {
     if ($js_asset['type'] !== 'file') {
         throw new \Exception('Only file JavaScript assets can be optimized.');
     }
     if ($js_asset['type'] === 'file' && !$js_asset['preprocess']) {
         throw new \Exception('Only file JavaScript assets with preprocessing enabled can be optimized.');
     }
     // If a BOM is found, convert the file to UTF-8, then use substr() to
     // remove the BOM from the result.
     $data = file_get_contents($js_asset['data']);
     if ($encoding = Unicode::encodingFromBOM($data)) {
         $data = Unicode::substr(Unicode::convertToUtf8($data, $encoding), 1);
     } elseif (isset($js_asset['attributes']['charset'])) {
         $data = Unicode::convertToUtf8($data, $js_asset['attributes']['charset']);
     }
     // No-op optimizer: no optimizations are applied to JavaScript assets.
     return $data;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:22,代码来源:JsOptimizer.php


注:本文中的Drupal\Component\Utility\Unicode::substr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。