コード例 #1
0
 public function testItCanBeDisabled()
 {
     $app = new Application();
     $app['exception_handler'] = new PhraseaExceptionHandlerSubscriber(PhraseaExceptionHandler::register());
     $app->get('/', function () {
         throw new \Exception();
     });
     $app['exception_handler']->disable();
     $client = new Client($app);
     $this->setExpectedException('\\Exception');
     $client->request('GET', '/');
 }
コード例 #2
0
 /**
  * @dataProvider provideExceptionsAndCode
  */
 public function testErrorOnOtherRoutes($exception, $code, $contentType)
 {
     $app = new Application('test');
     unset($app['exception_handler']);
     $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', '/');
 }
コード例 #3
0
ファイル: Application.php プロジェクト: luisbrito/Phraseanet
 public function __construct($environment = self::ENV_PROD)
 {
     parent::__construct();
     error_reporting(-1);
     $this->environment = $environment;
     $this->setupCharset();
     $this->setupApplicationPaths();
     $this->setupConstants();
     $this['debug'] = $this->share(function (Application $app) {
         return Application::ENV_PROD !== $app->getEnvironment();
     });
     if ($this['debug']) {
         ini_set('log_errors', 'on');
         ini_set('error_log', $this['root.path'] . '/logs/php_error.log');
     }
     $this->register(new ConfigurationServiceProvider());
     $this->register(new MonologServiceProvider());
     $this->setupMonolog();
     $this->register(new FilesystemServiceProvider());
     $this->register(new CacheServiceProvider());
     $this->register(new CacheConnectionServiceProvider());
     $this->register(new PhraseanetServiceProvider());
     $this->register(new ConfigurationTesterServiceProvider());
     $this->register(new DoctrineServiceProvider());
     $this->setupDBAL();
     $this->register(new DoctrineOrmServiceProvider());
     $this->setupOrms();
     $this->register(new ORMServiceProvider());
     $this->register(new BasketMiddlewareProvider());
     $this->register(new TokenMiddlewareProvider());
     $this->register(new AccountServiceProvider());
     $this->register(new ApiApplicationMiddlewareProvider());
     $this->register(new ACLServiceProvider());
     $this->register(new APIServiceProvider());
     $this->register(new AuthenticationManagerServiceProvider());
     $this->register(new AuthorizationServiceProvider());
     $this->register(new BrowserServiceProvider());
     $this->register(new ConvertersServiceProvider());
     $this->register(new CSVServiceProvider());
     $this->register(new RegistrationServiceProvider());
     $this->register(new ImagineServiceProvider());
     $this->setUpImagine();
     $this->register(new JMSSerializerServiceProvider());
     $this->register(new FFMpegServiceProvider());
     $this->register(new FeedServiceProvider());
     $this->register(new FtpServiceProvider());
     $this->register(new GeonamesServiceProvider());
     $this->register(new StatusServiceProvider());
     $this->setupGeonames();
     $this->register(new MediaAlchemystServiceProvider());
     $this->setupMediaAlchemyst();
     $this->register(new MediaVorusServiceProvider());
     $this->register(new MP4BoxServiceProvider());
     $this->register(new NotificationDelivererServiceProvider());
     $this->register(new RepositoriesServiceProvider());
     $this->register(new ManipulatorServiceProvider());
     $this->register(new InstallerServiceProvider());
     $this->register(new PhraseaVersionServiceProvider());
     $this->register(new PHPExiftoolServiceProvider());
     $this->register(new RandomGeneratorServiceProvider());
     $this->register(new ReCaptchaServiceProvider());
     $this->register(new SubdefServiceProvider());
     $this->register(new ZippyServiceProvider());
     $this->setupRecaptacha();
     if ($this['configuration.store']->isSetup()) {
         $this->register(new SearchEngineServiceProvider());
         $this->register(new BorderManagerServiceProvider());
     }
     $this->register(new SessionHandlerServiceProvider());
     $this->register(new SessionServiceProvider(), ['session.test' => $this->getEnvironment() === static::ENV_TEST, 'session.storage.options' => ['cookie_lifetime' => 0]]);
     $this->setupSession();
     $this->register(new SerializerServiceProvider());
     $this->register(new ServiceControllerServiceProvider());
     $this->register(new SwiftmailerServiceProvider());
     $this->setupSwiftMailer();
     $this->register(new TasksServiceProvider());
     $this->register(new TemporaryFilesystemServiceProvider());
     $this->register(new TokensServiceProvider());
     $this->register(new HttpFragmentServiceProvider());
     $this->register(new TwigServiceProvider());
     $this->setupTwig();
     $this->register(new TranslationServiceProvider(), ['locale_fallbacks' => ['fr'], 'translator.cache-options' => ['debug' => $this['debug'], 'cache_dir' => $this->share(function ($app) {
         return $app['cache.path'] . '/translations';
     })]]);
     $this->setupTranslation();
     $this->register(new FormServiceProvider());
     $this->setupForm();
     $this->register(new UnoconvServiceProvider());
     $this->register(new UrlGeneratorServiceProvider());
     $this->setupUrlGenerator();
     $this->register(new UnicodeServiceProvider());
     $this->register(new ValidatorServiceProvider());
     $this->register(new XPDFServiceProvider());
     $this->setupXpdf();
     $this->register(new FileServeServiceProvider());
     $this->register(new ManipulatorServiceProvider());
     $this->register(new PluginServiceProvider());
     $this->register(new PhraseaEventServiceProvider());
     $this->register(new ContentNegotiationServiceProvider());
     $this->register(new CorsServiceProvider(), ['alchemy_cors.debug' => $this['debug'], 'alchemy_cors.cache_path' => function (Application $app) {
         return rtrim($app['cache.path'], '/\\') . '/alchemy_cors.cache.php';
     }]);
     $this['phraseanet.api_cors.options_provider'] = function (Application $app) {
         $paths = [];
         if (isset($app['phraseanet.configuration']['api_cors'])) {
             $config = $app['phraseanet.configuration']['api_cors'];
             if (isset($config['enabled']) && $config['enabled']) {
                 unset($config['enabled']);
                 $paths['/api/v\\d+/'] = $config;
             }
         }
         return new DefaultProvider($paths, []);
     };
     $this['alchemy_cors.options_providers'][] = 'phraseanet.api_cors.options_provider';
     $this->register(new LocaleServiceProvider());
     $this->setupEventDispatcher();
     $this['phraseanet.exception_handler'] = $this->share(function ($app) {
         $handler = PhraseaExceptionHandler::register($app['debug']);
         $handler->setTranslator($app['translator']);
         $handler->setLogger($app['monolog']);
         return $handler;
     });
     $providers = ['Alchemy\\Phrasea\\ControllerProvider\\Admin\\Collection' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\ConnectedUsers' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Dashboard' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Databox' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Databoxes' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Feeds' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Fields' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Plugins' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Root' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\SearchEngine' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Setup' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Subdefs' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\TaskManager' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Admin\\Users' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Client\\Root' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Datafiles' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Lightbox' => [], 'Alchemy\\Phrasea\\ControllerProvider\\MediaAccessor' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Minifier' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Permalink' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\BasketProvider' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Bridge' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\DoDownload' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Download' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Edit' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Export' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Feed' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Language' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Lazaret' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\MoveCollection' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Order' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Printer' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Property' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Push' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Query' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Record' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Root' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Share' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Story' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Tools' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Tooltip' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\TOU' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\Upload' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\UsrLists' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Prod\\WorkZone' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Report\\Activity' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Report\\Information' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Report\\Root' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Root\\Account' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Root\\Developers' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Root\\Login' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Root\\Root' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Root\\RSSFeeds' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Root\\Session' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Setup' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Thesaurus\\Thesaurus' => [], 'Alchemy\\Phrasea\\ControllerProvider\\Thesaurus\\Xmlhttp' => [], 'Alchemy\\Phrasea\\ControllerProvider\\User\\Notifications' => [], 'Alchemy\\Phrasea\\ControllerProvider\\User\\Preferences' => []];
     foreach ($providers as $class => $values) {
         $this->register(new $class(), $values);
     }
 }
