1. Go to this page and download the library: Download kutny/autowiring-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kutny / autowiring-bundle example snippets
namespace Acme\DemoBundle\Controller;
use Acme\DemoBundle\Facade\ProductsFacade;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
/**
* @Route(service="controller.products_controller")
*/
class ProductsController
{
private $productsPerPageLimit;
private $productsFacade;
public function __construct($productsPerPageLimit, ProductsFacade $productsFacade)
{
$this->productsPerPageLimit = $productsPerPageLimit;
$this->productsFacade = $productsFacade;
}
/**
* @Route("/", name="route.products")
* @Template()
*/
public function productsAction()
{
return array(
'products' => $this->productsFacade->getProducts($this->productsPerPageLimit)
);
}
namespace Acme\DemoBundle\Facade;
use Acme\DemoBundle\Repository\ProductsRepository;
class ProductsFacade
{
private $productsRepository;
public function __construct(ProductsRepository $productsRepository) {
$this->productsRepository = $productsRepository;
}
public function getProducts($productsPerPageLimit) {
return $this->productsRepository->getProducts($productsPerPageLimit);
}
namespace Acme\DemoBundle\Repository;
use Doctrine\ORM\EntityManager;
class ProductsRepository
{
private $entityManager;
public function __construct(EntityManager $entityManager) {
$this->entityManager = $entityManager;
}
public function getProducts($productsPerPageLimit) {
$query = $this->entityManager->createQueryBuilder()
->select('p')
->from('AcmeDemoBundle:Product', 'p')
->setMaxResults($productsPerPageLimit)
->getQuery();
return $query->getResult();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.