Skip to content

Commit f577693

Browse files
committed
cleanup and cs fixer
1 parent b742147 commit f577693

27 files changed

+206
-182
lines changed

.travis.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ php:
66
- 5.5
77

88
env:
9-
- SYMFONY_VERSION=2.5.*
9+
- SYMFONY_VERSION=2.6.*
1010

1111
matrix:
1212
allow_failures:
13-
- env: SYMFONY_VERSION=dev-master
13+
- env: SYMFONY_VERSION=2.7.*
1414
include:
1515
- php: 5.5
1616
env: SYMFONY_VERSION=2.3.*
1717
- php: 5.5
1818
env: SYMFONY_VERSION=2.4.*
1919
- php: 5.5
20-
env: SYMFONY_VERSION=dev-master
20+
env: SYMFONY_VERSION=2.5.*
21+
- php: 5.5
22+
env: SYMFONY_VERSION=2.7.*
2123

2224
before_script:
2325
- composer self-update

Admin/BlogAdmin.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
1312
namespace Symfony\Cmf\Bundle\BlogBundle\Admin;
1413

1514
use Sonata\AdminBundle\Datagrid\ListMapper;
@@ -18,7 +17,7 @@
1817
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
1918

2019
/**
21-
* Blog Admin
20+
* Blog Admin.
2221
*
2322
* @author Daniel Leech <[email protected]>
2423
*/
@@ -28,7 +27,7 @@ class BlogAdmin extends Admin
2827
protected $blogRoot;
2928

3029
/**
31-
* Constructor
30+
* Constructor.
3231
*
3332
* @param string $code
3433
* @param string $class

Admin/PostAdmin.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
1312
namespace Symfony\Cmf\Bundle\BlogBundle\Admin;
1413

1514
use Sonata\AdminBundle\Datagrid\ListMapper;
@@ -18,7 +17,7 @@
1817
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
1918

2019
/**
21-
* Post Admin
20+
* Post Admin.
2221
*
2322
* @author Daniel Leech <[email protected]>
2423
*/
@@ -28,7 +27,7 @@ class PostAdmin extends Admin
2827
protected $blogClass;
2928

