Наследование: extends Eloquent
Пример #1
0
 public function __construct($declarations_string, Rule $rule)
 {
     parent::__construct();
     $pairs = DeclarationList::parse($declarations_string);
     foreach ($pairs as $index => $pair) {
         list($prop, $value) = $pair;
         // Directives.
         if ($prop === 'extends') {
             $rule->setExtendSelectors($value);
             unset($pairs[$index]);
         } elseif ($prop === 'name') {
             if (!$rule->name) {
                 $rule->name = $value;
             }
             unset($pairs[$index]);
         }
     }
     // Build declaration list.
     foreach ($pairs as $index => &$pair) {
         list($prop, $value) = $pair;
         if (trim($value) !== '') {
             if ($prop === 'mixin') {
                 $this->flattened = false;
                 $this->store[] = $pair;
             } else {
                 // Only store to $this->data if the value does not itself make a
                 // this() call to avoid circular references.
                 if (!preg_match(Regex::$patt->thisFunction, $value)) {
                     $this->data[strtolower($prop)] = $value;
                 }
                 $this->add($prop, $value, $index);
             }
         }
     }
 }
Пример #2
0
function plugin_typology_uninstall()
{
    global $DB;
    // Plugin tables deletion
    $tables = array("glpi_plugin_typology_profiles", "glpi_plugin_typology_typologies", "glpi_plugin_typology_typologycriterias", "glpi_plugin_typology_typologycriteriadefinitions", "glpi_plugin_typology_typologies_items");
    foreach ($tables as $table) {
        $DB->query("DROP TABLE IF EXISTS `{$table}`;");
    }
    // Plugin adding information on general table deletion
    $tables_glpi = array("glpi_displaypreferences", "glpi_documents_items", "glpi_bookmarks", "glpi_logs");
    foreach ($tables_glpi as $table_glpi) {
        $DB->query("DELETE FROM `{$table_glpi}` WHERE `itemtype` = 'PluginTypologyTypology';");
    }
    //drop rules
    $Rule = new Rule();
    $a_rules = $Rule->find("`sub_type`='PluginTypologyRuleTypology'");
    foreach ($a_rules as $data) {
        $Rule->delete($data);
    }
    $notif = new Notification();
    $options = array('itemtype' => 'PluginTypologyTypology', 'event' => 'AlertNotValidatedTypology', 'FIELDS' => 'id');
    foreach ($DB->request('glpi_notifications', $options) as $data) {
        $notif->delete($data);
    }
    return true;
}
Пример #3
0
 public function add(Rule $rule, $type)
 {
     if (!isset(self::$types[$type])) {
         throw new \OutOfBoundsException('Unknown rule type: ' . $type);
     }
     $hash = $rule->getHash();
     // Do not add if rule already exists
     if (isset($this->rulesByHash[$hash])) {
         $potentialDuplicates = $this->rulesByHash[$hash];
         foreach ($potentialDuplicates as $potentialDuplicate) {
             if ($rule->equals($potentialDuplicate)) {
                 return;
             }
         }
     }
     if (!isset($this->rules[$type])) {
         $this->rules[$type] = array();
     }
     $this->rules[$type][] = $rule;
     $this->ruleById[$this->nextRuleId] = $rule;
     $rule->setType($type);
     $this->nextRuleId++;
     if (!isset($this->rulesByHash[$hash])) {
         $this->rulesByHash[$hash] = array($rule);
     } else {
         $this->rulesByHash[$hash][] = $rule;
     }
 }
Пример #4
0
 /**
  * Creates a new node watching the first and second literals of the rule.
  *
  * @param Rule $rule The rule to wrap
  */
 public function __construct($rule)
 {
     $this->rule = $rule;
     $literals = $rule->getLiterals();
     $this->watch1 = count($literals) > 0 ? $literals[0] : 0;
     $this->watch2 = count($literals) > 1 ? $literals[1] : 0;
 }
