Skip to content

Commit 12042bf

Browse files
authored
9.1.2 (#427)
* updating libs to accommodate caching path from the method and global constant
1 parent a78c95a commit 12042bf

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
33

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

6+
## [9.1.2]
7+
8+
### Added
9+
- Updates on DI container to support caching and better performance.
10+
611
## [9.1.1]
712

813
### Added
@@ -638,6 +643,7 @@ Init setup
638643

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

646+
[9.1.2]: https://github.com/infinum/eightshift-libs/compare/9.1.1...9.1.2
641647
[9.1.1]: https://github.com/infinum/eightshift-libs/compare/9.1.0...9.1.1
642648
[9.1.0]: https://github.com/infinum/eightshift-libs/compare/9.0.2...9.1.0
643649
[9.0.2]: https://github.com/infinum/eightshift-libs/compare/9.0.1...9.0.2

src/Main/AbstractMain.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ public function buildDiContainer(): Container
9999
return $this->container;
100100
}
101101

102+
/**
103+
* Get the path to the cache folder.
104+
*
105+
* @return string
106+
*/
107+
public function getCachedFolderPath(): string
108+
{
109+
$sep = \DIRECTORY_SEPARATOR;
110+
$cacheFolder = __DIR__ . "{$sep}Cache";
111+
112+
if (\defined('EIGHTSHIFT_DI_CACHE_FOLDER')) {
113+
$cacheFolder = \trim(\EIGHTSHIFT_DI_CACHE_FOLDER, $sep);
114+
}
115+
116+
return $cacheFolder;
117+
}
118+
102119
/**
103120
* Merges the autowired definition list with custom user-defined definition list.
104121
*
@@ -187,17 +204,18 @@ private function getDiContainer(array $services): Container
187204

188205
$builder = new ContainerBuilder();
189206

190-
if ((\defined('WP_ENVIRONMENT_TYPE') && \WP_ENVIRONMENT_TYPE !== 'development') && !\defined('WP_CLI')) {
207+
if (
208+
(\defined('WP_ENVIRONMENT_TYPE') &&
209+
(\WP_ENVIRONMENT_TYPE !== 'development')) &&
210+
!\defined('WP_CLI')
211+
) {
191212
$file = \explode('\\', $this->namespace);
192213

193-
$sep = \DIRECTORY_SEPARATOR;
194-
$cacheFolder = __DIR__ . "{$sep}Cache";
214+
$cacheFolder = $this->getCachedFolderPath();
195215

196-
if (\defined('EIGHTSHIFT_DI_CACHE_FOLDER')) {
197-
$cacheFolder = \trim(\EIGHTSHIFT_DI_CACHE_FOLDER, $sep);
216+
if (!$cacheFolder) {
217+
$builder->enableCompilation($cacheFolder, "{$file[0]}CompiledContainer");
198218
}
199-
200-
$builder->enableCompilation($cacheFolder, "{$file[0]}CompiledContainer");
201219
}
202220

203221
return $builder->addDefinitions($definitions)->build();

0 commit comments

Comments
 (0)