Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aspect breaks when certain class' constructor injects classes #8

Open
Edwinws opened this issue Jul 20, 2017 · 6 comments
Open

Aspect breaks when certain class' constructor injects classes #8

Edwinws opened this issue Jul 20, 2017 · 6 comments

Comments

@Edwinws
Copy link

Edwinws commented Jul 20, 2017

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.

@lisachenko
Copy link
Member

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: goaop/goaop-symfony-bundle#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.

@Edwinws
Copy link
Author

Edwinws commented Jul 26, 2017

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.

@lisachenko
Copy link
Member

So, is it working now for you?

@Edwinws
Copy link
Author

Edwinws commented Jul 26, 2017

Yup, with the workaround.

@lisachenko
Copy link
Member

Ok, let's keep this open, maybe I will be able to reproduce it somehow and prepare a fix for that.

@lisachenko lisachenko added the bug label Jul 26, 2017
@Edwinws
Copy link
Author

Edwinws commented Jul 26, 2017

thanks! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants