PHP code example of devmachine / services-injector-bundle
1. Go to this page and download the library: Download devmachine/services-injector-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/ */
devmachine / services-injector-bundle example snippets
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Devmachine\Bundle\ServicesInjectorBundle\DevmachineServicesInjectorBundle(),
);
}
namespace Acme\UserBundle\Controller;
use Devmachine\Bundle\ServicesInjectorBundle\Configuration\Service;
use Devmachine\Bundle\ServicesInjectorBundle\Request\Services;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Inject to all actions.
*
* @Service(user_manager="fos_user.user_manager")
*/
class UserController
{
/**
* Multiple definitions.
*
* @Service("twig")
* @Service("translator")
*/
public function indexAction(Services $services)
{
$params = [
// Use explicit service name.
'title' => $services->get('translator')->trans('users'),
// Use __call() i.e. same as $services->get('user_manager').
'users' => $services->getUserManager()->findAll(),
];
return new Response($services->getTwig()->render('AcmeUserBundle:User:index', $params));
}
/**
* Array definition.
*
* @Service({"ff"="form.factory", "url_generator"="router", "translator", "twig"})
*/
public function editAction(Request $request, $username, Services $services)
{
$user = $services->getUserManager()->findByUsername($username);
$form = $services->get('ff')->createForm('acme_user', $user);
// ...
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.