Merge branch '3.2'

* 3.2:
  Revamped the README file
  Fix missing namespace in AddConstraintValidatorPassTest
  [SecurityBundle] simplified code
  [ExpressionLanguage] Registering functions after calling evaluate(), compile() or parse() is not supported
This commit is contained in:
Fabien Potencier 2017-02-24 05:59:04 -08:00
commit e58be70aca
6 changed files with 142 additions and 59 deletions

View File

@ -1,57 +1,74 @@
README
======
<p align="center"><a href="https://symfony.com" target="_blank">
<img src="https://symfony.com/logos/symfony_black_02.svg">
</a></p>
What is Symfony?
-----------------
Symfony is a PHP full-stack web framework. It is written with speed and
flexibility in mind. It allows developers to build better and easy to maintain
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.
[Symfony][1] is a **PHP framework** for web applications and a set of reusable
**PHP components**. Symfony is used by thousands of web applications (including
BlaBlaCar.com and Spotify.com) and most of the [popular PHP projects][2] (including
Drupal and Magento).
Installation
------------
The best way to install Symfony is to use the [official Symfony Installer][7].
It allows you to start a new project based on the version you want.
* [Install Symfony][4] with Composer or with our own installer (see
[requirements details][3]).
* Symfony follows the [semantic versioning][5] strictly, publishes "Long Term
Support" (LTS) versions and has a [release process][6] that is predictable and
business-friendly.
Documentation
-------------
The "[Quick Tour][1]" tutorial gives you a first feeling of the framework. If,
like us, you think that Symfony can help speed up your development and take
the quality of your work to the next level, read the official
[Symfony documentation][2].
* Read the [Getting Started guide][7] if you are new to Symfony.
* Try the [Symfony Demo application][23] to learn Symfony in practice.
* Master Symfony with the [Guides and Tutorials][8], the [Components docs][9]
and the [Best Practices][10] reference.
Community
---------
* [Join the Symfony Community][11] and meet other members at the [Symfony events][12].
* [Get Symfony support][13] on StackOverflow, Slack, IRC, etc.
* Follow us on [GitHub][14], [Twitter][15] and [Facebook][16].
Contributing
------------
Symfony is an open source, community-driven project. If you'd like to contribute,
please read the [Contributing Code][3] part of the documentation. If you're submitting
a pull request, please follow the guidelines in the [Submitting a Patch][4] section
and use [Pull Request Template][5].
Symfony is an Open Source, community-driven project with thousands of
[contributors][19]. Join them [contributing code][17] or [contributing documentation][18].
Community Reviews
-----------------
Security Issues
---------------
If you don't feel ready to contribute code or patches, reviewing issues and pull
requests can be a great start to get involved and give back. In fact, people who
"triage" issues are the backbone to Symfony's success!
More information can be found in the [Community Reviews][8] guide.
If you discover a security vulnerability within Symfony, please follow our
[disclosure procedure][20].
Running Symfony Tests
----------------------
About Us
--------
Information on how to run the Symfony test suite can be found in the
[Running Symfony Tests][6] section.
Symfony development is sponsored by [SensioLabs][21], lead by the
[Symfony Core Team][22] and supported by [Symfony contributors][19].
[1]: https://symfony.com/doc/current/quick_tour/index.html
[2]: https://symfony.com/doc/current/
[3]: https://symfony.com/doc/current/contributing/code/index.html
[4]: https://symfony.com/doc/current/contributing/code/patches.html#check-list
[5]: https://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request
[6]: https://symfony.com/doc/master/contributing/code/tests.html
[7]: https://symfony.com/doc/current/book/installation.html#installing-the-symfony-installer
[8]: https://symfony.com/doc/current/contributing/community/reviews.html
[1]: https://symfony.com
[2]: https://symfony.com/projects
[3]: https://symfony.com/doc/current/reference/requirements.html
[4]: https://symfony.com/doc/current/setup.html
[5]: http://semver.org
[6]: https://symfony.com/doc/current/contributing/community/releases.html
[7]: https://symfony.com/doc/current/page_creation.html
[8]: https://symfony.com/doc/current/index.html
[9]: https://symfony.com/doc/current/components/index.html
[10]: https://symfony.com/doc/current/best_practices/index.html
[11]: https://symfony.com/community
[12]: https://symfony.com/events/
[13]: https://symfony.com/support
[14]: https://github.com/symfony
[15]: https://twitter.com/symfony
[16]: https://www.facebook.com/SymfonyFramework/
[17]: https://symfony.com/doc/current/contributing/code/index.html
[18]: https://symfony.com/doc/current/contributing/documentation/index.html
[19]: https://symfony.com/contributors
[20]: https://symfony.com/security
[21]: https://sensiolabs.com
[22]: https://symfony.com/doc/current/contributing/code/core_team.html
[23]: https://github.com/symfony/symfony-demo

