Ejemplo n.º 1
0
 * Application and Providers Configuration
 *
 *
 */
use Silex\Application;
use MJanssen\Provider\RoutingServiceProvider;
$app->register(new Silex\Provider\HttpCacheServiceProvider());
$app->register(new Silex\Provider\SessionServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
// Template Engine Definition
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.options' => array('cache' => isset($app['twig.options.cache']) ? $app['twig.options.cache'] : false, 'strict_variables' => true), 'twig.path' => array(PATH_VIEWS), 'twig.options' => array('debug' => $app['debug'])));
// Database Definition
$app->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_mysql', 'host' => 'localhost', 'dbname' => '', 'user' => '', 'password' => '', 'charset' => 'utf8')));
//Routes
$routes = array('home' => array('pattern' => '/', 'controller' => 'App\\Controller\\IndexController::indexAction', 'method' => array('get', 'post', 'put', 'delete', 'options', 'head')), 'homeReview' => array('pattern' => '/reviewID{id}', 'controller' => 'App\\Controller\\IndexController::ReviewAction', 'method' => array('get', 'post', 'put', 'delete', 'options', 'head')), 'indexReview' => array('pattern' => '/addreview', 'controller' => 'App\\Controller\\ReviewController::IndexAction', 'method' => array('get', 'put', 'delete', 'options', 'head')), 'addReview' => array('pattern' => '/addreview', 'controller' => 'App\\Controller\\ReviewController::AddReviewAction', 'method' => array('post')));
$routingServiceProvider = new RoutingServiceProvider();
$routingServiceProvider->addRoutes($app, $routes);
// Security Definition
$app->register(new Silex\Provider\SecurityServiceProvider(), array('security.firewalls' => array('index' => array('pattern' => '^/$', 'anonymous' => true), 'addreview' => array('pattern' => '^/addreview$', 'anonymous' => true), 'review' => array('pattern' => '^/reviewID{id}$', 'anonymous' => true))));
$app['security.authentication.success_handler.admin'] = $app->share(function () use($app) {
    // Success Authentication
    return new App\Service\Authentication\CustomAuthenticationSuccessHandler($app['security.http_utils'], array(), $app);
});
// Log Definition
$app->register(new Silex\Provider\MonologServiceProvider(), array('monolog.logfile' => PATH_LOG . '/app.log', 'monolog.name' => 'app', 'monolog.level' => 300));
// Errors Exception
$app->error(function (\Exception $e, $code) use($app) {
    $file = pathinfo($e->getFile());
    return $app->json(['success' => false, 'message' => 'Error', 'error' => $e->getMessage(), 'serverror' => $code, 'source' => $file['filename'], 'line' => $e->getLine()], $code);
});
Ejemplo n.º 2
0
$whoops = new Run();
switch ($environment) {
    case Environment::PRODUCTION:
        $whoops->pushHandler(function () {
            echo 'There was a problem with our services, please contact the System Administrator.';
        });
        break;
    case Environment::DEVELOPMENT:
        $whoops->pushHandler(new PrettyPageHandler());
        break;
}
$whoops->register();
/**
 * Setting up the application
 */
$application = new Application();
/**
 * Set up Routing
 */
$routingServiceProvider = new RoutingServiceProvider();
$routes = new Routes('Blog\\Api\\');
$routingServiceProvider->addRoutes($application, $routes->get());
/**
 * Set up the injections
 */
$container = new Container($application);
$container->loadDependencies();
/**
 * Run the application
 */
$application->run();