Пример #1
0
 /**
  * weaving
  */
 public function weave()
 {
     if (is_null($this->aspectResolver)) {
         return;
     }
     foreach ($this->aspectResolver->getResolver() as $class => $pointcuts) {
         $bind = (new AspectBind($this->filesystem, $this->configure['cache_dir'], $this->cacheable))->bind($class, $pointcuts);
         $compiledClass = $this->compiler->compile($class, $bind);
         if (isset($this->app->contextual[$class])) {
             $this->resolveContextualBindings($class, $compiledClass);
         }
         $this->app->bind($class, function (Container $app) use($bind, $compiledClass) {
             $instance = $app->make($compiledClass);
             $instance->bindings = $bind->getBindings();
             return $instance;
         });
     }
 }
Пример #2
0
<?php

require __DIR__ . '/vendor/autoload.php';
use Ray\Aop\Pointcut;
use Ray\Aop\Matcher;
use Ray\Aop\Bind;
use Ray\Aop\Compiler;
$pointcut = new Pointcut((new Matcher())->any(), (new Matcher())->annotatedWith(BlockEveryDay::class), [new EverydayBlocker()]);
$bind = (new Bind())->bind(NotRelatedService::class, [$pointcut]);
$tmpDir = __DIR__ . '/tmp';
$compiler = new Compiler($tmpDir);
$billing = $compiler->newInstance(RealBillingService::class, [], $bind);
try {
    echo $billing->chargeOrder() . "\n";
} catch (RuntimeException $e) {
    echo $e->getMessage() . "\n";
    exit(1);
}