Ejemplo n.º 1
0
 /**
  * @param array $ruleArray
  */
 protected function parseRules(array $ruleArray)
 {
     $rules = array();
     $currentRule = new Rule();
     foreach ($ruleArray as $ruleLine) {
         if ('' === $ruleLine) {
             continue;
         }
         $matches = array();
         $isMatch = preg_match('/^(?P<chapter>[0-9])(?P<major>[0-9]{2})?\\.(?P<minor>[0-9]+)?(?:(?P<paragraph>[a-z])|\\.)?\\s*/S', $ruleLine, $matches);
         if (!$isMatch) {
             $currentRule->addRuletextLine($ruleLine);
             continue;
         }
         $depth = 1;
         $id = rtrim(trim($matches[0]), '.');
         $subId = rtrim(trim(end($matches)), '.');
         $currentRule = new Rule();
         $currentRule->setId($id)->setSubId($subId)->setRuletext(substr($ruleLine, strlen($matches[0])));
         $this->objectManager->persist($currentRule);
         if (empty($matches['major'])) {
             $currentRule->setDepth($depth);
             $rules[$matches['chapter']] = $currentRule;
             continue;
         }
         ++$depth;
         $parentRule = $rules[$matches['chapter']];
         if (!empty($matches['minor'])) {
             $parentRule = $parentRule->getChildRule($matches['major']);
             ++$depth;
         }
         if (!empty($matches['paragraph'])) {
             $parentRule = $parentRule->getChildRule($matches['minor']);
             ++$depth;
         }
         $currentRule->setDepth($depth);
         $parentRule->addChildRule($currentRule);
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function setId($id)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setId', array($id));
     return parent::setId($id);
 }