<?php
namespace TestApp;
class Application extends \Silex\Application {
var $app;
public function __construct( ) {
parent::__construct( );
$app = &$this;
$app[ 'config' ] = $app->share( function( ) {
$config = \Symfony\Component\Yaml\Yaml::parse( dirname( $_SERVER[ "CONTEXT_DOCUMENT_ROOT" ] ) . '/config/config.yml' );
function change( &$config ) {
foreach( $config as $keyname => $value ) {
if( empty( $config[ $keyname ] ) ) {
return;
} elseif( is_array( $config[ $keyname ] ) ) {
change( $config[ $keyname ] );
} ELSEIF( is_string( $config[ $keyname ] ) ) {
$config[ $keyname ] = str_replace( '\\', '/', str_replace( '__DIR__', dirname( __FILE__ ), $value ) );
}
}
}
change( $config );
foreach( $config['ormOptions']['mappings']['path'] as $key => $value ) {
$value = str_replace( '\\', '/', str_replace( '__DIR__', dirname( __FILE__ ), $value ) );
$config[ 'ormOptions' ][ 'mappings' ][ 'path' ][ $key ] = $value;
}
return $config;
} );
$app->register( new \Silex\Provider\TwigServiceProvider( ), array(
'debug' => $app[ 'config' ]['debug'],
'twig.path' => array(
dirname(__FILE__). '/Templates' ),
)
);
$app->register( new \Silex\Provider\DoctrineServiceProvider( ), array( 'db.options' => $app[ 'config' ][ 'database' ] ) );
$app->mount( '', new Controller\Provider\HomeControllerProvider( ) );
}
}