Skip to content

Commit

Permalink
cleanup and cs fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Mar 26, 2015
1 parent 9132390 commit 09de934
Show file tree
Hide file tree
Showing 29 changed files with 205 additions and 183 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ Tests/Resources/app/logs
bin/
composer.lock
vendor/
.idea
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ php:
- 5.5

env:
- SYMFONY_VERSION=2.5.*
- SYMFONY_VERSION=2.6.*

matrix:
allow_failures:
- env: SYMFONY_VERSION=dev-master
- env: SYMFONY_VERSION=2.7.*
include:
- php: 5.5
env: SYMFONY_VERSION=2.3.*
- php: 5.5
env: SYMFONY_VERSION=2.4.*
- php: 5.5
env: SYMFONY_VERSION=dev-master
env: SYMFONY_VERSION=2.5.*
- php: 5.5
env: SYMFONY_VERSION=2.7.*

before_script:
- composer self-update
Expand Down
5 changes: 2 additions & 3 deletions Admin/BlogAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\BlogBundle\Admin;

use Sonata\AdminBundle\Datagrid\ListMapper;
Expand All @@ -18,7 +17,7 @@
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;

/**
* Blog Admin
* Blog Admin.
*
* @author Daniel Leech <[email protected]>
*/
Expand All @@ -28,7 +27,7 @@ class BlogAdmin extends Admin
protected $blogRoot;

/**
* Constructor
* Constructor.
*
* @param string $code
* @param string $class
Expand Down
5 changes: 2 additions & 3 deletions Admin/PostAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\BlogBundle\Admin;

use Sonata\AdminBundle\Datagrid\ListMapper;
Expand All @@ -18,7 +17,7 @@
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;

/**
* Post Admin
* Post Admin.
*
* @author Daniel Leech <[email protected]>
*/
Expand All @@ -28,7 +27,7 @@ class PostAdmin extends Admin
protected $blogClass;

