<commit_before><?php
namespace Payum\Silex;

use Payum\Core\Bridge\Symfony\Action\ObtainCreditCardAction;
use Payum\Core\Bridge\Symfony\Form\Type\CreditCardExpirationDateType;
use Payum\Core\Bridge\Symfony\Form\Type\CreditCardType;
use Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter;
use Payum\Core\Bridge\Symfony\Security\HttpRequestVerifier;
use Payum\Core\Bridge\Symfony\Security\TokenFactory;
use Payum\Core\Bridge\Twig\Action\RenderTemplateAction;
use Payum\Core\Bridge\Twig\TwigFactory;
use Payum\Core\PaymentInterface;
use Payum\Core\Registry\SimpleRegistry;
use Payum\Core\Reply\ReplyInterface;
use Payum\Silex\Controller\AuthorizeController;
use Payum\Silex\Controller\CaptureController;
use Payum\Silex\Controller\NotifyController;
use Payum\Silex\Controller\RefundController;
use Silex\Application;
use Silex\ServiceProviderInterface;

class PayumProvider implements ServiceProviderInterface
{
    /**
     * {@inheritDoc}
     */
    public function register(Application $app)
    {
        $this->registerService($app);
        $this->registerControllers($app);
        $this->registerListeners($app);
    }

    /**
     * {@inheritDoc}
     */
    public function boot(Application $app)
    {
    }

