- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
Lines 11 to 26 in cecfc9d
| public function view() | |
| { | |
| $this->set('corp', $this->getPackageConfig()->get('security.cross_origin_resource_policy')); | |
| $this->set('coop', $this->getPackageConfig()->get('security.cross_origin_opener_policy')); | |
| $this->set('coep', $this->getPackageConfig()->get('security.cross_origin_embedder_policy')); | |
| $this->set('accessControlAllowOrigin', $this->getPackageConfig()->get('security.access_control_allow_origin')); | |
| $this->set('nosniff', $this->getPackageConfig()->get('security.x_content_type_options')); | |
| } | |
| protected function getPackageConfig() | |
| { | |
| /** @var PackageService $packageService */ | |
| $packageService = $this->app->make(PackageService::class); | |
| $package = $packageService->getClass('md_security_header_extended'); | |
| return $package->getFileConfig(); | |
| } | 
I noticed that in the code snippet above, the PackageService class is instantiated multiple times by $this->getPackageConfig() method calls, which can impact performance.
To optimize this, we can implement two approaches:
Approach 1
Retrieve the config array once and use its values directly:
$security = $this->getPackageConfig()->get('security');Approach 2
Introduce a new property to cache the package config and reuse it:
if (!$this->pkgConfig) {
    $this->pkgConfig = // Set the property here
}Implementing either of these approaches can help optimize performance by reducing redundant calls to $this->getPackageConfig().
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request