本文整理汇总了PHP中Rule类的典型用法代码示例。如果您正苦于以下问题:PHP Rule类的具体用法?PHP Rule怎么用?PHP Rule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Rule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
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: plugin_typology_uninstall
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: add
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: __construct
/**
* 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: localize
/**
* @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: register
private function register(Rule $rule)
{
if (!isset($this->rules[$rule->getNodeType()])) {
$this->rules[$rule->getNodeType()] = [];
}
$this->rules[$rule->getNodeType()][] = $rule;
}
示例7: parse
/**
* 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: resolveIdentifier
/**
* resolves the identifier
*
* @param string|Rule $identifier
*
* @return string
*/
private function resolveIdentifier($identifier)
{
if ($identifier instanceof Rule) {
return $identifier->identifier();
}
return $identifier;
}
示例9: getRules
/**
* @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: addRule
/**
* @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: addRule
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;
}
示例12: prepareDB
/**
* @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);
}
示例13: AddComputer
/**
* 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)');
}
示例14: setRules
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;
}
示例15: getRules
/**
* @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;
}