Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
base.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Controller
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Joomla Platform Base Controller Class
14  *
15  * @package Joomla.Platform
16  * @subpackage Controller
17  * @since 12.1
18  */
19 abstract class JControllerBase implements JController
20 {
21  /**
22  * The application object.
23  *
24  * @var JApplicationBase
25  * @since 12.1
26  */
27  protected $app;
28 
29  /**
30  * The input object.
31  *
32  * @var JInput
33  * @since 12.1
34  */
35  protected $input;
36 
37  /**
38  * Instantiate the controller.
39  *
40  * @param JInput $input The input object.
41  * @param JApplicationBase $app The application object.
42  *
43  * @since 12.1
44  */
45  public function __construct(JInput $input = null, JApplicationBase $app = null)
46  {
47  // Setup dependencies.
48  $this->app = isset($app) ? $app : $this->loadApplication();
49  $this->input = isset($input) ? $input : $this->loadInput();
50  }
51 
52  /**
53  * Get the application object.
54  *
55  * @return JApplicationBase The application object.
56  *
57  * @since 12.1
58  */
59  public function getApplication()
60  {
61  return $this->app;
62  }
63 
64  /**
65  * Get the input object.
66  *
67  * @return JInput The input object.
68  *
69  * @since 12.1
70  */
71  public function getInput()
72  {
73  return $this->input;
74  }
75 
76  /**
77  * Serialize the controller.
78  *
79  * @return string The serialized controller.
80  *
81  * @since 12.1
82  */
83  public function serialize()
84  {
85  return serialize($this->input);
86  }
87 
88  /**
89  * Unserialize the controller.
90  *
91  * @param string $input The serialized controller.
92  *
93  * @return JController Supports chaining.
94  *
95  * @since 12.1
96  * @throws UnexpectedValueException if input is not the right class.
97  */
98  public function unserialize($input)
99  {
100  // Setup dependencies.
101  $this->app = $this->loadApplication();
102 
103  // Unserialize the input.
104  $this->input = unserialize($input);
105 
106  if (!($this->input instanceof JInput))
107  {
108  throw new UnexpectedValueException(sprintf('%s::unserialize would not accept a `%s`.', get_class($this), gettype($this->input)));
109  }
110 
111  return $this;
112  }
113 
114  /**
115  * Load the application object.
116  *
117  * @return JApplicationBase The application object.
118  *
119  * @since 12.1
120  */
121  protected function loadApplication()
122  {
123  return JFactory::getApplication();
124  }
125 
126  /**
127  * Load the input object.
128  *
129  * @return JInput The input object.
130  *
131  * @since 12.1
132  */
133  protected function loadInput()
134  {
135  return $this->app->input;
136  }
137 }