]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/TApplicationComponent.php
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / TApplicationComponent.php
1 <?php
2 /**
3  * TApplicationComponent class
4  *
5  * @author Qiang Xue <qiang.xue@gmail.com>
6  * @link https://github.com/pradosoft/prado
7  * @copyright Copyright &copy; 2005-2016 The PRADO Group
8  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9  * @package System
10  */
11
12 /**
13  * TApplicationComponent class
14  *
15  * TApplicationComponent is the base class for all components that are
16  * application-related, such as controls, modules, services, etc.
17  *
18  * TApplicationComponent mainly defines a few properties that are shortcuts
19  * to some commonly used methods. The {@link getApplication Application}
20  * property gives the application instance that this component belongs to;
21  * {@link getService Service} gives the current running service;
22  * {@link getRequest Request}, {@link getResponse Response} and {@link getSession Session}
23  * return the request and response modules, respectively;
24  * And {@link getUser User} gives the current user instance.
25  *
26  * Besides, TApplicationComponent defines two shortcut methods for
27  * publishing private files: {@link publishAsset} and {@link publishFilePath}.
28  *
29  * @author Qiang Xue <qiang.xue@gmail.com>
30  * @package System
31  * @since 3.0
32  */
33 class TApplicationComponent extends TComponent
34 {
35         /**
36          * @return TApplication current application instance
37          */
38         public function getApplication()
39         {
40                 return Prado::getApplication();
41         }
42
43         /**
44          * @return IService the current service
45          */
46         public function getService()
47         {
48                 return Prado::getApplication()->getService();
49         }
50
51         /**
52          * @return THttpRequest the current user request
53          */
54         public function getRequest()
55         {
56                 return Prado::getApplication()->getRequest();
57         }
58
59         /**
60          * @return THttpResponse the response
61          */
62         public function getResponse()
63         {
64                 return Prado::getApplication()->getResponse();
65         }
66
67         /**
68          * @return THttpSession user session
69          */
70         public function getSession()
71         {
72                 return Prado::getApplication()->getSession();
73         }
74
75         /**
76          * @return IUser information about the current user
77          */
78         public function getUser()
79         {
80                 return Prado::getApplication()->getUser();
81         }
82
83         /**
84          * Publishes a private asset and gets its URL.
85          * This method will publish a private asset (file or directory)
86          * and gets the URL to the asset. Note, if the asset refers to
87          * a directory, all contents under that directory will be published.
88          * Also note, it is recommended that you supply a class name as the second
89          * parameter to the method (e.g. publishAsset($assetPath,__CLASS__) ).
90          * By doing so, you avoid the issue that child classes may not work properly
91          * because the asset path will be relative to the directory containing the child class file.
92          *
93          * @param string path of the asset that is relative to the directory containing the specified class file.
94          * @param string name of the class whose containing directory will be prepend to the asset path. If null, it means get_class($this).
95          * @return string URL to the asset path.
96          */
97         public function publishAsset($assetPath,$className=null)
98         {
99                 if($className===null)
100                         $className=get_class($this);
101                 $class=new ReflectionClass($className);
102                 $fullPath=dirname($class->getFileName()).DIRECTORY_SEPARATOR.$assetPath;
103                 return $this->publishFilePath($fullPath);
104         }
105
106         /**
107          * Publishes a file or directory and returns its URL.
108          * @param string absolute path of the file or directory to be published
109          * @return string URL to the published file or directory
110          */
111         public function publishFilePath($fullPath, $checkTimestamp=false)
112         {
113                 return Prado::getApplication()->getAssetManager()->publishFilePath($fullPath, $checkTimestamp);
114         }
115 }
116