Skip to content

Commit 300cb47

Browse files
authored
Fixed issues with debugging
2 parents 944641d + 751eb2d commit 300cb47

File tree

5 files changed

+41
-13
lines changed

5 files changed

+41
-13
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "okapi/aop",
33
"description": "PHP AOP is a PHP library that provides a powerful Aspect Oriented Programming (AOP) implementation for PHP.",
4-
"version": "1.2.9",
4+
"version": "1.2.10",
55
"type": "library",
66
"homepage": "https://github.com/okapi-web/php-aop",
77
"license": "MIT",
@@ -26,7 +26,7 @@
2626
"require": {
2727
"php": ">=8.1",
2828
"nette/php-generator": "^4.0",
29-
"okapi/code-transformer": "1.3.5",
29+
"okapi/code-transformer": "1.3.6",
3030
"okapi/wildcards": "^1.0",
3131
"okapi/singleton": "^1.0",
3232
"php-di/php-di": "^7.0"

src/Core/AutoloadInterceptor/ClassLoader.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Okapi\Aop\Core\Matcher\AspectMatcher;
77
use Okapi\CodeTransformer\Core\AutoloadInterceptor;
88
use Okapi\CodeTransformer\Core\AutoloadInterceptor\ClassLoader as CodeTransformerClassLoader;
9+
use Okapi\CodeTransformer\Core\CachedStreamFilter;
910
use Okapi\CodeTransformer\Core\Options\Environment;
1011
use Okapi\CodeTransformer\Core\StreamFilter;
1112
use Okapi\CodeTransformer\Core\StreamFilter\FilterInjector;
@@ -71,26 +72,50 @@ public function findFile($namespacedClass): false|string
7172
&& $cacheState
7273
) {
7374
// Use the cached file if aspects have been applied
75+
if ($cacheFilePath = $cacheState->getFilePath()) {
76+
$this->classContainer->addClassContext(
77+
$filePath,
78+
$namespacedClass,
79+
$cacheFilePath,
80+
);
81+
82+
// For cached files, the debugger will have trouble finding the
83+
// original file, that's why we rewrite the file path with a PHP
84+
// stream filter
85+
/** @see CachedStreamFilter::filter() */
86+
return $this->filterInjector->rewriteCached($filePath);
87+
}
88+
7489
// Or return the original file if no aspects have been applied
75-
return $cacheState->getFilePath() ?? $filePath;
90+
return $filePath;
7691
}
7792

7893
// In development mode, check if the cache is fresh
7994
elseif ($this->options->getEnvironment() === Environment::DEVELOPMENT
8095
&& $cacheState
8196
&& $cacheState->isFresh()
8297
) {
83-
return $cacheState->getFilePath() ?? $filePath;
98+
if ($cacheFilePath = $cacheState->getFilePath()) {
99+
$this->classContainer->addClassContext(
100+
$filePath,
101+
$namespacedClass,
102+
$cacheFilePath,
103+
);
104+
105+
return $this->filterInjector->rewriteCached($filePath);
106+
}
107+
108+
return $filePath;
84109
}
85110

86111

87112
// Match the aspects
88-
$matchedAspects = $this->aspectMatcher->matchByClassLoader(
113+
$matchedAspects = $this->aspectMatcher->matchByClassLoaderAndStore(
89114
$namespacedClass,
90115
);
91116

92117
// Match the transformer
93-
$matchedTransformers = $this->transformerMatcher->match(
118+
$matchedTransformers = $this->transformerMatcher->matchAndStore(
94119
$namespacedClass,
95120
$filePath,
96121
);
@@ -101,7 +126,7 @@ public function findFile($namespacedClass): false|string
101126
}
102127

103128
// Add the class to store the file path
104-
$this->classContainer->addNamespacedClassPath($filePath, $namespacedClass);
129+
$this->classContainer->addClassContext($filePath, $namespacedClass);
105130

106131
// Replace the file path with a PHP stream filter
107132
/** @see StreamFilter::filter() */

src/Core/Matcher/AspectMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class AspectMatcher
7878
*
7979
* @return bool
8080
*/
81-
public function matchByClassLoader(string $namespacedClass): bool
81+
public function matchByClassLoaderAndStore(string $namespacedClass): bool
8282
{
8383
// Get the reflection class
8484
$refClass = $this->reflectionHelper->getReflectionClass($namespacedClass);

test

Whitespace-only changes.

tests/ClassLoaderMockTrait.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
namespace Okapi\Aop\Tests;
44

55
use Okapi\Aop\Core\AutoloadInterceptor\ClassLoader;
6-
use Okapi\Aop\Core\Cache\CachePaths;
7-
use Okapi\CodeTransformer\Core\DI;
6+
use Okapi\CodeTransformer\Core\CachedStreamFilter;
87
use Okapi\CodeTransformer\Core\StreamFilter;
98
use Okapi\CodeTransformer\Core\StreamFilter\FilterInjector;
109
use Okapi\Path\Path;
@@ -65,9 +64,13 @@ public function assertWillBeWoven(string $className): void
6564

6665
public function assertAspectLoadedFromCache(string $className): void
6766
{
68-
$filePath = $this->findOriginalClassMock($className);
69-
$cachePaths = DI::get(CachePaths::class);
70-
$cachePath = $cachePaths->getProxyCachePath($filePath);
67+
$filePath = Path::resolve($this->findOriginalClassMock($className));
68+
69+
$cachePath =
70+
FilterInjector::PHP_FILTER_READ .
71+
CachedStreamFilter::CACHED_FILTER_ID . '/resource=' .
72+
$filePath;
73+
7174
$filePathMock = $this->findClassMock($className);
7275

7376
Assert::assertEquals(

0 commit comments

Comments
 (0)