コード例 #4
0
 public function __construct($environment = self::ENV_PROD)
 {
     parent::__construct();
     error_reporting(-1);
     $this['root.path'] = realpath(__DIR__ . '/../../..');
     $this->environment = $environment;
     mb_internal_encoding("UTF-8");
     !defined('JETON_MAKE_SUBDEF') ? define('JETON_MAKE_SUBDEF', 0x1) : '';
     !defined('JETON_WRITE_META_DOC') ? define('JETON_WRITE_META_DOC', 0x2) : '';
     !defined('JETON_WRITE_META_SUBDEF') ? define('JETON_WRITE_META_SUBDEF', 0x4) : '';
     !defined('JETON_WRITE_META') ? define('JETON_WRITE_META', 0x6) : '';
     $this['charset'] = 'UTF-8';
     $this['debug'] = $this->share(function (Application $app) {
         return Application::ENV_PROD !== $app->getEnvironment();
     });
     if ($this['debug'] === true) {
         ini_set('log_errors', 'on');
         ini_set('error_log', $this['root.path'] . '/logs/php_error.log');
     }
     $this->register(new BasketMiddlewareProvider());
     $this->register(new ACLServiceProvider());
     $this->register(new AuthenticationManagerServiceProvider());
     $this->register(new BorderManagerServiceProvider());
     $this->register(new BrowserServiceProvider());
     $this->register(new ConfigurationServiceProvider());
     $this->register(new ConfigurationTesterServiceProvider());
     $this->register(new ConvertersServiceProvider());
     $this->register(new RegistrationServiceProvider());
     $this->register(new CacheServiceProvider());
     $this->register(new CacheConnectionServiceProvider());
     $this->register(new ImagineServiceProvider());
     $this->register(new JMSSerializerServiceProvider());
     $this->register(new FFMpegServiceProvider());
     $this->register(new FeedServiceProvider());
     $this->register(new FilesystemServiceProvider());
     $this->register(new FtpServiceProvider());
     $this->register(new GeonamesServiceProvider());
     $this['geonames.server-uri'] = $this->share(function (Application $app) {
         return $app['conf']->get(['registry', 'webservices', 'geonames-server'], 'http://geonames.alchemyasp.com/');
     });
     $this->register(new MediaAlchemystServiceProvider());
     $this['media-alchemyst.configuration'] = $this->share(function (Application $app) {
         $configuration = [];
         foreach (['swftools.pdf2swf.binaries' => 'pdf2swf_binary', 'swftools.swfrender.binaries' => 'swf_render_binary', 'swftools.swfextract.binaries' => 'swf_extract_binary', 'unoconv.binaries' => 'unoconv_binary', 'mp4box.binaries' => 'mp4box_binary', 'gs.binaries' => 'ghostscript_binary', 'ffmpeg.ffmpeg.binaries' => 'ffmpeg_binary', 'ffmpeg.ffprobe.binaries' => 'ffprobe_binary', 'ffmpeg.ffmpeg.timeout' => 'ffmpeg_timeout', 'ffmpeg.ffprobe.timeout' => 'ffprobe_timeout', 'gs.timeout' => 'gs_timeout', 'mp4box.timeout' => 'mp4box_timeout', 'swftools.timeout' => 'swftools_timeout', 'unoconv.timeout' => 'unoconv_timeout'] as $parameter => $key) {
             if ($this['conf']->has(['main', 'binaries', $key])) {
                 $configuration[$parameter] = $this['conf']->get(['main', 'binaries', $key]);
             }
         }
         $imagineDriver = $app['conf']->get(['registry', 'executables', 'imagine-driver']);
         $configuration['ffmpeg.threads'] = $app['conf']->get(['registry', 'executables', 'ffmpeg-threads']);
         $configuration['imagine.driver'] = $imagineDriver ?: null;
         return $configuration;
     });
     $this['media-alchemyst.logger'] = $this->share(function (Application $app) {
         return $app['monolog'];
     });
     $this->register(new MediaVorusServiceProvider());
     $this->register(new MonologServiceProvider());
     $this['monolog.name'] = 'Phraseanet logger';
     $this['monolog.handler'] = $this->share(function () {
         return new NullHandler();
     });
     $this['monolog'] = $this->share($this->extend('monolog', function (Logger $monolog) {
         $monolog->pushProcessor(new IntrospectionProcessor());
         return $monolog;
     }));
     $this->register(new MP4BoxServiceProvider());
     $this->register(new NotificationDelivererServiceProvider());
     $this->register(new ORMServiceProvider());
     $this->register(new ManipulatorServiceProvider());
     $this->register(new InstallerServiceProvider());
     $this->register(new PhraseanetServiceProvider());
     $this->register(new PhraseaVersionServiceProvider());
     $this->register(new PHPExiftoolServiceProvider());
     $this->register(new ReCaptchaServiceProvider());
     $this->register(new SubdefServiceProvider());
     $this->register(new ZippyServiceProvider());
     $this['recaptcha.public-key'] = $this->share(function (Application $app) {
         if ($app['conf']->get(['registry', 'webservices', 'captcha-enabled'])) {
             return $app['conf']->get(['registry', 'webservices', 'recaptcha-public-key']);
         }
     });
     $this['recaptcha.private-key'] = $this->share(function (Application $app) {
         if ($app['conf']->get(['registry', 'webservices', 'captcha-enabled'])) {
             return $app['conf']->get(['registry', 'webservices', 'recaptcha-private-key']);
         }
     });
     $this->register(new SearchEngineServiceProvider());
     $this->register(new SessionHandlerServiceProvider());
     $this->register(new SessionServiceProvider(), ['session.test' => $this->getEnvironment() === static::ENV_TEST]);
     $this['session.storage.test'] = $this->share(function ($app) {
         return new MockArraySessionStorage();
     });
     $this['session.storage.handler'] = $this->share(function ($app) {
         return $this['session.storage.handler.factory']->create($app['conf']);
     });
     $this->register(new SerializerServiceProvider());
     $this->register(new ServiceControllerServiceProvider());
     $this->register(new SwiftmailerServiceProvider());
     $this->register(new TasksServiceProvider());
     $this->register(new TemporaryFilesystemServiceProvider());
     $this->register(new TokensServiceProvider());
     $this->register(new TwigServiceProvider(), ['twig.options' => ['cache' => $this['root.path'] . '/tmp/cache_twig/']]);
     $this->register(new TranslationServiceProvider(), ['locale_fallbacks' => ['fr'], 'translator.cache-options' => ['debug' => $this['debug'], 'cache_dir' => $this['root.path'] . '/tmp/translations']]);
     $this['translator'] = $this->share($this->extend('translator', function (CachedTranslator $translator, $app) {
         $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.fr.xlf', 'fr', 'messages');
         $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.fr.xlf', 'fr', 'validators');
         $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.en.xlf', 'en', 'messages');
         $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.en.xlf', 'en', 'validators');
         $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.de.xlf', 'de', 'messages');
         $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.de.xlf', 'de', 'validators');
         $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/messages.nl.xlf', 'nl', 'messages');
         $translator->addResource('xlf', __DIR__ . '/../../../resources/locales/validators.nl.xlf', 'nl', 'validators');
         return $translator;
     }));
     $this->register(new FormServiceProvider());
     $this['form.type.extensions'] = $this->share($this->extend('form.type.extensions', function ($extensions) {
         $extensions[] = new HelpTypeExtension();
         return $extensions;
     }));
     $this->setupTwig();
     $this->register(new UnoconvServiceProvider());
     $this->register(new UrlGeneratorServiceProvider());
     $this->setupUrlGenerator();
     $this->register(new UnicodeServiceProvider());
     $this->register(new ValidatorServiceProvider());
     $this->register(new XPDFServiceProvider());
     $this->register(new FileServeServiceProvider());
     $this->register(new ManipulatorServiceProvider());
     $this->register(new PluginServiceProvider());
     $this['phraseanet.exception_handler'] = $this->share(function ($app) {
         $handler = PhraseaExceptionHandler::register($app['debug']);
         $handler->setTranslator($app['translator']);
         return $handler;
     });
     $this['swiftmailer.transport'] = $this->share(function ($app) {
         if ($app['conf']->get(['registry', 'email', 'smtp-enabled'])) {
             $transport = new \Swift_Transport_EsmtpTransport($app['swiftmailer.transport.buffer'], [$app['swiftmailer.transport.authhandler']], $app['swiftmailer.transport.eventdispatcher']);
             $encryption = null;
             if (in_array($app['conf']->get(['registry', 'email', 'smtp-secure-mode']), ['ssl', 'tls'])) {
                 $encryption = $app['conf']->get(['registry', 'email', 'smtp-secure-mode']);
             }
             $options = $app['swiftmailer.options'] = array_replace(['host' => $app['conf']->get(['registry', 'email', 'smtp-host']), 'port' => $app['conf']->get(['registry', 'email', 'smtp-port']), 'username' => $app['conf']->get(['registry', 'email', 'smtp-user']), 'password' => $app['conf']->get(['registry', 'email', 'smtp-password']), 'encryption' => $encryption, 'auth_mode' => null], $app['swiftmailer.options']);
             $transport->setHost($options['host']);
             $transport->setPort($options['port']);
             // tls or ssl
             $transport->setEncryption($options['encryption']);
             if ($app['conf']->get(['registry', 'email', 'smtp-auth-enabled'])) {
                 $transport->setUsername($options['username']);
                 $transport->setPassword($options['password']);
                 $transport->setAuthMode($options['auth_mode']);
             }
         } else {
             $transport = new \Swift_Transport_MailTransport(new \Swift_Transport_SimpleMailInvoker(), $app['swiftmailer.transport.eventdispatcher']);
         }
         return $transport;
     });
     $this['imagine.factory'] = $this->share(function (Application $app) {
         if ($app['conf']->get(['registry', 'executables', 'imagine-driver']) != '') {
             return $app['conf']->get(['registry', 'executables', 'imagine-driver']);
         }
         if (class_exists('\\Gmagick')) {
             return 'gmagick';
         }
         if (class_exists('\\Imagick')) {
             return 'imagick';
         }
         if (extension_loaded('gd')) {
             return 'gd';
         }
         throw new \RuntimeException('No Imagine driver available');
     });
     $app = $this;
     $this['phraseanet.logger'] = $this->protect(function ($databox) use($app) {
         try {
             return \Session_Logger::load($app, $databox);
         } catch (\Exception_Session_LoggerNotFound $e) {
             return \Session_Logger::create($app, $databox, $app['browser']);
         }
     });
     $this['date-formatter'] = $this->share(function (Application $app) {
         return new \phraseadate($app);
     });
     $this['xpdf.pdftotext'] = $this->share($this->extend('xpdf.pdftotext', function (PdfToText $pdftotext, Application $app) {
         if ($app['conf']->get(['registry', 'executables', 'pdf-max-pages'])) {
             $pdftotext->setPageQuantity($app['conf']->get(['registry', 'executables', 'pdf-max-pages']));
         }
         return $pdftotext;
     }));
     $this['dispatcher'] = $this->share($this->extend('dispatcher', function ($dispatcher, Application $app) {
         $dispatcher->addListener(KernelEvents::REQUEST, [$app, 'initSession'], 254);
         $dispatcher->addListener(KernelEvents::RESPONSE, [$app, 'addUTF8Charset'], -128);
         $dispatcher->addSubscriber(new LogoutSubscriber());
         $dispatcher->addSubscriber(new PhraseaLocaleSubscriber($app));
         $dispatcher->addSubscriber(new MaintenanceSubscriber($app));
         $dispatcher->addSubscriber(new CookiesDisablerSubscriber($app));
         return $dispatcher;
     }));
     $this['log.channels'] = ['monolog', 'task-manager.logger'];
     $this->register(new LocaleServiceProvider());
     $this->mount('/include/minify/', new Minifier());
     $this->mount('/permalink/', new Permalink());
     $this->mount('/lightbox/', new Lightbox());
     $app['plugins.directory'] = $app->share(function () {
         $dir = __DIR__ . '/../../../plugins';
         if (is_dir($dir)) {
             return realpath($dir);
         }
         return $dir;
     });
 }