ensure we register the Zend namespace for the StandardAutoloader
[zf2.biz/galerie.git] / public / index.php
1 <?php
2 use Zend\Loader\AutoloaderFactory;
3 use Zend\ServiceManager\ServiceManager;
4 use Zend\Mvc\Service\ServiceManagerConfiguration;
5
6 chdir(dirname(__DIR__));
7
8 // Composer autoloading
9 if (file_exists('vendor/autoload.php')) {
10     $loader = include 'vendor/autoload.php';
11 }
12
13 // Support for ZF2_PATH environment variable or git submodule
14 if ($zf2Path = getenv('ZF2_PATH') ?: (is_dir('vendor/ZF2/library') ? 'vendor/ZF2/library' : false)) {
15     if (isset($loader)) {
16         $loader->add('Zend', $zf2Path . '/Zend');
17     } else {
18         include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
19         AutoloaderFactory::factory(array(
20             'Zend\Loader\StandardAutoloader' => array(
21                 'autoregister_zf' => true
22             )
23         ));
24     }
25 }
26
27 if (!class_exists('Zend\Loader\AutoloaderFactory')) {
28     throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
29 }
30
31 // Get application stack configuration
32 $configuration = include 'config/application.config.php';
33
34 // Setup service manager
35 $serviceManager = new ServiceManager(new ServiceManagerConfiguration($configuration['service_manager']));
36 $serviceManager->setService('ApplicationConfiguration', $configuration);
37 $serviceManager->get('ModuleManager')->loadModules();
38
39 // Run application
40 $serviceManager->get('Application')->bootstrap()->run()->send();