Elgg  Version master
CalculateSRI.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Views;
4 
10 class CalculateSRI {
11 
19  public function __invoke(\Elgg\Event $event) {
20  $view = $event->getParam('view');
21  if (empty($view)) {
22  return;
23  }
24 
25  $type = $event->getType();
26 
27  $data = _elgg_services()->serverCache->load('sri') ?? [];
28  if (!isset($data[$type])) {
29  $data[$type] = [];
30  }
31 
32  if (isset($data[$type][$view])) {
33  return;
34  }
35 
36  $hash = base64_encode(hash('sha256', $event->getValue(), true));
37  $data[$type][$view] = "sha256-{$hash}";
38  _elgg_services()->serverCache->save('sri', $data);
39  }
40 }
$type
Definition: delete.php:21
Calculates SRI for simplecache resources.
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
if(!empty($avatar)&&!$avatar->isValid()) elseif(empty($avatar)) if(!$owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
Definition: upload.php:39
_elgg_services()
Get the global service provider.
Definition: elgglib.php:351
Models an event passed to event handlers.
Definition: Event.php:11
__invoke(\Elgg\Event $event)
Calculates the SRI of a simplecache resource file for future use.