Merge remote-tracking branch 'remotes/symfony/master'
This commit is contained in:
commit
cc49cd9498
29
README.md
29
README.md
@ -11,28 +11,25 @@ websites with PHP.
|
||||
Symfony can be used to develop all kind of websites, from your personal blog
|
||||
to high traffic ones like Dailymotion or Yahoo! Answers.
|
||||
|
||||
High Performance
|
||||
----------------
|
||||
|
||||
Built with performance in mind, Symfony2 is one of the fastest PHP frameworks.
|
||||
It is up to 3 times faster than symfony 1.4 or Zend Framework 1.10 and
|
||||
consumes half the memory.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
Symfony2 is only supported on PHP 5.3.2 and up.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
The best way to install Symfony2 is to download the Symfony Standard Edition
|
||||
available at [http://symfony.com/download][1].
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
Symfony 2.0 is still in the early stages of development, but the
|
||||
"[Quick Tour][1]" tutorial can get you started fast.
|
||||
The "[Quick Tour][2]" tutorial gives you a first feeling of the framework. If,
|
||||
like us, you think that Symfony2 can help speed up your development and take
|
||||
the quality of your work to the next level, read the official
|
||||
[Symfony2 documentation][3].
|
||||
|
||||
The "Quick Tour" tutorial barely scratches the surface of Symfony 2.0, but it
|
||||
gives you a first feeling of the framework. If, like us, you think that
|
||||
Symfony2 can help speed up your development and take the quality of your work
|
||||
to the next level, visit the official [Symfony2 website][2] to learn more.
|
||||
|
||||
[1]: http://symfony.com/get_started
|
||||
[2]: http://symfony.com/
|
||||
[1]: http://symfony.com/download
|
||||
[2]: http://symfony.com/get_started
|
||||
[3]: http://symfony.com/doc/current/
|
||||
|
22
UPDATE.md
22
UPDATE.md
@ -6,6 +6,28 @@ one. It only discusses changes that need to be done when using the "public"
|
||||
API of the framework. If you "hack" the core, you should probably follow the
|
||||
timeline closely anyway.
|
||||
|
||||
beta2 to beta3
|
||||
--------------
|
||||
|
||||
* The settings under "framework.annotations" have changed slightly:
|
||||
|
||||
Before:
|
||||
|
||||
framework:
|
||||
annotations:
|
||||
cache: file
|
||||
file_cache:
|
||||
debug: true
|
||||
dir: /foo
|
||||
|
||||
After:
|
||||
|
||||
framework:
|
||||
annotations:
|
||||
cache: file
|
||||
debug: true
|
||||
file_cache_dir: /foo
|
||||
|
||||
beta1 to beta2
|
||||
--------------
|
||||
|
||||
|
@ -7,16 +7,28 @@
|
||||
<parameters>
|
||||
<parameter key="assetic.filter.jpegtran.class">Assetic\Filter\JpegtranFilter</parameter>
|
||||
<parameter key="assetic.filter.jpegtran.bin">/usr/bin/jpegtran</parameter>
|
||||
<parameter key="assetic.filter.jpegtran.copy">null</parameter>
|
||||
<parameter key="assetic.filter.jpegtran.optimize">false</parameter>
|
||||
<parameter key="assetic.filter.jpegtran.progressive">false</parameter>
|
||||
<parameter key="assetic.filter.jpegtran.restart">null</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="assetic.filter.jpegtran" class="%assetic.filter.jpegtran.class%">
|
||||
<tag name="assetic.filter" alias="jpegtran" />
|
||||
<argument>%assetic.filter.jpegtran.bin%</argument>
|
||||
<call method="setCopy">
|
||||
<argument>%assetic.filter.jpegtran.copy%</argument>
|
||||
</call>
|
||||
<call method="setOptimize">
|
||||
<argument>%assetic.filter.jpegtran.optimize%</argument>
|
||||
</call>
|
||||
<call method="setProgressive">
|
||||
<argument>%assetic.filter.jpegtran.progressive%</argument>
|
||||
</call>
|
||||
<call method="setRestart">
|
||||
<argument>%assetic.filter.jpegtran.restart%</argument>
|
||||
</call>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
@ -7,12 +7,16 @@
|
||||
<parameters>
|
||||
<parameter key="assetic.filter.optipng.class">Assetic\Filter\OptiPngFilter</parameter>
|
||||
<parameter key="assetic.filter.optipng.bin">/usr/bin/optipng</parameter>
|
||||
<parameter key="assetic.filter.optipng.level">null</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="assetic.filter.optipng" class="%assetic.filter.optipng.class%">
|
||||
<tag name="assetic.filter" alias="optipng" />
|
||||
<argument>%assetic.filter.optipng.bin%</argument>
|
||||
<call method="setLevel">
|
||||
<argument>%assetic.filter.optipng.level%</argument>
|
||||
</call>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
@ -50,7 +50,9 @@ class XmlDriver extends BaseXmlDriver
|
||||
);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) {
|
||||
$fileName = $file->getBasename($this->_fileExtension);
|
||||
|
||||
if ($fileName == $file->getBasename() || $fileName == $this->_globalFile) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,9 @@ class YamlDriver extends BaseYamlDriver
|
||||
);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
if (($fileName = $file->getBasename($this->_fileExtension)) == $file->getBasename()) {
|
||||
$fileName = $file->getBasename($this->_fileExtension);
|
||||
|
||||
if ($fileName == $file->getBasename() || $fileName == $this->_globalFile) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -274,13 +274,8 @@ class Configuration implements ConfigurationInterface
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('cache')->defaultValue('file')->end()
|
||||
->arrayNode('file_cache')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('dir')->defaultValue('%kernel.cache_dir%/annotations')->end()
|
||||
->booleanNode('debug')->defaultValue($this->debug)->end()
|
||||
->end()
|
||||
->end()
|
||||
->scalarNode('file_cache_dir')->defaultValue('%kernel.cache_dir%/annotations')->end()
|
||||
->booleanNode('debug')->defaultValue($this->debug)->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
@ -517,23 +517,24 @@ class FrameworkExtension extends Extension
|
||||
$loader->load('annotations.xml');
|
||||
|
||||
if ('file' === $config['cache']) {
|
||||
$cacheDir = $container->getParameterBag()->resolveValue($config['file_cache']['dir']);
|
||||
$cacheDir = $container->getParameterBag()->resolveValue($config['file_cache_dir']);
|
||||
if (!is_dir($cacheDir) && false === @mkdir($cacheDir, 0777, true)) {
|
||||
throw new \RuntimeException(sprintf('Could not create cache directory "%s".', $cacheDir));
|
||||
}
|
||||
|
||||
$container
|
||||
->getDefinition('annotations.cache.file_cache')
|
||||
->replaceArgument(0, $cacheDir)
|
||||
->replaceArgument(1, $config['file_cache']['debug'])
|
||||
->getDefinition('annotations.file_cache_reader')
|
||||
->replaceArgument(1, $cacheDir)
|
||||
->replaceArgument(2, $config['debug'])
|
||||
;
|
||||
} else if ('none' === $config['cache']) {
|
||||
$container->setAlias('annotation_reader', 'annotations.reader');
|
||||
} else {
|
||||
$container->setAlias('annotation_reader', 'annotations.file_cache_reader');
|
||||
} else if('none' !== $config['cache']) {
|
||||
$container
|
||||
->getDefinition('annotations.cached_reader')
|
||||
->replaceArgument(1, new Reference($config['cache']))
|
||||
->replaceArgument(2, $config['debug'])
|
||||
;
|
||||
$container->setAlias('annotation_reader', 'annotations.cached_reader');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,25 +5,26 @@
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
|
||||
<parameters>
|
||||
<parameter key="annotations.cache.file_cache.class">Doctrine\Common\Annotations\Cache\FileCache</parameter>
|
||||
|
||||
<parameter key="annotations.reader.class">Doctrine\Common\Annotations\AnnotationReader</parameter>
|
||||
<parameter key="annotations.cached_reader.class">Doctrine\Common\Annotations\CachedReader</parameter>
|
||||
<parameter key="annotations.file_cache_reader.class">Doctrine\Common\Annotations\FileCacheReader</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
<service id="annotations.cache.file_cache" class="%annotations.cache.file_cache.class%" public="false">
|
||||
<argument /><!-- Cache Directory -->
|
||||
<argument /><!-- Debug-Flag -->
|
||||
</service>
|
||||
|
||||
<service id="annotations.reader" class="%annotations.reader.class%" public="false" />
|
||||
|
||||
<service id="annotations.cached_reader" class="%annotations.cached_reader.class%" public="false">
|
||||
<argument type="service" id="annotations.reader" />
|
||||
<argument type="service" id="annotations.cache.file_cache" />
|
||||
<argument /><!-- Cache Implementation -->
|
||||
<argument /><!-- Debug-Flag -->
|
||||
</service>
|
||||
|
||||
<service id="annotation_reader" alias="annotations.cached_reader" />
|
||||
<service id="annotations.file_cache_reader" class="%annotations.file_cache_reader.class%" public="false">
|
||||
<argument type="service" id="annotations.reader" />
|
||||
<argument /><!-- Cache-Directory -->
|
||||
<argument /><!-- Debug Flag -->
|
||||
</service>
|
||||
|
||||
<service id="annotation_reader" alias="annotations.reader" />
|
||||
</services>
|
||||
</container>
|
||||
|
@ -128,15 +128,8 @@
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="annotations">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="file-cache" type="annotations.file_cache" minOccurs="0" maxOccurs="1" />
|
||||
</xsd:sequence>
|
||||
|
||||
<xsd:attribute name="cache" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="annotations.file_cache">
|
||||
<xsd:attribute name="dir" type="xsd:string" />
|
||||
<xsd:attribute name="debug" type="xsd:string" />
|
||||
<xsd:attribute name="file-cache-dir" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
||||
|
@ -59,9 +59,7 @@ $container->loadFromExtension('framework', array(
|
||||
),
|
||||
'annotations' => array(
|
||||
'cache' => 'file',
|
||||
'file_cache' => array(
|
||||
'dir' => '%kernel.cache_dir%/annotations',
|
||||
'debug' => true,
|
||||
)
|
||||
'debug' => true,
|
||||
'file_cache_dir' => '%kernel.cache_dir%/annotations',
|
||||
),
|
||||
));
|
||||
|
@ -31,8 +31,6 @@
|
||||
</framework:templating>
|
||||
<framework:translator enabled="true" fallback="fr" />
|
||||
<framework:validation enabled="true" cache="apc" />
|
||||
<framework:annotations cache="file">
|
||||
<framework:file-cache dir="%kernel.cache_dir%/annotations" debug="true" />
|
||||
</framework:annotations>
|
||||
<framework:annotations cache="file" debug="true" file-cache-dir="%kernel.cache_dir%/annotations" />
|
||||
</framework:config>
|
||||
</container>
|
||||
|
@ -45,6 +45,5 @@ framework:
|
||||
cache: apc
|
||||
annotations:
|
||||
cache: file
|
||||
file_cache:
|
||||
dir: %kernel.cache_dir%/annotations
|
||||
debug: true
|
||||
debug: true
|
||||
file_cache_dir: %kernel.cache_dir%/annotations
|
||||
|
@ -172,8 +172,8 @@ abstract class FrameworkExtensionTest extends TestCase
|
||||
{
|
||||
$container = $this->createContainerFromFile('full');
|
||||
|
||||
$this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.cache.file_cache')->getArgument(0));
|
||||
$this->assertEquals('annotations.cached_reader', (string) $container->getAlias('annotation_reader'));
|
||||
$this->assertEquals($container->getParameter('kernel.cache_dir').'/annotations', $container->getDefinition('annotations.file_cache_reader')->getArgument(1));
|
||||
$this->assertInstanceOf('Doctrine\Common\Annotations\FileCacheReader', $container->get('annotation_reader'));
|
||||
}
|
||||
|
||||
public function testValidationAnnotations()
|
||||
|
@ -15,12 +15,10 @@
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="handler">
|
||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element name="processor" type="xsd:string" />
|
||||
</xsd:choice>
|
||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element name="member" type="xsd:string" />
|
||||
</xsd:choice>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="processor" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="member" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="type" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="priority" type="xsd:integer" />
|
||||
<xsd:attribute name="level" type="level" />
|
||||
|
@ -15,6 +15,10 @@ use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
use Symfony\Component\DependencyInjection\Alias;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
|
||||
use Symfony\Component\Config\Loader\DelegatingLoader;
|
||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Parameter;
|
||||
@ -566,7 +570,15 @@ class SecurityExtension extends Extension
|
||||
// load service templates
|
||||
$c = new ContainerBuilder();
|
||||
$parameterBag = $container->getParameterBag();
|
||||
$loader = new XmlFileLoader($c, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
|
||||
$locator = new FileLocator(__DIR__.'/../Resources/config');
|
||||
$resolver = new LoaderResolver(array(
|
||||
new XmlFileLoader($c, $locator),
|
||||
new YamlFileLoader($c, $locator),
|
||||
new PhpFileLoader($c, $locator),
|
||||
));
|
||||
$loader = new DelegatingLoader($resolver);
|
||||
|
||||
$loader->load('security_factories.xml');
|
||||
|
||||
// load user-created listener factories
|
||||
|
67
src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php
Normal file
67
src/Symfony/Bundle/TwigBundle/Extension/ActionsExtension.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?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\TwigBundle\Extension;
|
||||
|
||||
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Twig extension for Symfony actions helper
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ActionsExtension extends \Twig_Extension
|
||||
{
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param ContainerInterface $container The service container
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Response content for a given controller or URI.
|
||||
*
|
||||
* @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI
|
||||
* @param array $attributes An array of request attributes
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @see Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver::render()
|
||||
*/
|
||||
public function renderAction($controller, array $attributes = array(), array $options = array())
|
||||
{
|
||||
return $this->container->get('templating.helper.actions')->render($controller, $attributes, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the token parser instance to add to the existing list.
|
||||
*
|
||||
* @return array An array of Twig_TokenParser instances
|
||||
*/
|
||||
public function getTokenParsers()
|
||||
{
|
||||
return array(
|
||||
// {% render 'BlogBundle:Post:list' with { 'limit': 2 }, { 'alt': 'BlogBundle:Post:error' } %}
|
||||
new RenderTokenParser(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'actions';
|
||||
}
|
||||
}
|
76
src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php
Normal file
76
src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?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\TwigBundle\Extension;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class AssetsExtension extends \Twig_Extension
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return array An array of functions
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
'asset' => new \Twig_Function_Method($this, 'getAssetUrl'),
|
||||
'assets_version' => new \Twig_Function_Method($this, 'getAssetsVersion'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public path of an asset
|
||||
*
|
||||
* Absolute paths (i.e. http://...) are returned unmodified.
|
||||
*
|
||||
* @param string $path A public path
|
||||
* @param string $packageName The name of the asset package to use
|
||||
*
|
||||
* @return string A public path which takes into account the base path and URL path
|
||||
*/
|
||||
public function getAssetUrl($path, $packageName = null)
|
||||
{
|
||||
return $this->container->get('templating.helper.assets')->getUrl($path, $packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of the assets in a package
|
||||
*
|
||||
* @param string $packageName
|
||||
* @return int
|
||||
*/
|
||||
public function getAssetsVersion($packageName = null)
|
||||
{
|
||||
return $this->container->get('templating.helper.assets')->getVersion($packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'assets';
|
||||
}
|
||||
}
|
@ -12,16 +12,20 @@
|
||||
namespace Symfony\Bundle\TwigBundle\Extension;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Bundle\TwigBundle\TokenParser\RenderTokenParser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class TemplatingExtension extends \Twig_Extension
|
||||
class CodeExtension extends \Twig_Extension
|
||||
{
|
||||
protected $container;
|
||||
private $container;
|
||||
|
||||
/**
|
||||
* Constructor of Twig Extension to provide functions for code formatting
|
||||
*
|
||||
* @param Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper $helper Helper to use
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
@ -44,74 +48,6 @@ class TemplatingExtension extends \Twig_Extension
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return array An array of functions
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return array(
|
||||
'asset' => new \Twig_Function_Method($this, 'getAssetUrl'),
|
||||
'assets_version' => new \Twig_Function_Method($this, 'getAssetsVersion'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the public path of an asset
|
||||
*
|
||||
* Absolute paths (i.e. http://...) are returned unmodified.
|
||||
*
|
||||
* @param string $path A public path
|
||||
* @param string $packageName The name of the asset package to use
|
||||
*
|
||||
* @return string A public path which takes into account the base path and URL path
|
||||
*/
|
||||
public function getAssetUrl($path, $packageName = null)
|
||||
{
|
||||
return $this->container->get('templating.helper.assets')->getUrl($path, $packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of the assets in a package
|
||||
*
|
||||
* @param string $packageName
|
||||
* @return int
|
||||
*/
|
||||
public function getAssetsVersion($packageName = null)
|
||||
{
|
||||
return $this->container->get('templating.helper.assets')->getVersion($packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Response content for a given controller or URI.
|
||||
*
|
||||
* @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI
|
||||
* @param array $attributes An array of request attributes
|
||||
* @param array $options An array of options
|
||||
*
|
||||
* @see Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver::render()
|
||||
*/
|
||||
public function renderAction($controller, array $attributes = array(), array $options = array())
|
||||
{
|
||||
$options['attributes'] = $attributes;
|
||||
|
||||
return $this->container->get('http_kernel')->render($controller, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the token parser instance to add to the existing list.
|
||||
*
|
||||
* @return array An array of Twig_TokenParser instances
|
||||
*/
|
||||
public function getTokenParsers()
|
||||
{
|
||||
return array(
|
||||
// {% render 'BlogBundle:Post:list' with { 'limit': 2 }, { 'alt': 'BlogBundle:Post:error' } %}
|
||||
new RenderTokenParser(),
|
||||
);
|
||||
}
|
||||
|
||||
public function abbrClass($class)
|
||||
{
|
||||
return $this->container->get('templating.helper.code')->abbrClass($class);
|
||||
@ -152,13 +88,8 @@ class TemplatingExtension extends \Twig_Extension
|
||||
return $this->container->get('templating.helper.code')->formatFileFromText($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the extension.
|
||||
*
|
||||
* @return string The extension name
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'templating';
|
||||
return 'code';
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ class RenderNode extends \Twig_Node
|
||||
{
|
||||
$compiler
|
||||
->addDebugInfo($this)
|
||||
->write("echo \$this->env->getExtension('templating')->renderAction(")
|
||||
->write("echo \$this->env->getExtension('actions')->renderAction(")
|
||||
->subcompile($this->getNode('expr'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('attributes'))
|
||||
|
@ -9,6 +9,15 @@
|
||||
<parameter key="twig.loader.class">Symfony\Bundle\TwigBundle\Loader\FilesystemLoader</parameter>
|
||||
<parameter key="templating.engine.twig.class">Symfony\Bundle\TwigBundle\TwigEngine</parameter>
|
||||
<parameter key="twig.cache_warmer.class">Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheCacheWarmer</parameter>
|
||||
<parameter key="twig.extension.trans.class">Symfony\Bridge\Twig\Extension\TranslationExtension</parameter>
|
||||
<parameter key="twig.extension.assets.class">Symfony\Bundle\TwigBundle\Extension\AssetsExtension</parameter>
|
||||
<parameter key="twig.extension.actions.class">Symfony\Bundle\TwigBundle\Extension\ActionsExtension</parameter>
|
||||
<parameter key="twig.extension.code.class">Symfony\Bundle\TwigBundle\Extension\CodeExtension</parameter>
|
||||
<parameter key="twig.extension.routing.class">Symfony\Bridge\Twig\Extension\RoutingExtension</parameter>
|
||||
<parameter key="twig.extension.yaml.class">Symfony\Bridge\Twig\Extension\YamlExtension</parameter>
|
||||
<parameter key="twig.extension.form.class">Symfony\Bridge\Twig\Extension\FormExtension</parameter>
|
||||
<parameter key="twig.extension.text.class">Twig_Extensions_Extension_Text</parameter>
|
||||
<parameter key="twig.extension.debug.class">Twig_Extensions_Extension_Debug</parameter>
|
||||
</parameters>
|
||||
|
||||
<services>
|
||||
@ -33,32 +42,42 @@
|
||||
<argument type="service" id="templating.globals" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.trans" class="Symfony\Bridge\Twig\Extension\TranslationExtension" public="false">
|
||||
<service id="twig.extension.trans" class="%twig.extension.trans.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
<argument type="service" id="translator" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.helpers" class="Symfony\Bundle\TwigBundle\Extension\TemplatingExtension" public="false">
|
||||
<service id="twig.extension.assets" class="%twig.extension.assets.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.routing" class="Symfony\Bridge\Twig\Extension\RoutingExtension" public="false">
|
||||
<service id="twig.extension.actions" class="%twig.extension.actions.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.code" class="%twig.extension.code.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.routing" class="%twig.extension.routing.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
<argument type="service" id="router" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.yaml" class="Symfony\Bridge\Twig\Extension\YamlExtension" public="false">
|
||||
<service id="twig.extension.yaml" class="%twig.extension.yaml.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.form" class="Symfony\Bridge\Twig\Extension\FormExtension" public="false">
|
||||
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
<argument>%twig.form.resources%</argument>
|
||||
</service>
|
||||
|
||||
<service id="twig.extension.text" class="Twig_Extensions_Extension_Text" public="false" />
|
||||
<service id="twig.extension.text" class="%twig.extension.text.class%" public="false" />
|
||||
|
||||
<service id="twig.extension.debug" class="Twig_Extensions_Extension_Debug" public="false" />
|
||||
<service id="twig.extension.debug" class="%twig.extension.debug.class%" public="false" />
|
||||
</services>
|
||||
</container>
|
||||
|
@ -29,24 +29,32 @@ class Cookie
|
||||
protected $domain;
|
||||
protected $secure;
|
||||
protected $httponly;
|
||||
protected $rawValue;
|
||||
|
||||
/**
|
||||
* Sets a cookie.
|
||||
*
|
||||
* @param string $name The cookie name
|
||||
* @param string $value The value of the cookie
|
||||
* @param string $expires The time the cookie expires
|
||||
* @param string $path The path on the server in which the cookie will be available on
|
||||
* @param string $domain The domain that the cookie is available
|
||||
* @param Boolean $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
|
||||
* @param Boolean $httponly The cookie httponly flag
|
||||
* @param string $name The cookie name
|
||||
* @param string $value The value of the cookie
|
||||
* @param string $expires The time the cookie expires
|
||||
* @param string $path The path on the server in which the cookie will be available on
|
||||
* @param string $domain The domain that the cookie is available
|
||||
* @param Boolean $secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
|
||||
* @param Boolean $httponly The cookie httponly flag
|
||||
* @param Boolean $encodedValue Whether the value is encoded or not
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($name, $value, $expires = null, $path = '/', $domain = '', $secure = false, $httponly = true)
|
||||
public function __construct($name, $value, $expires = null, $path = '/', $domain = '', $secure = false, $httponly = true, $encodedValue = false)
|
||||
{
|
||||
if ($encodedValue) {
|
||||
$this->value = urldecode($value);
|
||||
$this->rawValue = $value;
|
||||
} else {
|
||||
$this->value = $value;
|
||||
$this->rawValue = urlencode($value);
|
||||
}
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
$this->expires = null === $expires ? null : (integer) $expires;
|
||||
$this->path = empty($path) ? '/' : $path;
|
||||
$this->domain = $domain;
|
||||
@ -63,7 +71,7 @@ class Cookie
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$cookie = sprintf('%s=%s', $this->name, urlencode($this->value));
|
||||
$cookie = sprintf('%s=%s', $this->name, $this->rawValue);
|
||||
|
||||
if (null !== $this->expires) {
|
||||
$cookie .= '; expires='.substr(\DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('UTC'))->format(static::DATE_FORMAT), 0, -5);
|
||||
@ -110,12 +118,13 @@ class Cookie
|
||||
|
||||
$values = array(
|
||||
'name' => trim($name),
|
||||
'value' => urldecode(trim($value)),
|
||||
'value' => trim($value),
|
||||
'expires' => null,
|
||||
'path' => '/',
|
||||
'domain' => '',
|
||||
'secure' => false,
|
||||
'httponly' => false,
|
||||
'passedRawValue' => true,
|
||||
);
|
||||
|
||||
if (null !== $url) {
|
||||
@ -162,7 +171,8 @@ class Cookie
|
||||
$values['path'],
|
||||
$values['domain'],
|
||||
$values['secure'],
|
||||
$values['httponly']
|
||||
$values['httponly'],
|
||||
$values['passedRawValue']
|
||||
);
|
||||
}
|
||||
|
||||
@ -190,6 +200,18 @@ class Cookie
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the raw value of the cookie.
|
||||
*
|
||||
* @return string The cookie value
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getRawValue()
|
||||
{
|
||||
return $this->rawValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the expires time of the cookie.
|
||||
*
|
||||
|
@ -100,20 +100,24 @@ class CookieJar
|
||||
/**
|
||||
* Returns not yet expired cookie values for the given URI.
|
||||
*
|
||||
* @param string $uri A URI
|
||||
* @param string $uri A URI
|
||||
* @param Boolean $returnsRawValue returnes raw value or urldecoded value
|
||||
*
|
||||
* @return array An array of cookie values
|
||||
*/
|
||||
public function allValues($uri)
|
||||
public function allValues($uri, $returnsRawValue = false)
|
||||
{
|
||||
$this->flushExpiredCookies();
|
||||
|
||||
$parts = parse_url($uri);
|
||||
$parts = array_replace(array('path' => '/'), parse_url($uri));
|
||||
|
||||
$cookies = array();
|
||||
foreach ($this->cookieJar as $cookie) {
|
||||
if ($cookie->getDomain() && $cookie->getDomain() != substr($parts['host'], -strlen($cookie->getDomain()))) {
|
||||
continue;
|
||||
if ($cookie->getDomain()) {
|
||||
$domain = ltrim($cookie->getDomain(), '.');
|
||||
if ($domain != substr($parts['host'], -strlen($domain))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($cookie->getPath() != substr($parts['path'], 0, strlen($cookie->getPath()))) {
|
||||
@ -124,12 +128,24 @@ class CookieJar
|
||||
continue;
|
||||
}
|
||||
|
||||
$cookies[$cookie->getName()] = $cookie->getValue();
|
||||
$cookies[$cookie->getName()] = $returnsRawValue ? $cookie->getRawValue() : $cookie->getValue();
|
||||
}
|
||||
|
||||
return $cookies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns not yet expired raw cookie values for the given URI.
|
||||
*
|
||||
* @param string $uri A URI
|
||||
*
|
||||
* @return array An array of cookie values
|
||||
*/
|
||||
public function allRawValues($uri)
|
||||
{
|
||||
return $this->allValues($uri, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all expired cookies.
|
||||
*/
|
||||
|
@ -79,7 +79,8 @@ class CookieJarTest extends \PHPUnit_Framework_TestCase
|
||||
$cookieJar->set($cookie1 = new Cookie('foo_nothing', 'foo'));
|
||||
$cookieJar->set($cookie2 = new Cookie('foo_expired', 'foo', time() - 86400));
|
||||
$cookieJar->set($cookie3 = new Cookie('foo_path', 'foo', null, '/foo'));
|
||||
$cookieJar->set($cookie4 = new Cookie('foo_domain', 'foo', null, '/', 'example.com'));
|
||||
$cookieJar->set($cookie4 = new Cookie('foo_domain', 'foo', null, '/', '.example.com'));
|
||||
$cookieJar->set($cookie4 = new Cookie('foo_strict_domain', 'foo', null, '/', '.www4.example.com'));
|
||||
$cookieJar->set($cookie5 = new Cookie('foo_secure', 'foo', null, '/', '', true));
|
||||
|
||||
$this->assertEquals($values, array_keys($cookieJar->allValues($uri)), '->allValues() returns the cookie for a given URI');
|
||||
@ -88,11 +89,22 @@ class CookieJarTest extends \PHPUnit_Framework_TestCase
|
||||
public function provideAllValuesValues()
|
||||
{
|
||||
return array(
|
||||
array('http://www.example.com', array('foo_nothing', 'foo_domain')),
|
||||
array('http://www.example.com/', array('foo_nothing', 'foo_domain')),
|
||||
array('http://foo.example.com/', array('foo_nothing', 'foo_domain')),
|
||||
array('http://foo.example1.com/', array('foo_nothing')),
|
||||
array('https://foo.example.com/', array('foo_nothing', 'foo_domain', 'foo_secure')),
|
||||
array('http://www.example.com/foo/bar', array('foo_nothing', 'foo_path', 'foo_domain')),
|
||||
array('http://www4.example.com/', array('foo_nothing', 'foo_domain', 'foo_strict_domain')),
|
||||
);
|
||||
}
|
||||
|
||||
public function testEncodedValues()
|
||||
{
|
||||
$cookieJar = new CookieJar();
|
||||
$cookieJar->set($cookie = new Cookie('foo', 'bar%3Dbaz', null, '/', '', false, true, true));
|
||||
|
||||
$this->assertEquals(array('foo' => 'bar=baz'), $cookieJar->allValues('/'));
|
||||
$this->assertEquals(array('foo' => 'bar%3Dbaz'), $cookieJar->allRawValues('/'));
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ class CookieTest extends \PHPUnit_Framework_TestCase
|
||||
array('foo=bar; secure'),
|
||||
array('foo=bar; httponly'),
|
||||
array('foo=bar; domain=google.com; path=/foo; secure; httponly'),
|
||||
array('foo=bar=baz'),
|
||||
array('foo=bar%3Dbaz'),
|
||||
);
|
||||
}
|
||||
|
||||
@ -70,6 +72,17 @@ class CookieTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar');
|
||||
$this->assertEquals('bar', $cookie->getValue(), '->getValue() returns the cookie value');
|
||||
|
||||
$cookie = new Cookie('foo', 'bar%3Dbaz', null, '/', '', false, true, true); // raw value
|
||||
$this->assertEquals('bar=baz', $cookie->getValue(), '->getValue() returns the urldecoded cookie value');
|
||||
}
|
||||
|
||||
public function testGetRawValue()
|
||||
{
|
||||
$cookie = new Cookie('foo', 'bar=baz'); // decoded value
|
||||
$this->assertEquals('bar%3Dbaz', $cookie->getRawValue(), '->getRawValue() returns the urlencoded cookie value');
|
||||
$cookie = new Cookie('foo', 'bar%3Dbaz', null, '/', '', false, true, true); // raw value
|
||||
$this->assertEquals('bar%3Dbaz', $cookie->getRawValue(), '->getRawValue() returns the non-urldecoded cookie value');
|
||||
}
|
||||
|
||||
public function testGetPath()
|
||||
|
@ -10,6 +10,15 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
CAUTION: This file installs the dependencies needed to run the Symfony2 test suite.
|
||||
If you want to create a new project, download the Symfony Standard Edition instead:
|
||||
|
||||
http://symfony.com/download
|
||||
|
||||
*/
|
||||
|
||||
if (!is_dir($vendorDir = dirname(__FILE__).'/vendor')) {
|
||||
mkdir($vendorDir, 0777, true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user