Exemplo n.º 1
0
 protected function joomlaHookTest()
 {
     $testProjectPath = realpath('../../../administrator');
     $this->nonequ($testProjectPath, false);
     $aop = AOP::getInstance($testProjectPath);
     $aop->addPointCut(PointCut::getInstance()->setFilename('index.php'));
     $pointCut = PointCut::getInstance();
     $pointCut->setFilename('/components/com_login/controller.php');
     //$pointCut->setNamespace('');
     $pointCut->setClass('LoginController');
     $pointCut->setFunction('login');
     $pointCut->setType('before');
     $pointCut->setCallback('gymadarasz\\aop\\AOPTests::testJoomlaAdminLoginBefore');
     $aop->addPointCut($pointCut);
     $aop->infect();
 }
Exemplo n.º 2
0
 public static function hook($filename)
 {
     $hookfname = $filename . '.aop.php';
     if (!file_exists($hookfname)) {
         // todo ...
         $cwd = getcwd();
         $hookfname = $cwd . DIRECTORY_SEPARATOR . pathinfo($filename, PATHINFO_BASENAME) . '.aop.php';
         if (!file_exists($hookfname)) {
             $includePaths = explode(';', get_include_path());
             $found = false;
             foreach ($includePaths as $includePath) {
                 $hookfname = $includePath . DIRECTORY_SEPARATOR . pathinfo($filename, PATHINFO_BASENAME) . '.aop.php';
                 if (file_exists($hookfname)) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 $errmsg = 'Hook (.aop.php) not found for ' . $filename;
                 if (self::EXCEPTION_ON_HOOK_NOT_FOUND) {
                     throw new \Exception($errmsg);
                 }
                 if (self::WARNING_ON_HOOK_NOT_FOUND) {
                     trigger_error($errmsg);
                 }
                 self::$errors[] = $errmsg;
                 $hookfname = PointCut::getInstance()->hook($filename);
                 PointCut::saveHooks();
             }
         } else {
             $hookfname = $filename;
         }
     }
     return $hookfname;
 }