/**
  * 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;
 }
 /**
  * This will read the $name file and parse it to the PageTemplate
  *
  * @param string $name
  * @return PageTemplate
  * @throws \Exception
  */
 public function parse($name)
 {
     $nameParts = explode(':', $name);
     if (count($nameParts) != 2) {
         throw new \Exception(sprintf('Malformed namespaced configuration name "%s" (expecting "namespace:pagename.yml").', $name));
     }
     list($namespace, $name) = $nameParts;
     $path = $this->kernel->locateResource('@' . $namespace . '/Resources/config/pageparts/' . $name . '.yml');
     $rawData = Yaml::parse(file_get_contents($path));
     if (!array_key_exists('types', $rawData)) {
         $rawData['types'] = array();
     }
     if (array_key_exists('extends', $rawData)) {
         if (!is_array($rawData['extends'])) {
             $rawData['extends'] = array($rawData['extends']);
         }
         foreach ($rawData['extends'] as $extend) {
             $recursiveResult = $this->parse($namespace . ':' . $extend);
             $rawData['types'] = array_merge($recursiveResult->getPossiblePagePartTypes(), $rawData['types']);
         }
     }
     $types = array();
     foreach ($rawData['types'] as $type) {
         if ($type['class'] == '' || is_null($type['class'])) {
             if (array_key_exists($type['name'], $types)) {
                 unset($types[$type['name']]);
             }
         } else {
             $types[$type['name']] = array('name' => $type['name'], 'class' => $type['class']);
             if (isset($type['pagelimit'])) {
                 $types[$type['name']]['pagelimit'] = $type['pagelimit'];
             }
         }
     }
     $result = new PagePartAdminConfigurator();
     $result->setName($rawData['name']);
     $result->setInternalName($name);
     $result->setPossiblePagePartTypes(array_values($types));
     $result->setContext($rawData['context']);
     return $result;
 }