/**
  * Creates a rule description instance with specified XML string. 
  * 
  * @param string $ruleDescriptionXml A XML string representing the 
  * rule description.
  * 
  * @return none
  */
 public static function create($ruleDescriptionXml)
 {
     $ruleDescription = new RuleDescription();
     $root = simplexml_load_string($ruleDescriptionXml);
     $nameSpaces = $root->getNameSpaces();
     $ruleDescriptionArray = (array) $root;
     if (array_key_exists('Filter', $ruleDescriptionArray)) {
         $filterItem = $ruleDescriptionArray['Filter'];
         $filterAttributes = $filterItem->attributes('i', true);
         $filterItemArray = (array) $filterItem;
         $filterType = (string) $filterAttributes['type'];
         $filter = null;
         switch ($filterType) {
             case 'TrueFilter':
                 $filter = new TrueFilter();
                 break;
             case 'FalseFilter':
                 $filter = new FalseFilter();
                 break;
             case 'CorrelationFilter':
                 $filter = new CorrelationFilter();
                 if (array_key_exists('CorrelationId', $filterItemArray)) {
                     $filter->setCorrelationId((string) $filterItemArray['CorrelationId']);
                 }
                 break;
             case 'SqlFilter':
                 $filter = new SqlFilter();
                 if (array_key_exists('SqlExpression', $filterItemArray)) {
                     $filter->setSqlExpression((string) $filterItemArray['SqlExpression']);
                 }
                 break;
             default:
                 $filter = new Filter();
         }
         if (array_key_exists('CompatibilityLevel', $filterItemArray)) {
             $filter->setCompatibilityLevel((int) $filterItemArray['CompatibilityLevel']);
         }
         $ruleDescription->setFilter($filter);
     }
     if (array_key_exists('Action', $ruleDescriptionArray)) {
         $actionItem = $ruleDescriptionArray['Action'];
         $actionAttributes = $actionItem->attributes('i', true);
         $actionType = (string) $actionAttributes['type'];
         $action = null;
         switch ($actionType) {
             case 'EmptyRuleAction':
                 $action = new EmptyRuleAction();
                 break;
             case 'SqlRuleAction':
                 $action = new SqlRuleAction();
                 if (array_key_exists('SqlExpression', $actionItem)) {
                     $action->setSqlExpression((string) $actionItem['SqlExpression']);
                 }
                 break;
             default:
                 $action = new Action();
         }
         $ruleDescription->setAction($action);
     }
     if (array_key_exists('Name', $ruleDescriptionArray)) {
         $ruleDescription->setName((string) $ruleDescriptionArray['Name']);
     }
     return $ruleDescription;
 }
Example #2
0
 /** 
  * Creates a true filter with default parameter. 
  */
 public function __construct()
 {
     parent::__construct();
     $this->attributes['xsi:type'] = 'TrueFilter';
 }