    /**
     * @param Application $app
     */
    protected function registerService(Application $app)
    {
        $app['payum.template.layout'] = '@PayumCore/layout.html.twig';
        $app['payum.template.obtain_credit_card'] = '@PayumSymfonyBridge/obtainCreditCard.html.twig';

        $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function($loader, $app) {
            /** @var  \Twig_Loader_Filesystem $loader */

            $loader->addPath(TwigFactory::guessViewsPath('Payum\Core\Payment'), 'PayumCore');
            $loader->addPath(TwigFactory::guessViewsPath('Payum\Stripe\PaymentFactory'), 'PayumStripe');
            $loader->addPath(TwigFactory::guessViewsPath('Payum\Klarna\Checkout\PaymentFactory'), 'PayumKlarnaCheckout');
            $loader->addPath(TwigFactory::guessViewsPath('Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter'), 'PayumSymfonyBridge');

            return $loader;
        }));

        $app['payum.action.render_template'] = $app->share(function($app) {
            return new RenderTemplateAction($app['twig'], $app['payum.template.layout']);
        });

        $app['payum.action.obtain_credit_card'] = $app->share(function($app) {
            $action = new ObtainCreditCardAction($app['form.factory'], $app['payum.template.obtain_credit_card']);
            $action->setRequest($app['request']);

            return $action;
        });

        $app['payum.security.token_storage'] = $app->share(function() {
            throw new \LogicException('This service has to be overwritten. Check the example in the doc at payum.org');
        });

        $app['payum.reply_to_symfony_response_converter'] = $app->share(function($app) {
            return new ReplyToSymfonyResponseConverter();
        });

        $app['payum.security.http_request_verifier'] = $app->share(function($app) {
            return new HttpRequestVerifier($app['payum.security.token_storage']);
        });

        $app['payum.security.token_factory'] = $app->share(function($app) {
            return new TokenFactory(
                $app['url_generator'],
                $app['payum.security.token_storage'],
                $app['payum'],
                'payum_capture_do',
                'payum_notify_do',
                'payum_authorize_do'
            );
        });

        $app['form.types'] = $app->share($app->extend('form.types', function ($types) use ($app) {
            $types[] = new CreditCardType();
            $types[] = new CreditCardExpirationDateType();

            return $types;
        }));

        $app['payum.payments'] = $app->share(function () {
            return [
                // name => instance of PaymentInterface<commit_msg>make compatible with changes in core 0.13<commit_after><?php
namespace Payum\Silex;

use Payum\Core\Bridge\Symfony\Action\ObtainCreditCardAction;
use Payum\Core\Bridge\Symfony\Form\Type\CreditCardExpirationDateType;
use Payum\Core\Bridge\Symfony\Form\Type\CreditCardType;
use Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter;
use Payum\Core\Bridge\Symfony\Security\HttpRequestVerifier;
use Payum\Core\Bridge\Symfony\Security\TokenFactory;
use Payum\Core\Bridge\Twig\Action\RenderTemplateAction;
use Payum\Core\Bridge\Twig\TwigFactory;
use Payum\Core\Registry\SimpleRegistry;
use Payum\Core\Reply\ReplyInterface;
use Payum\Silex\Controller\AuthorizeController;
use Payum\Silex\Controller\CaptureController;
use Payum\Silex\Controller\NotifyController;
use Payum\Silex\Controller\RefundController;
use Silex\Application;
use Silex\ServiceProviderInterface;

class PayumProvider implements ServiceProviderInterface
{
    /**
     * {@inheritDoc}
     */
    public function register(Application $app)
    {
        $this->registerService($app);
        $this->registerControllers($app);
        $this->registerListeners($app);
    }

    /**
     * {@inheritDoc}
     */
    public function boot(Application $app)
    {
    }

    /**
     * @param Application $app
     */
    protected function registerService(Application $app)
    {
        $app['payum.template.layout'] = '@PayumCore/layout.html.twig';
        $app['payum.template.obtain_credit_card'] = '@PayumSymfonyBridge/obtainCreditCard.html.twig';

        $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function($loader, $app) {
            /** @var  \Twig_Loader_Filesystem $loader */

            $loader->addPath(TwigFactory::guessViewsPath('Payum\Core\Payment'), 'PayumCore');
            $loader->addPath(TwigFactory::guessViewsPath('Payum\Stripe\PaymentFactory'), 'PayumStripe');
            $loader->addPath(TwigFactory::guessViewsPath('Payum\Klarna\Checkout\PaymentFactory'), 'PayumKlarnaCheckout');
            $loader->addPath(TwigFactory::guessViewsPath('Payum\Core\Bridge\Symfony\ReplyToSymfonyResponseConverter'), 'PayumSymfonyBridge');

            return $loader;
        }));

        $app['payum.action.render_template'] = $app->share(function($app) {
            return new RenderTemplateAction($app['twig'], $app['payum.template.layout']);
        });

        $app['payum.action.obtain_credit_card'] = $app->share(function($app) {
            $action = new ObtainCreditCardAction($app['form.factory'], $app['payum.template.obtain_credit_card']);
            $action->setRequest($app['request']);

            return $action;
        });

        $app['payum.security.token_storage'] = $app->share(function() {
            throw new \LogicException('This service has to be overwritten. Check the example in the doc at payum.org');
        });

        $app['payum.reply_to_symfony_response_converter'] = $app->share(function($app) {
            return new ReplyToSymfonyResponseConverter();
        });

        $app['payum.security.http_request_verifier'] = $app->share(function($app) {
            return new HttpRequestVerifier($app['payum.security.token_storage']);
        });

        $app['payum.security.token_factory'] = $app->share(function($app) {
            return new TokenFactory(
                $app['url_generator'],
                $app['payum.security.token_storage'],
                $app['payum'],
                'payum_capture_do',
                'payum_notify_do',
                'payum_authorize_do',
                'payum_refund_do'
            );
        });

        $app['form.types'] = $app->share($app->extend('form.types', function ($types) use ($app) {
            $types[] = new CreditCardType();
            $types[] = new CreditCardExpirationDateType();

            return $types;
        }));

        $app['payum.payments'] = $app->share(function () {
            return [
                // name => instance of PaymentInterface
{'fraction_non_alphanumeric': 0.14255212258226577, 'fraction_numerical': 0.00037678975131876413, 'mean_word_length': 3.098301595470921, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3497892', 'n_tokens_mistral': 2419, 'n_tokens_neox': 2343, 'n_words': 318}