/**
  * @dataProvider provideExceptionsAndCode
  */
 public function testError($exception, $code)
 {
     $app = new Application('test');
     $app['api'] = function () use($app) {
         return new \API_V1_adapter($app);
     };
     $app->register(new \API_V1_Timer());
     $app['dispatcher']->addSubscriber(new ApiExceptionHandlerSubscriber($app));
     $app->get('/', function () use($exception) {
         throw $exception;
     });
     $client = new Client($app);
     $client->request('GET', '/');
     $this->assertEquals($code, $client->getResponse()->getStatusCode());
     $this->assertEquals('application/json', $client->getResponse()->headers->get('content-type'));
 }
 /**
  * @dataProvider provideExceptionsAndCode
  */
 public function testErrorOnOtherRoutes($exception, $code, $contentType)
 {
     $app = new Application('test');
     unset($app['exception_handler']);
     $app['api'] = function () use($app) {
         return new \API_V1_adapter($app);
     };
     $app->register(new \API_V1_Timer());
     $app['dispatcher']->addSubscriber(new ApiOauth2ErrorsSubscriber(PhraseaExceptionHandler::register(), $this->createTranslatorMock()));
     $app->get('/', function () use($exception) {
         throw $exception;
     });
     $client = new Client($app);
     $this->setExpectedException(get_class($exception));
     $client->request('GET', '/');
 }
Example #3
0
use Alchemy\Phrasea\Core\Event\ApiLoadEndEvent;
use Alchemy\Phrasea\Core\Event\ApiLoadStartEvent;
use Alchemy\Phrasea\Core\Event\Subscriber\ApiOauth2ErrorsSubscriber;
use Alchemy\Phrasea\Core\Event\Subscriber\ApiExceptionHandlerSubscriber;
use Monolog\Logger;
use Monolog\Processor\WebProcessor;
use Silex\Application as SilexApplication;
use Symfony\Component\HttpFoundation\Request;
return call_user_func(function ($environment = PhraseaApplication::ENV_PROD) {
    $app = new PhraseaApplication($environment);
    $app->loadPlugins();
    $app['exception_handler'] = $app->share(function ($app) {
        return new ApiExceptionHandlerSubscriber($app);
    });
    $app['monolog'] = $app->share($app->extend('monolog', function (Logger $monolog) {
        $monolog->pushProcessor(new WebProcessor());
        return $monolog;
    }));
    $app->register(new \API_V1_Timer());
    $app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_START, new ApiLoadStartEvent());
    $app->get('/api/', function (Request $request, SilexApplication $app) {
        $apiAdapter = new \API_V1_adapter($app);
        $result = new \API_V1_result($app, $request, $apiAdapter);
        return $result->set_datas(['name' => $app['conf']->get(['registry', 'general', 'title']), 'type' => 'phraseanet', 'description' => $app['conf']->get(['registry', 'general', 'description']), 'documentation' => 'https://docs.phraseanet.com/Devel', 'versions' => ['1' => ['number' => $apiAdapter->get_version(), 'uri' => '/api/v1/', 'authenticationProtocol' => 'OAuth2', 'authenticationVersion' => 'draft#v9', 'authenticationEndPoints' => ['authorization_token' => '/api/oauthv2/authorize', 'access_token' => '/api/oauthv2/token']]]])->get_response();
    });
    $app->mount('/api/oauthv2', new Oauth2());
    $app->mount('/api/v1', new V1());
    $app['dispatcher']->addSubscriber(new ApiOauth2ErrorsSubscriber($app['phraseanet.exception_handler'], $app['translator']));
    $app['dispatcher']->dispatch(PhraseaEvents::API_LOAD_END, new ApiLoadEndEvent());
    return $app;
}, isset($environment) ? $environment : PhraseaApplication::ENV_PROD);
 protected function set_user_agent($user_agent, Application $app)
 {
     $app['browser']->setUserAgent($user_agent);
     $app->register(new \Silex\Provider\TwigServiceProvider());
     $app->setupTwig();
     self::$DI['client'] = self::$DI->share(function ($DI) use($app) {
         return new Client($app, []);
     });
 }
Example #5
0
                 if ('setup_upgrade_instructions' !== $app['request']->attributes->get('_route')) {
                     return $app->redirectPath('setup_upgrade_instructions');
                 }
             }
         } elseif (!$app['phraseanet.configuration-tester']->isBlank()) {
             return $app->redirectPath('homepage');
         }
     } else {
         if (false === strpos($request->getPathInfo(), '/include/minify')) {
             $app['firewall']->requireSetup();
         }
     }
 }, Application::EARLY_EVENT);
 $app->bindRoutes();
 if (PhraseaApplication::ENV_DEV === $app->getEnvironment()) {
     $app->register($p = new WebProfilerServiceProvider(), ['profiler.cache_dir' => $app['cache.path'] . '/profiler']);
     $app->mount('/_profiler', $p);
     if ($app['phraseanet.configuration-tester']->isInstalled()) {
         $app->register(new DoctrineProfilerServiceProvider());
         $app['db'] = $app->share(function (PhraseaApplication $app) {
             return $app['orm.em']->getConnection();
         });
     }
 }
 $app['dispatcher'] = $app->share($app->extend('dispatcher', function (EventDispatcherInterface $dispatcher, PhraseaApplication $app) {
     $dispatcher->addSubscriber(new BridgeExceptionSubscriber($app));
     $dispatcher->addSubscriber(new FirewallSubscriber());
     $dispatcher->addSubscriber(new JsonRequestSubscriber());
     $dispatcher->addSubscriber(new DebuggerSubscriber($app));
     return $dispatcher;
 }));