1--TEST--
2Check for Sample application
3--SKIPIF--
4<?php if (!extension_loaded("yaf")) print "skip"; ?>
5--INI--
6yaf.use_spl_autoload=0
7yaf.lowcase_path=0
8yaf.use_namespace=0
9
10--FILE--
11<?php
12require "build.inc";
13startup();
14
15$config = array(
16	"application" => array(
17		"directory" => APPLICATION_PATH,
18        "dispatcher" => array (
19           "catchException" => true,
20        ),
21        "library" => array(
22        ),
23	),
24);
25
26file_put_contents(APPLICATION_PATH . "/controllers/Error.php", <<<PHP
27<?php
28   class ErrorController extends Yaf_Controller_Abstract {
29         public function errorAction(\$exception) {
30              var_dump(\$exception->getMessage());
31              return FALSE;
32         }
33   }
34PHP
35);
36
37file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<<PHP
38<?php
39   class Bootstrap extends Yaf_Bootstrap_Abstract {
40        public function _initConfig(Yaf_Dispatcher \$dispatcher) {
41            Yaf_Registry::set("config", Yaf_Application::app()->getConfig());
42        }
43        public function _initPlugin(Yaf_Dispatcher \$dispatcher) {
44            \$dispatcher->registerPlugin(new TestPlugin());
45        }
46   }
47PHP
48);
49
50file_put_contents(APPLICATION_PATH . "/plugins/Test.php", <<<PHP
51<?php
52   class TestPlugin extends Yaf_Plugin_Abstract {
53        public function routerStartup(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
54            var_dump("routerStartup");
55        }
56        public function routerShutdown(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
57            var_dump("routerShutdown");
58        }
59        public function dispatchLoopStartup(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
60            var_dump("dispatchLoopStartup");
61        }
62        public function preDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
63            var_dump("preDispatch");
64        }
65        public function postDispatch(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
66            var_dump("postDispatch");
67        }
68        public function dispatchLoopShutdown(Yaf_Request_Abstract \$request, Yaf_Response_Abstract \$response) {
69            global \$value;
70            var_dump("dispatchLoopShutdown, global var is:" . \$value);
71        }
72   }
73PHP
74);
75
76$value = NULL;
77
78file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<<PHP
79<?php
80   class IndexController extends Yaf_Controller_Abstract {
81         public function init() {
82            var_dump("init");
83         }
84         public function indexAction() {
85            global \$value;
86            var_dump("action");
87            var_dump(Yaf_Registry::get("config")->application->dispatcher->catchException);
88            \$this->getView()->assignRef("ref", \$value);
89         }
90   }
91PHP
92);
93
94file_put_contents(APPLICATION_PATH . "/views/index/index.phtml",
95                "<?php var_dump('view'); \$ref = \"changed\"; ?>");
96
97$app = new Yaf_Application($config);
98$app->bootstrap()->run();
99
100?>
101--CLEAN--
102<?php
103/* unlink foo2.phtml permission denied */
104require "build.inc";
105shutdown();
106?>
107--EXPECTF--
108string(13) "routerStartup"
109string(14) "routerShutdown"
110string(19) "dispatchLoopStartup"
111string(11) "preDispatch"
112string(4) "init"
113string(6) "action"
114bool(true)
115string(12) "postDispatch"
116string(43) "dispatchLoopShutdown, global var is:changed"
117string(4) "view"
118