PHP code example of guanguans / yii-goaop

1. Go to this page and download the library: Download guanguans/yii-goaop library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

guanguans / yii-goaop example snippets

 php


return [
    'bootstrap' => [
        'aop',
    ],
    'components' => [
        'aop' => [
            'class'   => 'Guanguans\YiiGoAop\GoAopComponent',
            'initOptions'  => [
                // AOP Debug Mode
                'debug'          => false,
                // Application Root Directory
                'appDir'         => dirname(dirname(__DIR__)),
                // AOP Cache Directory
                'cacheDir'       => dirname(__DIR__).'/runtime/aspect',
                // Cache File Mode
                'cacheFileMode'  => 511,
                // Miscellaneous AOP Engine Features
                'features'       => 0,
                // Directories White List
                '
 php


namespace frontend\aspects;

use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Before;
use Go\Lang\Annotation\After;
use Yii;

class LoggingAspect implements Aspect
{
    /**
     * Method that will be called before real method
     * @param  MethodInvocation  $invocation  Invocation
     * @Before("execution(public frontend\controllers\SiteController->*Index(*))")
     */
    public function beforeMethodExecution(MethodInvocation $invocation)
    {
        file_put_contents(Yii::$app->getRuntimePath().'/logs/logging.log', 'this is a before method testing.'.PHP_EOL, FILE_APPEND);
    }

    /**
     * Method that will be called after real method
     * @param  MethodInvocation  $invocation  Invocation
     * @After("execution(public frontend\controllers\SiteController->*Index(*))")
     */
    public function afterMethodExecution(MethodInvocation $invocation)
    {
        file_put_contents(Yii::$app->getRuntimePath().'/logs/logging.log', 'this is a after method testing.'.PHP_EOL, FILE_APPEND);
    }
}