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

Skip to content

[Workflow] Added a context to Workflow::apply() #29146

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 1 commit into from
Mar 6, 2019

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Nov 8, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27925 (maybe #28253 and #28266)
License MIT
Doc PR

@lyrixx
Copy link
Member Author

lyrixx commented Nov 8, 2018

I thought it will be easy, but the Property Access does not support passing 2 arguments to a setter (super logic after all).

I don't know how to achieve this. Some randome ideas

  1. Pass a PlaceAndContext to the POPO. but the BC layer will be impossible
  2. do not rely on the the PropertyAccess anymore (but this imply re-code a (small) part of it in the workflow)
  3. Add a MarkingStoreWithContext that does not rely on ProperyAccess and support only setXXXX method call (or with an Interface)
  4. use the PropertyAccess to call setMarking then setContext

Have you other ideas ? What do you prefer ?

Actually I prefer the 2/
It quite easy. we only need to check if a property if public or if method marking() exist, or setMarking() exist. We could still use the PropertyAccessor for getMarking.

@stof
Copy link
Member

stof commented Nov 8, 2018

@lyrixx I think you are forgetting the fact that PropertyAccess takes a property path as input, not just a property name. Using PropertyAccess to read but a simpler implementation supporting only property names to write will not work.

@lyrixx
Copy link
Member Author

lyrixx commented Nov 8, 2018

Ah you are right. So we should go to 3/

What do you think ?

@lyrixx
Copy link
Member Author

lyrixx commented Nov 8, 2018

Just one question, as we do not mention we are using the Property Path component, is it a BC break a change the implementation ?

@nicolas-grekas nicolas-grekas added this to the next milestone Nov 8, 2018
@nicolas-grekas
Copy link
Member

Not if nothing changes on the outside surface.What would be the user visible side effect?

@lyrixx
Copy link
Member Author

lyrixx commented Nov 8, 2018

@nicolas-grekas It could change someting to the end user if they use this kind of configuration:

framework:
    workflows:
        my_workflow:
            marking_store:
                type: multiple_state
                arguments: 
                    - 'property1.property2'
  1. the arguments is documented there : https://symfony.com/doc/current/workflow/usage.html#creating-a-workflow
  2. We don't explain that property1.property2 is supported.

So, if no one is using this feature (we can not be sure, I know, but really I doubt someone is using it), there are no difference for the end user

@lyrixx
Copy link
Member Author

lyrixx commented Nov 8, 2018

I case of you think it's a BC break, what do you think if the last commit?

@noniagriconomie
Copy link
Contributor

@lyrixx thank you on coding this 👍

just a question: what is the aim behind MethodSingleStateMarkingStore? not sure to understand (i mainly use this component with single state)

also, how can we deal with sort of "validation" of the context?
optionresolver? interface? i think it could be safer to have this kind of control

@lyrixx
Copy link
Member Author

lyrixx commented Nov 12, 2018

The aim of MethodSingleStateMarkingStore is to be able to call $subject->setMarking($place, $context).

also, how can we deal with sort of "validation" of the context?

We will not validate the context. It's not the role of the workflow component to do that.

@noniagriconomie
Copy link
Contributor

fair enough :) 👍

@lyrixx
Copy link
Member Author

lyrixx commented Nov 13, 2018

Here we go. I think this PR is ready.

Here is the diff the developer will have to do to use this new feature:
lyrixx/SFLive-Paris2016-Workflow#21

Copy link
Contributor

@noniagriconomie noniagriconomie left a comment

Choose a reason for hiding this comment

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

thank you for the feature

Copy link
Contributor

@noniagriconomie noniagriconomie left a comment

Choose a reason for hiding this comment

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

hope this feature will be merged and documented soon :)

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

LGTM thanks. Here are some comments (+rebase needed)

@lyrixx
Copy link
Member Author

lyrixx commented Dec 4, 2018

Note: I lost the integration with the framework bundle. I will fix it asap

@lyrixx lyrixx force-pushed the workflow-context branch 2 times, most recently from cdd911d to b2cbe22 Compare December 4, 2018 17:26
@lyrixx
Copy link
Member Author

lyrixx commented Dec 4, 2018

Hi!

I finished this PR

But (in another PR) I would like to:

  • deprecate SingleStateMarkingStore and MultipleStateMarkingStore. The new MethodMarkingStore could replace them for most a use case. If people are doing very complex thing, I would suggest using a service for that. We already have all infrastructure for it. My motivation are simplicity and expliciteness. the semantic configuration will me more explicit (instead of arguments: [true, marking] will could have arguments: {single_state: true, property: marking}). Thus I will be able to delete some code ❤️

  • I don't really understand why we have the ValidateWorkflowsPass. It adds some complexity and I don't really see the use case here. @Nyholm Why did you added it ? We could directly validate the definition in the Framework Extension

What do you think ?

