Skip to content

Commit

Permalink
feat: add depedency missing exception
Browse files Browse the repository at this point in the history
Since the documentation path is filled, it means that the documentation
controller will be rendered, which needs twig to work. This exception is
an early warning. I feel comfortable with it!
  • Loading branch information
Nek- committed Dec 10, 2021
1 parent 128ccf9 commit 6add5a8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/DependencyInjection/MelodiiaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Doctrine\Persistence\AbstractManagerRegistry;
use SwagIndustries\Melodiia\Crud\FilterInterface;
use SwagIndustries\Melodiia\Exception\DependencyMissingException;
use SwagIndustries\Melodiia\MelodiiaConfiguration;
use SwagIndustries\Melodiia\Serialization\Context\ContextBuilderInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -28,6 +30,9 @@ public function load(array $configs, ContainerBuilder $container)
$xmlLoader = new XmlFileLoader($container, $configFileLocator);
$xmlLoader->load('error-management.xml');

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

if (class_exists(AbstractManagerRegistry::class)) {
$loader->load('doctrine.yaml');
}
Expand All @@ -41,11 +46,15 @@ public function load(array $configs, ContainerBuilder $container)

if (class_exists(Environment::class)) {
$loader->load('twig.yaml');
} elseif ('dev' === $container->getParameter('kernel.environment')) {
// This is just a helpful layer in case some dependency is missing, because twig is optional.
foreach ($config['api'] as $endpoint) {
if (!empty($endpoint[MelodiiaConfiguration::CONFIGURATION_OPENAPI_PATH])) {
throw new DependencyMissingException('You specified a documentation path but twig is not activated. Melodiia will not be able to render your documentation.');
}
}
}

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$container->setParameter('melodiia.config', $config);

// Autoconf
Expand Down
9 changes: 9 additions & 0 deletions src/Exception/DependencyMissingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace SwagIndustries\Melodiia\Exception;

class DependencyMissingException extends MelodiiaLogicException
{
}

0 comments on commit 6add5a8

Please sign in to comment.