Пример #5
0
 /**
  * @param \Rule $rule
  * @param string $format
  * @return string $message
  */
 private function localize($rule, $format = null)
 {
     $reflection = new ReflectionClass($rule);
     $rule_name = strtolower($reflection->getShortName());
     $format = $rule->message(!$format ? $this->getLocalizedString($rule_name) : $format);
     return $format;
 }
Пример #6
0
 private function register(Rule $rule)
 {
     if (!isset($this->rules[$rule->getNodeType()])) {
         $this->rules[$rule->getNodeType()] = [];
     }
     $this->rules[$rule->getNodeType()][] = $rule;
 }
Пример #7
0
 /**
  * Transform file content to structured Rules
  * @return Rules The valid ruleset
  */
 public function parse()
 {
     $rules = new Rules();
     $userAgent = $rule = null;
     $separator = "\r\n";
     $line = strtok($this->content, $separator);
     while ($line !== false) {
         if (strpos($line, '#') !== 0) {
             if (preg_match('/^User-Agent\\: (.*)$/i', $line, $matches)) {
                 if ($userAgent !== null && $rule !== null) {
                     $rules->add($userAgent, $rule);
                 }
                 $userAgent = $matches[1];
                 $rule = new Rule();
             } elseif (preg_match('/^Allow: (.*)$/i', $line, $matches)) {
                 $rule->allow($matches[1]);
             } elseif (preg_match('/^Disallow: (.*)$/i', $line, $matches)) {
                 $rule->disallow($matches[1]);
             }
         }
         $line = strtok($separator);
     }
     //Handle the last item in the loop
     if ($rule instanceof Rule) {
         $rules->add($userAgent, $rule);
     }
     return $rules;
 }
Пример #8
0
 /**
  * resolves the identifier
  *
  * @param string|Rule $identifier
  *
  * @return string
  */
 private function resolveIdentifier($identifier)
 {
     if ($identifier instanceof Rule) {
         return $identifier->identifier();
     }
     return $identifier;
 }
 /**
  * @inheritdoc
  */
 public function getRules()
 {
     $rules = new Rules();
     if (!array_key_exists('rules', $this->data)) {
         throw new ConfigurationException(".INI Configuration must contain 'rules' section.");
     }
     foreach ($this->data['rules'] as $patternStr => $probability) {
         $pattern = new RulePattern((int) $probability);
         $startToken = '';
         foreach (explode(' ', $patternStr) as $tokenStr) {
             if (strlen($tokenStr) <= 2) {
                 throw new ConfigurationException("Pattern {$patternStr}: Token {$tokenStr} must exceed 2 characters.");
             }
             $isStartToken = false;
             if ($tokenStr[0] === '<' && substr($tokenStr, -1) === '>') {
                 $isStartToken = true;
                 $tokenStr = substr($tokenStr, 1, -1);
                 $startToken = $tokenStr;
             }
             $token = new RulePatternToken($tokenStr, $isStartToken);
             $pattern->addToken($token);
         }
         if (empty($startToken)) {
             throw new ConfigurationException("Pattern {$patternStr}: Must contain start token.");
         }
         $rule = new Rule($startToken);
         $rule->addPattern($pattern);
         $rules->addRule($rule);
     }
     return $rules;
 }
Пример #10
0
 /**
  * @param Rule $rule
  */
 public function addRule(Rule $rule)
 {
     if (array_key_exists($rule->getTokenName(), $this->rules)) {
         $this->rules[$rule->getTokenName()]->addPatterns($rule->getPatterns());
     } else {
         $this->rules[$rule->getTokenName()] = $rule;
     }
 }
