Skip to content

Commit

Permalink
Symfony 7.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsykun committed Oct 8, 2023
1 parent e6f93ec commit b5d318f
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 66 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/composer.lock
/vendor/*
/var/*
.phpunit.result.cache
25 changes: 0 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,6 @@ return [
]
```

For Symfony 3.4

```php
<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ....
new Okvpn\Bundle\DatadogBundle\OkvpnDatadogBundle(), //Should loaded after framework bundle
);
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
}
```

3. Base configuration to enable the datadog client in your `config.yml`

```
Expand Down
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
"psr-4": { "Okvpn\\Bundle\\DatadogBundle\\Tests\\": "tests/" }
},
"require": {
"php":">=7.2",
"symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"php":">=7.4",
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0 || ^7.0",
"graze/dog-statsd": "^0.4 || ^1.0"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"doctrine/doctrine-bundle": "^1.6.10 || ^2.0.6",
"doctrine/orm": "2.5.11 || 2.6.x-dev as 2.6.3 || ^2.7.0",
"phpunit/phpunit": "^6.2 || ^8.5",
"symfony/browser-kit": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"symfony/console": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"symfony/security-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"symfony/var-dumper": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"symfony/monolog-bundle": "^3.2.0"
"doctrine/doctrine-bundle": "^2.6",
"doctrine/orm": "^2.7",
"phpunit/phpunit": "^8.5 || ^10.0",
"symfony/browser-kit": "^4.4 || ^5.4 || ^6.0 || ^7.0",
"symfony/console": "^4.4 || ^5.4 || ^6.0 || ^7.0",
"symfony/security-bundle": "^4.4 || ^5.4 || ^6.0 || ^7.0",
"symfony/phpunit-bridge": "^4.4 || ^5.4 || ^6.0 || ^7.0",
"symfony/var-dumper": "^4.4 || ^5.4 || ^6.0 || ^7.0",
"symfony/yaml": "^4.4 || ^5.4 || ^6.0 || ^7.0",
"symfony/monolog-bundle": "^3.2"
}
}
2 changes: 1 addition & 1 deletion src/Client/ClientWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function event($title, $text, array $metadata = [], array $tags = [])
*/
public function getOption(string $option, $default = null)
{
return isset($this->options[$option]) ? $this->options[$option] : $default;
return $this->options[$option] ?? $default;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Client/DatadogDns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Okvpn\Bundle\DatadogBundle\Client;

class DatadogDns
{
public static function parser(string $dsn): array
{

}
}
15 changes: 15 additions & 0 deletions src/Client/DatadogFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Okvpn\Bundle\DatadogBundle\Client;

class DatadogFactory implements DatadogFactoryInterface
{
/**
* {@inheritdoc}
*/
public function createClient(array $options): DogStatsInterface
{
}
}
10 changes: 10 additions & 0 deletions src/Client/DatadogFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Okvpn\Bundle\DatadogBundle\Client;

interface DatadogFactoryInterface
{
public function createClient(array $options): DogStatsInterface;
}
4 changes: 1 addition & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('okvpn_datadog');
$rootNode = \method_exists($treeBuilder, 'getRootNode') ?
$treeBuilder->getRootNode() :
$treeBuilder->root('okvpn_datadog');
$rootNode = $treeBuilder->getRootNode();

$rootNode->children()
->arrayNode('handle_exceptions')
Expand Down
2 changes: 1 addition & 1 deletion src/Logging/ErrorBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function flush(): void

public function rootError(): ?array
{
return isset($this->errors[0]) ? $this->errors[0] : null;
return $this->errors[0] ?? null;
}

public function getErrors(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Logging/Watcher/DefaultWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function watch(): array
$context = [];
if ($this->tokenStorage instanceof TokenStorageInterface) {
$token = $this->tokenStorage->getToken();
if (null !== $token) {
if (null !== $token) {
$context['token'] = method_exists($token, '__toString') ? $token->__toString() : $token->serialize();
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/Services/ExceptionHashService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public function hash(\Throwable $exception): string
}
}

$hash = sha1($hash);
return $hash;
return sha1($hash);
}
}
6 changes: 6 additions & 0 deletions tests/Functional/App/Controller/AppDatadogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Controller;

use Doctrine\Persistence\ManagerRegistry;
use Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Entity\DatadogUser;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
Expand Down Expand Up @@ -39,6 +40,11 @@ public function entity()
class AppDatadogController extends AbstractController
{
use AppDatadogControllerTrait;

public function getDoctrine(): ManagerRegistry
{
return $this->container->get('doctrine');
}
}
} else {
class AppDatadogController extends Controller
Expand Down
5 changes: 5 additions & 0 deletions tests/Functional/App/Entity/DatadogUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/**
* @ORM\Entity
*/
#[ORM\Entity]
class DatadogUser
{
/**
Expand All @@ -18,13 +19,17 @@ class DatadogUser
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Column('id', type: 'integer')]
#[ORM\Id]
#[ORM\CustomIdGenerator]
private $id;

/**
* @var string
*
* @ORM\Column(type="string", length=64)
*/
#[ORM\Column('username', type: 'string', length: 64)]
private $username;

/**
Expand Down
43 changes: 30 additions & 13 deletions tests/Functional/App/OkvpnKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,45 @@
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouteCollectionBuilder;

trait OkvpnKernelTrait
{
if (Kernel::MAJOR_VERSION >= 5) {
trait OkvpnKernelTrait
{
public function loadRoutes()
{
$routes = new RouteCollection();

/**
* @param LoaderInterface $loader
* @return RouteCollection
*/
public function loadRoutes(LoaderInterface $loader)
$routes->add('index', $this->createRoute("/", "app.controller.base_controller::index"));
$routes->add("exception", $this->createRoute('/exception', "app.controller.base_controller::exception"));
$routes->add("entity", $this->createRoute('/entity', "app.controller.base_controller::entity"));
return $routes;
}

private function createRoute(string $path, string $controller): Route
{
return new Route($path, ['_controller' => $controller]);
}
}
} else {
trait OkvpnKernelTrait
{
$routes = new RouteCollectionBuilder($loader);
public function loadRoutes(LoaderInterface $loader)
{
$routes = new RouteCollectionBuilder($loader);

$routes->add('/', "app.controller.base_controller:index");
$routes->add('/exception', "app.controller.base_controller:exception");
$routes->add('/entity', "app.controller.base_controller:entity");
$routes->add('/', "app.controller.base_controller:index");
$routes->add('/exception', "app.controller.base_controller:exception");
$routes->add('/entity', "app.controller.base_controller:entity");

return $routes->build();
return $routes->build();
}
}
}


