/**
  * @param \RokCommon_XMLElement $xml_node
  *
  * @throws \RokCommon_Config_Exception
  */
 protected function initialize(RokCommon_XMLElement $xml_node)
 {
     $this->xml_node = $xml_node;
     // get the name of the entry
     if (!isset($this->xml_node['name'])) {
         throw new RokCommon_Config_Exception(rc__('Meta Config entry in %s does not have a name', $this->parent_identifier));
     }
     $this->name = (string) $this->xml_node['name'];
     // set the identifier name
     $id_parts = explode(self::ENTRY_SEPERATOR, $this->parent_identifier);
     $id_parts[] = $this->name;
     $this->identifier = implode(self::ENTRY_SEPERATOR, $id_parts);
     // get the filename of the entry
     if (!isset($this->xml_node['filename'])) {
         throw new RokCommon_Config_Exception(rc__('Meta Config entry %s does not have a filename', $this->identifier));
     }
     $this->filename = (string) $this->xml_node['filename'];
     // get the mode
     if (isset($this->xml_node['mode'])) {
         $this->mode = (string) $this->xml_node['mode'];
     }
     // get the jointype
     if (isset($this->xml_node['jointype'])) {
         $this->jointype = (string) $this->xml_node['jointype'];
     }
     // see if there is a library and add it to the lib path
     $library_paths = $xml_node->xpath('libraries/library');
     if ($library_paths) {
         foreach ($library_paths as $library_path) {
             $resolved_lib_path = RokCommon_Config::replaceTokens((string) $library_path, dirname($this->root_file));
             if (is_dir($resolved_lib_path)) {
                 RokCommon_ClassLoader::addPath($resolved_lib_path);
             }
         }
     }
     // get the paths for the config
     $paths = $xml_node->xpath('paths/path');
     if (!$paths) {
         throw new RokCommon_Config_Exception(rc__('Meta Config entry %s must have at least one path.', $this->identifier));
     }
     foreach ($paths as $path_entry) {
         $priority = RokCommon_Composite::DEFAULT_PRIORITY;
         if (isset($path_entry['priority'])) {
             $priority = (string) $path_entry['priority'];
         }
         $path = RokCommon_Config::replaceTokens((string) $path_entry, dirname($this->root_file));
         if (is_dir($path)) {
             // see if there is a testservice entry
             if (isset($path_entry['testservice'])) {
                 // see if the testservice extists
                 $testservice_name = (string) $path_entry['testservice'];
                 $container = RokCommon_Service::getContainer();
                 /** @var $testservice RokCommon_Config_PathTest */
                 $testservice = $container->{$testservice_name};
                 if (!$container->hasService($testservice_name)) {
                     throw new RokCommon_Config_Exception(rc__('Path test service %s does not exist', $testservice_name));
                 }
                 // see if we can add the
                 if ($testservice->isPathAvailable()) {
                     $this->addPath($path, $priority);
                 }
             } else {
                 // add the path if there is no testclass
                 $this->addPath($path, $priority);
             }
         } else {
             // TODO log unable to find path
         }
     }
     // add any subconfigs
     $subconfigs = $xml_node->xpath('subconfigs/subconfig');
     if ($subconfigs) {
         foreach ($subconfigs as $subconfig_entry) {
             $subconfig = new self($this->identifier, $this->root_file, $subconfig_entry);
             $this->subentries[$subconfig->getName()] = $subconfig;
         }
     }
     $this->context = RokCommon_Composite::get($this->identifier);
 }
Example #2
0
 /**
  * @param $type
  *
  * @return RokSprocket_ConfigForm
  */
 protected function getPerItemsForm($type)
 {
     $options = new RokCommon_Options();
     $container = RokCommon_Service::getContainer();
     // load up the layouts
     $layoutinfo = $container['roksprocket.layouts.' . $type];
     if (isset($layoutinfo->options->peritem)) {
         $section = new RokCommon_Options_Section('peritem_' . $type, $layoutinfo->options->peritem);
         foreach ($layoutinfo->paths as $layoutpath) {
             $section->addPath($layoutpath);
         }
         $options->addSection($section);
     }
     $rcform = $rcform = new RokSprocket_ConfigForm(new RokCommon_Form('roksprocket_peritem'));
     $xml = $options->getJoinedXml();
     $jxml = new RokCommon_XMLElement($xml->asXML());
     $fieldsets = $jxml->xpath('/config/fields[@name = "params"]/fieldset');
     foreach ($fieldsets as $fieldset) {
         $overwrite = (string) $fieldset['overwrite'] == 'true' ? true : false;
         $rcform->load($fieldset, $overwrite, '/config');
     }
     return $rcform;
 }