1
+ <?php
2
+ /**
3
+ * @author Dmytro Karpovych
4
+ * @copyright 2015 NRE
5
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
6
+ */
7
+
8
+ namespace nullref \core \components ;
9
+
10
+ use Yii ;
11
+ use yii \base \InvalidCallException ;
12
+ use yii \base \ViewContextInterface ;
13
+ use yii \web \View as BaseView ;
14
+
15
+ class View extends BaseView
16
+ {
17
+ protected function findViewFile ($ view , $ context = null )
18
+ {
19
+ if (strncmp ($ view , '@ ' , 1 ) === 0 ) {
20
+ // e.g. "@app/views/main"
21
+ $ file = Yii::getAlias ($ view );
22
+ } elseif (strncmp ($ view , '// ' , 2 ) === 0 ) {
23
+ // e.g. "//layouts/main"
24
+ $ file = Yii::$ app ->getViewPath () . DIRECTORY_SEPARATOR . ltrim ($ view , '/ ' );
25
+ } elseif (strncmp ($ view , '/ ' , 1 ) === 0 ) {
26
+ // e.g. "/site/index"
27
+ if (Yii::$ app ->controller !== null ) {
28
+ $ file = Yii::$ app ->controller ->module ->getViewPath () . DIRECTORY_SEPARATOR . ltrim ($ view , '/ ' );
29
+ } else {
30
+ throw new InvalidCallException ("Unable to locate view file for view ' $ view': no active controller. " );
31
+ }
32
+ } elseif ($ context instanceof ViewContextInterface) {
33
+ $ file = $ context ->getViewPath () . DIRECTORY_SEPARATOR . $ view ;
34
+ if (Yii::$ app ->controller !== null ) {
35
+ $ newFile = Yii::getAlias ('@app/modules/ '
36
+ . Yii::$ app ->controller ->module ->uniqueId
37
+ . '/views/ ' . Yii::$ app ->controller ->id
38
+ . '/ ' . $ view . '. ' . $ this ->defaultExtension );
39
+ if (file_exists ($ newFile )) {
40
+ $ file = $ newFile ;
41
+ }
42
+ }
43
+ } elseif (($ currentViewFile = $ this ->getViewFile ()) !== false ) {
44
+ $ file = dirname ($ currentViewFile ) . DIRECTORY_SEPARATOR . $ view ;
45
+ } else {
46
+ throw new InvalidCallException ("Unable to resolve view file for view ' $ view': no active view context. " );
47
+ }
48
+
49
+ if (pathinfo ($ file , PATHINFO_EXTENSION ) !== '' ) {
50
+ return $ file ;
51
+ }
52
+ $ path = $ file . '. ' . $ this ->defaultExtension ;
53
+ if ($ this ->defaultExtension !== 'php ' && !is_file ($ path )) {
54
+ $ path = $ file . '.php ' ;
55
+ }
56
+
57
+ return $ path ;
58
+ }
59
+
60
+ }
0 commit comments