@lyrixx lyrixx force-pushed the workflow-context branch from b2cbe22 to 906967c Compare March 6, 2019 18:12
@lyrixx lyrixx force-pushed the workflow-context branch from 906967c to 7d5b7a3 Compare March 6, 2019 18:16
@lyrixx lyrixx merged commit 7d5b7a3 into symfony:master Mar 6, 2019
@lyrixx
Copy link
Member Author

lyrixx commented Mar 6, 2019

@noniagriconomie here we go. I rebased the PR and merged it. You can now test it and give me feedback. Thanks

@lyrixx lyrixx deleted the workflow-context branch March 6, 2019 18:32
lyrixx added a commit that referenced this pull request Mar 6, 2019
…ixx)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Workflow] Added a context to `Workflow::apply()`

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27925 (maybe #28253 and #28266)
| License       | MIT
| Doc PR        |

Commits
-------

7d5b7a3 [Workflow] Added a context to `Workflow::apply()`
@lyrixx
Copy link
Member Author

lyrixx commented Mar 6, 2019

an usage example base on https://github.com/lyrixx/SFLive-Paris2016-Workflow
(I will update the demo asap)

    /**
     * @Route("/apply-transition/{id}", methods={"POST"}, name="article_apply_transition")
     */
    public function applyTransitionAction(Request $request, Article $article)
    {
        try {
            $this->get('workflow.article')
                ->apply($article, $request->request->get('transition'), ['time' => time()]);

            $this->get('doctrine')->getManager()->flush();
        } catch (ExceptionInterface $e) {
            $this->get('session')->getFlashBag()->add('danger', $e->getMessage());
        }

        return $this->redirect(
            $this->generateUrl('article_show', ['id' => $article->getId()])
        );
    }

and the Article::setMarkingMethod:

    public function setMarking($marking, array $context = [])
    {
        $this->marking = $marking;
        dump($context);
    }

@lyrixx
Copy link
Member Author

lyrixx commented Mar 6, 2019

Here we go: How to use it and the demo

@noniagriconomie
Copy link
Contributor

noniagriconomie commented Mar 6, 2019

@lyrixx many thanks :)

Will of course test it and use it asap

Edit :
http://symfony-workflow-demo.herokuapp.com/task/show/1263 is broken (wanted to test on state machine also)

Also, can you have a second look at
symfony/symfony-docs#10751 ?

Thank you

@nicolas-grekas
Copy link
Member

Caught :)
See #30524

symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Mar 13, 2019
…rameworkExtension (lyrixx)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Workflow] Move code from ValidateWorkflowsPass to the FrameworkExtension

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

---

Just some cleaning. See
symfony/symfony#29146 (comment)

Commits
-------

a608797165 [Workflow] Move code from ValidateWorkflowsPass to the FrameworkExtension
symfony-splitter pushed a commit to symfony/workflow that referenced this pull request Mar 13, 2019
…rameworkExtension (lyrixx)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Workflow] Move code from ValidateWorkflowsPass to the FrameworkExtension

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

---

Just some cleaning. See
symfony/symfony#29146 (comment)

Commits
-------

a608797165 [Workflow] Move code from ValidateWorkflowsPass to the FrameworkExtension
lyrixx added a commit that referenced this pull request Mar 13, 2019
…rameworkExtension (lyrixx)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Workflow] Move code from ValidateWorkflowsPass to the FrameworkExtension

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

---

Just some cleaning. See
#29146 (comment)

Commits
-------

a608797 [Workflow] Move code from ValidateWorkflowsPass to the FrameworkExtension
@vudaltsov
Copy link
Contributor

@lyrixx , why not making MethodMarkingStore final? I think, we should not encourage extending it, WDYT? On my practice, whenever I wanted to store markings differently, I always wrote a new implementation.

@lyrixx
Copy link
Member Author

lyrixx commented Mar 22, 2019

@vudaltsov Good idea 👍 I will do that :)

@vudaltsov
Copy link
Contributor

@lyrixx , I can do a PR for you, if you wish, have some time now!

@lyrixx
Copy link
Member Author

lyrixx commented Mar 22, 2019

oh yes. Please do :)

symfony-splitter pushed a commit to symfony/workflow that referenced this pull request Mar 22, 2019
This PR was merged into the 4.3-dev branch.

Discussion
----------

Make MethodMarkingStore final

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

Made `MethodMarkingStore` final as proposed in symfony/symfony#29146 (comment).

Commits
-------

bbf582bce5 Make MethodMarkingStore final
lyrixx added a commit that referenced this pull request Mar 22, 2019
This PR was merged into the 4.3-dev branch.

Discussion
----------

Make MethodMarkingStore final

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

Made `MethodMarkingStore` final as proposed in #29146 (comment).

Commits
-------

bbf582b Make MethodMarkingStore final
@lyrixx
Copy link
Member Author

lyrixx commented Apr 7, 2019

@noniagriconomie The demo has been fixed. Thanks for hint.

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.

10 participants