1<?php
2
3/**
4 * Swift Mailer Decorator Replacements Container
5 * Please read the LICENSE file
6 * @author Chris Corbyn <chris@w3style.co.uk>
7 * @package Swift_Plugin
8 * @subpackage Decorator
9 * @license GNU Lesser General Public License
10 */
11
12
13/**
14 * Swift Decorator Plugin Replacements.
15 * Provides and manages the list of replacements for the decorator plugin.
16 * @package Swift_Plugin
17 * @subpackage Decorator
18 * @author Chris Corbyn <chris@w3style.co.uk>
19 */
20class Swift_Plugin_Decorator_Replacements
21{
22  /**
23   * The list of replacements as a 2-d array
24   * @var array,array
25   */
26  protected $replacements;
27
28  /**
29   * Ctor.
30   * @param array The replacements as a 2-d array, optional
31   */
32  public function __construct($replacements = array())
33  {
34    $this->setReplacements($replacements);
35  }
36  /**
37   * Add a list of replacements for a given address.
38   * @param string The e-mail address
39   * @param array The replacements as (search => replacement) form.
40   */
41  public function addReplacements($address, $replacements)
42  {
43    $this->replacements[strtolower($address)] = (array)$replacements;
44  }
45  /**
46   * Set the complete list of replacements as a 2-d array.
47   * The array is formed thus (address => (search => replace), address => (search => replace))
48   * @param array,array The replacements.
49   */
50  public function setReplacements($replacements)
51  {
52    $this->replacements = array_change_key_case((array) $replacements, CASE_LOWER);
53  }
54  /**
55   * Get the entire list of replacements as a 2-d array
56   * @return array,array
57   */
58  public function getReplacements()
59  {
60    return $this->replacements;
61  }
62  /**
63   * Get the list of replacements for the address given.
64   * Returns an array where (search => replacement).
65   * @param string The address to get replacements for
66   * @return array
67   */
68  public function getReplacementsFor($address)
69  {
70    $address = strtolower($address);
71    if (array_key_exists($address, $this->replacements))
72    {
73      return (array)$this->replacements[$address];
74    }
75    else return array();
76  }
77}
78