Skip to content
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

Use annotations to tag services #540

Merged
merged 11 commits into from Jul 3, 2019

Conversation

Projects
None yet
3 participants
@aschempp
Copy link
Contributor

commented Jun 28, 2019

This is the successor of #526

As discussed, the terminal42/service-annotation-bundle allows any service to use annotations to define tags. In Contao, we can use this and extend it for our own tags, providing specific annotations.

use Contao\CoreBundle\ServiceAnnotation\FrontendModule;

/**
 * @FrontendModule(category="miscellaneous")
 */
class FoobarController extends AbstractFrontendModuleController
{
    public function getResponse()
    {
    }
}

Contrary to #526, we don't explicitly parse fragments, but simply add tags to the service container which will then again be read by later compiler passes.

TODO:

  • Support hooks and callbacks
  • Better docs
  • Release 1.0 of terminal42/service-annotation-bundle
  • Unit Tests

@aschempp aschempp added the feature label Jun 28, 2019

@aschempp aschempp added this to the 4.8 milestone Jun 28, 2019

@aschempp aschempp requested review from ausi, Toflar and leofeyer Jun 28, 2019

@aschempp aschempp self-assigned this Jun 28, 2019

@leofeyer
Copy link
Member

left a comment

Unit tests are missing.

Show resolved Hide resolved composer.json Outdated
Show resolved Hide resolved core-bundle/src/ServiceAnnotation/Hook.php Outdated
@aschempp

This comment has been minimized.

Copy link
Contributor Author

commented Jul 2, 2019

Tests done. The failing one is not related to this PR.

@aschempp aschempp removed the tests missing label Jul 2, 2019

@aschempp aschempp requested review from ausi and leofeyer Jul 3, 2019

@aschempp

This comment has been minimized.

Copy link
Contributor Author

commented Jul 3, 2019

I have updated the PR and greatly simplified the annotations, as I learned about the value property and optional attributes.

Tagging a hook is now as simple as:

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Terminal42\ServiceAnnotationBundle\ServiceAnnotationInterface;

class FoobarListener implements ServiceAnnotationInterface
{
    /**
     * @Hook("onPageLayout")
     */
    public function modifyPageLayout()
    {
    }
}
@leofeyer

This comment has been minimized.

Copy link
Member

commented Jul 3, 2019

This is great, however, now the unit tests fail. 🙈

@leofeyer
Copy link
Member

left a comment

👍 besides the failing unit tests.

leofeyer and others added some commits Jul 3, 2019

@leofeyer leofeyer merged commit 81885dc into master Jul 3, 2019

5 checks passed

Travis CI - Branch Build Passed
Details
Travis CI - Pull Request Build Passed
Details
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
coverage/coveralls Coverage increased (+0.3%) to 87.146%
Details
@leofeyer

This comment has been minimized.

Copy link
Member

commented Jul 3, 2019

Thank you @aschempp.

@leofeyer leofeyer deleted the feature/service-annotations branch Jul 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.