Skip to main content

Announcing Disco 0.5.0

This blog post might be outdated!
This blog post was published more than one year ago and might be outdated!
· 3 min read
Stephan Hochdörfer
Head of IT Business Operations

Yesterday I was finally able to release a new version of Disco which comes with 4 major changes that I want to highlight briefly in this blog post.

1. PHP 5.x support was dropped which means we can now make use of return type declarations instead of trying to parse and guess the type based on the @return annotation. In addition tot that the configuration code looks much cleaner now:

/**
* @Configuration
*/
class MyConfiguration
{
/**
* @Bean
*/
public function mySampleService() : SampleService
{
return new SampleService();
}
}

2. Disco is now able to return primitive types. The handling for primitive types is similar to the handling for objects except for the scope and lazy attributes. Since both settings do not make sense for primitive types, Disco will ignore them when dealing with primitive types:

/**
* @Configuration
*/
class MyConfiguration
{
/**
* @Bean
*/
public function myInt() : int
{
return 5;
}
}

3. Handling of session-aware beans has changed: In previous versions of Disco one could serialize and unserialize the \bitExpert\Disco\AnnotationBeanFactory instance. This does not work any more. With Disco 0.5.0 a separate bean store instance got introduced which holds the session-scoped beans. Simply serialize and unserialize the bean store as follows:

$config = new \bitExpert\Disco\BeanFactoryConfiguration('/tmp/');
$beanFactory = new AnnotationBeanFactory(Config::class, [], $config);
BeanFactoryRegistry::register($beanFactory);

$sessionBeans = serialize($config->getSessionBeanStore());
$sessionBeans = unserialize($sessionBeans);

$config = new \bitExpert\Disco\BeanFactoryConfiguration('/tmp/');
$config->setSessionBeanStore($sessionBeans);

$beanFactory = new AnnotationBeanFactory(Config::class, [], $config);
BeanFactoryRegistry::register($beanFactory);

4. Bean aliases were added: One of the down-sides when relying on method names as identifiers for bean instances is the limited character set which can be used for naming your bean instance. It was not possible to use characters like backslash, colon and such as those are not valid characters for method names in PHP. At first I thought some simple normalization rules might work fine but @ocramius convinced me to look for a "better solution". Aliases for beans made the most sense in this case:

/**
* @Configuration
*/
class MyConfiguration
{
/**
* @Bean({"alias"="\My\Custom\Alias"})
*/
public function mySampleService() : SampleService
{
return new SampleService();
}
}

I am pretty happy with the current release, especially the move to ProxyManager 2 and PHP 7 is a big deal for Disco. Having not to rely on type guessing any more is a clear win, especially if you make use of traits for your bean configuration.