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