goaop-laravel-bridge
goaop-laravel-bridge copied to clipboard
Aspect breaks when certain class' constructor injects classes
I have this function in AuditAspect
/**
* @Around("execution(public * *Repository->create(*))")
*/
public function repositoryCreate(MethodInvocation $invocation) {
\Illuminate\Support\Facades\Log::info('Method intercepted');
...
It's supposed to intercept public function create(array $data)
in class PositionRepository extends Repository
(Repository
extends Optimus\Genie\Repository
)
In AuditService
's constructor, I have the following
public function __construct(
DatabaseManager $database,
Dispatcher $dispatcher,
AuditRepository $auditRepository,
PositionService $positionService
) {
$this->database = $database;
$this->dispatcher = $dispatcher;
$this->auditRepository = $auditRepository;
$this->positionService = $positionService;
}
The repositoryCreate()
function fail to be executed when a *Repository->create()
function is executed.
Removing Position $positionService
in the constructor parameter and $this->positionService = $positionService
in the constructor body (and deleting the _transformation.cache
file) will make repositoryCreate()
work again.
Not sure if this would help, but here are the cache files
With the lines in AuditService
constructor
<?php return array (
AOP_ROOT_DIR . '/api/Audits/Services/AuditService.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Audits/Repositories/AuditRepository.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Audits/Models/Audit.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Services/PositionService.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Repositories/PositionRepository.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Models/Position.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Repositories/PositionAssignmentRepository.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Models/PositionAssignment.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Repositories/UserAssignmentRepository.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Models/UserAssignment.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Controllers/PositionsController.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Users/Models/User.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Requests/CreatePositionRequest.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Enums/PositionStatus.php' =>
array (
'filemtime' => 1500536968,
'cacheUri' => NULL,
),
);
Without the lines:
<?php return array (
AOP_ROOT_DIR . '/api/Audits/Services/AuditService.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Audits/Repositories/AuditRepository.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Audits/Models/Audit.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Controllers/PositionsController.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Services/PositionService.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => AOP_CACHE_DIR . '/api/Positions/Services/PositionService.php',
),
AOP_ROOT_DIR . '/api/Positions/Repositories/PositionRepository.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => AOP_CACHE_DIR . '/api/Positions/Repositories/PositionRepository.php',
),
AOP_ROOT_DIR . '/api/Positions/Models/Position.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Repositories/PositionAssignmentRepository.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => AOP_CACHE_DIR . '/api/Positions/Repositories/PositionAssignmentRepository.php',
),
AOP_ROOT_DIR . '/api/Positions/Models/PositionAssignment.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Repositories/UserAssignmentRepository.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => AOP_CACHE_DIR . '/api/Positions/Repositories/UserAssignmentRepository.php',
),
AOP_ROOT_DIR . '/api/Positions/Models/UserAssignment.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Users/Models/User.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Requests/CreatePositionRequest.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Positions/Enums/PositionStatus.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
AOP_ROOT_DIR . '/api/Audits/Enums/AuditEvent.php' =>
array (
'filemtime' => 1500536999,
'cacheUri' => NULL,
),
);
Also, unrelated question: How is the _transformation.cache
file (re)generated? Sometimes when I add new code, an OutOfBoundsException
will be thrown:
Value aspect.Infrastructure\Aspects\AuditAspect is not defined in the container in /var/www/laravel/vendor/goaop/framework/src/Core/Container.php:84
the only way to fix this is to delete the cache file.
Hi!
Unfortunately, from your comment it isn't clear how to detect what is the root cause for this strange behaviour.
Only possible glitch if you try to use advised service in the aspect. There is an issue for Symfony: https://github.com/goaop/goaop-symfony-bundle/issues/15 about circular references. Maybe this case is also applied to the Laravel itself.
Regarding your question about cache invalidation - it triggered automatically in the dev mode when file is changed. However, if some method is declared in parent classes and you advise it in children classes, then children classes won't be automatically updated and can lead to manual cleaning of the cache.
_transformation.cache
file is automatically regenerated if there was a new file or a class that was processed by the engine. During call to the destructor this information is dumped back to the filesystem and invalidated in the opcache.
I see, thanks for the response. I managed to work around this by using App::make()
inside methods that need the classes, instead of injecting it in the constructor.
So, is it working now for you?
Yup, with the workaround.
Ok, let's keep this open, maybe I will be able to reproduce it somehow and prepare a fix for that.
thanks! 👍