Skip to content

Commit

Permalink
Initial code dump
Browse files Browse the repository at this point in the history
  • Loading branch information
ONGR Team committed Oct 30, 2014
0 parents commit f251b94
Show file tree
Hide file tree
Showing 37 changed files with 2,919 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.idea/
.DS_Store
/vendor/
composer.lock
/Tests/app/cache/
/Tests/app/logs/
/Tests/app/build/
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php
php:
- 5.4
- 5.5
- 5.6
services:
- elasticsearch
before_script:
- composer update --prefer-dist
script:
- vendor/bin/phpunit
- vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor/,Tests/app/ ./
53 changes: 53 additions & 0 deletions Controller/ContentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ContentBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;

/**
* Controller for content pages.
*
* @SuppressWarnings(UnusedFormalParameter)
*/
class ContentController extends Controller
{
/**
* Returns template data for snippetAction.
*
* @param string $slug
*
* @return array
*/
protected function snippetActionData($slug)
{
return $this->get('ongr_content.content_service')->getDataForSnippet($slug);
}

/**
* Render cms body in template.
*
* @param string $slug
* @param string $template
*
* @return Response
*/
public function snippetAction(
$slug,
$template = 'ONGRContentBundle:Content:plain_cms_snippet.html.twig'
) {
return $this->render(
$template,
$this->snippetActionData($slug)
);
}
}
58 changes: 58 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ContentBundle\DependencyInjection;

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

/**
* This is the class that validates and merges configuration from app/config files.
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('ongr_content');

$rootNode
->children()
->arrayNode('es')
->isRequired()
->children()
->arrayNode('repositories')
->children()
->scalarNode('product')->isRequired()->end()
->scalarNode('content')->isRequired()->end()
->scalarNode('category')->isRequired()->end()
->end()
->end()
->end()
->end()
->arrayNode('snippet')
->cannotBeOverwritten()
->addDefaultsIfNotSet()
->children()
->scalarNode('render_strategy')
->defaultValue('esi')
->info('Default template render strategy')
->end()
->end()
->end()
->end();

return $treeBuilder;
}
}
52 changes: 52 additions & 0 deletions DependencyInjection/ONGRContentExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace ONGR\ContentBundle\DependencyInjection;

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

/**
* This is the class that loads and manages bundle configuration.
*/
class ONGRContentExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

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

// Inject manager and repository to services.
$repositories = $config['es']['repositories'];

$container->setParameter('ongr_content.es.repositories', $repositories);

$contentService = $container->getDefinition('ongr_content.content_service');
$contentService->addArgument(new Reference($repositories['content']));

$twigExtension = $container->getDefinition('ongr_content.twig.content_extension');
$twigExtension->addArgument(new Reference($repositories['content']));

$categoryService = $container->getDefinition('ongr_content.category_service');
$categoryService->addArgument(new Reference($repositories['category']));

$container->setParameter('ongr_content.snippet.render_strategy', $config['snippet']['render_strategy']);
}
}
Loading

0 comments on commit f251b94

Please sign in to comment.