/**
* Constructor
* Constructor.
*
* @param string $code
* @param string $class
Expand Down
3 changes: 1 addition & 2 deletions CmfBlogBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\BlogBundle;

use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
Expand All @@ -26,7 +25,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
array(
realpath(__DIR__ . '/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\BlogBundle\Doctrine\Phpcr',
realpath(__DIR__.'/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\BlogBundle\Doctrine\Phpcr',
),
array('cmf_blog.persistence.phpcr.manager_name'),
false,
Expand Down
18 changes: 5 additions & 13 deletions Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\BlogBundle\Controller;

use Knp\Component\Pager\Paginator;
use Symfony\Cmf\Bundle\BlogBundle\Model\Post;
use Symfony\Cmf\Bundle\BlogBundle\Model\Blog;
use Symfony\Cmf\Bundle\BlogBundle\Repository\PostRepository;
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use FOS\RestBundle\View\ViewHandlerInterface;
use FOS\RestBundle\View\View;

/**
* Base Controller
*
* @author Daniel Leech <[email protected]>
* Base Controller.
*/
abstract class BaseController
{
Expand All @@ -47,11 +38,11 @@ abstract class BaseController
protected $viewHandler;

/**
* Constructor
* Constructor.
*
* @param EngineInterface $templating
* @param EngineInterface $templating
* @param SecurityContextInterface $securityContext
* @param ViewHandlerInterface $viewHandler
* @param ViewHandlerInterface $viewHandler
*/
public function __construct(
EngineInterface $templating,
Expand All @@ -68,6 +59,7 @@ protected function renderResponse($contentTemplate, $params)
if ($this->viewHandler) {
$view = new View($params);
$view->setTemplate($contentTemplate);

return $this->viewHandler->handle($view);
}

Expand Down
17 changes: 8 additions & 9 deletions Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\BlogBundle\Controller;

use Symfony\Cmf\Bundle\BlogBundle\Model\Blog;
Expand All @@ -19,9 +18,10 @@
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use FOS\RestBundle\View\ViewHandlerInterface;
use Knp\Component\Pager\Paginator;

/**
* Blog Controller
* Blog Controller.
*
* @author Daniel Leech <[email protected]>
*/
Expand All @@ -38,7 +38,7 @@ class BlogController extends BaseController
protected $postRepository;

/**
* @var \Knp\Component\Pager\Paginator
* @var Paginator
*/
protected $paginator;

Expand All @@ -53,7 +53,7 @@ public function __construct(
ViewHandlerInterface $viewHandler = null,
BlogRepository $blogRepository,
PostRepository $postRepository,
$paginator = null,
Paginator $paginator = null,
$postsPerPage = 0
) {
parent::__construct($templating, $securityContext, $viewHandler);
Expand All @@ -64,7 +64,7 @@ public function __construct(
}

/**
* List blogs
* List blogs.
*/
public function listAction(Request $request)
{
Expand All @@ -77,7 +77,7 @@ public function listAction(Request $request)
}

/**
* Blog detail - list posts in a blog, optionally paginated
* Blog detail - list posts in a blog, optionally paginated.
*/
public function detailAction(Request $request, Blog $contentDocument, $contentTemplate = null)
{
Expand All @@ -87,16 +87,15 @@ public function detailAction(Request $request, Blog $contentDocument, $contentTe
'blogId' => $blog->getId(),
));

$pager = false;
if ($this->postsPerPage) {
$pager = $posts = $this->paginator->paginate(
$posts = $this->paginator->paginate(
$posts,
$request->query->get('page', 1),
$this->postsPerPage
);
}

$templateFilename = $pager ? 'detailPaginated' : 'detail';
$templateFilename = $this->postsPerPage ? 'detailPaginated' : 'detail';
$contentTemplate = $this->getTemplateForResponse(
$request,
$contentTemplate ?: sprintf('CmfBlogBundle:Blog:%s.{_format}.twig', $templateFilename)
Expand Down
76 changes: 48 additions & 28 deletions DependencyInjection/CmfBlogExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\BlogBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

use Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter;

/**
* This is the class that loads and manages your bundle configuration
* This is the class that loads and manages your bundle configuration.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
Expand All @@ -38,25 +37,29 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.xml');

if (isset($config['persistence']['phpcr'])) {
$this->loadPhpcrPersistence($config, $loader, $container);
$this->loadPhpcrPersistence($config['persistence']['phpcr'], $loader, $container);
}

if (isset($config['sonata_admin']) && $config['sonata_admin']['enabled']) {
$this->loadSonataAdmin($config, $loader, $container);
if ($config['sonata_admin']['enabled']) {
$this->loadSonataAdmin($config['sonata_admin'], $loader, $container);
}

if (isset($config['integrate_menu']) && $config['integrate_menu']['enabled']) {
$this->loadMenuIntegration($config, $loader, $container);
if ($config['menu']['enabled']) {
$this->loadMenu($config['menu'], $loader, $container);
}

$this->loadPaginationIntegration($config, $container);
if (!$this->handlePagination($config['pagination'], $loader, $container)) {
// this parameter is used in the cmf_blog.blog_controller service definition, so
// it must be defined until it's a viable option to use the expression language instead
$container->setParameter($this->getAlias().'.pagination.posts_per_page', 0);
}
}

protected function loadPhpcrPersistence($config, XmlFileLoader $loader, ContainerBuilder $container)
private function loadPhpcrPersistence($config, XmlFileLoader $loader, ContainerBuilder $container)
{
$container->setParameter($this->getAlias().'.blog_basepath', $config['persistence']['phpcr']['blog_basepath']);
$container->setParameter($this->getAlias().'.blog_basepath', $config['blog_basepath']);

foreach ($config['persistence']['phpcr']['class'] as $type => $classFqn) {
foreach ($config['class'] as $type => $classFqn) {
$container->setParameter(
$param = sprintf('cmf_blog.phpcr.%s.class', $type),
$classFqn
Expand All @@ -67,47 +70,64 @@ protected function loadPhpcrPersistence($config, XmlFileLoader $loader, Containe
$loader->load('doctrine-phpcr.xml');
}

protected function loadSonataAdmin(array $config, XmlFileLoader $loader, ContainerBuilder $container)
private function loadSonataAdmin(array $config, XmlFileLoader $loader, ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');
if (!isset($bundles['SonataDoctrinePHPCRAdminBundle'])) {
return;
if ('auto' === $config['enabled']) {
return;
}

throw new InvalidConfigurationException('Explicitly enabled sonata admin integration but SonataDoctrinePHPCRAdminBundle is not loaded');
}

$loader->load('admin.xml');
}

protected function loadMenuIntegration(array $config, XmlFileLoader $loader, ContainerBuilder $container)
private function loadMenu(array $config, XmlFileLoader $loader, ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');
if (!isset($bundles['CmfMenuBundle'])) {
return;
if ('auto' === $config['enabled']) {
return;
}

throw new InvalidConfigurationException('Explicitly enabled menu integration but CmfMenuBundle is not loaded');
}

if (empty($config['integrate_menu']['content_key'])) {
if (empty($config['content_key'])) {
if (!class_exists('Symfony\\Cmf\\Bundle\\RoutingBundle\\Routing\\DynamicRouter')) {
throw new \RuntimeException('You need to set the content_key when not using the CmfRoutingBundle DynamicRouter');
if ('auto' === $config['enabled']) {
return;
}

throw new InvalidConfigurationException('You need to set the content_key when not using the CmfRoutingBundle DynamicRouter');
}
$contentKey = DynamicRouter::CONTENT_KEY;
} else {
$contentKey = $config['integrate_menu']['content_key'];
$contentKey = $config['content_key'];
}

$container->setParameter('cmf_blog.content_key', $contentKey);
$container->setParameter($this->getAlias().'.content_key', $contentKey);

$loader->load('menu.xml');
}

protected function loadPaginationIntegration(array $config, ContainerBuilder $container)
private function handlePagination(array $config, XmlFileLoader $loader, ContainerBuilder $container)
{
if (isset($config['pagination']) && $config['pagination']['enabled']) {
$container->setParameter($this->getAlias().'.pagination.enabled', true);
$container->setParameter($this->getAlias().'.pagination.posts_per_page', $config['pagination']['posts_per_page']);
} else {
// this parameter is used in the cmf_blog.blog_controller service definition, so
// it must be defined until it's a viable option to use the expression language instead
$container->setParameter($this->getAlias().'.pagination.posts_per_page', 0);
if (!$config['enabled']) {
return false;
}
if (!isset($bundles['KnpPaginatorBundle'])) {
if ('auto' === $config['enabled']) {
return false;
}

throw new InvalidConfigurationException('Explicitly enabled pagination but KnpPaginatorBundle is not loaded');
}
$container->setParameter($this->getAlias().'.pagination.posts_per_page', $config['pagination']['posts_per_page']);

return true;
}

/**
Expand Down
Loading

0 comments on commit 09de934

Please sign in to comment.