/**
  * This will read the $name file and parse it to the PageTemplate
  *
  * @param string $name
  * @param PagePartAdminConfiguratorInterface[] $existing
  *
  * @return PagePartAdminConfiguratorInterface
  * @throws \Exception
  */
 public function parse($name, array $existing = [])
 {
     if (in_array($name, $this->stack)) {
         throw new \RuntimeException(sprintf('Recursion detected when parsing %s -> %s', implode(' -> ', $this->stack), $name));
     }
     $this->stack[] = $name;
     $value = $this->getValue($name);
     if (!array_key_exists('types', $value)) {
         $value['types'] = [];
     }
     if (array_key_exists('extends', $value)) {
         $namespace = '';
         if (false !== strpos($name, ':')) {
             $namespace = substr($name, 0, strpos($name, ':') + 1);
         }
         foreach ((array) $value['extends'] as $extend) {
             if (false === strpos($extend, ':')) {
                 $extend = $namespace . $extend;
             }
             if (false === isset($existing[$extend])) {
                 $existing[$extend] = $this->parse($extend, $existing);
             }
             $value['types'] = array_merge($existing[$extend]->getPossiblePagePartTypes(), $value['types']);
         }
     }
     $types = [];
     foreach ($value['types'] as $type) {
         if ("" === (string) $type['class']) {
             unset($types[$type['name']]);
             continue;
         }
         $types[$type['name']] = ['name' => $type['name'], 'class' => $type['class']];
         if (isset($type['pagelimit'])) {
             $types[$type['name']]['pagelimit'] = $type['pagelimit'];
         }
     }
     $result = new PagePartAdminConfigurator();
     $result->setName($value['name']);
     $result->setInternalName($name);
     $result->setPossiblePagePartTypes(array_values($types));
     $result->setContext($value['context']);
     if (isset($value['widget_template'])) {
         $result->setWidgetTemplate($value['widget_template']);
     }
     array_pop($this->stack);
     return $result;
 }