Skip to content

Commit

Permalink
created configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
orbeji committed Jan 16, 2024
1 parent 88b7fc1 commit 94c0ca4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ return [
## TODO
- [x] Write a log file per day
- [x] Add tests
- [ ] Add pipelines
- [x] Add pipelines
- [x] Check style
- [ ] Run Tests
- [ ] Coverage check
- [x] Run Tests
- [x] Coverage check
- [x] Phpstan
- [ ] Improve Readme with description and usage
- [ ] See if it's possible to autogenerate a bundle config file when installing
Expand Down
33 changes: 33 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Orbeji\UnusedRoutes\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Webmozart\Assert\Assert;

class Configuration implements ConfigurationInterface
{

public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('unused_routes');

$rootNode = $treeBuilder->getRootNode();
Assert::isInstanceOf($rootNode, ArrayNodeDefinition::class);

$rootNode
->children()
->scalarNode('file_path')
->defaultValue('/var/log')
->end()
->scalarNode('file_name')
->defaultValue('accessed_routes.log')
->end()
->end()
;

return $treeBuilder;
}
}
34 changes: 2 additions & 32 deletions src/DependencyInjection/UnusedRoutesExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
namespace Orbeji\UnusedRoutes\DependencyInjection;

use Exception;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Webmozart\Assert\Assert;

final class UnusedRoutesExtension extends Extension implements ConfigurationInterface
final class UnusedRoutesExtension extends Extension
{
/**
* @throws Exception
Expand All @@ -22,35 +18,9 @@ public function load(array $configs, ContainerBuilder $container): void
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$loader->load('services.yaml');

$configuration = $this->getConfiguration($configs, $container);
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$container->setParameter('unused_routes.file_path', $config['file_path']);
$container->setParameter('unused_routes.file_name', $config['file_name']);
}

public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
{
return $this;
}

public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('unused_routes');

$rootNode = $treeBuilder->getRootNode();
Assert::isInstanceOf($rootNode, ArrayNodeDefinition::class);

$rootNode
->children()
->scalarNode('file_path')
->defaultValue('/var/log')
->end()
->scalarNode('file_name')
->defaultValue('accessed_routes.log')
->end()
->end()
;

return $treeBuilder;
}
}

0 comments on commit 94c0ca4

Please sign in to comment.