Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
<?php
/*
* 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\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class FragmentController implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function indexAction(Request $request)
{
return $this->container->get('templating')->renderResponse('fragment.html.php', array('bar' => new Bar()));
}
public function inlinedAction($options, $_format)
{
return new Response($options['bar']->getBar().' '.$_format);
}
public function customFormatAction($_format)
{
return new Response($_format);
}
public function customLocaleAction(Request $request)
{
return new Response($request->getLocale());
}
public function forwardLocaleAction(Request $request)
{
return new Response($request->getLocale());
}
}
class Bar
{
private $bar = 'bar';
public function getBar()
{
return $this->bar;
}
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* 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\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Response;
class ProfilerController implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function indexAction()
{
return new Response('Hello');
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*
* 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\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
class SessionController implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function welcomeAction(Request $request, $name = null)
{
$session = $request->getSession();
// new session case
if (!$session->has('name')) {
if (!$name) {
return new Response('You are new here and gave no name.');
}
// remember name
$session->set('name', $name);
return new Response(sprintf('Hello %s, nice to meet you.', $name));
}
// existing session
$name = $session->get('name');
return new Response(sprintf('Welcome back %s, nice to meet you.', $name));
}
public function logoutAction(Request $request)
{
$request->getSession()->invalidate();
return new Response('Session cleared.');
}
public function setFlashAction(Request $request, $message)
{
$session = $request->getSession();
$session->getFlashBag()->set('notice', $message);
return new RedirectResponse($this->container->get('router')->generate('session_showflash'));
}
public function showFlashAction(Request $request)
{
$session = $request->getSession();
if ($session->getFlashBag()->has('notice')) {
list($output) = $session->getFlashBag()->get('notice');
} else {
$output = 'No flash was set.';
}
return new Response($output);
}
}

View File

@@ -0,0 +1,68 @@
<?php
/*
* 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\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
class SubRequestController implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function indexAction()
{
$handler = $this->container->get('fragment.handler');
$errorUrl = $this->generateUrl('subrequest_fragment_error', array('_locale' => 'fr', '_format' => 'json'));
$altUrl = $this->generateUrl('subrequest_fragment', array('_locale' => 'fr', '_format' => 'json'));
// simulates a failure during the rendering of a fragment...
// should render fr/json
$content = $handler->render($errorUrl, 'inline', array('alt' => $altUrl));
// ...to check that the FragmentListener still references the right Request
// when rendering another fragment after the error occurred
// should render en/html instead of fr/json
$content .= $handler->render(new ControllerReference('TestBundle:SubRequest:fragment'));
// forces the LocaleListener to set fr for the locale...
// should render fr/json
$content .= $handler->render($altUrl);
// ...and check that after the rendering, the original Request is back
// and en is used as a locale
// should use en/html instead of fr/json
$content .= '--'.$this->generateUrl('subrequest_fragment');
// The RouterListener is also tested as if it does not keep the right
// Request in the context, a 301 would be generated
return new Response($content);
}
public function fragmentAction(Request $request)
{
return new Response('--'.$request->getLocale().'/'.$request->getRequestFormat());
}
public function fragmentErrorAction()
{
throw new \RuntimeException('error');
}
protected function generateUrl($name, $arguments = array())
{
return $this->container->get('router')->generate($name, $arguments);
}
}

View File

@@ -0,0 +1,24 @@
<?php
/*
* 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\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config;
class CustomConfig
{
public function addConfiguration($rootNode)
{
$rootNode
->children()
->scalarNode('custom')->end()
->end()
;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*
* 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\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
private $customConfig;
public function __construct($customConfig = null)
{
$this->customConfig = $customConfig;
}
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('test');
if ($this->customConfig) {
$this->customConfig->addConfiguration($rootNode);
}
return $treeBuilder;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* 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\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
class TestExtension extends Extension implements PrependExtensionInterface
{
private $customConfig;
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);
}
/**
* {@inheritdoc}
*/
public function prepend(ContainerBuilder $container)
{
$container->prependExtensionConfig('test', array('custom' => 'foo'));
}
/**
* {@inheritdoc}
*/
public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($this->customConfig);
}
public function setCustomConfig($customConfig)
{
$this->customConfig = $customConfig;
}
}

View File

@@ -0,0 +1,46 @@
session_welcome:
path: /session
defaults: { _controller: TestBundle:Session:welcome }
session_welcome_name:
path: /session/{name}
defaults: { _controller: TestBundle:Session:welcome }
session_logout:
path: /session_logout
defaults: { _controller: TestBundle:Session:logout}
session_setflash:
path: /session_setflash/{message}
defaults: { _controller: TestBundle:Session:setFlash}
session_showflash:
path: /session_showflash
defaults: { _controller: TestBundle:Session:showFlash}
profiler:
path: /profiler
defaults: { _controller: TestBundle:Profiler:index }
subrequest_index:
path: /subrequest/{_locale}.{_format}
defaults: { _controller: TestBundle:SubRequest:index, _format: "html" }
schemes: [https]
subrequest_fragment_error:
path: /subrequest/fragment/error/{_locale}.{_format}
defaults: { _controller: TestBundle:SubRequest:fragmentError, _format: "html" }
schemes: [http]
subrequest_fragment:
path: /subrequest/fragment/{_locale}.{_format}
defaults: { _controller: TestBundle:SubRequest:fragment, _format: "html" }
schemes: [http]
fragment_home:
path: /fragment_home
defaults: { _controller: TestBundle:Fragment:index, _format: txt }
fragment_inlined:
path: /fragment_inlined
defaults: { _controller: TestBundle:Fragment:inlined }

View File

@@ -0,0 +1,29 @@
<?php
/*
* 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\FrameworkBundle\Tests\Functional\Bundle\TestBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\DependencyInjection\Config\CustomConfig;
class TestBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
/** @var $extension DependencyInjection\TestExtension */
$extension = $container->getExtension('test');
$extension->setCustomConfig(new CustomConfig());
}
}