Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@coderbyheart
Created August 7, 2012 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderbyheart/3283693 to your computer and use it in GitHub Desktop.
Save coderbyheart/3283693 to your computer and use it in GitHub Desktop.
Testing a silex app with services
<?php
# app.php
# Read the configuration
$config = parse_ini_file(__DIR__ . '/data/config.ini', true);
# The config looks like this
# [app]
# logfile=./logs/dev.log
# debug = true
# [webservice]
# url=http://somehost/someservice
$app = new \Silex\Application();4
$app['debug'] = $config['app']['debug'];
# set up monolog
$app->register(new \Silex\Provider\MonologServiceProvider(), array(
'monolog.logfile' => $config['app']['logfile']
));
# register webservice implementation
$app['webservice'] = function() use($config, $app)
{
return new Webservice($config['webservice']['url']);
};
# Routes
$app->post('/paymentresult', function(Request $request) use($app)
{
$result = PaymentResult::fromPost($_POST);
/** @var PaymentResultListener $listener */
$listener = $app['resultlistener'];
$listener->onResult($result);
});
# $app->run();
# or return $app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment