Skip to content

Commit

Permalink
Added Production/Development environment option
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterWoshid committed Nov 1, 2023
1 parent 57b54ae commit 1c1c50a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/AopKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
*
* The AOP Kernel is the heart of the AOP library.
* It manages an environment for Aspect Oriented Programming.
*
* 1. Extend this class and define a list of aspects in the {@link $aspects}
* property.
* 2. Call the {@link init()} method early in the application lifecycle.
*
* If you want to modify the kernel options dynamically, override the
* {@link configureOptions()} method.
*/
abstract class AopKernel extends CodeTransformerKernel
{
Expand Down
20 changes: 18 additions & 2 deletions src/Core/AutoloadInterceptor/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Okapi\Aop\Core\Matcher\AspectMatcher;
use Okapi\CodeTransformer\Core\AutoloadInterceptor;
use Okapi\CodeTransformer\Core\AutoloadInterceptor\ClassLoader as CodeTransformerClassLoader;
use Okapi\CodeTransformer\Core\Options\Environment;
use Okapi\CodeTransformer\Core\StreamFilter;
use Okapi\CodeTransformer\Core\StreamFilter\FilterInjector;
use Okapi\Path\Path;
Expand Down Expand Up @@ -58,13 +59,28 @@ public function findFile($namespacedClass): false|string
// Query cache state
$cacheState = $this->cacheStateManager->queryCacheState($filePath);

// If the cache is cached and up to date
if ($cacheState?->isFresh() && !$this->options->isDebug()) {
// When debugging, bypass the caching mechanism
if ($this->options->isDebug()) {
// ...
}

// In production mode, use the cache without checking if it is fresh
elseif ($this->options->getEnvironment() === Environment::PRODUCTION
&& $cacheState
) {
// Use the cached file if aspects have been applied
// Or return the original file if no aspects have been applied
return $cacheState->getFilePath() ?? $filePath;
}

// In development mode, check if the cache is fresh
elseif ($this->options->getEnvironment() === Environment::DEVELOPMENT
&& $cacheState
&& $cacheState->isFresh()
) {
return $cacheState->getFilePath() ?? $filePath;
}


// Match the aspects
$matchedAspects = $this->aspectMatcher->matchByClassLoader(
Expand Down

0 comments on commit 1c1c50a

Please sign in to comment.