PHP code example of coolephp / goaop

1. Go to this page and download the library: Download coolephp/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/ */

    

coolephp / goaop example snippets

 php


return [
    /*
     * App 名称
     */
    'name' => env('APP_NAME', 'Coole'),
    
    ...

    /*
     * 第三方服务
     */
    'providers' => [
        \Coole\Goaop\GoAopServiceProvider::class
    ],
    
    ...
];

 php


return [
    /*
     * AOP Debug Mode
     */
    'debug' => env('GOAOP_DEBUG', env('APP_DEBUG', false)),
    
    ...
    
    /*
     * Yours aspects
     */
    'aspects' => [
        \App\Aspect\LoggingServiceAspect::class,
    ],
];
 php


namespace App\Service;

class LoggingService
{
    public static function logging()
    {
        return true;
    }
}
 php


namespace App\Aspect;

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

class LoggingServiceAspect implements Aspect
{
    /**
     * Method that will be called before real method.
     *
     * @param MethodInvocation $invocation Invocation
     * @Before("execution(public App\Service\LoggingService::logging(*))")
     */
    public function beforeMethodExecution(MethodInvocation $invocation)
    {
        file_put_contents(base_path('runtime/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 App\Service\LoggingService::logging(*))")
     */
    public function afterMethodExecution(MethodInvocation $invocation)
    {
        file_put_contents(base_path('runtime/logging.log'), 'this is a after method testing.'.PHP_EOL, FILE_APPEND);
    }
}