Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PostController.php #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions Controller/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@
class PostController extends AbstractController
{

private function _getRequestArrayWithDisqusShortname($array)
{
$config = $this->container->getParameter('stfalcon_blog.config');
return array_merge(
$array,
array('disqus_shortname' => $config['disqus_shortname'])
);
}

/**
* List of posts for admin
*
Expand All @@ -37,7 +28,7 @@ private function _getRequestArrayWithDisqusShortname($array)
*
* @return array
*/
public function indexAction($page)
public function indexAction(int $page): array
{
$allPosts = $this->get('doctrine')->getEntityManager()
->getRepository("StfalconBlogBundle:Post")->getAllPosts();
Expand All @@ -48,9 +39,9 @@ public function indexAction($page)
$breadcrumbs->addChild('Блог')->setCurrent(true);
}

return $this->_getRequestArrayWithDisqusShortname(array(
return $this->_getRequestDataWithDisqusShortname([
'posts' => $posts
));
]);
}

/**
Expand All @@ -63,17 +54,17 @@ public function indexAction($page)
*
* @return array
*/
public function viewAction(Post $post)
public function viewAction(Post $post): array
{
if ($this->has('application_default.menu.breadcrumbs')) {
$breadcrumbs = $this->get('application_default.menu.breadcrumbs');
$breadcrumbs->addChild('Блог', array('route' => 'blog'));
$breadcrumbs->addChild($post->getTitle())->setCurrent(true);
}

return $this->_getRequestArrayWithDisqusShortname(array(
return $this->_getRequestDataWithDisqusShortname([
'post' => $post
));
]);
}

/**
Expand All @@ -91,14 +82,14 @@ public function rssAction()

$feed->setTitle($config['rss']['title']);
$feed->setDescription($config['rss']['description']);
$feed->setLink($this->generateUrl('blog_rss', array(), true));
$feed->setLink($this->generateUrl('blog_rss', [], true));

$posts = $this->get('doctrine')->getEntityManager()
->getRepository("StfalconBlogBundle:Post")->getAllPosts();
foreach ($posts as $post) {
$entry = new \Zend\Feed\Writer\Entry();
$entry->setTitle($post->getTitle());
$entry->setLink($this->generateUrl('blog_post_view', array('slug' => $post->getSlug()), true));
$entry->setLink($this->generateUrl('blog_post_view', ['slug' => $post->getSlug()], true));

$feed->addEntry($entry);
}
Expand All @@ -115,11 +106,11 @@ public function rssAction()
*
* @return array()
*/
public function lastAction($count = 1)
public function lastAction(int $count = 1): array
{
$posts = $this->get('doctrine')->getEntityManager()
->getRepository("StfalconBlogBundle:Post")->getLastPosts($count);

return array('posts' => $posts);
return ['posts' => $posts];
}
}
}