Пример #11
0
 function addRule($indent, $lines, &$out)
 {
     $rule = new Rule($this, $lines);
     $this->rules[$rule->name] = $rule;
     $out[] = $indent . '/* ' . $rule->name . ':' . $rule->rule . ' */' . PHP_EOL;
     $out[] = $rule->compile($indent);
     $out[] = PHP_EOL;
 }
 public function _applies()
 {
     try {
         $output = (bool) $this->decoree->applies();
     } catch (Exception $e) {
         $output = $this->supressed_result;
     }
     return $output;
 }
 /**
  * @test
  */
 public function prepareDB()
 {
     global $DB;
     $DB->connect();
     $_SESSION['glpiactive_entity'] = 0;
     $_SESSION["plugin_fusioninventory_entity"] = 0;
     $_SESSION["glpiname"] = 'Plugin_FusionInventory';
     $rule = new Rule();
     $ruleCriteria = new RuleCriteria();
     $ruleAction = new RuleAction();
     // * computer model assign
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'computer model', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/latitude(.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'computermodels_id', 'value' => 1);
     $this->ruleactions_id = $ruleAction->add($input);
     // * computer model regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'computer model 2', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/longitude(.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'regex_result', 'field' => 'computermodels_id', 'value' => '#0');
     $this->ruleactions_id = $ruleAction->add($input);
     // * user regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'user', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/user (.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'regex_result', 'field' => 'user', 'value' => '#0');
     $this->ruleactions_id = $ruleAction->add($input);
     // * softwareversion regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'softwareversion 3.0', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/version (.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'regex_result', 'field' => 'softwareversion', 'value' => '#0');
     $this->ruleactions_id = $ruleAction->add($input);
     // * otherserial regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'otherserial', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/other (.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'regex_result', 'field' => 'otherserial', 'value' => '#0');
     $this->ruleactions_id = $ruleAction->add($input);
     // * otherserial regex
     $input = array('entities_id' => 0, 'sub_type' => 'PluginFusioninventoryCollectRule', 'name' => 'otherserial assign', 'match' => 'AND');
     $rules_id = $rule->add($input);
     $input = array('rules_id' => $rules_id, 'criteria' => 'filename', 'condition' => 6, 'pattern' => "/serial (.*)/");
     $ruleCriteria->add($input);
     $input = array('rules_id' => $rules_id, 'action_type' => 'assign', 'field' => 'otherserial', 'value' => 'ttuujj');
     $this->ruleactions_id = $ruleAction->add($input);
     // * create items
     $computerModel = new ComputerModel();
     $input = array('name' => '6430u');
     $computerModel->add($input);
 }
 /**
  * Add computer in entity `ent1` (with rules)
  *
  * @test
  */
 public function AddComputer()
 {
     global $DB;
     $DB->connect();
     plugin_init_fusioninventory();
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`)\n         VALUES (1, 'ent1', 0, 'Entité racine > ent1', 2)");
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`)\n         VALUES (2, 'ent2', 0, 'Entité racine > ent2', 2)");
     $_SESSION['glpiactive_entity'] = 0;
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     $computer = new Computer();
     $pfEntity = new PluginFusioninventoryEntity();
     $pfEntity->update(array('id' => 1, 'entities_id' => 0, 'transfers_id_auto' => 1));
     $a_inventory = array();
     $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc1');
     $a_inventory['CONTENT']['BIOS'] = array('SSN' => 'xxyyzz');
     // * Add rule ignore
     $rule = new Rule();
     $ruleCriteria = new RuleCriteria();
     $ruleAction = new RuleAction();
     $input = array();
     $input['sub_type'] = 'PluginFusioninventoryInventoryRuleEntity';
     $input['name'] = 'pc1';
     $input['match'] = 'AND';
     $input['is_active'] = 1;
     $rules_id = $rule->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['criteria'] = 'name';
     $input['condition'] = 0;
     $input['pattern'] = 'pc1';
     $ruleCriteria->add($input);
     $input = array();
     $input['rules_id'] = $rules_id;
     $input['action_type'] = 'assign';
     $input['field'] = 'entities_id';
     $input['value'] = 1;
     $ruleAction->add($input);
     // ** Add agent
     $pfAgent = new PluginFusioninventoryAgent();
     $a_agents_id = $pfAgent->add(array('name' => 'pc-2013-02-13', 'device_id' => 'pc-2013-02-13'));
     $_SESSION['plugin_fusioninventory_agents_id'] = $a_agents_id;
     // ** Add
     $pfiComputerInv->import("pc-2013-02-13", "", $a_inventory);
     // creation
     $computer->getFromDB(1);
     $this->assertEquals(1, $computer->fields['entities_id'], 'Add computer');
     $this->AgentEntity(1, 1, 'Add computer on entity 1');
     // ** Update
     $pfiComputerInv->import("pc-2013-02-13", "", $a_inventory);
     // update
     $nbComputers = countElementsInTable("glpi_computers");
     $this->assertEquals(1, $nbComputers, 'Nb computer for update computer');
     $computer->getFromDB(1);
     $this->assertEquals(1, $computer->fields['entities_id'], 'Update computer');
     $this->AgentEntity(1, 1, 'Update computer on entity 1 (not changed)');
 }
