Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Expression language extensibility #12006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 28, 2014

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Sep 23, 2014

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #10512
License MIT
Doc PR not yet

The way we can add functions to an ExpressionLanguage instance is by using inheritance. #10512 tries to make the expression language in the routing flexible but using inheritance won't work when several bundles want to add functions.

So, this PR takes another approach to solve the problem globally.

Todo:

  • add some more tests
  • add some docs

@Taluu
Copy link
Contributor

Taluu commented Sep 23, 2014

I just needed this not later than this afternoon, so a big 👍

interface ExpressionFunctionProviderInterface
{
/**
* @return Function[] An array of Function instances
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExpressionFunction[]

@stof
Copy link
Member

stof commented Sep 23, 2014

IMO, it would be worth providing a compiler pass registering the providers (we ned a separate tag for the security and the routing), to avoid each bundle to register a compiler pass for that

@fabpot
Copy link
Member Author

fabpot commented Sep 23, 2014

@stof I agree. This PR is in the early stages, but I wanted some feedback about this approach before investing too much time on it.

@stof
Copy link
Member

stof commented Sep 25, 2014

@fabpot this looks good to me. Actually, I already wrapped the functions in an object in my project, to allow registering them with a compiler pass (except that I'm doing ->addMethodCall('register', array($name, array(new Reference($id), 'compile'), array(new Reference($id), 'evaluate'))) in my current code instead of having methods returning a callable, but my approach does not allow to write an interface for the classes given that the signature of compile and evaluate depend on the function

@fabpot fabpot force-pushed the expression-language-extensibility branch 2 times, most recently from 35f8b78 to 66102d9 Compare September 25, 2014 15:27
@fabpot
Copy link
Member Author

fabpot commented Sep 25, 2014

PR ready now. I've added some more tests and a compiler pass.

@fabpot
Copy link
Member Author

fabpot commented Sep 25, 2014

ping @symfony/deciders

@Taluu
Copy link
Contributor

Taluu commented Sep 25, 2014

How come is there the commits bc23ee6 & aca9e49 in the commit list ? Shouldn't you do a rebase ?

@jakzal
Copy link
Contributor

jakzal commented Sep 28, 2014

Looks good to me 👍

@fabpot fabpot merged commit 7c24188 into symfony:master Sep 28, 2014
fabpot added a commit that referenced this pull request Sep 28, 2014
This PR was merged into the 2.6-dev branch.

Discussion
----------

Expression language extensibility

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10512
| License       | MIT
| Doc PR        | not yet

The way we can add functions to an ExpressionLanguage instance is by using inheritance. #10512 tries to make the expression language in the routing flexible but using inheritance won't work when several bundles want to add functions.

So, this PR takes another approach to solve the problem globally.

Todo:

 * [x] add some more tests
 * [ ] add some docs

Commits
-------

7c24188 [FrameworkBundle] added a compiler pass for expression language providers
4195a91 [Routing] added support for custom expression language functions
1a39046 [Security] added support for custom expression language functions
79bcd52 [DependencyInjection] added support for custom expression language functions
184742c [ExpressionLanguage] added ExpressionFunction and ExpressionFunctionProviderInterface
xabbuh added a commit to xabbuh/symfony that referenced this pull request Sep 30, 2014
Since symfony#12006, the `ContainerBuilder` contains the
`addExpressionLanguageProvider()` method which references a class from
the ExpressionLanguage component. By default, the PHPUnit mock API
tries to mock all methods of the class being doubled. Since the
ExpressionLanguage component is not required to run the tests,
creating the mock objects fails when the mock API fails to mock
the `addExpressionLanguageProvider()` method.
@xabbuh xabbuh mentioned this pull request Sep 30, 2014
fabpot added a commit that referenced this pull request Oct 1, 2014
This PR was merged into the 2.3 branch.

Discussion
----------

fix components tests

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

Since #12006, the `ContainerBuilder` contains the `addExpressionLanguageProvider()` method which references a class from the ExpressionLanguage component. By default, the PHPUnit mock API tries to mock all methods of the class being doubled. Since the ExpressionLanguage component is not required to run the tests, creating the mock objects fails when the mock API fails to mock the `addExpressionLanguageProvider()` method.

Commits
-------

2f2a732 fix components tests
@fabpot fabpot deleted the expression-language-extensibility branch October 9, 2014 19:01
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Nov 24, 2014
This PR was merged into the 2.6 branch.

Discussion
----------

Documented ExpressionLanguage extensibility

| Q   | A
| --- | ---
| Doc fix? | no
| New docs? | yes (symfony/symfony#12006)
| Applies to | 2.6+
| Fixed tickets | #4289

Commits
-------

086885b Applied comments
ef4ca42 Documented new tags
c553193 Documented expressionlanguage extensibility
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants