コード例 #1
0
 /**
  * Object constructor.
  *
  * Builds the object depending on the Module configuration, given to the object
  * itself as an instance of a ModuleConfig class.
  *
  * @since 5.1
  * @param ModuleConfig $config Configuration object.
  */
 public function __construct(\Innomatic\Module\ModuleConfig $config)
 {
     // Assigns the config and retrieves fully qualified name for value object.
     $this->config = $config;
     $vo_fqcn = $this->config->getValueObjectClass();
     if (!strlen($vo_fqcn)) {
         $vo_fqcn = '\\Innomatic\\Module\\Util\\ModuleEmptyValueObject';
     }
     // Imports value object.
     require_once $vo_fqcn . '.php';
     $vo_class = strpos($vo_fqcn, '/') ? substr($vo_fqcn, strrpos($vo_fqcn, '/') + 1) : $vo_fqcn;
     if (!class_exists($vo_class, true)) {
         throw new ModuleException('Value object class ' . $vo_class . ' does not exists');
     }
     // Instantiates the value object.
     $this->valueObject = new $vo_class();
     // If there are user defined fields, adds them to the value object.
     // This is useful for value objects whose structure is stored in
     // configuration files or determined at runtime.
     $vo_fields = $this->config->getValueObjectFields();
     if (count($vo_fields)) {
         foreach ($vo_fields as $field) {
             $this->valueObject->addField($field);
         }
     }
 }