Пример #15
0
 public function setRules($rules)
 {
     $this->rules()->delete();
     foreach ($rules as $rule) {
         $ruleModel = new Rule($rule);
         if (isset($rule['conditions'])) {
             $ruleModel->setConditions($rule['conditions']);
         }
         $this->rules()->associate($ruleModel);
     }
     return $this;
 }
Пример #16
0
 /**
  * @inheritdoc
  */
 public function getRules()
 {
     $data = $this->data;
     $rules = new Rules();
     foreach ($data->rule as $ruleData) {
         $rule = new Rule((string) $ruleData->token);
         $patternIdx = 0;
         foreach ($ruleData->patterns->pattern as $patternData) {
             $patternName = "Pattern {$rule->getTokenName()}#{$patternIdx}";
             $hasStartToken = false;
             $potentialStartTokenIdxs = [];
             $tokens = [];
             foreach ($patternData->token as $tokenData) {
                 $tokenName = (string) $tokenData;
                 $isStartToken = (bool) $tokenData['is_start_token'];
                 $tokens[] = ['name' => $tokenName, 'is_start_token' => $isStartToken];
                 if ($isStartToken) {
                     if ($tokenName !== $rule->getTokenName()) {
                         throw new ConfigurationException("{$patternName}: Only {$rule->getTokenName()} tokens can have the 'is_start_token' attribute.");
                     }
                     if ($hasStartToken) {
                         throw new ConfigurationException("{$patternName}: Multiple {$rule->getTokenName()} tokens with 'is_start_token' attribute found. Only one is allowed.");
                     } else {
                         $hasStartToken = true;
                     }
                 }
                 if ($tokenName === $rule->getTokenName()) {
                     $potentialStartTokenIdxs[] = count($tokens) - 1;
                 }
             }
             if (!$hasStartToken) {
                 if (count($potentialStartTokenIdxs) === 0) {
                     throw new ConfigurationException("Pattern {$rule->getTokenName()}/#{$patternIdx} must have unambiguous start token. No {$rule->getTokenName()} token found.");
                 } elseif (count($potentialStartTokenIdxs) > 1) {
                     throw new ConfigurationException("Pattern {$rule->getTokenName()}/#{$patternIdx} must have unambiguous start token. Multiple {$rule->getTokenName()} tokens found.");
                 } else {
                     $potentialStartTokenIdx = $potentialStartTokenIdxs[0];
                     $tokens[$potentialStartTokenIdx]['is_start_token'] = true;
                 }
             }
             $pattern = new RulePattern((int) $patternData['probability']);
             foreach ($tokens as $token) {
                 $pattern->addToken(new RulePatternToken($token['name'], $token['is_start_token']));
             }
             $rule->addPattern($pattern);
             $patternIdx++;
         }
         $rules->addRule($rule);
     }
     return $rules;
 }
Пример #17
0
 public static function createRule($userID, $ruleName, $type = 3)
 {
     $rule = new Rule($userID);
     $entryID = $type;
     if ($type == 3) {
         $max_res = DB::execute("SELECT MAX(entryID) AS max FROM rules WHERE userID='" . ms($userID) . "'");
         if (count($max_res) > 0 && $max_res["max"] > 3) {
             $entryID = $max_res["max"] + 1;
         }
     }
     $rule->setEntryID($entryID);
     $rule->setRuleName($ruleName);
     return $rule;
 }
