Skip to content

Commit de46b45

Browse files
authored
Feature/improve (#2)
1 parent 0ad48d2 commit de46b45

33 files changed

+1794
-56
lines changed

.scrutinizer.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@ build:
1515
tests:
1616
stop_on_failure: true
1717
override:
18-
- php-scrutinizer-run --enable-security-analysis
19-
-
20-
command: make codestyle
21-
analysis:
22-
file: 'build/reports/cs-data'
23-
format: 'php-cs-checkstyle'
2418
-
2519
command: make coverage
2620
idle_timeout: 1200
2721
coverage:
2822
file: 'build/coverage/clover.xml'
2923
format: 'php-clover'
24+
- php-scrutinizer-run --enable-security-analysis
25+
- make codestyle
3026
cache:
3127
directories:
3228
- ~/.composer
@@ -39,8 +35,6 @@ build:
3935
COMPOSER_OPTIONS: '--optimize-autoloader'
4036
COVERAGE_OUTPUT_STYLE: 'clover'
4137
COVERAGE_CLOVER_FILE_PATH: 'build/coverage/clover.xml'
42-
PHPCS_REPORT_STYLE: 'checkstyle'
43-
PHPCS_REPORT_FILE: 'build/reports/cs-data'
4438
php:
4539
version: "7.1"
4640
timezone: UTC

.travis.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
language: php
22

33
php:
4-
- '7.0'
54
- '7.1'
65
- '7.2'
6+
- '7.3'
77

88
env:
99
global:
1010
CI: 'true'
1111
TEST_OUTPUT_STYLE: 'pretty'
1212
PHPCS_REPORT_STYLE: 'full'
1313
COMPOSER_OPTIONS: '--optimize-autoloader'
14+
matrix:
15+
- SYMFONY_VERSION: '~3.0'
16+
- SYMFONY_VERSION: '~4.0'
1417

1518
sudo: false
1619

@@ -19,9 +22,10 @@ matrix:
1922

2023
before_install:
2124
# remove xdebug to speed up build
22-
- phpenv config-rm xdebug.ini
25+
- phpenv config-rm xdebug.ini || true
2326

2427
install:
28+
- composer require symfony/http-foundation:$SYMFONY_VERSION symfony/http-kernel:$SYMFONY_VERSION symfony/config:$SYMFONY_VERSION symfony/dependency-injection:$SYMFONY_VERSION
2529
- make build
2630
script:
2731
- make test-technical

composer.json

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
{
2-
"name": "yoanm/symfony-jsonrpc-http-server-doc",
3-
"description": "Symfony bundle for easy JSON-RPC server documentation",
4-
"license": "MIT",
5-
"type": "library",
6-
"support": {
7-
"issues": "https://github.com/yoanm/symfony-jsonrpc-http-server-doc/issues"
8-
},
9-
"authors": [
10-
{
11-
"name": "Yoanm",
12-
"email": "yoanm@users.noreply.github.com",
13-
"role": "Developer"
14-
}
15-
],
16-
"autoload": {
17-
"psr-4": {
18-
"Yoanm\\SymfonyJsonRpcHttpServerDoc\\": "src"
19-
}
20-
},
21-
"autoload-dev": {
22-
"psr-4": {
23-
"Tests\\": "tests",
24-
"Tests\\Functional\\BehatContext\\": "features/bootstrap"
25-
}
26-
},
27-
"require": {
28-
"php": ">=5.5",
29-
"yoanm/jsonrpc-server-sdk": "dev-release/3.0.0 || dev-master",
30-
"yoanm/jsonrpc-server-doc-sdk": "dev-release/1.0.0 || dev-master",
31-
"yoanm/symfony-jsonrpc-http-server": "dev-release/3.0.0 || dev-master",
32-
"symfony/http-foundation": "^3.0 || ^4.0",
33-
"symfony/http-kernel": "^3.0 || ^4.0",
34-
"symfony/config": "^3.0 || ^4.0",
35-
"symfony/dependency-injection": "^3.0 || ^4.0"
36-
},
37-
"require-dev": {
38-
"behat/behat": "~3.0",
39-
"squizlabs/php_codesniffer": "3.*",
40-
"phpunit/phpunit": "^6.0 || ^7.0",
41-
"matthiasnoback/symfony-dependency-injection-test": "^2.0 || ^3.0",
42-
"matthiasnoback/symfony-config-test": "^3.0 || ^4.0",
43-
"symfony/framework-bundle": "^3.4",
44-
"yoanm/php-unit-extended": "~1.0"
2+
"name": "yoanm/symfony-jsonrpc-http-server-doc",
3+
"description": "Symfony bundle for easy JSON-RPC server documentation",
4+
"license": "MIT",
5+
"type": "library",
6+
"minimum-stability": "dev",
7+
"support": {
8+
"issues": "https://github.com/yoanm/symfony-jsonrpc-http-server-doc/issues"
9+
},
10+
"authors": [
11+
{
12+
"name": "Yoanm",
13+
"email": "yoanm@users.noreply.github.com",
14+
"role": "Developer"
4515
}
16+
],
17+
"autoload": {
18+
"psr-4": {
19+
"Yoanm\\SymfonyJsonRpcHttpServerDoc\\": "src"
20+
}
21+
},
22+
"autoload-dev": {
23+
"psr-4": {
24+
"Tests\\": "tests",
25+
"Tests\\Functional\\BehatContext\\": "features/bootstrap"
26+
}
27+
},
28+
"require": {
29+
"php": ">=7.1",
30+
"yoanm/jsonrpc-server-sdk": "dev-release/3.0.0",
31+
"yoanm/jsonrpc-server-doc-sdk": "dev-release/1.0.0",
32+
"yoanm/symfony-jsonrpc-http-server": "dev-release/2.0.0",
33+
"symfony/http-foundation": "^3.0 || ^4.0",
34+
"symfony/http-kernel": "^3.0 || ^4.0",
35+
"symfony/config": "^3.0 || ^4.0",
36+
"symfony/dependency-injection": "^3.0 || ^4.0"
37+
},
38+
"require-dev": {
39+
"behat/behat": "~3.0",
40+
"squizlabs/php_codesniffer": "3.*",
41+
"phpunit/phpunit": "^6.0 || ^7.0",
42+
"matthiasnoback/symfony-dependency-injection-test": "^2.0 || ^3.0",
43+
"matthiasnoback/symfony-config-test": "^3.0 || ^4.0",
44+
"symfony/framework-bundle": "^3.0 || ^4.0",
45+
"yoanm/php-unit-extended": "~1.0"
46+
}
4647
}

phpunit.xml.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
processIsolation="false"
99

1010
stopOnRisky="true"
11-
processUncoveredFilesFromWhitelist="true"
12-
addUncoveredFilesFromWhitelist="true"
13-
checkForUnintentionallyCoveredCode="true"
1411

1512
stopOnError="true"
1613
stopOnFailure="true"
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
namespace Yoanm\SymfonyJsonRpcHttpServerDoc\Creator;
3+
4+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
5+
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodAwareInterface;
6+
use Yoanm\JsonRpcServer\Domain\JsonRpcMethodInterface;
7+
use Yoanm\JsonRpcServerDoc\Domain\Model\HttpServerDoc;
8+
use Yoanm\JsonRpcServerDoc\Domain\Model\MethodDoc;
9+
use Yoanm\JsonRpcServerDoc\Domain\Model\ServerDoc;
10+
use Yoanm\SymfonyJsonRpcHttpServerDoc\Event\MethodDocCreatedEvent;
11+
use Yoanm\SymfonyJsonRpcHttpServerDoc\Event\ServerDocCreatedEvent;
12+
13+
/**
14+
* Class HttpServerDocCreator
15+
*/
16+
class HttpServerDocCreator implements JsonRpcMethodAwareInterface
17+
{
18+
/** @var EventDispatcherInterface */
19+
private $dispatcher;
20+
/** @var JsonRpcMethodInterface[] */
21+
private $methodList = [];
22+
/** @var string|null */
23+
private $jsonRpcEndpoint = null;
24+
25+
/**
26+
* @param EventDispatcherInterface $dispatcher
27+
* @param string|null $jsonRpcEndpoint
28+
*/
29+
public function __construct(EventDispatcherInterface $dispatcher, string $jsonRpcEndpoint = null)
30+
{
31+
$this->dispatcher = $dispatcher;
32+
$this->jsonRpcEndpoint = $jsonRpcEndpoint;
33+
}
34+
/**
35+
* @param string|null $host
36+
*
37+
* @return HttpServerDoc
38+
*/
39+
public function create($host = null) : HttpServerDoc
40+
{
41+
$serverDoc = new HttpServerDoc();
42+
if (null !== $this->jsonRpcEndpoint) {
43+
$serverDoc->setEndpoint($this->jsonRpcEndpoint);
44+
}
45+
if (null !== $host) {
46+
$serverDoc->setHost($host);
47+
}
48+
49+
$this->appendMethodsDoc($serverDoc);
50+
51+
$event = new ServerDocCreatedEvent($serverDoc);
52+
$this->dispatcher->dispatch($event::EVENT_NAME, $event);
53+
54+
return $serverDoc;
55+
}
56+
57+
/**
58+
* {@inheritdoc}
59+
*/
60+
public function addJsonRpcMethod(string $methodName, JsonRpcMethodInterface $method) : void
61+
{
62+
$this->methodList[$methodName] = $method;
63+
}
64+
65+
/**
66+
* @param ServerDoc $serverDoc
67+
*/
68+
protected function appendMethodsDoc(ServerDoc $serverDoc)
69+
{
70+
foreach ($this->methodList as $methodName => $method) {
71+
$event = (
72+
new MethodDocCreatedEvent(
73+
new MethodDoc($methodName)
74+
)
75+
)
76+
->setMethod($method);
77+
78+
$this->dispatcher->dispatch($event::EVENT_NAME, $event);
79+
80+
$serverDoc->addMethod($event->getDoc());
81+
}
82+
}
83+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Yoanm\SymfonyJsonRpcHttpServerDoc\DependencyInjection;
3+
4+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
5+
use Symfony\Component\Config\Definition\ConfigurationInterface;
6+
7+
/**
8+
* Class Configuration
9+
*/
10+
class Configuration implements ConfigurationInterface
11+
{
12+
const DEFAULT_ENDPOINT = '/doc';
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
public function getConfigTreeBuilder()
17+
{
18+
$treeBuilder = new TreeBuilder();
19+
20+
$rootNode = $treeBuilder->root(JsonRpcHttpServerDocExtension::EXTENSION_IDENTIFIER);
21+
22+
$rootNode
23+
->addDefaultsIfNotSet()
24+
->children()
25+
->variableNode('endpoint')
26+
->info('Your custom http doc endpoint path')
27+
->treatNullLike(self::DEFAULT_ENDPOINT)
28+
->defaultValue(self::DEFAULT_ENDPOINT)
29+
->end()
30+
->end()
31+
;
32+
33+
return $treeBuilder;
34+
}
35+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
namespace Yoanm\SymfonyJsonRpcHttpServerDoc\DependencyInjection;
3+
4+
use Symfony\Component\Config\Definition\Processor;
5+
use Symfony\Component\Config\FileLocator;
6+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7+
use Symfony\Component\DependencyInjection\ContainerBuilder;
8+
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
9+
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
10+
use Symfony\Component\DependencyInjection\Reference;
11+
12+
/**
13+
* Class JsonRpcHttpServerDocExtension
14+
*/
15+
class JsonRpcHttpServerDocExtension implements ExtensionInterface, CompilerPassInterface
16+
{
17+
/** Tags */
18+
/** Use this tag to inject your custom documentation creator */
19+
const DOC_PROVIDER_TAG = 'json_rpc_server_doc.doc_provider';
20+
21+
// Extension identifier (used in configuration for instance)
22+
const EXTENSION_IDENTIFIER = 'json_rpc_http_server_doc';
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
public function load(array $configs, ContainerBuilder $container)
28+
{
29+
$this->compileAndProcessConfigurations($configs, $container);
30+
31+
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
32+
33+
$loader->load('services.sdk.yaml');
34+
$loader->load('services.private.yaml');
35+
$loader->load('services.public.yaml');
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
public function process(ContainerBuilder $container)
42+
{
43+
$this->appendDocumentationProvider($container);
44+
}
45+
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function getNamespace()
51+
{
52+
return 'http://example.org/schema/dic/'.$this->getAlias();
53+
}
54+
55+
/**
56+
* {@inheritdoc}
57+
*/
58+
public function getXsdValidationBasePath()
59+
{
60+
return '';
61+
}
62+
63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function getAlias()
67+
{
68+
return self::EXTENSION_IDENTIFIER;
69+
}
70+
71+
/**
72+
* @param ContainerBuilder $container
73+
*/
74+
private function appendDocumentationProvider(ContainerBuilder $container)
75+
{
76+
$docProviderDefinition = $container->getDefinition('json_rpc_http_server_doc.finder.normalized_doc');
77+
$docCreatorServiceList = $container->findTaggedServiceIds(self::DOC_PROVIDER_TAG);
78+
foreach (array_keys($docCreatorServiceList) as $serviceId) {
79+
$docProviderDefinition->addMethodCall('addProvider', [new Reference($serviceId)]);
80+
}
81+
}
82+
83+
/**
84+
* @param array $configs
85+
* @param ContainerBuilder $container
86+
*/
87+
private function compileAndProcessConfigurations(array $configs, ContainerBuilder $container)
88+
{
89+
$configuration = new Configuration();
90+
$config = (new Processor())->processConfiguration($configuration, $configs);
91+
92+
$httpEndpointPath = $config['endpoint'];
93+
94+
$container->setParameter(self::EXTENSION_IDENTIFIER.'.http_endpoint_path', $httpEndpointPath);
95+
}
96+
}

0 commit comments

Comments
 (0)