Author: XE Developers (developers@xpressengine.com)
コード例 #1
0
 /**
  * advisor를 추가한다.
  *
  * @param Advisor $advisor  추가하려는 advisor
  * @param null    $relation 추가하려는 advisor의 before, after 관계에 있는 advisor 목록. 아래와 같은 형식이 될 수 있다.
  *                          ```
  *                          ['before'=>'advisor1', 'after'=>['advisor2','advisor3']]
  *                          ```
  *
  * @return void
  */
 public function put(Advisor $advisor, $relation = null)
 {
     $name = $advisor->getName();
     $pointCutStrList = $advisor->getPointCut();
     // add advisor
     if (array_key_exists($name, $this->advisorArr)) {
         throw new AdvisorNameAlreadyExistsException(['name' => $name]);
     }
     $this->advisorArr[$name] = $advisor;
     foreach ($pointCutStrList as $pointCutStr) {
         list($class, $method) = explode('@', $pointCutStr);
         if (isset($this->aliases[$class])) {
             //$pointCutStr = $this->aliases[$class].'@'.$method;
             $class = $this->aliases[$class];
         }
         $box = $this->getPointCutBox($class, $method);
         $box->advisorArr[] = $name;
     }
     // add relation
     $added = false;
     if (isset($relation['before']) && $relation['before'] !== null) {
         $this->sorter->add($name, Sorter::BEFORE, $relation['before']);
         $added = true;
     }
     if (isset($relation['after']) && $relation['after'] !== null) {
         $this->sorter->add($name, Sorter::AFTER, $relation['after']);
         $added = true;
     }
     if (!$added) {
         $this->sorter->add($name);
     }
 }
コード例 #2
0
 /**
  * @depends testCreate
  *
  */
 public function testSetAdvice(Advisor $advisor)
 {
     $advisor->setAdvice(function ($target, $args) {
         return $target($args) . 'bar';
     });
     $advice = $advisor->getAdvice();
     $this->assertEquals('foobar', $advice(function ($arg) {
         return $arg;
     }, 'foo'));
 }