Skip to content

Commit

Permalink
9.1.2 (#427)
Browse files Browse the repository at this point in the history
* updating libs to accommodate caching path from the method and global constant
  • Loading branch information
iruzevic authored Sep 9, 2024
1 parent a78c95a commit 12042bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.

This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).

## [9.1.2]

### Added
- Updates on DI container to support caching and better performance.

## [9.1.1]

### Added
Expand Down Expand Up @@ -638,6 +643,7 @@ Init setup

[Unreleased]: https://github.com/infinum/eightshift-libs/compare/main...HEAD

[9.1.2]: https://github.com/infinum/eightshift-libs/compare/9.1.1...9.1.2
[9.1.1]: https://github.com/infinum/eightshift-libs/compare/9.1.0...9.1.1
[9.1.0]: https://github.com/infinum/eightshift-libs/compare/9.0.2...9.1.0
[9.0.2]: https://github.com/infinum/eightshift-libs/compare/9.0.1...9.0.2
Expand Down
32 changes: 25 additions & 7 deletions src/Main/AbstractMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ public function buildDiContainer(): Container
return $this->container;
}

/**
* Get the path to the cache folder.
*
* @return string
*/
public function getCachedFolderPath(): string
{
$sep = \DIRECTORY_SEPARATOR;
$cacheFolder = __DIR__ . "{$sep}Cache";

if (\defined('EIGHTSHIFT_DI_CACHE_FOLDER')) {
$cacheFolder = \trim(\EIGHTSHIFT_DI_CACHE_FOLDER, $sep);
}

return $cacheFolder;
}

/**
* Merges the autowired definition list with custom user-defined definition list.
*
Expand Down Expand Up @@ -187,17 +204,18 @@ private function getDiContainer(array $services): Container

$builder = new ContainerBuilder();

if ((\defined('WP_ENVIRONMENT_TYPE') && \WP_ENVIRONMENT_TYPE !== 'development') && !\defined('WP_CLI')) {
if (
(\defined('WP_ENVIRONMENT_TYPE') &&
(\WP_ENVIRONMENT_TYPE !== 'development')) &&
!\defined('WP_CLI')
) {
$file = \explode('\\', $this->namespace);

$sep = \DIRECTORY_SEPARATOR;
$cacheFolder = __DIR__ . "{$sep}Cache";
$cacheFolder = $this->getCachedFolderPath();

if (\defined('EIGHTSHIFT_DI_CACHE_FOLDER')) {
$cacheFolder = \trim(\EIGHTSHIFT_DI_CACHE_FOLDER, $sep);
if (!$cacheFolder) {
$builder->enableCompilation($cacheFolder, "{$file[0]}CompiledContainer");
}

$builder->enableCompilation($cacheFolder, "{$file[0]}CompiledContainer");
}

return $builder->addDefinitions($definitions)->build();
Expand Down

0 comments on commit 12042bf

Please sign in to comment.