1528 search results for symfony bundle

Creating a Reusable Amazing Symfony Bundle

Want to share some code between projects, or maybe with the whole world? Let's do it! By creating a Symfony bundle! In this tutorial, we'll learn about bundles, their super-powers, how to add services & routes and the ...

20 videos
|
2:21:06
// ... lines 1 - 11
namespace Symfony\Bundle\FrameworkBundle\Controller;
// ... lines 13 - 38
abstract class Controller implements ContainerAwareInterface
{
// ... lines 41 - 185
protected function render($view, array $parameters = array(), Response $response = null)
{
if ($this->container->has('templating')) {
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
}
// ... lines 191 - 202
}
// ... lines 204 - 396
}
See Code Block in Script
// ... lines 1 - 4
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security\FirewallConfig;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Bundle\SecurityBundle\Security\TargetPathHelper;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
// ... lines 12 - 39
See Code Block in Script
// ... lines 1 - 4
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security\FirewallConfig;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Bundle\SecurityBundle\Security\TargetPathHelper;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class TargetPathHelperTest extends TestCase
{
public function testSavePath()
{
$session = $this->createMock(SessionInterface::class);
$firewallMap = $this->createMock(FirewallMap::class);
$requestStack = $this->createMock(RequestStack::class);
$request = new Request();
$requestStack->expects($this->once())
->method('getMasterRequest')
->willReturn($request);
$firewallConfig = new FirewallConfig('firewall_name', '');
$firewallMap->expects($this->once())
->method('getFirewallConfig')
->with($request)
->willReturn($firewallConfig);
$session->expects($this->once())
->method('set')
->with('_security.firewall_name.target_path', '/foo');
$targetPathHelper = new TargetPathHelper($session, $firewallMap, $requestStack);
$targetPathHelper->savePath('/foo');
}
}
See Code Block in Script
// ... lines 1 - 2
namespace Symfony\Bundle\SecurityBundle\Tests\Security;
use PHPUnit\Framework\TestCase;
class TargetPathHelperTest extends TestCase
{
// ... lines 9 - 12
}
See Code Block in Script
// ... lines 1 - 2
namespace Symfony\Bundle\SecurityBundle\Security;
class TargetPathHelper
{
public function savePath(string $uri)
{
}
}
See Code Block in Script
// ... lines 1 - 2
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SecurityBundle\Security;
class TargetPathHelper
{
// ... lines 16 - 24
}
See Code Block in Script
// ... lines 1 - 2
namespace Symfony\Bundle\SecurityBundle\Tests\Security;
use PHPUnit\Framework\TestCase;
class TargetPathHelperTest extends TestCase
{
public function testSavePath()
{
}
}
See Code Block in Script
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
// ... lines 6 - 12
<services>
// ... lines 14 - 135
<service id="security.firewall.map" class="Symfony\Bundle\SecurityBundle\Security\FirewallMap">
<argument /> <!-- Firewall context locator -->
<argument /> <!-- Request matchers -->
</service>
// ... lines 140 - 147
<service id="security.firewall.config" class="Symfony\Bundle\SecurityBundle\Security\FirewallConfig" abstract="true">
<argument /> <!-- name -->
<argument /> <!-- user_checker -->
<argument /> <!-- request_matcher -->
<argument /> <!-- security enabled -->
<argument /> <!-- stateless -->
<argument /> <!-- provider -->
<argument /> <!-- context -->
<argument /> <!-- entry_point -->
<argument /> <!-- access_denied_handler -->
<argument /> <!-- access_denied_url -->
<argument type="collection" /> <!-- listeners -->
<argument /> <!-- switch_user -->
</service>
// ... lines 162 - 223
</services>
</container>
See Code Block in Script
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
// ... lines 6 - 12
<services>
// ... lines 14 - 167
<service id="Symfony\Bundle\SecurityBundle\Security\TargetPathHelper" alias="security.target_path_helper" />
// ... lines 169 - 223
</services>
</container>
See Code Block in Script
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
// ... lines 6 - 12
<services>
// ... lines 14 - 162
<service id="security.target_path_helper" class="Symfony\Bundle\SecurityBundle\Security\TargetPathHelper">
<argument type="service" id="session" />
<argument type="service" id="security.firewall.map" />
<argument type="service" id="request_stack" />
</service>
// ... lines 168 - 223
</services>
</container>
See Code Block in Script
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
// ... lines 6 - 12
<services>
// ... lines 14 - 162
<service id="security.target_path_helper" class="Symfony\Bundle\SecurityBundle\Security\TargetPathHelper">
// ... lines 164 - 166
</service>
// ... lines 168 - 223
</services>
</container>
See Code Block in Script
// ... lines 1 - 38
abstract class Controller implements ContainerAwareInterface
{
// ... lines 41 - 317
/**
* Get a user from the Security Token Storage.
*
* @return mixed
*
* @throws \LogicException If SecurityBundle is not available
*
* @see TokenInterface::getUser()
*/
protected function getUser()
{
if (!$this->container->has('security.token_storage')) {
throw new \LogicException('The SecurityBundle is not registered in your application.');
}
if (null === $token = $this->container->get('security.token_storage')->getToken()) {
return;
}
if (!is_object($user = $token->getUser())) {
// e.g. anonymous authentication
return;
}
return $user;
}
// ... lines 344 - 396
}
See Code Block in Script
// ... lines 1 - 38
abstract class Controller implements ContainerAwareInterface
{
// ... lines 41 - 274
/**
* Creates and returns a Form instance from the type of the form.
*
* @param string|FormTypeInterface $type The built type of the form
* @param mixed $data The initial data for the form
* @param array $options Options for the form
*
* @return Form
*/
protected function createForm($type, $data = null, array $options = array())
{
return $this->container->get('form.factory')->create($type, $data, $options);
}
// ... lines 288 - 396
}
See Code Block in Script
// ... lines 1 - 21
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
// ... lines 23 - 38
abstract class Controller implements ContainerAwareInterface
{
// ... lines 41 - 257
/**
* Returns an AccessDeniedException.
*
* This will result in a 403 response code. Usage example:
*
* throw $this->createAccessDeniedException('Unable to access this page!');
*
* @param string $message A message
* @param \Exception|null $previous The previous exception
*
* @return AccessDeniedException
*/
protected function createAccessDeniedException($message = 'Access Denied.', \Exception $previous = null)
{
return new AccessDeniedException($message, $previous);
}
// ... lines 274 - 396
}
See Code Block in Script
// ... lines 1 - 38
abstract class Controller implements ContainerAwareInterface
{
// ... lines 41 - 102
/**
* Adds a flash message to the current session for type.
*
* @param string $type The type
* @param string $message The message
*
* @throws \LogicException
*/
protected function addFlash($type, $message)
{
if (!$this->container->has('session')) {
throw new \LogicException('You can not use the addFlash method if sessions are disabled.');
}
$this->container->get('session')->getFlashBag()->add($type, $message);
}
// ... lines 119 - 396
}
See Code Block in Script
// ... lines 1 - 38
abstract class Controller implements ContainerAwareInterface
{
// ... lines 41 - 185
protected function render($view, array $parameters = array(), Response $response = null)
{
if ($this->container->has('templating')) {
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
}
if (!$this->container->has('twig')) {
throw new \LogicException('You can not use the "render" method if the Templating Component or the Twig Bundle are not available.');
}
if (null === $response) {
$response = new Response();
}
$response->setContent($this->container->get('twig')->render($view, $parameters));
return $response;
}
// ... lines 204 - 396
}
See Code Block in Script
// ... lines 1 - 38
abstract class Controller implements ContainerAwareInterface
{
// ... lines 41 - 185
protected function render($view, array $parameters = array(), Response $response = null)
{
if ($this->container->has('templating')) {
return $this->container->get('templating')->renderResponse($view, $parameters, $response);
}
// ... lines 191 - 202
}
// ... lines 204 - 396
}
See Code Block in Script
// ... lines 1 - 33
public function load(array $configs, ContainerBuilder $container)
{
// ... lines 36 - 86
if (!empty($config['globals'])) {
$def = $container->getDefinition('twig');
foreach ($config['globals'] as $key => $global) {
// ... lines 90 - 92
$def->addMethodCall('addGlobal', array($key, $global['value']));
// ... line 94
}
}
// ... lines 97 - 130
}
// ... lines 132 - 157
See Code Block in Script
// ... lines 1 - 33
public function load(array $configs, ContainerBuilder $container)
{
// ... lines 36 - 51
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
var_dump($config);die;
// ... lines 56 - 131
}
// ... lines 133 - 158
See Code Block in Script