View File

@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;

View File

@ -11,9 +11,9 @@
namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\Exception\LogicException;
/**
@ -23,6 +23,8 @@ use Symfony\Component\DependencyInjection\Exception\LogicException;
*/
class AddSecurityVotersPass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;
/**
* {@inheritdoc}
*/
@ -32,15 +34,7 @@ class AddSecurityVotersPass implements CompilerPassInterface
return;
}
$voters = array();
foreach ($container->findTaggedServiceIds('security.voter') as $id => $attributes) {
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
$voters[$priority][] = new Reference($id);
}
krsort($voters);
$voters = call_user_func_array('array_merge', $voters);
$voters = $this->findAndSortTaggedServices('security.voter', $container);
if (!$voters) {
throw new LogicException('No security voters found. You need to tag at least one with "security.voter"');
}

View File

@ -18,6 +18,21 @@ use Symfony\Component\DependencyInjection\Reference;
class AddSecurityVotersPassTest extends TestCase
{
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
*/
public function testNoVoters()
{
$container = new ContainerBuilder();
$container
->register('security.access.decision_manager', 'Symfony\Component\Security\Core\Authorization\AccessDecisionManager')
->addArgument(array())
;
$compilerPass = new AddSecurityVotersPass();
$compilerPass->process($container);
}
public function testThatSecurityVotersAreProcessedInPriorityOrder()
{
$container = new ContainerBuilder();
@ -45,15 +60,9 @@ class AddSecurityVotersPassTest extends TestCase
$compilerPass->process($container);
$calls = $container->getDefinition('security.access.decision_manager')->getMethodCalls();
$this->assertEquals(
array(
new Reference('highest_prio_service'),
new Reference('lowest_prio_service'),
new Reference('no_prio_service'),
new Reference('zero_prio_service'),
),
$calls[0][1][0]
);
$refs = $calls[0][1][0];
$this->assertEquals(new Reference('highest_prio_service'), $refs[0]);
$this->assertEquals(new Reference('lowest_prio_service'), $refs[1]);
$this->assertCount(4, $refs);
}
}

View File

@ -122,10 +122,16 @@ class ExpressionLanguage
* @param callable $compiler A callable able to compile the function
* @param callable $evaluator A callable able to evaluate the function
*
* @throws \LogicException when registering a function after calling evaluate(), compile() or parse()
*
* @see ExpressionFunction
*/
public function register($name, callable $compiler, callable $evaluator)
{
if (null !== $this->parser) {
throw new \LogicException('Registering functions after calling evaluate(), compile() or parse() is not supported.');
}
$this->functions[$name] = array('compiler' => $compiler, 'evaluator' => $evaluator);
}

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\ExpressionLanguage\Tests;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use PHPUnit\Framework\TestCase;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\ExpressionLanguage\ParsedExpression;
@ -218,4 +219,58 @@ class ExpressionLanguageTest extends TestCase
$expressionLanguage->compile($expression, array('a', 'B' => 'b'));
$expressionLanguage->compile($expression, array('B' => 'b', 'a'));
}
/**
* @dataProvider getRegisterCallbacks
* @expectedException \LogicException
*/
public function testRegisterAfterParse($registerCallback)
{
$el = new ExpressionLanguage();
$el->parse('1 + 1', array());
$registerCallback($el);
}
/**
* @dataProvider getRegisterCallbacks
* @expectedException \LogicException
*/
public function testRegisterAfterEval($registerCallback)
{
$el = new ExpressionLanguage();
$el->evaluate('1 + 1');
$registerCallback($el);
}
/**
* @dataProvider getRegisterCallbacks
* @expectedException \LogicException
*/
public function testRegisterAfterCompile($registerCallback)
{
$el = new ExpressionLanguage();
$el->compile('1 + 1');
$registerCallback($el);
}
public function getRegisterCallbacks()
{
return array(
array(
function (ExpressionLanguage $el) {
$el->register('fn', function () {}, function () {});
},
),
array(
function (ExpressionLanguage $el) {
$el->addFunction(new ExpressionFunction('fn', function () {}, function () {}));
},
),
array(
function (ExpressionLanguage $el) {
$el->registerProvider(new TestProvider());
},
),
);
}
}