php-framework-skeleton

Skeleton for php-framework
git clone git://git.finwo.net/misc/php-framework-skeleton
Log | Files | Refs

index.php (1261B)


      1 <?php
      2 
      3 // Load composer
      4 require implode(DIRECTORY_SEPARATOR, array(
      5   __DIR__,
      6   '..',
      7   'vendor',
      8   'autoload.php',
      9 ));
     10 
     11 // Definitions
     12 define('DS', DIRECTORY_SEPARATOR);
     13 define('APPROOT', rtrim(dirname(__DIR__),DS));
     14 
     15 // Keep the code somewhat short
     16 use \Finwo\Framework\Bundle\AbstractBundle;
     17 use \Finwo\Framework\Config\Config;
     18 use \Finwo\Framework\Service\AbstractService;
     19 
     20 // Initialize router
     21 $router = new Klein\Klein();
     22 
     23 // Initialize services
     24 $services = array();
     25 foreach( Config::get('services') as $name => $serviceClass ) {
     26   if(!class_exists($serviceClass)) continue;
     27   $service = new $serviceClass();
     28   if(!($service instanceof AbstractService)) continue;
     29   $services[$name] = $service;
     30 }
     31 Config::set('service', $services);
     32 
     33 // Initialize registered bundles
     34 $bundles = array();
     35 foreach( Config::get('bundles') as $bundleName ) {
     36   $class = $bundleName . "\\" . @array_pop(explode("\\",$bundleName));
     37   if(!class_exists($class)) continue;
     38   $bundle = new $class($router);
     39   if (!($bundle instanceof AbstractBundle)) continue;
     40   array_push($bundles, new $class($router));
     41 }
     42 Config::set( 'bundles', $bundles );
     43 
     44 // Handle pre-forked start
     45 if(isset($_SERVER['argc'])) {
     46   require(APPROOT.DS.'init.php');
     47 }
     48 
     49 // Kickoff the request
     50 $router->dispatch();