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/ */
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);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.