Skip to main content

Disco 0.9.0

· 3 min read
Stephan Hochdörfer
Head of IT Business Operations

Last week we released Disco version 0.9.0 with a few new features and unfortunately some BC breaks. The BC breaks are all covered in the upgrade guide, but I would like to discuss them in greater detail to give you a better understanding why those changes happened:

Disco 0.9.0 will no longer run on PHP 7, but requires PHP 7.1. This is mostly due to the upgrade of the ocramius/proxy-manager package to its latest version. The version of ocramius/proxy-manager targeting PHP 7 only is no longer actively maintained, thus the move made sense. Since PHP 7.1 is out for quite a while now, this should not be a real show-stopper for the users.

The "biggest" BC breaks were done in the way aliases and parameters get defined. In the "new way" both get attached to the @Bean annotation as attributes which in the end looks like this:

 /**
* @Bean({
* "aliases"={
* @Alias({"name" = "\Identifier\With\Namespace"})
* },
* "parameters"={
* @Parameter({"name" = "test"})
* }
* })
*/

On the plus side, the change means that a) you are able to define multiple aliases per bean - each alias still needs to be unique! - and b) the configuration format is now more consistent. There is no need any more for the separate @Parameters annotation. Given my experience with Disco, not many bean definitions contain parameter or alias defintions, thus the needed changes should be easy to implement.

As a bonus point of the change, we were able to introduce a new feature to make it possible to refer to bean type - the return type of the bean definition method, if you will. In my recent Disco presentations I mentioned this as a big drawback when it comes to using annotations for configuration. In the example above "\Identifier\With\Namespace" is a string even though this might be concrete type in your application. That means whenever you renamed or moved the type, your IDE would replace all code occurences but most likely not the string in the alias definition. To fix that, and to make it a bit less to type, you can now set the type attribute to true for the @Alias annotation and Disco will register the bean configuration method's return type as an alias for the bean automatically:

 /**
* @Bean({
* "aliases"={
* @Alias({"type" = true})
* }
* })
*/

Last but not least, the final BC break in this Disco version affects the BeanFactoryPostProcessor, which got removed from the code base. The BeanFactoryPostProcessor was used to allow the BeanFactory to automatically get injected into classes marked with the BeanFactoryAware interface, this is commonly refered to as interface injection. Or, in this specific case as "container injection". Since I preach a lot that container injection is not a good practice at all, I thought it is finally time to get rid of this functionaility in Disco. However the whole BeanPostProcessor logic is still in place, which means you can still add a custom BeanPostProcessor implementation in your codebase, register it with Disco and nothing will change.