vendor/codeages/biz-framework/src/Service/ServiceProxy.php line 36

Open in your IDE?
  1. <?php
  2. namespace Codeages\Biz\Framework\Service;
  3. use Codeages\Biz\Framework\Context\Biz;
  4. class ServiceProxy
  5. {
  6.     private $biz;
  7.     private $className;
  8.     private $class;
  9.     private $interceptors;
  10.     private $interceptorDatas = array();
  11.     public function __construct(Biz $biz$className)
  12.     {
  13.         $this->biz $biz;
  14.         $this->className $className;
  15.         $this->class = new $className($biz);
  16.         $this->handleInterceptors();
  17.     }
  18.     public function __call($funcName$arguments)
  19.     {
  20.         $beforeResult = array();
  21.         foreach ($this->interceptorDatas as $interceptorName => $interceptorData) {
  22.             if (!empty($interceptorData[$funcName])) {
  23.                 try {
  24.                     $beforeResult $this->interceptors[$interceptorName]->beforeExec($funcName$arguments);
  25.                 } catch (\Exception $exception) {
  26.                     throw $exception;
  27.                 }
  28.             }
  29.         }
  30.         $result call_user_func_array(array($this->class$funcName), $arguments);
  31.         foreach ($this->interceptorDatas as $interceptorName => $interceptorData) {
  32.             if (!empty($interceptorData[$funcName])) {
  33.                 $this->interceptors[$interceptorName]->afterExec($funcName$arguments$result$beforeResult);
  34.             }
  35.         }
  36.         return $result;
  37.     }
  38.     public function getClassName()
  39.     {
  40.         return $this->className;
  41.     }
  42.     public function getClass()
  43.     {
  44.         return $this->class;
  45.     }
  46.     public function handleInterceptors()
  47.     {
  48.         $biz $this->biz;
  49.         foreach ($biz['interceptors'] as $name => $interceptor) {
  50.             $this->interceptors[$name] = new $interceptor($this->biz$this->className);
  51.             $this->interceptorDatas[$name] = $this->interceptors[$name]->getInterceptorData();
  52.         }
  53.     }
  54. }