PHP code example of goaop / framework

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

    

goaop / framework example snippets


if (isset($this->property) || $__joinPoint->getField()->isInitialized($this)) {
    return $__joinPoint->read($this, $this->property);
} else {
    return $__joinPoint->read($this);
}


// app/ApplicationAspectKernel.php

use Go\Core\AspectKernel;
use Go\Core\AspectContainer;

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

    /**
     * Configure an AspectContainer with advisors, aspects and pointcuts
     */
    protected function configureAop(AspectContainer $container): void
    {
    }
}


// public/index.php

ion aspect container
$applicationAspectKernel = ApplicationAspectKernel::getInstance();
$applicationAspectKernel->init([
    'debug'        => true, // use 'false' for production mode
    'appDir'       => __DIR__ . '/..', // Application root directory
    'cacheDir'     => __DIR__ . '/../var/cache/aop', // Cache directory
    // Include paths restricts the directories where aspects should be applied, or empty for all source files
    '



// Aspect/MonitorAspect.php

namespace Aspect;

use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Attribute\Before;

/**
 * Monitor aspect
 */
class MonitorAspect implements Aspect
{

    /**
     * Method that will be called before real method
     */
    #[Before("execution(public Example->*(*))")]
    public function beforeMethodExecution(MethodInvocation $invocation): void
    {
        echo 'Calling Before Interceptor for: ',
            $invocation,
            ' with arguments: ',
            json_encode($invocation->getArguments()),
            "<br>\n";
    }
}

static $__joinPoint = InterceptorInjector::forMethod(
    self::class,
    'doSomething',
    [
        Interceptor::before(The::aspect(MonitorAspect::class)->beforeMethodExecution(...)),
    ],
    $this->doSomethingOriginalAlias(...),
);

Interceptor::around(The::advice('advisor.Demo\Aspect\DynamicMethodsAspect->aroundMagicMethods')),


// app/ApplicationAspectKernel.php

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

//...

    protected function configureAop(AspectContainer $container): void
    {
        // Deferred (recommended): constructed on first use
        $container->addLazyService(MonitorAspect::class, static fn() => new MonitorAspect());

        // Eager alternative: $container->add(MonitorAspect::class, new MonitorAspect());
    }

//...

use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Go\Bridge\Doctrine\WovenEntityClassLocator;

$configuration->setMetadataDriverImpl(
    new AttributeDriver(WovenEntityClassLocator::createFromDirectories([__DIR__ . '/src/Entity'])),
);

use Doctrine\ORM\Events;
use Go\Bridge\Doctrine\MetadataLoadInterceptor;

$configuration->enableNativeLazyObjects(true);
$eventManager->addEventListener(Events::loadClassMetadata, new MetadataLoadInterceptor());