/**
  * Loads and fuses the schemata for all collections attached to this agent.
  *
  * @return Schema
  */
 public function loadSchemata()
 {
     $fused_options = array();
     foreach ($this->_collections as $collection) {
         $context = array('collection' => $collection->getId());
         $schema_options = $this->loadCollectionSchema($collection)->toArray();
         // Just set the schema options on the first pass.
         if (!$fused_options) {
             $fused_options = $schema_options;
             continue;
         }
         // The unique field must be the same across collections.
         if ($schema_options['unique_field'] != $fused_options['unique_field']) {
             $message = 'Collections must have the same unique field.';
             throw new \InvalidArgumentException($message);
         }
         // Define the field or check for field incompatibilities.
         foreach ($schema_options['fields'] as $field_id => $field_options) {
             if (!isset($fused_options['fields'][$field_id])) {
                 $fused_options['fields'][$field_id] = $field_options;
             } elseif ($fused_options['fields'][$field_id] != $field_options) {
                 $message = 'Field definitions for "' . $field_id . '"must match.';
                 throw new \InvalidArgumentException($message);
             }
         }
     }
     // Build the fused schema.
     $schema = new Schema();
     $schema->build($fused_options);
     // Populate the field type cache.
     foreach ($schema as $id => $field) {
         $this->_fieldTypes[$id] = $field->getType();
     }
     return $schema;
 }
Пример #2
0
 /**
  * Parses configuration options from YAML configuration files related to the
  * configurable object.
  *
  * This method throws the SearchEvents::CONFIG_LOAD event. If configurations
  * are loaded during this event, processing stops and the directories are
  * not scanned for configuration files.
  *
  * @return array
  *   An associative array of options.
  *
  * @throws ParseException
  */
 public function load()
 {
     $log = $this->_agent->getLogger();
     $context = array('collection' => $this->_collection->getId());
     // Allow the schema to be loaded from another source.
     $event = new SchemaLoaderEvent($this->_agent, $this->_collection);
     $this->_agent->dispatchEvent(SearchEvents::SCHEMA_LOAD, $event);
     if (!($options = $event->getOptions())) {
         if ($conf_dir = $this->getConfDir()) {
             $filename = $this->_collection->getConfigBasename() . '.yml';
             $filepath = $conf_dir . '/' . $filename;
             $context['filepath'] = $filepath;
             $log->debug('Attempting to parse schema configuration file', $context);
             $options = Yaml::parse($filepath);
             $log->debug('Schema options parsed from configuration file', $context);
         } else {
             $log->notice('Path to conf directory could not be resolved', $context);
         }
     } else {
         $log->debug('Schema configuration loaded from an external source.', $context);
     }
     $schema = new Schema();
     $schema->build($options);
     return $schema;
 }