示例#1
0
 /**
  * @param string $xmlContent
  * @return Miaox_Aop_XmlElement
  */
 public static function &fromString($xmlContent)
 {
     $xmlReader = new Miaox_Aop_XmlReader($xmlContent);
     return $xmlReader->_parse($xmlContent);
 }
示例#2
0
 /**
  * Инициализация объекта
  *
  */
 public function init()
 {
     // Checking if file exists
     if (!file_exists($this->_xmlFile)) {
         throw new Miaox_Aop_Exception("<b>[ Aspect Error ]:</b> File <b>" . $this->_xmlFile . "</b> does not exist!");
     }
     // Get file contents
     $fContent = implode("", file($this->_xmlFile));
     // Parse XML file into an array map
     $xmlReader = Miaox_Aop_XmlReader::fromString($fContent);
     // Solve Advice src directory reference. Changes actual working directory
     $oldWorkDir = getcwd();
     chdir(dirname(realpath($this->_xmlFile)));
     // Check for Root Element
     if (strtolower($xmlReader->getTag()) == "aspect") {
         foreach ($xmlReader->getChildNodes() as $k => $v) {
             if ($v->getTag() == "pointcut") {
                 // Check for attributes
                 $class = $v->getAttribute("class") === null ? "" : $v->getAttribute("class");
                 $function = $v->getAttribute("function") === null ? "" : $v->getAttribute("function");
                 $nclass = $v->getAttribute("nclass") === null ? "" : $v->getAttribute("nclass");
                 $nfunction = $v->getAttribute("nfunction") === null ? "" : $v->getAttribute("nfunction");
                 // Implement some advice code creation via appending fragments
                 $advice = new Miaox_Aop_Advice();
                 foreach ($v->getChildNodes() as $c => $a) {
                     // Append Advice fragment, depending from its source ( CDATA or External File )
                     if ($a->getTag() == "advice") {
                         $asRequire = $a->getAttribute("asrequire") === null ? "" : trim($a->getAttribute("asrequire"));
                         if ($asRequire == "true") {
                             $adviceCode = " require \"" . realpath(getcwd() . "/" . $a->getAttribute("src")) . "\"; ";
                         } else {
                             if ($asRequire == "" || $asRequire == "false") {
                                 $adviceCode = implode("", file($a->getAttribute("src")));
                                 if (substr($adviceCode, 0, 2) == "<?") {
                                     // Crop begin and end of archive
                                     if (substr($adviceCode, 2, 3) == "php") {
                                         $adviceCode = substr($adviceCode, 5);
                                     } else {
                                         $adviceCode = substr($adviceCode, 2);
                                     }
                                 } else {
                                     $adviceCode = "?>" . $adviceCode;
                                 }
                                 if (substr($adviceCode, -2, 2) == "?>") {
                                     $adviceCode = substr($adviceCode, 0, -2);
                                 } else {
                                     $adviceCode .= "<?php";
                                 }
                             } else {
                                 throw new Miaox_Aop_Exception("<b>[ Aspect Error ]:</b> Undefined value <b>" . $asRequire . "</b> for advice tag!");
                             }
                         }
                     } else {
                         $adviceCode = $a->getValue();
                     }
                     $advice->addData($adviceCode);
                 }
                 // Appending AutoPointcut or CustomPointcut to PointcutList
                 if ($v->getAttribute("name") === null && $v->getAttribute("auto") !== null) {
                     $this->addPointcut(new Miaox_Aop_Pointcut_Auto($advice, $class, $function, $v->getAttribute("auto"), $nclass, $nfunction));
                 } else {
                     if ($v->getAttribute("name") !== null && $v->getAttribute("auto") === null) {
                         $this->addPointcut(new Miaox_Aop_Pointcut_Custom($advice, $class, $function, $v->getAttribute("name"), $nclass, $nfunction));
                     }
                 }
             }
         }
     }
     // Re-configure Work directory
     chdir($oldWorkDir);
     // Lazy load flag change
     $this->_initialized = true;
 }