]> dev.renevier.net Git - syj.git/blob - application/Bootstrap.php
f3fb3999fbdf836831c3fb20a20f7ee74c846ef7
[syj.git] / application / Bootstrap.php
1 <?php
2 /*  This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3     and is published under the AGPL license. */
4
5 class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
6     protected static $libns = array('gisconverter', 'phptojs', 'pwdgen');
7
8     public function _bootstrap($resource = null) {
9         $autoloader = Zend_Loader_Autoloader::getInstance();
10         foreach (self::$libns as $namespace) {
11             $autoloader->pushAutoloader(array($this, 'syj_autoload'), array($namespace, 'Syj_'));
12         }
13
14         parent::_bootstrap($resource);
15     }
16
17     public function run() {
18         Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->initView(APPLICATION_PATH . '/views/', 'Syj_View');
19         parent::run();
20     }
21
22     static public function syj_autoload($class) {
23         foreach (self::$libns as $namespace) {
24             if (strpos ($class, $namespace) === 0) {
25                 include_once ($namespace . ".php");
26                 return;
27             }
28         }
29
30         if (strpos ($class, "Syj_") === 0) {
31             $segments = explode ('_', $class);
32
33             if (count($segments) < 2) {
34                 return;
35             }
36
37             if (count($segments) == 2) {
38                 $filename = APPLICATION_PATH . '/' . end($segments) . '.php';
39                 if (Zend_Loader::isReadable($filename)) {
40                     include_once $filename;
41                 }
42                 return;
43             }
44
45             if (count($segments) < 3) {
46                 return;
47             }
48
49             $isinterface = false;
50             if (strtolower(end($segments)) == "interface") {
51                 $isinterface = true;
52                 array_pop($segments);
53             }
54
55             $dirpath = implode(DIRECTORY_SEPARATOR, array_map('strtolower', array_slice($segments, 1, -1)));
56             if ($isinterface) {
57                 $dirpath = "interface" . DIRECTORY_SEPARATOR . $dirpath;
58             }
59             $filename = APPLICATION_PATH . '/' . ($dirpath ? $dirpath . '/' : '') . end($segments) . '.php';
60             if (Zend_Loader::isReadable($filename)) {
61                 include_once $filename;
62             }
63         }
64     }
65
66 }