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

GOAOP not working in Php7.1.3 #319

Closed
team-ultra opened this issue Mar 21, 2017 · 5 comments
Closed

GOAOP not working in Php7.1.3 #319

team-ultra opened this issue Mar 21, 2017 · 5 comments
Milestone

Comments

@team-ultra
Copy link

Version Details
PHP 7.1.3 (cli)
GOAOP 2.1.0

I have made a simple goaop component, while running the code i have put debug on before method but it dosen't return expected result

Folder Structure

goaop
--- app
app.php
ApplicationAspectKernel.php
--- aspect
MonitorAspect.php
SampleClass.php

app.php

include __DIR__ . '/../vendor/autoload.php';
require_once 'ApplicationAspectKernel.php';
use Goaop\Aspect\SampleClass;

ApplicationAspectKernel::getInstance()->init(['appDir' => __DIR__,
    'cacheDir' => null, 'includePaths' => [], 'debug' => true]
);

$sampleClass = new SampleClass();
$sampleClass->testCondition();

ApplicationAspectKernel.php

<?php
// app/ApplicationAspectKernel.php

use Go\Core\AspectKernel;
use Go\Core\AspectContainer;
use Goaop\Aspect\MonitorAspect;

/**
 * Application Aspect Kernel
 */
class ApplicationAspectKernel extends AspectKernel
{

    /**
     * Configure an AspectContainer with advisors, aspects and pointcuts
     *
     * @param AspectContainer $container
     *
     * @return void
     */
    protected function configureAop(AspectContainer $container)
    {
		$container->registerAspect(new MonitorAspect());
    }
}

MonitorAspect.php

<?php
namespace Goaop\Aspect;

use Go\Aop\Aspect;
use Go\Aop\Intercept\FieldAccess;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\After;
use Go\Lang\Annotation\Before;
use Go\Lang\Annotation\Around;
use Go\Lang\Annotation\Pointcut;
use Goaop\Aspect\SampleClass;

class MonitorAspect implements Aspect
{

    /**
     * @param MethodInvocation $invocation Invocation
     * @Before("execution(public Goaop\Aspect\SampleClass->testCondition(*))")
     */
    public function beforeMethodExecution(MethodInvocation $invocation)
    {
        echo "Before method\n";
    }
}

SampleClass.php

<?php
namespace Goaop\Aspect;

class SampleClass {
	public function testCondition($test = "test") {
		echo "Test condition working fine\n";
	}
}

composer.json

{
    "require": {
        "goaop/framework": "^2.1"
    },
	"autoload": {
        "psr-4": {
          "Goaop\\Aspect\\": "aspect"
		}
	}
}

Expected Result:
Before method
Test condition working fine

Output
Test condition working fine

Same component which work in below configuration

Version Details
PHP 5.4 (cli)
GOAOP 0.5.0

please help me on this to resolve

thanks in advance
krishna

lisachenko added a commit that referenced this issue Mar 26, 2017
* origin/1.x:
  Do not try to use CachedAspectLoader when cache is not configured, related to #319
@lisachenko
Copy link
Member

Hi! Sorry for the late response.

I manually checked your source code and detected several issues:

  1. Your application rootDir option was set to the app folder and not to the aspect directory where test class is located, so AOP engine just ignores files from other directories. Need to specify valid directory, for example, 'appDir' => __DIR__ . '/../aspect'
  2. You didn't specify valid cache directory to store transformed files and modern version of framework heavily rely on caching. There was also a bug in GoAspectContainer class, which is fixed now in the master branch. So you can try you example one more time with configured cacheDir or by updating AOP to the dev-master manually for testing.

@lisachenko
Copy link
Member

After that you will get expected string:

Before method Test condition working fine 

@team-ultra
Copy link
Author

Thank you so much @lisachenko, working as expected 👍

@lisachenko
Copy link
Member

You are welcome!

@lisachenko lisachenko added this to the 2.1.1 milestone Apr 25, 2017
@sonicoder86
Copy link

@lisachenko This issue is related to Codeception/AspectMock#146
When i specify the cache directory, throws another error.

It is definitely a breaking change introduced in a feature version.
Before cache directory was not necessary.

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

No branches or pull requests

3 participants