Skip to content

make jms optional #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
"symfony/http-kernel": "~2.7 || ~3.0",
"scaytrase/json-rpc-client": "~1.0",
"bankiru/rpc-server-bundle": "~1.1",
"nelmio/api-doc-bundle": "~2.9",
"jms/serializer-bundle": "~1.1"
"nelmio/api-doc-bundle": "~2.9"
},
"require-dev": {
"phpunit/phpunit": "~4.8 || ~5.1",
"symfony/browser-kit": "~2.7 || ~3.0",
"phpunit/php-code-coverage": "~2.1 || ~3.0",
"jms/serializer-bundle": "~1.1",
"doctrine/doctrine-bundle": "~1.6",
"doctrine/orm": "~2.3"
},
"suggest": {
"jms/serializer-bundle": "For serializing response",
"doctrine/doctrine-bundle": "For relations handler",
"doctrine/orm": "For relations handler"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public function process(ContainerBuilder $container)
return;
}

if (!$container->has('jms_serializer.metadata.doctrine_type_driver')) {
return;
}

$container->register('jms_serializer.driver.relation', HandledTypeDriver::class)
->setArguments(
[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Bankiru\Api\JsonRpc\DependencyInjection\Compiler;

use Bankiru\Api\JsonRpc\Listener\SerializedJsonRpcResponseListener;
use Bankiru\Api\Rpc\RpcEvents;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class JmsSerializerPass implements CompilerPassInterface
{
/** {@inheritdoc} */
public function process(ContainerBuilder $container)
{
if (!$container->has('jms_serializer')) {
return;
}

$definition = $container->register('jsonrpc.view.serialize_response', SerializedJsonRpcResponseListener::class);
$definition->setArguments(
[
new Reference('jms_serializer'),
]
);
$definition->addTag(
'kernel.event_listener',
[
'event' => RpcEvents::VIEW,
'method' => 'onPlainResponse',
'priority' => -254,
]
);
}
}
2 changes: 2 additions & 0 deletions src/Bankiru/Api/JsonRpc/JsonRpcBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Bankiru\Api\JsonRpc;

use Bankiru\Api\JsonRpc\DependencyInjection\Compiler\JmsDriverPass;
use Bankiru\Api\JsonRpc\DependencyInjection\Compiler\JmsSerializerPass;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -15,5 +16,6 @@ public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new JmsDriverPass(), PassConfig::TYPE_BEFORE_REMOVING);
$container->addCompilerPass(new JmsSerializerPass());
}
}
7 changes: 0 additions & 7 deletions src/Bankiru/Api/JsonRpc/Resources/config/jsonrpc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ services:
tags:
- { name: kernel.event_listener, event: rpc.response, method: filterNotificationResponse, priority: -255 }

jsonrpc.view.serialize_response:
class: Bankiru\Api\JsonRpc\Listener\SerializedJsonRpcResponseListener
arguments:
- "@jms_serializer"
tags:
- { name: kernel.event_listener, event: rpc.view, method: onPlainResponse, priority: -254 }

jsonrpc.reponse_listener.match_id:
class: Bankiru\Api\JsonRpc\Listener\IdMatcherListener
tags:
Expand Down