]> dev.renevier.net Git - syj.git/blob - application/Bootstrap.php
a8bc3a66e91d07ab3daa2ac79780c5bb2af9067d
[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         $sessionConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/session.ini', APPLICATION_ENV);
19         Zend_Session::setOptions($sessionConfig->toArray());
20         Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')->initView(APPLICATION_PATH . '/views/', 'Syj_View');
21
22         parent::run();
23     }
24
25     static public function syj_autoload($class) {
26         foreach (self::$libns as $namespace) {
27             if (strpos ($class, $namespace) === 0) {
28                 include_once ($namespace . ".php");
29                 return;
30             }
31         }
32
33         if (strpos ($class, "Syj_") === 0) {
34             $segments = explode ('_', $class);
35
36             if (count($segments) < 3) {
37                 return;
38             }
39
40             $isinterface = false;
41             if (strtolower(end($segments)) == "interface") {
42                 $isinterface = true;
43                 array_pop($segments);
44             }
45
46             $dirpath = implode(DIRECTORY_SEPARATOR, array_map('strtolower', array_slice($segments, 1, -1)));
47             if ($isinterface) {
48                 $dirpath = "interface" . DIRECTORY_SEPARATOR . $dirpath;
49             }
50             $filename = APPLICATION_PATH . '/' . ($dirpath ? $dirpath . '/' : '') . end($segments) . '.php';
51             if (Zend_Loader::isReadable($filename)) {
52                 include_once $filename;
53             }
54         }
55     }
56
57 }