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


PHP Crypt::hashBase64方法代码示例

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


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

示例1: testFeed

 /**
  * Generates a test feed and simulates last-modified and etags.
  *
  * @param $use_last_modified
  *   Set TRUE to send a last modified header.
  * @param $use_etag
  *   Set TRUE to send an etag.
  * @param Request $request
  *   Information about the current HTTP request.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  *   A feed that forces cache validation.
  */
 public function testFeed($use_last_modified, $use_etag, Request $request)
 {
     $response = new Response();
     $last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
     $etag = Crypt::hashBase64($last_modified);
     $if_modified_since = strtotime($request->server->get('HTTP_IF_MODIFIED_SINCE'));
     $if_none_match = stripslashes($request->server->get('HTTP_IF_NONE_MATCH'));
     // Send appropriate response. We respond with a 304 not modified on either
     // etag or on last modified.
     if ($use_last_modified) {
         $response->headers->set('Last-Modified', gmdate(DateTimePlus::RFC7231, $last_modified));
     }
     if ($use_etag) {
         $response->headers->set('ETag', $etag);
     }
     // Return 304 not modified if either last modified or etag match.
     if ($last_modified == $if_modified_since || $etag == $if_none_match) {
         $response->setStatusCode(304);
         return $response;
     }
     // The following headers force validation of cache.
     $response->headers->set('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
     $response->headers->set('Cache-Control', 'must-revalidate');
     $response->headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
     // Read actual feed from file.
     $file_name = drupal_get_path('module', 'aggregator_test') . '/aggregator_test_rss091.xml';
     $handle = fopen($file_name, 'r');
     $feed = fread($handle, filesize($file_name));
     fclose($handle);
     $response->setContent($feed);
     return $response;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:45,代码来源:AggregatorTestRssController.php

示例2: dump

 /**
  * {@inheritdoc}
  *
  * The file name for the CSS or JS cache file is generated from the hash of
  * the aggregated contents of the files in $data. This forces proxies and
  * browsers to download new CSS when the CSS changes.
  */
 public function dump($data, $file_extension)
 {
     // Prefix filename to prevent blocking by firewalls which reject files
     // starting with "ad*".
     $filename = $file_extension . '_' . Crypt::hashBase64($data) . '.' . $file_extension;
     // Create the css/ or js/ path within the files folder.
     $path = 'public://' . $file_extension;
     $uri = $path . '/' . $filename;
     // Create the CSS or JS file.
     file_prepare_directory($path, FILE_CREATE_DIRECTORY);
     if (!file_exists($uri) && !file_unmanaged_save_data($data, $uri, FILE_EXISTS_REPLACE)) {
         return FALSE;
     }
     // If CSS/JS gzip compression is enabled and the zlib extension is available
     // then create a gzipped version of this file. This file is served
     // conditionally to browsers that accept gzip using .htaccess rules.
     // It's possible that the rewrite rules in .htaccess aren't working on this
     // server, but there's no harm (other than the time spent generating the
     // file) in generating the file anyway. Sites on servers where rewrite rules
     // aren't working can set css.gzip to FALSE in order to skip
     // generating a file that won't be used.
     if (extension_loaded('zlib') && \Drupal::config('system.performance')->get($file_extension . '.gzip')) {
         if (!file_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
             return FALSE;
         }
     }
     return $uri;
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:35,代码来源:AssetDumper.php

示例3: generateHash

 /**
  * Generates a unique hash for identification purposes.
  *
  * @param string $source_path
  *   Source path of the redirect.
  * @param array $source_query
  *   Source query as an array.
  * @param string $language
  *   Redirect language.
  *
  * @return string
  *   Base 64 hash.
  */
 public static function generateHash($source_path, array $source_query, $language)
 {
     $hash = array('source' => Unicode::strtolower($source_path), 'language' => $language);
     if (!empty($source_query)) {
         $hash['source_query'] = $source_query;
     }
     redirect_sort_recursive($hash, 'ksort');
     return Crypt::hashBase64(serialize($hash));
 }
开发者ID:omero,项目名称:camp-gdl,代码行数:22,代码来源:Redirect.php

示例4: testActionConfiguration

 /**
  * Tests configuration of advanced actions through administration interface.
  */
 function testActionConfiguration()
 {
     // Create a user with permission to view the actions administration pages.
     $user = $this->drupalCreateUser(array('administer actions'));
     $this->drupalLogin($user);
     // Make a POST request to admin/config/system/actions.
     $edit = array();
     $edit['action'] = Crypt::hashBase64('action_goto_action');
     $this->drupalPostForm('admin/config/system/actions', $edit, t('Create'));
     $this->assertResponse(200);
     // Make a POST request to the individual action configuration page.
     $edit = array();
     $action_label = $this->randomMachineName();
     $edit['label'] = $action_label;
     $edit['id'] = strtolower($action_label);
     $edit['url'] = 'admin';
     $this->drupalPostForm('admin/config/system/actions/add/' . Crypt::hashBase64('action_goto_action'), $edit, t('Save'));
     $this->assertResponse(200);
     // Make sure that the new complex action was saved properly.
     $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully saved the complex action.");
     $this->assertText($action_label, "Make sure the action label appears on the configuration page after we've saved the complex action.");
     // Make another POST request to the action edit page.
     $this->clickLink(t('Configure'));
     preg_match('|admin/config/system/actions/configure/(.+)|', $this->getUrl(), $matches);
     $aid = $matches[1];
     $edit = array();
     $new_action_label = $this->randomMachineName();
     $edit['label'] = $new_action_label;
     $edit['url'] = 'admin';
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertResponse(200);
     // Make sure that the action updated properly.
     $this->assertText(t('The action has been successfully saved.'), "Make sure we get a confirmation that we've successfully updated the complex action.");
     $this->assertNoText($action_label, "Make sure the old action label does NOT appear on the configuration page after we've updated the complex action.");
     $this->assertText($new_action_label, "Make sure the action label appears on the configuration page after we've updated the complex action.");
     $this->clickLink(t('Configure'));
     $element = $this->xpath('//input[@type="text" and @value="admin"]');
     $this->assertTrue(!empty($element), 'Make sure the URL appears when re-editing the action.');
     // Make sure that deletions work properly.
     $this->drupalGet('admin/config/system/actions');
     $this->clickLink(t('Delete'));
     $this->assertResponse(200);
     $edit = array();
     $this->drupalPostForm("admin/config/system/actions/configure/{$aid}/delete", $edit, t('Delete'));
     $this->assertResponse(200);
     // Make sure that the action was actually deleted.
     $this->assertRaw(t('The action %action has been deleted.', array('%action' => $new_action_label)), 'Make sure that we get a delete confirmation message.');
     $this->drupalGet('admin/config/system/actions');
     $this->assertResponse(200);
     $this->assertNoText($new_action_label, "Make sure the action label does not appear on the overview page after we've deleted the action.");
     $action = entity_load('action', $aid);
     $this->assertFalse($action, 'Make sure the action is gone after being deleted.');
 }
开发者ID:jthoresen,项目名称:PladsenDrupal,代码行数:56,代码来源:ConfigurationTest.php

示例5: process

 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $settings = $this->settings;
     if ($settings['settings_source'] === 'global') {
         $config = \Drupal::config('pathologic.settings');
         $settings['protocol_style'] = $config->get('protocol_style');
         $settings['local_paths'] = $config->get('local_paths');
     } else {
         $settings = $settings['local_settings'];
     }
     // @todo Move code from .module file to inside here.
     return new FilterProcessResult(_pathologic_filter($text, $settings, Crypt::hashBase64(serialize($settings))));
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:16,代码来源:FilterPathologic.php

示例6: testAssignOwnerNodeActionConfiguration

 /**
  * Tests configuration of the node_assign_owner_action action.
  */
 public function testAssignOwnerNodeActionConfiguration()
 {
     // Create a user with permission to view the actions administration pages.
     $user = $this->drupalCreateUser(['administer actions']);
     $this->drupalLogin($user);
     // Make a POST request to admin/config/system/actions.
     $edit = [];
     $edit['action'] = Crypt::hashBase64('node_assign_owner_action');
     $this->drupalPostForm('admin/config/system/actions', $edit, t('Create'));
     $this->assertResponse(200);
     // Make a POST request to the individual action configuration page.
     $edit = [];
     $action_label = $this->randomMachineName();
     $edit['label'] = $action_label;
     $edit['id'] = strtolower($action_label);
     $edit['owner_uid'] = $user->id();
     $this->drupalPostForm('admin/config/system/actions/add/' . Crypt::hashBase64('node_assign_owner_action'), $edit, t('Save'));
     $this->assertResponse(200);
     // Make sure that the new action was saved properly.
     $this->assertText(t('The action has been successfully saved.'), 'The node_assign_owner_action action has been successfully saved.');
     $this->assertText($action_label, 'The label of the node_assign_owner_action action appears on the actions administration page after saving.');
     // Make another POST request to the action edit page.
     $this->clickLink(t('Configure'));
     preg_match('|admin/config/system/actions/configure/(.+)|', $this->getUrl(), $matches);
     $aid = $matches[1];
     $edit = [];
     $new_action_label = $this->randomMachineName();
     $edit['label'] = $new_action_label;
     $edit['owner_uid'] = $user->id();
     $this->drupalPostForm(NULL, $edit, t('Save'));
     $this->assertResponse(200);
     // Make sure that the action updated properly.
     $this->assertText(t('The action has been successfully saved.'), 'The node_assign_owner_action action has been successfully updated.');
     $this->assertNoText($action_label, 'The old label for the node_assign_owner_action action does not appear on the actions administration page after updating.');
     $this->assertText($new_action_label, 'The new label for the node_assign_owner_action action appears on the actions administration page after updating.');
     // Make sure that deletions work properly.
     $this->drupalGet('admin/config/system/actions');
     $this->clickLink(t('Delete'));
     $this->assertResponse(200);
     $edit = [];
     $this->drupalPostForm("admin/config/system/actions/configure/{$aid}/delete", $edit, t('Delete'));
     $this->assertResponse(200);
     // Make sure that the action was actually deleted.
     $this->assertRaw(t('The action %action has been deleted.', ['%action' => $new_action_label]), 'The delete confirmation message appears after deleting the node_assign_owner_action action.');
     $this->drupalGet('admin/config/system/actions');
     $this->assertResponse(200);
     $this->assertNoText($new_action_label, 'The label for the node_assign_owner_action action does not appear on the actions administration page after deleting.');
     $action = Action::load($aid);
     $this->assertFalse($action, 'The node_assign_owner_action action is not available after being deleted.');
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:53,代码来源:NodeActionsConfigurationTest.php

示例7: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $actions = array();
     foreach ($this->manager->getDefinitions() as $id => $definition) {
         if (is_subclass_of($definition['class'], '\\Drupal\\Core\\Plugin\\PluginFormInterface')) {
             $key = Crypt::hashBase64($id);
             $actions[$key] = $definition['label'] . '...';
         }
     }
     $form['parent'] = array('#type' => 'details', '#title' => $this->t('Create an advanced action'), '#attributes' => array('class' => array('container-inline')), '#open' => TRUE);
     $form['parent']['action'] = array('#type' => 'select', '#title' => $this->t('Action'), '#title_display' => 'invisible', '#options' => $actions, '#empty_option' => $this->t('Choose an advanced action'));
     $form['parent']['actions'] = array('#type' => 'actions');
     $form['parent']['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Create'));
     return $form;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:18,代码来源:ActionAdminManageForm.php

示例8: buildForm

 /**
  * {@inheritdoc}
  *
  * @param string $action_id
  *   The hashed version of the action ID.
  */
 public function buildForm(array $form, FormStateInterface $form_state, $action_id = NULL)
 {
     // In \Drupal\action\Form\ActionAdminManageForm::buildForm() the action
     // are hashed. Here we have to decrypt it to find the desired action ID.
     foreach ($this->actionManager->getDefinitions() as $id => $definition) {
         $key = Crypt::hashBase64($id);
         if ($key === $action_id) {
             $this->entity->setPlugin($id);
             // Derive the label and type from the action definition.
             $this->entity->set('label', $definition['label']);
             $this->entity->set('type', $definition['type']);
             break;
         }
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:22,代码来源:ActionAddForm.php

示例9: testActionEntityClone

  public function testActionEntityClone() {
    foreach (\Drupal::service('plugin.manager.action')->getDefinitions() as $id => $definition) {
      if (is_subclass_of($definition['class'], '\Drupal\Core\Plugin\PluginFormInterface') && $definition['label'] == 'Send email') {
        $action_key = Crypt::hashBase64($id);
        break;
      }
    }

    $edit = [
      'label' => 'Test send email action for clone',
      'id' => 'test_send_email_for_clone',
      'recipient' => 'test@recipient.com',
      'subject' => 'test subject',
      'message' => 'test message',
    ];
    $this->drupalPostForm("admin/config/system/actions/add/$action_key", $edit, t('Save'));

    $actions = \Drupal::entityTypeManager()
      ->getStorage('action')
      ->loadByProperties([
        'id' => $edit['id'],
      ]);
    $action = reset($actions);

    $edit = [
      'label' => 'Test send email action cloned',
      'id' => 'test_send_email_cloned',
    ];
    $this->drupalPostForm('entity_clone/action/' . $action->id(), $edit, t('Clone'));

    $actions = \Drupal::entityTypeManager()
      ->getStorage('action')
      ->loadByProperties([
        'id' => $edit['id'],
      ]);
    $action = reset($actions);
    $this->assertTrue($action, 'Test action cloned found in database.');
  }
开发者ID:eloiv,项目名称:botafoc.cat,代码行数:38,代码来源:EntityCloneActionTest.php

示例10: autoImportConfig

 /**
  * Reinstall changed config files.
  */
 public function autoImportConfig()
 {
     $config = $this->getSettings();
     $changed = FALSE;
     foreach ($config->get('auto_import') as $key => $file) {
         $contents = @file_get_contents($file['filename']);
         if (!$contents) {
             continue;
         }
         $hash = Crypt::hashBase64($contents);
         if ($hash != $file['hash']) {
             $changed = TRUE;
             $config->set("auto_import.{$key}.hash", $hash);
             $data = (new InstallStorage())->decode($contents);
             $config_name = basename($file['filename'], '.yml');
             $entity_type_id = $this->configManager->getEntityTypeIdByName($config_name);
             if ($entity_type_id) {
                 $entity_storage = $this->getStorage($entity_type_id);
                 $entity_id = $this->getEntityId($entity_storage, $config_name);
                 $entity_type = $entity_storage->getEntityType();
                 $id_key = $entity_type->getKey('id');
                 $data[$id_key] = $entity_id;
                 $entity = $entity_storage->create($data);
                 if ($existing_entity = $entity_storage->load($entity_id)) {
                     $entity->set('uuid', $existing_entity->uuid())->enforceIsNew(FALSE);
                 }
                 $entity_storage->save($entity);
             } else {
                 $this->configFactory->getEditable($config_name)->setData($data)->save();
             }
         }
     }
     if ($changed) {
         $config->save();
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:39,代码来源:ConfigDevelAutoImportSubscriber.php

示例11: getPropertyInstance

 /**
  * Get a typed data instance for a property of a given typed data object.
  *
  * This method will use prototyping for fast and efficient instantiation of
  * many property objects with the same property path; e.g.,
  * when multiple comments are used comment_body.0.value needs to be
  * instantiated very often.
  * Prototyping is done by the root object's data type and the given
  * property path, i.e. all property instances having the same property path
  * and inheriting from the same data type are prototyped.
  *
  * @param \Drupal\Core\TypedData\TypedDataInterface $object
  *   The parent typed data object, implementing the TypedDataInterface and
  *   either the ListInterface or the ComplexDataInterface.
  * @param string $property_name
  *   The name of the property to instantiate, or the delta of an list item.
  * @param mixed $value
  *   (optional) The data value. If set, it has to match one of the supported
  *   data type formats as documented by the data type classes.
  *
  * @throws \InvalidArgumentException
  *   If the given property is not known, or the passed object does not
  *   implement the ListInterface or the ComplexDataInterface.
  *
  * @return \Drupal\Core\TypedData\TypedDataInterface
  *   The new property instance.
  *
  * @see \Drupal\Core\TypedData\TypedDataManager::create()
  */
 public function getPropertyInstance(TypedDataInterface $object, $property_name, $value = NULL)
 {
     $definition = $object->getRoot()->getDataDefinition();
     // If the definition is a list, we need to look at the data type and the
     // settings of its item definition.
     if ($definition instanceof ListDataDefinition) {
         $definition = $definition->getItemDefinition();
     }
     $key = $definition->getDataType();
     if ($settings = $definition->getSettings()) {
         $key .= ':' . Crypt::hashBase64(serialize($settings));
     }
     $key .= ':' . $object->getPropertyPath() . '.';
     // If we are creating list items, we always use 0 in the key as all list
     // items look the same.
     $key .= is_numeric($property_name) ? 0 : $property_name;
     // Make sure we have a prototype. Then, clone the prototype and set object
     // specific values, i.e. the value and the context.
     if (!isset($this->prototypes[$key]) || !$key) {
         // Create the initial prototype. For that we need to fetch the definition
         // of the to be created property instance from the parent.
         if ($object instanceof ComplexDataInterface) {
             $definition = $object->getDataDefinition()->getPropertyDefinition($property_name);
         } elseif ($object instanceof ListInterface) {
             $definition = $object->getItemDefinition();
         } else {
             throw new \InvalidArgumentException("The passed object has to either implement the ComplexDataInterface or the ListInterface.");
         }
         // Make sure we have got a valid definition.
         if (!$definition) {
             throw new \InvalidArgumentException('Property ' . String::checkPlain($property_name) . ' is unknown.');
         }
         // Now create the prototype using the definition, but do not pass the
         // given value as it will serve as prototype for any further instance.
         $this->prototypes[$key] = $this->create($definition, NULL, $property_name, $object);
     }
     // Clone from the prototype, then update the parent relationship and set the
     // data value if necessary.
     $property = clone $this->prototypes[$key];
     $property->setContext($property_name, $object);
     if (isset($value)) {
         $property->setValue($value, FALSE);
     }
     return $property;
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:74,代码来源:TypedDataManager.php

示例12: getContext

 /**
  * {@inheritdoc}
  */
 public function getContext()
 {
     $sid = $this->requestStack->getCurrentRequest()->getSession()->getId();
     return Crypt::hashBase64($sid);
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:8,代码来源:SessionCacheContext.php

示例13: calculateAggregateFilename

 /**
  * Calculates the aggregated file URI of a group of JavaScript assets.
  *
  * @param array $js_assets
  *   A group of JavaScript assets.
  * @return string
  *   A file URI.
  *
  * @see testAggregation()
  * @see testAggregationOrder()
  */
 protected function calculateAggregateFilename($js_assets)
 {
     $data = '';
     foreach ($js_assets as $js_asset) {
         $data .= file_get_contents($js_asset['data']) . ";\n";
     }
     return file_create_url('public://js/js_' . Crypt::hashBase64($data) . '.js');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:19,代码来源:JavaScriptTest.php

示例14: storeLoginSessionData

 /**
  * Store the Session ID and ticket for single-log-out purposes.
  *
  * @param string $session_id
  *   The session ID, to be used to kill the session later.
  * @param string $ticket
  *   The CAS service ticket to be used as the lookup key.
  *
  * @codeCoverageIgnore
  */
 protected function storeLoginSessionData($session_id, $ticket)
 {
     if ($this->settings->get('cas.settings')->get('logout.enable_single_logout') === TRUE) {
         $plainsid = $session_id;
     } else {
         $plainsid = '';
     }
     $this->connection->insert('cas_login_data')->fields(array('sid', 'plainsid', 'ticket'), array(Crypt::hashBase64($session_id), $plainsid, $ticket))->execute();
 }
开发者ID:pulibrary,项目名称:recap,代码行数:19,代码来源:CasLogin.php

示例15: normalizeCid

 /**
  * Normalizes a cache ID in order to comply with database limitations.
  *
  * @param string $cid
  *   The passed in cache ID.
  *
  * @return string
  *   An ASCII-encoded cache ID that is at most 255 characters long.
  */
 protected function normalizeCid($cid)
 {
     // Nothing to do if the ID is a US ASCII string of 255 characters or less.
     $cid_is_ascii = mb_check_encoding($cid, 'ASCII');
     if (strlen($cid) <= 255 && $cid_is_ascii) {
         return $cid;
     }
     // Return a string that uses as much as possible of the original cache ID
     // with the hash appended.
     $hash = Crypt::hashBase64($cid);
     if (!$cid_is_ascii) {
         return $hash;
     }
     return substr($cid, 0, 255 - strlen($hash)) . $hash;
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:24,代码来源:DatabaseBackend.php


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