Skip to content

Commit

Permalink
use type hinting in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Aug 14, 2019
1 parent df10235 commit 12540ac
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 44 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ gpslab_pagination:
```php
class ArticleController extends Controller
{
const PER_PAGE = 30; // articles per page
private const PER_PAGE = 30; // articles per page

public function indexAction(Request $request)
public function index(Request $request): Response
{
$rep = $this->getDoctrine()->getRepository('AcmeDemoBundle:Article');
$rep = $this->getDoctrine()->getRepository(Article::class);

$total = $rep->getTotalPublished();
$total_pages = ceil($total / self::PER_PAGE);
Expand All @@ -75,7 +75,7 @@ Display pagination in template:

```twig
<nav class="pagination">
{{ pagination_render(pagination) }}
{{- pagination_render(pagination) -}}
</nav>
```

Expand Down
22 changes: 9 additions & 13 deletions docs/base_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Base usage
```php
namespace Acme\DemoBundle\Controller;

use Acme\DemoBundle\Entity\Article;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -13,29 +14,23 @@ class ArticleController extends Controller
{
/**
* Articles per page.
*
* @var int
*/
const PER_PAGE = 100;
private const PER_PAGE = 100;

/**
* @Configuration\Route("/article/", name="article_index")
* @Configuration\Method({"GET"})
*
* @param Request $request
*
* @return Response
*/
public function indexAction(Request $request)
public function index(Request $request): Response
{
$em = $this->get('doctrine.orm.default_entity_manager');
$router = $this->get('router');

// get total articles
$total = (int)$em
$total = (int) $this->
->getDoctrine()
->createQueryBuilder()
->select('COUNT(*)')
->from('AcmeDemoBundle:Article', 'a')
->from(Article::class, 'a')
->getQuery()
->getSingleScalarResult()
;
Expand All @@ -57,10 +52,11 @@ class ArticleController extends Controller
;

// get articles chunk
$articles = $em
$articles = $this->
->getDoctrine()
->createQueryBuilder()
->select('*')
->from('AcmeDemoBundle:Article', 'a')
->from(Article::class, 'a')
->setFirstResult(($pagination->getCurrentPage() - 1) * self::PER_PAGE)
->setMaxResults(self::PER_PAGE)
->getQuery()
Expand Down
13 changes: 4 additions & 9 deletions docs/from_qb.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ From QueryBuilder
```php
namespace Acme\DemoBundle\Controller;

use Acme\DemoBundle\Entity\Article;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -14,26 +15,20 @@ class ArticleController extends Controller
{
/**
* Articles per page.
*
* @var int
*/
const PER_PAGE = 100;
private const PER_PAGE = 100;

/**
* @Configuration\Route("/article/", name="article_index")
* @Configuration\Method({"GET"})
*
* @param Request $request
*
* @return Response
*/
public function indexAction(Request $request)
public function index(Request $request): Response
{
// create get articles query
// would be better move this query to repository class
$query = $this
->getDoctrine()
->getRepository('AcmeDemoBundle:Article')
->getRepository(Article::calss)
->createQueryBuilder('a')
->where('a.enabled = :enabled')
->setParameter('enabled', true)
Expand Down
13 changes: 4 additions & 9 deletions docs/from_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ From HTTP request
```php
namespace Acme\DemoBundle\Controller;

use Acme\DemoBundle\Entity\Article;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -15,22 +16,16 @@ class ArticleController extends Controller
{
/**
* Articles per page.
*
* @var int
*/
const PER_PAGE = 100;
private const PER_PAGE = 100;

/**
* @Configuration\Route("/article/", name="article_index")
* @Configuration\Method({"GET"})
*
* @param Request $request
*
* @return Response
*/
public function indexAction(Request $request)
public function index(Request $request): Response
{
$rep = $this->getDoctrine()->getRepository('AcmeDemoBundle:Article');
$rep = $this->getDoctrine()->getRepository(Article::calss);

$total = $rep->getTotalPublished();
$total_pages = ceil($total / self::PER_PAGE);
Expand Down
13 changes: 4 additions & 9 deletions docs/from_request_and_qb.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ From HTTP request and QueryBuilder
```php
namespace Acme\DemoBundle\Controller;

use Acme\DemoBundle\Entity\Article;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -15,26 +16,20 @@ class ArticleController extends Controller
{
/**
* Articles per page.
*
* @var int
*/
const PER_PAGE = 100;
private const PER_PAGE = 100;

/**
* @Configuration\Route("/article/", name="article_index")
* @Configuration\Method({"GET"})
*
* @param Request $request
*
* @return Response
*/
public function indexAction(Request $request)
public function index(Request $request): Response
{
// create get articles query
// would be better move this query to repository class
$query = $this
->getDoctrine()
->getRepository('AcmeDemoBundle:Article')
->getRepository(Article::calss)
->createQueryBuilder('a')
->where('a.enabled = :enabled')
->setParameter('enabled', true)
Expand Down

0 comments on commit 12540ac

Please sign in to comment.