Пример #18
0
 /**
  * Add a Rule to this validator.
  * Supports two signatures:
  * - addRule(Rule $rule)
  * - addRule(array $attribs)
  * @param mixed $data Rule object or XML attribs (array) from <rule/> element.
  * @return Rule The added Rule.
  */
 public function addRule($data)
 {
     if ($data instanceof Rule) {
         $rule = $data; // alias
         $rule->setValidator($this);
         $this->ruleList[] = $rule;
         return $rule;
     }
     else {
         $rule = new Rule();
         $rule->setValidator($this);
         $rule->loadFromXML($data);
         return $this->addRule($rule); // call self w/ different param
     }
 }
Пример #19
0
 /**
  * Check all registered rules
  *
  * @return bool
  */
 public function check()
 {
     if (!empty($this->options['rules'])) {
         foreach ($this->options['rules'] as $index => $name) {
             $rule_name = is_array($name) ? $index : $name;
             $rule_options = is_array($name) ? $name : [];
             $rule = new Rule($rule_name, $this->value, $rule_options);
             if (!$rule->check()) {
                 $real_name = explode(':', $rule_name);
                 $this->error = !empty($this->options['messages'][$real_name[0]]) ? $this->options['messages'][$real_name[0]] : $rule->getError();
             }
         }
     }
     return empty($this->error);
 }
 protected function doExecute()
 {
     $id = $this->get('_id');
     $condId = $this->get('condId');
     $rule = Rule::findById($id);
     if ($rule) {
         //var_dump($rule);
         $exists = false;
         if (is_array($rule->conditions)) {
             foreach ($rule->conditions as $idx => $rc) {
                 if ($rc->condId == $condId) {
                     $exists = true;
                     array_splice($rule->conditions, $idx, 1);
                     break;
                 }
             }
         }
         if ($exists) {
             $ret = $rule->save();
             if ($ret) {
                 return $this->success($ret);
             } else {
                 return $this->error(ErrorInfo::ERROR_NO_DB_OPERATION_ERROR, 'add ruleCondition failed');
             }
         } else {
             return $this->error(ErrorInfo::ERROR_NO_DATA_NOT_FOUND, 'ruleCondition not found for _id=' . $id . ' and condId=' . $condId);
         }
     } else {
         return $this->error(ErrorInfo::ERROR_NO_DATA_NOT_FOUND, 'rule not found for _id=' . $id);
     }
 }
