Author: XE Developers (developers@xpressengine.com)
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton(['xe.interception' => InterceptionHandler::class], function ($app) {
         $advisorCollection = new AdvisorCollection();
         $loader = new FileLoader(storage_path('app/interception'), $app['config']->get('app.debug') === true);
         //$loader = new EvalLoader();
         $passes = [new ClassPass(), new MethodDefinitionPass()];
         $generator = new ProxyGenerator($loader, $passes);
         if ($app->runningInConsole()) {
             $generator->clear();
         }
         $interceptionHandler = new InterceptionHandler($advisorCollection, $generator);
         return $interceptionHandler;
     });
 }
Ejemplo n.º 2
0
 /**
  * 타겟 클래스의 프록시 클래스를 생성하여 로드하고, 생성된 프록시 클래스 이름을 반환한다.
  * 만약 어떤 클래스에 interception을 적용하고 싶을 때 이 메소드를 사용하면 된다.
  *
  * ```
  * $targetClassName = 'My\Namespace\PostManager';
  * $proxyClass = XeInterception::proxy($targetClass, 'Post');
  *
  * $postManager = new $proxyClass();
  * ```
  * 두번째 파라메터를 사용하여 타겟클래스의 alias 이름을 등록할 수 있다. alias 이름을 지정하면,
  * 타겟 클래스에 interception을 등록할 때, alias 이름을 사용할 수 있다.
  *
  * ```
  * // Post alias를 사용
  * intercept('Post@insert', 'spam_filter', function(){...});
  * ```
  *
  * @param string      $targetClass 타겟 클래스
  * @param string|null $alias       타겟 클래스의 별칭
  *
  * @return string
  */
 public function proxy($targetClass, $alias = null)
 {
     $targetClass = trim($targetClass);
     if ($alias !== null) {
         $this->advisorCollection->setAlias($alias, $targetClass);
     }
     $proxyClass = $this->proxyGenerator->generate($targetClass);
     $this->proxyList[$targetClass] = $proxyClass;
     return $proxyClass;
 }
 /**
  * 기생성된 Proxy 파일을 모두 삭제한다.
  *
  * @return void
  */
 public function clearProxies()
 {
     $this->proxyGenerator->clear();
 }