1 <?php
2 /**
3 * Part of the Joomla Framework Uri Package
4 *
5 * @copyright Copyright (C) 2005 - 2016 Open Source Matters. All rights reserved.
6 * @license GNU General Public License version 2 or later; see LICENSE
7 */
8
9 namespace Joomla\Uri;
10
11 /**
12 * Uri Class
13 *
14 * This is an immutable version of the uri class.
15 *
16 * @since 1.0
17 */
18 final class UriImmutable extends AbstractUri
19 {
20 /**
21 * @var boolean Has this class been instantiated yet.
22 * @since 1.0
23 */
24 private $constructed = false;
25
26 /**
27 * Prevent setting undeclared properties.
28 *
29 * @param string $name This is an immutable object, setting $name is not allowed.
30 * @param mixed $value This is an immutable object, setting $value is not allowed.
31 *
32 * @return null This method always throws an exception.
33 *
34 * @since 1.0
35 * @throws \BadMethodCallException
36 */
37 public function __set($name, $value)
38 {
39 throw new \BadMethodCallException('This is an immutable object');
40 }
41
42 /**
43 * This is a special constructor that prevents calling the __construct method again.
44 *
45 * @param string $uri The optional URI string
46 *
47 * @since 1.0
48 * @throws \BadMethodCallException
49 */
50 public function __construct($uri = null)
51 {
52 if ($this->constructed === true)
53 {
54 throw new \BadMethodCallException('This is an immutable object');
55 }
56
57 $this->constructed = true;
58
59 parent::__construct($uri);
60 }
61 }
62