ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AttributeAdd.php
Go to the documentation of this file.
1 <?php
2 
12 
16  private $replace = FALSE;
17 
18 
24  private $attributes = array();
25 
26 
33  public function __construct($config, $reserved) {
34  parent::__construct($config, $reserved);
35 
36  assert(is_array($config));
37 
38  foreach($config as $name => $values) {
39  if(is_int($name)) {
40  if($values === '%replace') {
41  $this->replace = TRUE;
42  } else {
43  throw new Exception('Unknown flag: ' . var_export($values, TRUE));
44  }
45  continue;
46  }
47 
48  if(!is_array($values)) {
49  $values = array($values);
50  }
51  foreach($values as $value) {
52  if(!is_string($value)) {
53  throw new Exception('Invalid value for attribute ' . $name . ': ' .
54  var_export($values, TRUE));
55  }
56  }
57 
58  $this->attributes[$name] = $values;
59  }
60  }
61 
62 
70  public function process(&$request) {
71  assert(is_array($request));
72  assert(array_key_exists('Attributes', $request));
73 
74  $attributes =& $request['Attributes'];
75 
76  foreach($this->attributes as $name => $values) {
77  if($this->replace === TRUE || !array_key_exists($name, $attributes)) {
79  } else {
80  $attributes[$name] = array_merge($attributes[$name], $values);
81  }
82  }
83  }
84 
85 }
$config
Definition: bootstrap.php:15
foreach($paths as $path) $request
Definition: asyncclient.php:32
__construct($config, $reserved)
Initialize this filter.
$values
$attributes
Attributes which should be added/appended.
process(&$request)
Apply filter to add or replace attributes.
$replace
Flag which indicates wheter this filter should append new values or replace old values.