Пример #21
0
 public static function validate($result, $extractor)
 {
     $triples = $result->getTriples();
     $md = $extractor->getMetadata();
     if (isset($md[IGNOREVALIDATION]) && $md[IGNOREVALIDATION] == true) {
         return;
     }
     if (!isset($md[PRODUCES]) || count($md[PRODUCES]) == 0) {
         die('extractor ' . $extractor->getExtractorID() . ' not set in Extractorconfiguration');
     }
     $produces = $md[PRODUCES];
     foreach ($triples as $triple) {
         $checked = false;
         foreach ($produces as $rule) {
             if ($rule['type'] == STARTSWITH && Rule::checkStartsWith($rule, $triple)) {
                 $checked = true;
                 break;
             }
             if ($rule['type'] == EXACT && Rule::checkExactmatch($rule, $triple)) {
                 $checked = true;
                 break;
             }
         }
         if ($checked != true) {
             print_r($produces);
             die("Extractor: " . get_class($extractor) . " has wrong settings (see ExtractorConfiguration) in metadata['produces'] at \n" . $triple->toString());
         }
     }
 }
 protected function doExecute()
 {
     $id = $this->get('_id');
     $rule = Rule::findById($id);
     if ($rule) {
         $ruleCondition = RuleCondition::create($this->get('ruleCondition'));
         $exists = false;
         if ($ruleCondition->condId) {
             if (is_array($rule->conditions)) {
                 foreach ($rule->conditions as $key => $rc) {
                     if ($rc->condId == $ruleCondition->condId) {
                         $exists = true;
                         $rule->conditions[$key] = $ruleCondition;
                         break;
                     }
                 }
             }
         } else {
             $ruleCondition->condId = ObjectUtil::guid();
         }
         if (!$exists) {
             $rule->conditions[] = $ruleCondition;
         }
         $ret = $rule->save();
         if ($ret) {
             return $this->success($ret);
         } else {
             return $this->error(ErrorInfo::ERROR_NO_DB_OPERATION_ERROR, 'add ruleCondition failed');
         }
     } else {
         return $this->error(ErrorInfo::ERROR_NO_DATA_NOT_FOUND, 'rule not found for _id=' . $id);
     }
 }
 protected function doExecute()
 {
     $params = array('url' => $this->url);
     if ($this->group !== '') {
         $params['group'] = $this->group;
     } else {
         $params['group'] = null;
     }
     $rules = Rule::find(array($params));
     if ($rules) {
         $contextMap = array(RuleConditionExpressionOperand::CONTEXT_TYPE_REQUEST => $_REQUEST, RuleConditionExpressionOperand::CONTEXT_TYPE_GET => $_GET, RuleConditionExpressionOperand::CONTEXT_TYPE_POST => $_POST, RuleConditionExpressionOperand::CONTEXT_TYPE_HEADER => HttpUtils::getHttpHeaders(), RuleConditionExpressionOperand::CONTEXT_TYPE_COOKIE => $_COOKIE);
         $matcher = new RuleResponseMatcher();
         foreach ($rules as $rule) {
             $res = $matcher->match($rule, $contextMap);
             if (isset($res)) {
                 if (is_array($res) || is_object($res)) {
                     $this->setReturnType(self::RETURN_TYPE_JSON);
                     return $this->success($rule->res);
                 } else {
                     return $res;
                 }
             }
         }
     }
     $this->setReturnType(self::RETURN_TYPE_JSON);
     return $this->error(1, 'can\'t match any url for [' . $this->url . ']');
 }
Пример #24
0
 /**
  * 检查数据
  * @param array $rules 数据规则数组
  * @return void
  */
 public static function validity($rules)
 {
     // 没有规则返回空
     if (!$rules) {
         return array();
     }
     // 数据加载
     $rules = static::load($rules);
     // 检查
     foreach ($rules as $key => $rule) {
         // 是否必须
         if (Rule::notExists($rule)) {
             throw new FormException($rule[5], $key);
         }
         // 对应数据类型检查
         $method = $rule[3];
         if ($rule[0] !== NULL && !Rule::$method($rule)) {
             throw new FormException($rule[5], $key);
         }
         // 设置合法值
         static::setData($rule);
     }
     // 结果返回
     return static::$data;
 }
Пример #25
0
 /**
  * Construct an Equal rule.
  *
  * @param string  $controller
  * @param string  $match
  * @param mixed[] $params
  * @param bool    $authoritative Whether the rule is authoritative.
  */
 public function __construct(string $controller, string $match, array $params = [], bool $authoritative = true)
 {
     parent::__construct($authoritative);
     $this->controller = $controller;
     $this->match = $match;
     $this->params = $params;
 }
Пример #26
0
 /**
  * Constructor.
  *
  * @param   string  $name       Name.
  * @param   int     $min        Minimum bound.
  * @param   int     $max        Maximum bound.
  * @param   mixed   $content    Content.
  * @param   string  $nodeId     Node ID.
  * @return  void
  */
 public function __construct($name, $min, $max, $content, $nodeId)
 {
     parent::__construct($name, $content, $nodeId);
     $this->_min = $min;
     $this->_max = $max;
     return;
 }
Пример #27
0
 public function __construct(callable $call, array $args = null, $config = [])
 {
     parent::__construct($config);
     $this->call = $call;
     if (!empty($args)) {
         $this->args = $args;
     }
 }
