1 <?php
2
3 namespace ICanBoogie\I18n;
4
5 use ICanBoogie\PropertyNotDefined;
6
7 /**
8 * A formatted string.
9 *
10 * The string is formatted by replacing placeholders with the values provided.
11 *
12 * @property-read string $format String format.
13 * @property-read array $args Format arguments.
14 * @property-read array $options I18n options.
15 */
16 class FormattedString
17 {
18 protected $format;
19 protected $args;
20 protected $options;
21
22 /**
23 * Initializes the {@link $format}, {@link $args} and {@link $options} properties.
24 *
25 * @param string $format String format.
26 * @param array $args Format arguments.
27 * @param array $options I18n options.
28 */
29 public function __construct($format, $args=null, array $options=array())
30 {
31 if (!is_array($args))
32 {
33 $args = func_get_args();
34 array_shift($args);
35 $options = array();
36 }
37
38 $this->format = $format;
39 $this->args = (array) $args;
40 $this->options = $options;
41 }
42
43 public function __get($property)
44 {
45 switch ($property)
46 {
47 case 'format': return $this->format;
48 case 'args': return $this->args;
49 case 'options': return $this->options;
50 }
51
52 throw new PropertyNotDefined(array($property, $this));
53 }
54
55 /**
56 * Returns the string formatted with the {@link format()} function.
57 *
58 * @return string
59 */
60 public function __toString()
61 {
62 return t($this->format, $this->args, $this->options);
63 }
64 }
65
66 namespace ICanBoogie;
67
68 class FormattedString extends I18n\FormattedString
69 {
70
71 }