class OkvpnKernel extends Kernel
{
use OkvpnKernelTrait;
Expand Down Expand Up @@ -58,7 +75,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
$container->addObjectResource($this);
$container->loadFromExtension('framework', [
'router' => [
'resource' => self::VERSION_ID > 40000 ? AppKernelRouting::class . '::loadRoutes' : 'kernel:loadRoutes',
'resource' => AppKernelRouting::class . '::loadRoutes',
'type' => 'service',
],
]);
Expand Down
75 changes: 75 additions & 0 deletions tests/Functional/App/config6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
framework:
secret: test
test: true
default_locale: en
profiler: { collect: true }
session:
storage_factory_id: session.storage.factory.mock_file

doctrine:
dbal:
driver: 'pdo_sqlite'
path: '%kernel.project_dir%/test.db'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/Entity'
prefix: 'Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Entity'

monolog:
handlers:
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug

security:
providers:
in_memory:
memory: ~
firewalls:
main:
lazy: true
provider: in_memory

okvpn_datadog:
profiling: true
namespace: app
dedup_keep_time: 5
handle_exceptions:
skip_instanceof:
- 'Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Command\DemoDatadogExceptionInterface'
skip_capture:
- 'UnderflowException'
skip_wildcard:
- '*entity aliases failed*'

parameters:
request_listener.http_port: 80
request_listener.https_port: 443

services:
okvpn_datadog.client_test_decorator:
class: Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Client\DebugDatadogClient
decorates: okvpn_datadog.client
public: true
arguments: ['@okvpn_datadog.client_test_decorator.inner']

app.command.exception_command:
class: Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Command\DatadogExceptionCommand
arguments: ['@logger']
tags:
- { name: console.command }

app.controller.base_controller:
class: Okvpn\Bundle\DatadogBundle\Tests\Functional\App\Controller\AppDatadogController
public: true
calls:
- [setContainer, ['@service_container']]

Okvpn\Bundle\DatadogBundle\Tests\Functional\App\AppKernelRouting:
tags: [routing.route_loader]
Loading

0 comments on commit b5d318f

Please sign in to comment.