Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
viniychuk committed Apr 27, 2017
1 parent 42e63de commit ed27334
Show file tree
Hide file tree
Showing 20 changed files with 1,158 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
composer.phar
phpunit.xml
vendor/
data/schema.graphql
composer.lock
20 changes: 20 additions & 0 deletions CommentsBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Youshido\CommentsBundle;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Youshido\CommentsBundle\DependencyInjection\CommentsExtension;
use Youshido\CommentsBundle\DependencyInjection\CompilerPass\CommentsCompilerPass;

class CommentsBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new CommentsCompilerPass());

}

}
34 changes: 34 additions & 0 deletions DependencyInjection/CommentsExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Youshido\CommentsBundle\DependencyInjection;


use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class CommentsExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

// $container->setParameter('graphql_extensions.files', $config['files']);
$this->setContainerParam($container, 'platform', $config['platform']);
$this->setContainerParam($container, 'host', null);
$this->setContainerParam($container, 'scheme', null);
$this->setContainerParam($container, 'allow_anonymous', $config['allow_anonymous']);
$this->setContainerParam($container, 'max_depth', $config['max_depth']);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}

private function setContainerParam(ContainerBuilder $container, $parameter, $value)
{
$container->setParameter(sprintf('comments.config.%s', $parameter), $value);
}

}
32 changes: 32 additions & 0 deletions DependencyInjection/CompilerPass/CommentsCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Youshido\CommentsBundle\DependencyInjection\CompilerPass;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class CommentsCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$storageDefinition = new Definition();
$models = [];
$platform = $container->getParameter('comments.config.platform');
switch ($platform) {
case 'orm':
$container->setAlias('comments.om', 'doctrine.orm.entity_manager');
$models['file'] = 'Youshido\GraphQLExtensionsBundle\Entity\File';
break;

case 'odm':
$container->setAlias('comments.om', 'doctrine_mongodb.odm.document_manager');
$models['file'] = 'Youshido\GraphQLExtensionsBundle\Document\File';
break;
}
$container->setParameter('comments.models', $models);
}


}
44 changes: 44 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
namespace Youshido\CommentsBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This file is a part of GraphQLExtensionsBundle project.
*
* @author Alexandr Viniychuk <[email protected]>
* created: 2/21/17 11:28 PM
*/
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('graphql_extensions');

$rootNode
->children()
->enumNode('storage')
->values(['s3', 'filesystem'])
->cannotBeEmpty()
->defaultValue('filesystem')
->end()
->enumNode('platform')
->values(['odm', 'orm'])
->cannotBeEmpty()
->defaultValue('orm')
->end()
->scalarNode('max_depth')
->defaultValue(1)
->cannotBeEmpty()
->end()
->booleanNode('allow_anonymous')
->defaultValue(false)
->end()
->end();
return $treeBuilder;
}


}
Loading

0 comments on commit ed27334

Please sign in to comment.