Пример #28
0
 /**
  * Skip this rule when configured line endings contain carriage returns.
  *
  * @return bool
  */
 protected function skip()
 {
     $lineEndings = $this->configuration->getLineEndings();
     if ($lineEndings == "\r\n" || $lineEndings == "\r") {
         return true;
     }
     return parent::skip();
 }
 /**
  * @test
  */
 public function TwoRegexpEntitiesTest()
 {
     global $DB;
     $DB->connect();
     $DB->query('DELETE FROM glpi_entities where id>0');
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`, `tag`)\n         VALUES (1, 'entity A', 0, 'Entité racine > entity A', 2, 'entA')");
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`, `tag`)\n         VALUES (2, 'entity B', 0, 'Entité racine > entity B', 2, 'entB')");
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`, `tag`)\n         VALUES (3, 'entity C', 0, 'Entité racine > entity C', 2, 'entC')");
     // Add a rule for get entity tag (1)
     $rule = new Rule();
     $input = array('is_active' => 1, 'name' => 'entity rule 1', 'match' => 'AND', 'sub_type' => 'PluginFusioninventoryInventoryRuleEntity', 'ranking' => 1);
     $rule1_id = $rule->add($input);
     // Add criteria
     $rulecriteria = new RuleCriteria();
     $input = array('rules_id' => $rule1_id, 'criteria' => "name", 'pattern' => "/^([A-Za-z0-9]*) - ([A-Za-z0-9]*) - (.*)\$/", 'condition' => PluginFusioninventoryInventoryRuleEntity::REGEX_MATCH);
     $rulecriteria->add($input);
     // Add action
     $ruleaction = new RuleAction();
     $input = array('rules_id' => $rule1_id, 'action_type' => 'regex_result', 'field' => '_affect_entity_by_tag', 'value' => '#2');
     $ruleaction->add($input);
     // Add a rule for get entity tag (2)
     $rule = new Rule();
     $input = array('is_active' => 1, 'name' => 'entity rule 2', 'match' => 'AND', 'sub_type' => 'PluginFusioninventoryInventoryRuleEntity', 'ranking' => 2);
     $rule2_id = $rule->add($input);
     // Add criteria
     $rulecriteria = new RuleCriteria();
     $input = array('rules_id' => $rule2_id, 'criteria' => "name", 'pattern' => "/^([A-Za-z0-9]*) - (.*)\$/", 'condition' => PluginFusioninventoryInventoryRuleEntity::REGEX_MATCH);
     $rulecriteria->add($input);
     // Add action
     $ruleaction = new RuleAction();
     $input = array('rules_id' => $rule2_id, 'action_type' => 'regex_result', 'field' => '_affect_entity_by_tag', 'value' => '#1');
     $ruleaction->add($input);
     $input = array('name' => 'computer01 - entC');
     $ruleEntity = new PluginFusioninventoryInventoryRuleEntityCollection();
     $ruleEntity->getCollectionPart();
     $ent = $ruleEntity->processAllRules($input, array());
     $a_references = array('entities_id' => 3, '_ruleid' => $rule2_id);
     $this->assertEquals($a_references, $ent, 'Entity C');
     $input = array('name' => 'computer01 - blabla - entB');
     $ruleEntity = new PluginFusioninventoryInventoryRuleEntityCollection();
     $ruleEntity->getCollectionPart();
     $ent = $ruleEntity->processAllRules($input, array());
     $a_references = array('entities_id' => 2, '_ruleid' => $rule1_id);
     $this->assertEquals($a_references, $ent, 'Entity B');
 }
Пример #30
0
 public function testConstructRule()
 {
     $rule = Rule::getInstance();
     $this->assertTrue($rule->isEnable(), "Status differs from default");
     $rule->disable();
     $this->assertFalse($rule->isEnable(), "Status differs from False after disabling");
     $rule->enable();
     $this->assertTrue($rule->isEnable(), "Status differs from True after enabling");
 }