當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Settings::getHashSalt方法代碼示例

本文整理匯總了PHP中Drupal\Core\Site\Settings::getHashSalt方法的典型用法代碼示例。如果您正苦於以下問題:PHP Settings::getHashSalt方法的具體用法?PHP Settings::getHashSalt怎麽用?PHP Settings::getHashSalt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Site\Settings的用法示例。


在下文中一共展示了Settings::getHashSalt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handleAutocomplete

 /**
  * Autocomplete the label of an entity.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object that contains the typed tags.
  * @param string $target_type
  *   The ID of the target entity type.
  * @param string $selection_handler
  *   The plugin ID of the entity reference selection handler.
  * @param string $selection_settings_key
  *   The hashed key of the key/value entry that holds the selection handler
  *   settings.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  *   The matched entity labels as a JSON response.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
  *   Thrown if the selection settings key is not found in the key/value store
  *   or if it does not match the stored data.
  */
 public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key)
 {
     $matches = array();
     // Get the typed string from the URL, if it exists.
     if ($input = $request->query->get('q')) {
         $typed_string = Tags::explode($input);
         $typed_string = Unicode::strtolower(array_pop($typed_string));
         // Selection settings are passed in as a hashed key of a serialized array
         // stored in the key/value store.
         $selection_settings = $this->keyValue->get($selection_settings_key, FALSE);
         if ($selection_settings !== FALSE) {
             $selection_settings_hash = Crypt::hmacBase64(serialize($selection_settings) . $target_type . $selection_handler, Settings::getHashSalt());
             if ($selection_settings_hash !== $selection_settings_key) {
                 // Disallow access when the selection settings hash does not match the
                 // passed-in key.
                 throw new AccessDeniedHttpException('Invalid selection settings key.');
             }
         } else {
             // Disallow access when the selection settings key is not found in the
             // key/value store.
             throw new AccessDeniedHttpException();
         }
         $matches = $this->matcher->getMatches($target_type, $selection_handler, $selection_settings, $typed_string);
     }
     return new JsonResponse($matches);
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:46,代碼來源:EntityAutocompleteController.php

示例2: getSystemData

 protected function getSystemData()
 {
     $systemManager = $this->getSystemManager();
     $requirements = $systemManager->listRequirements();
     $systemData = [];
     foreach ($requirements as $key => $requirement) {
         if ($requirement['title'] instanceof \Drupal\Core\StringTranslation\TranslatableMarkup) {
             $title = $requirement['title']->render();
         } else {
             $title = $requirement['title'];
         }
         $systemData['system'][$title] = $requirement['value'];
     }
     $kernelHelper = $this->getKernelHelper();
     $drupal = $this->getDrupalHelper();
     Settings::initialize($drupal->getRoot(), 'sites/default', $kernelHelper->getClassLoader());
     try {
         $hashSalt = Settings::getHashSalt();
     } catch (\Exception $e) {
         $hashSalt = '';
     }
     $systemData['system'][$this->trans('commands.site.status.messages.hash_salt')] = $hashSalt;
     $systemData['system'][$this->trans('commands.site.status.messages.console')] = $this->getApplication()->getVersion();
     return $systemData;
 }
開發者ID:GoZOo,項目名稱:DrupalConsole,代碼行數:25,代碼來源:SiteStatusCommand.php

示例3: getSystemData

 protected function getSystemData()
 {
     if (!$this->systemManager) {
         return [];
     }
     $requirements = $this->systemManager->listRequirements();
     $systemData = [];
     foreach ($requirements as $key => $requirement) {
         if ($requirement['title'] instanceof \Drupal\Core\StringTranslation\TranslatableMarkup) {
             $title = $requirement['title']->render();
         } else {
             $title = $requirement['title'];
         }
         $systemData['system'][$title] = $requirement['value'];
     }
     if ($this->settings) {
         try {
             $hashSalt = $this->settings->getHashSalt();
         } catch (\Exception $e) {
             $hashSalt = '';
         }
         $systemData['system'][$this->trans('commands.site.status.messages.hash_salt')] = $hashSalt;
         $systemData['system'][$this->trans('commands.site.status.messages.console')] = $this->getApplication()->getVersion();
     }
     return $systemData;
 }
開發者ID:ibonelli,項目名稱:DrupalConsole,代碼行數:26,代碼來源:StatusCommand.php

示例4: setUp

 protected function setUp()
 {
     // DrupalKernel relies on global $config_directories and requires those
     // directories to exist. Therefore, create the directories, but do not
     // invoke KernelTestBase::setUp(), since that would set up further
     // environment aspects, which would distort this test, because it tests
     // the DrupalKernel (re-)building itself.
     $this->prepareConfigDirectories();
     $this->settingsSet('php_storage', array('service_container' => array('bin' => 'service_container', 'class' => 'Drupal\\Component\\PhpStorage\\MTimeProtectedFileStorage', 'directory' => DRUPAL_ROOT . '/' . $this->publicFilesDirectory . '/php', 'secret' => Settings::getHashSalt())));
 }
開發者ID:ddrozdik,項目名稱:dmaps,代碼行數:10,代碼來源:DrupalKernelTest.php

示例5: doGenerate

 /**
  * Generates a hash that uniquely identifies the user's permissions.
  *
  * @param \Drupal\user\Entity\Role[] $roles
  *   The user's roles.
  *
  * @return string
  *   The permissions hash.
  */
 protected function doGenerate(array $roles)
 {
     // @todo Once Drupal gets rid of user_role_permissions(), we should be able
     // to inject the user role controller and call a method on that instead.
     $permissions_by_role = user_role_permissions($roles);
     foreach ($permissions_by_role as $role => $permissions) {
         sort($permissions);
         $permissions_by_role[$role] = $permissions;
     }
     return hash('sha256', $this->privateKey->get() . Settings::getHashSalt() . serialize($permissions_by_role));
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:20,代碼來源:PermissionsHash.php

示例6: getSystemData

 protected function getSystemData()
 {
     $systemManager = $this->getSystemManager();
     $requirements = $systemManager->listRequirements();
     $systemData = [];
     foreach ($requirements as $key => $requirement) {
         $systemData['system'][$requirement['title']] = $requirement['value'];
     }
     $kernelHelper = $this->getHelper('kernel');
     $drupalAutoLoad = $this->getHelperSet()->get('drupal-autoload');
     Settings::initialize($drupalAutoLoad->getDrupalRoot(), 'sites/default', $kernelHelper->getClassLoader());
     $systemData['system'][$this->trans('commands.site.status.messages.hash_salt')] = Settings::getHashSalt();
     $systemData['system'][$this->trans('commands.site.status.messages.console')] = $this->getApplication()->getVersion();
     return $systemData;
 }
開發者ID:nateswart,項目名稱:DrupalConsole,代碼行數:15,代碼來源:SiteStatusCommand.php

示例7: generatePlaceholder

 /**
  * #pre_render callback to generate a placeholder.
  *
  * Ensures the same token is used for all instances, hence resulting in the
  * same placeholder for all places rendering the status messages for this
  * request (e.g. in multiple blocks). This ensures we can put the rendered
  * messages in all placeholders in one go.
  * Also ensures the same context key is used for the #post_render_cache
  * property, this ensures that if status messages are rendered multiple times,
  * their individual (but identical!) #post_render_cache properties are merged,
  * ensuring the callback is only invoked once.
  *
  * @see ::renderMessages()
  * @param array $element
  *   A renderable array.
  *
  * @return array
  *   The updated renderable array containing the placeholder.
  */
 public static function generatePlaceholder(array $element)
 {
     $plugin_id = 'status_messages';
     $callback = get_class() . '::renderMessages';
     try {
         $hash_salt = Settings::getHashSalt();
     } catch (\RuntimeException $e) {
         // Status messages are also shown during the installer, at which time no
         // hash salt is defined yet.
         $hash_salt = Crypt::randomBytes(8);
     }
     $key = $plugin_id . $element['#display'];
     $context = ['display' => $element['#display'], 'token' => Crypt::hmacBase64($key, $hash_salt)];
     $placeholder = static::renderer()->generateCachePlaceholder($callback, $context);
     $element['#post_render_cache'] = [$callback => [$key => $context]];
     $element['#markup'] = $placeholder;
     return $element;
 }
開發者ID:Nikola-xiii,項目名稱:d8intranet,代碼行數:37,代碼來源:StatusMessages.php

示例8: get

 /**
  * Instantiates a storage for generated PHP code.
  *
  * By default, this returns an instance of the
  * \Drupal\Component\PhpStorage\MTimeProtectedFileStorage class.
  *
  * Classes implementing
  * \Drupal\Component\PhpStorage\PhpStorageInterface can be registered for a
  * specific bin or as a default implementation.
  *
  * @param string $name
  *   The name for which the storage should be returned. Defaults to 'default'
  *   The name is also used as the storage bin if one is not specified in the
  *   configuration.
  *
  * @return \Drupal\Component\PhpStorage\PhpStorageInterface
  *   An instantiated storage for the specified name.
  */
 static function get($name)
 {
     $overrides = Settings::get('php_storage');
     if (isset($overrides[$name])) {
         $configuration = $overrides[$name];
     } elseif (isset($overrides['default'])) {
         $configuration = $overrides['default'];
     } else {
         $configuration = array('class' => 'Drupal\\Component\\PhpStorage\\MTimeProtectedFileStorage', 'secret' => Settings::getHashSalt());
     }
     $class = isset($configuration['class']) ? $configuration['class'] : 'Drupal\\Component\\PhpStorage\\MTimeProtectedFileStorage';
     if (!isset($configuration['bin'])) {
         $configuration['bin'] = $name;
     }
     if (!isset($configuration['directory'])) {
         $configuration['directory'] = DRUPAL_ROOT . '/' . PublicStream::basePath() . '/php';
     }
     return new $class($configuration);
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:37,代碼來源:PhpStorageFactory.php

示例9: get

 /**
  * Instantiates a storage for generated PHP code.
  *
  * By default, this returns an instance of the
  * \Drupal\Component\PhpStorage\MTimeProtectedFileStorage class.
  *
  * Classes implementing
  * \Drupal\Component\PhpStorage\PhpStorageInterface can be registered for a
  * specific bin or as a default implementation.
  *
  * @param string $name
  *   The name for which the storage should be returned. Defaults to 'default'
  *   The name is also used as the storage bin if one is not specified in the
  *   configuration.
  *
  * @return \Drupal\Component\PhpStorage\PhpStorageInterface
  *   An instantiated storage for the specified name.
  */
 static function get($name)
 {
     $configuration = array();
     $overrides = Settings::get('php_storage');
     if (isset($overrides[$name])) {
         $configuration = $overrides[$name];
     } elseif (isset($overrides['default'])) {
         $configuration = $overrides['default'];
     }
     // Make sure all the necessary configuration values are set.
     $class = isset($configuration['class']) ? $configuration['class'] : 'Drupal\\Component\\PhpStorage\\MTimeProtectedFileStorage';
     if (!isset($configuration['secret'])) {
         $configuration['secret'] = Settings::getHashSalt();
     }
     if (!isset($configuration['bin'])) {
         $configuration['bin'] = $name;
     }
     if (!isset($configuration['directory'])) {
         $configuration['directory'] = PublicStream::basePath() . '/php';
     }
     return new $class($configuration);
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:40,代碼來源:PhpStorageFactory.php

示例10: getPathToken

 /**
  * {@inheritdoc}
  */
 public function getPathToken($uri)
 {
     // Return the first 8 characters.
     return substr(Crypt::hmacBase64($this->id() . ':' . $uri, \Drupal::service('private_key')->get() . Settings::getHashSalt()), 0, 8);
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:8,代碼來源:ImageStyle.php

示例11: testGetHashSaltEmpty

 /**
  * Tests Settings::getHashSalt() with no hash salt value.
  *
  * @covers ::getHashSalt
  *
  * @dataProvider providerTestGetHashSaltEmpty
  *
  * @expectedException \RuntimeException
  */
 public function testGetHashSaltEmpty(array $config)
 {
     // Re-create settings with no 'hash_salt' key.
     $settings = new Settings($config);
     $settings->getHashSalt();
 }
開發者ID:alnutile,項目名稱:drunatra,代碼行數:15,代碼來源:SettingsTest.php

示例12: computeToken

 /**
  * Generates a token based on $value, the token seed, and the private key.
  *
  * @param string $seed
  *   The per-session token seed.
  * @param string $value
  *   (optional) An additional value to base the token on.
  *
  * @return string
  *   A 43-character URL-safe token for validation, based on the token seed,
  *   the hash salt provided by Settings::getHashSalt(), and the
  *   'drupal_private_key' configuration variable.
  *
  * @see \Drupal\Core\Site\Settings::getHashSalt()
  */
 protected function computeToken($seed, $value = '')
 {
     return Crypt::hmacBase64($value, $seed . $this->privateKey->get() . Settings::getHashSalt());
 }
開發者ID:sarahwillem,項目名稱:OD8,代碼行數:19,代碼來源:CsrfTokenGenerator.php

示例13: getHashSalt

 /**
  * Gets a salt useful for hardening against SQL injection.
  *
  * @return string
  *   A salt based on information in settings.php, not in the database.
  *
  * @throws \RuntimeException
  */
 protected function getHashSalt()
 {
     return Settings::getHashSalt();
 }
開發者ID:RealLukeMartin,項目名稱:drupal8tester,代碼行數:12,代碼來源:ImageStyle.php

示例14: drupalGetToken

 /**
  * Stop-gap fix.
  *
  * @see http://drupal.org/node/1555862
  */
 protected function drupalGetToken($value = '')
 {
     // Use the same code as \Drupal\Core\Access\CsrfTokenGenerator::get().
     $private_key = $this->container->get('private_key')->get();
     /** @var \Drupal\Core\Session\MetadataBag $session_metadata */
     $session_metadata = $this->container->get('session_manager.metadata_bag');
     // @TODO Try to get seed from testing site, broken now.
     $seed = $session_metadata->getCsrfTokenSeed();
     return Crypt::hmacBase64($value, $seed . $private_key . Settings::getHashSalt());
 }
開發者ID:nicolaspoulain,項目名稱:bb8,代碼行數:15,代碼來源:MasqueradeWebTestBase.php

示例15: getKey

 /**
  * Generates a key from job item data that can be used in the URL.
  *
  * @param \Drupal\tmgmt\JobItemInterface $tmgmt_job_item
  *   Job item.
  *
  * @return string
  *   Returns hashed key that is safe to use in the URL.
  */
 public function getKey(JobItemInterface $tmgmt_job_item)
 {
     return Crypt::hmacBase64($tmgmt_job_item->id(), Settings::getHashSalt());
 }
開發者ID:andrewl,項目名稱:andrewlnet,代碼行數:13,代碼來源:KeyAccessCheck.php


注:本文中的Drupal\Core\Site\Settings::getHashSalt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。