/**
  * @param array $config
  * @param bool  $debug
  *
  * @return Serializer
  */
 protected function createSerializer(array $config, $debug)
 {
     $builder = new SerializerBuilder();
     if (isset($config['cache_dir'])) {
         $builder->setCacheDir($config['cache_dir']);
     }
     if (isset($config['default_handlers'])) {
         $builder->addDefaultHandlers();
     }
     if (isset($config['handlers'])) {
         foreach ($config['handlers'] as $handler) {
             $builder->configureHandlers($handler);
         }
     }
     if (isset($config['event_listeners'])) {
         foreach ($config['event_listeners'] as $handler) {
             $builder->configureListeners($handler);
         }
     }
     $builder->addMetadataDirs(array_get($config, 'paths', [base_path('app')]));
     $builder->setDebug($debug);
     return $builder->build();
 }