3029
/**
31-
* Constructor
30+
* Constructor.
3231
*
3332
* @param string $code
3433
* @param string $class

CmfBlogBundle.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
1312
namespace Symfony\Cmf\Bundle\BlogBundle;
1413

1514
use Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass;
@@ -26,7 +25,7 @@ public function build(ContainerBuilder $container)
2625
$container->addCompilerPass(
2726
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
2827
array(
29-
realpath(__DIR__ . '/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\BlogBundle\Doctrine\Phpcr',
28+
realpath(__DIR__.'/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\BlogBundle\Doctrine\Phpcr',
3029
),
3130
array('cmf_blog.persistence.phpcr.manager_name'),
3231
false,

Controller/BaseController.php

+5-13
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,16 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
1312
namespace Symfony\Cmf\Bundle\BlogBundle\Controller;
1413

15-
use Knp\Component\Pager\Paginator;
16-
use Symfony\Cmf\Bundle\BlogBundle\Model\Post;
17-
use Symfony\Cmf\Bundle\BlogBundle\Model\Blog;
18-
use Symfony\Cmf\Bundle\BlogBundle\Repository\PostRepository;
19-
use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishWorkflowChecker;
2014
use Symfony\Component\HttpFoundation\Request;
21-
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2215
use Symfony\Component\Security\Core\SecurityContextInterface;
2316
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
2417
use FOS\RestBundle\View\ViewHandlerInterface;
2518
use FOS\RestBundle\View\View;
2619

2720
/**
28-
* Base Controller
29-
*
30-
* @author Daniel Leech <[email protected]>
21+
* Base Controller.
3122
*/
3223
abstract class BaseController
3324
{
@@ -47,11 +38,11 @@ abstract class BaseController
4738
protected $viewHandler;
4839

4940
/**
50-
* Constructor
41+
* Constructor.
5142
*
52-
* @param EngineInterface $templating
43+
* @param EngineInterface $templating
5344
* @param SecurityContextInterface $securityContext
54-
* @param ViewHandlerInterface $viewHandler
45+
* @param ViewHandlerInterface $viewHandler
5546
*/
5647
public function __construct(
5748
EngineInterface $templating,
@@ -68,6 +59,7 @@ protected function renderResponse($contentTemplate, $params)
6859
if ($this->viewHandler) {
6960
$view = new View($params);
7061
$view->setTemplate($contentTemplate);
62+
7163
return $this->viewHandler->handle($view);
7264
}
7365

Controller/BlogController.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
1312
namespace Symfony\Cmf\Bundle\BlogBundle\Controller;
1413

1514
use Symfony\Cmf\Bundle\BlogBundle\Model\Blog;
@@ -19,9 +18,10 @@
1918
use Symfony\Component\Security\Core\SecurityContextInterface;
2019
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
2120
use FOS\RestBundle\View\ViewHandlerInterface;
21+
use Knp\Component\Pager\Paginator;
2222

2323
/**
24-
* Blog Controller
24+
* Blog Controller.
2525
*
2626
* @author Daniel Leech <[email protected]>
2727
*/
@@ -38,7 +38,7 @@ class BlogController extends BaseController
3838
protected $postRepository;
3939

4040
/**
41-
* @var \Knp\Component\Pager\Paginator
41+
* @var Paginator
4242
*/
4343
protected $paginator;
4444

@@ -53,7 +53,7 @@ public function __construct(
5353
ViewHandlerInterface $viewHandler = null,
5454
BlogRepository $blogRepository,
5555
PostRepository $postRepository,
56-
$paginator = null,
56+
Paginator $paginator = null,
5757
$postsPerPage = 0
5858
) {
5959
parent::__construct($templating, $securityContext, $viewHandler);
@@ -64,7 +64,7 @@ public function __construct(
6464
}
6565

6666
/**
67-
* List blogs
67+
* List blogs.
6868
*/
6969
public function listAction(Request $request)
7070
{
@@ -77,7 +77,7 @@ public function listAction(Request $request)
7777
}
7878

7979
/**
80-
* Blog detail - list posts in a blog, optionally paginated
80+
* Blog detail - list posts in a blog, optionally paginated.
8181
*/
8282
public function detailAction(Request $request, Blog $contentDocument, $contentTemplate = null)
8383
{
@@ -87,16 +87,15 @@ public function detailAction(Request $request, Blog $contentDocument, $contentTe
8787
'blogId' => $blog->getId(),
8888
));
8989

90-
$pager = false;
9190
if ($this->postsPerPage) {
92-
$pager = $posts = $this->paginator->paginate(
91+
$posts = $this->paginator->paginate(
9392
$posts,
9493
$request->query->get('page', 1),
9594
$this->postsPerPage
9695
);
9796
}
9897

99-
$templateFilename = $pager ? 'detailPaginated' : 'detail';
98+
$templateFilename = $this->postsPerPage ? 'detailPaginated' : 'detail';
10099
$contentTemplate = $this->getTemplateForResponse(
101100
$request,
102101
$contentTemplate ?: sprintf('CmfBlogBundle:Blog:%s.{_format}.twig', $templateFilename)

DependencyInjection/CmfBlogExtension.php

+48-28
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
1312
namespace Symfony\Cmf\Bundle\BlogBundle\DependencyInjection;
1413

14+
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\Config\FileLocator;
1717
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1818
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19-
2019
use Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter;
2120

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

4039
if (isset($config['persistence']['phpcr'])) {
41-
$this->loadPhpcrPersistence($config, $loader, $container);
40+
$this->loadPhpcrPersistence($config['persistence']['phpcr'], $loader, $container);
4241
}
4342

44-
if (isset($config['sonata_admin']) && $config['sonata_admin']['enabled']) {
45-
$this->loadSonataAdmin($config, $loader, $container);
43+
if ($config['sonata_admin']['enabled']) {
44+
$this->loadSonataAdmin($config['sonata_admin'], $loader, $container);
4645
}
4746

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

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

55-
protected function loadPhpcrPersistence($config, XmlFileLoader $loader, ContainerBuilder $container)
58+
private function loadPhpcrPersistence($config, XmlFileLoader $loader, ContainerBuilder $container)
5659
{
57-
$container->setParameter($this->getAlias().'.blog_basepath', $config['persistence']['phpcr']['blog_basepath']);
60+
$container->setParameter($this->getAlias().'.blog_basepath', $config['blog_basepath']);
5861

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

70-
protected function loadSonataAdmin(array $config, XmlFileLoader $loader, ContainerBuilder $container)
73+
private function loadSonataAdmin(array $config, XmlFileLoader $loader, ContainerBuilder $container)
7174
{
7275
$bundles = $container->getParameter('kernel.bundles');
7376
if (!isset($bundles['SonataDoctrinePHPCRAdminBundle'])) {
74-
return;
77+
if ('auto' === $config['enabled']) {
78+
return;
79+
}
80+
81+
throw new InvalidConfigurationException('Explicitly enabled sonata admin integration but SonataDoctrinePHPCRAdminBundle is not loaded');
7582
}
7683

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

80-
protected function loadMenuIntegration(array $config, XmlFileLoader $loader, ContainerBuilder $container)
87+
private function loadMenu(array $config, XmlFileLoader $loader, ContainerBuilder $container)
8188
{
8289
$bundles = $container->getParameter('kernel.bundles');
8390
if (!isset($bundles['CmfMenuBundle'])) {
84-
return;
91+
if ('auto' === $config['enabled']) {
92+
return;
93+
}
94+
95+
throw new InvalidConfigurationException('Explicitly enabled menu integration but CmfMenuBundle is not loaded');
8596
}
8697

87-
if (empty($config['integrate_menu']['content_key'])) {
98+
if (empty($config['content_key'])) {
8899
if (!class_exists('Symfony\\Cmf\\Bundle\\RoutingBundle\\Routing\\DynamicRouter')) {
89-
throw new \RuntimeException('You need to set the content_key when not using the CmfRoutingBundle DynamicRouter');
100+
if ('auto' === $config['enabled']) {
101+
return;
102+
}
103+
104+
throw new InvalidConfigurationException('You need to set the content_key when not using the CmfRoutingBundle DynamicRouter');
90105
}
91106
$contentKey = DynamicRouter::CONTENT_KEY;
92107
} else {
93-
$contentKey = $config['integrate_menu']['content_key'];
108+
$contentKey = $config['content_key'];
94109
}
95110

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

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

101-
protected function loadPaginationIntegration(array $config, ContainerBuilder $container)
116+
private function handlePagination(array $config, XmlFileLoader $loader, ContainerBuilder $container)
102117
{
103-
if (isset($config['pagination']) && $config['pagination']['enabled']) {
104-
$container->setParameter($this->getAlias().'.pagination.enabled', true);
105-
$container->setParameter($this->getAlias().'.pagination.posts_per_page', $config['pagination']['posts_per_page']);
106-
} else {
107-
// this parameter is used in the cmf_blog.blog_controller service definition, so
108-
// it must be defined until it's a viable option to use the expression language instead
109-
$container->setParameter($this->getAlias().'.pagination.posts_per_page', 0);
118+
if (!$config['enabled']) {
119+
return false;
110120
}
121+
if (!isset($bundles['KnpPaginatorBundle'])) {
122+
if ('auto' === $config['enabled']) {
123+
return false;
124+
}
125+
126+
throw new InvalidConfigurationException('Explicitly enabled pagination but KnpPaginatorBundle is not loaded');
127+
}
128+
$container->setParameter($this->getAlias().'.pagination.posts_per_page', $config['pagination']['posts_per_page']);
129+
130+
return true;
111131
}
112132

113133
/**

0 commit comments

Comments
 (0)