/**
  * @param string
  * @param array
  * @return IBuilder
  * @throws \Exception
  */
 protected function createBuilder($name, $options = [])
 {
     $builder = $this->configuration->getHandler()->handle($name, $options, $this->metadata, $this->configuration);
     if ($builder === NULL) {
         throw new \RuntimeException("No satisfying handler found.");
         //todo better exception
     }
     return $builder;
 }
 /**
  * @param object|string
  * @param bool|null
  */
 public function create($entity, $createMapper = self::AUTO)
 {
     $className = is_string($entity) ? $entity : get_class($entity);
     $classMetadata = $this->entityManager->getClassMetadata($className);
     /** @var FormBuilder $builder */
     $builder = $this->configuration->getHandler()->handle(NULL, [], $classMetadata, $this->configuration);
     if (!$builder instanceof FormBuilder) {
         throw new UnexpectedValueException("Builder created by root handler must be an instance of FormBuilder");
     }
     if ($createMapper === TRUE || $createMapper === self::AUTO && is_object($entity)) {
         if (!is_object($entity)) {
             throw new InvalidArgumentException("If you want to create mapper, you have to pass an entity.");
         }
         if (!$this->mapperFactory) {
             throw new InvalidStateException("MapperFactory has not been injected.");
         }
         $form = $builder->getForm();
         if (!$form instanceof IFormWithMapper) {
             throw new InvalidStateException("Form does not implement \\Librette\\Forms\\IFormWithMapper");
         }
         $form->setMapper($this->mapperFactory->create($entity));
     }
     return $builder;
 }