function __construct(OutletConfig $config, $entity, array $conf) { // $this->config = $config; if (!isset($conf['table'])) { throw new OutletConfigException('Mapping for entity [' . $entity . '] is missing element [table]'); } if (!isset($conf['props'])) { throw new OutletConfigException('Mapping for entity [' . $entity . '] is missing element [props]'); } // i need to leave this for for the outletgen script //if (!class_exists($entity)) throw new OutletConfigException('Class does not exist for mapped entity ['.$entity.']'); // validate that there's a pk $this->props = array(); $this->pks = array(); foreach ($conf['props'] as $propName => $propConf) { $propConf = new OutletPropertyConfig($propName, $propConf); $this->props[$propName] = $propConf; if ($propConf->isPK()) { $this->pks[$propName] = $propConf; } } if (count($this->pks) == 0) { throw new OutletConfigException("Entity [{$entity}] must have at least one column defined as a primary key in the configuration"); } // save basic data $this->table = $conf['table']; $this->clazz = $entity; // $this->props = $conf['props']; $this->sequenceName = isset($conf['sequenceName']) ? $conf['sequenceName'] : ''; $this->useGettersAndSetters = isset($conf['useGettersAndSetters']) ? $conf['useGettersAndSetters'] : $config->useGettersAndSetters(); }
/** * Construct a new instance of OutletEntityConfig * @param OutletConfig $config outlet configuration * @param object $entity entity * @param object $conf configuration * @return OutletEntityConfig instance */ function __construct(OutletConfig $config, $entity, array $conf) { $this->config = $config; if (!isset($conf['table'])) { throw new OutletConfigException('Mapping for entity [' . $entity . '] is missing element [table]'); } if (!isset($conf['props'])) { throw new OutletConfigException('Mapping for entity [' . $entity . '] is missing element [props]'); } // i need to leave this for for the outletgen script //if (!class_exists($entity)) throw new OutletConfigException('Class does not exist for mapped entity ['.$entity.']'); // validate that there's a pk foreach ($conf['props'] as $p => $f) { if (@$f[2]['pk']) { $pk = $p; break; } } if (!isset($pk)) { throw new OutletConfigException("Entity [{$entity}] must have at least one column defined as a primary key in the configuration"); } // save basic data $this->table = $conf['table']; $this->clazz = $entity; $this->props = $conf['props']; $this->sequenceName = isset($conf['sequenceName']) ? $conf['sequenceName'] : ''; $this->useGettersAndSetters = isset($conf['useGettersAndSetters']) ? $conf['useGettersAndSetters'] : $config->useGettersAndSetters(); // Adjusts sequence name for postgres if it is not specified if ($config->getConnection()->getDialect() == 'pgsql' && $this->sequenceName == '') { foreach ($this->props as $key => $d) { // Property needs to be primary key and auto increment if (isset($d[2]['pk']) && $d[2]['pk'] && (isset($d[2]['autoIncrement']) && $d[2]['autoIncrement'])) { // default name for sequence = {table}_{column}_seq $this->sequenceName = $this->table . '_' . $d[0] . '_seq'; break; } } } }
function __construct(OutletConfig $config, $entity, array $conf, OutletEntityConfig $superConfig = null) { // $this->config = $config; if ($superConfig !== null) { $this->superConfig = $superConfig; $this->isSubclass = true; } if (!$this->isSubclass && !isset($conf['table'])) { throw new OutletConfigException('Mapping for entity [' . $entity . '] is missing element [table]'); } if (!isset($conf['props'])) { throw new OutletConfigException('Mapping for entity [' . $entity . '] is missing element [props]'); } // i need to leave this for for the outletgen script //if (!class_exists($entity)) throw new OutletConfigException('Class does not exist for mapped entity ['.$entity.']'); // validate that there's a pk $this->props = array(); $this->allprops = array(); $this->subclasses = array(); $this->pks = array(); foreach ($conf['props'] as $propName => $propConf) { $propConf = new OutletPropertyConfig($propName, $propConf); $this->props[$propName] = $propConf; $this->allprops[$propName] = $propConf; if ($superConfig !== null) { $superConfig->allprops[$propName] = $propConf; } if (!$this->isSubclass && $propConf->isPK()) { $this->pks[$propName] = $propConf; } } if (!$this->isSubclass && count($this->pks) == 0) { throw new OutletConfigException("Entity [{$entity}] must have at least one column defined as a primary key in the configuration"); } if ($this->isSubclass) { foreach ($this->superConfig->getProperties() as $prop) { $this->props[$prop->getName()] = $prop; $this->allprops[$prop->getName()] = $prop; } } if ($this->isSubclass) { $this->pks = $this->superConfig->getPkProperties(); $this->table = $this->superConfig->getTable(); $this->discriminator = $this->superConfig->getDiscriminator(); $this->discriminatorValue = $conf['discriminator-value']; } else { $this->table = $conf['table']; } // save basic data $this->clazz = $entity; // $this->props = $conf['props']; $this->sequenceName = isset($conf['sequenceName']) ? $conf['sequenceName'] : ''; $this->useGettersAndSetters = isset($conf['useGettersAndSetters']) ? $conf['useGettersAndSetters'] : $config->useGettersAndSetters(); if (isset($conf['subclasses'])) { if (!isset($conf['discriminator'])) { throw new OutletConfigException('Mapping for entity [' . $key . '] is specifying subclasses but it is missing element [discriminator]'); } if (!isset($conf['discriminator-value'])) { throw new OutletConfigException('Mapping for entity [' . $key . '] is specifying subclasses but it is missing element [discriminator-value]'); } $this->discriminator = new OutletPropertyConfig('discriminator', $conf['discriminator']); $this->discriminatorValue = $conf['discriminator-value']; $this->allprops[$this->discriminator->getName()] = $this->discriminator; foreach ($conf['subclasses'] as $className => $classConf) { if (!isset($classConf['discriminator-value'])) { throw new OutletConfigException('Mapping for entity [' . $className . '] is specifying subclasses but it is missing element [discriminator-value]'); } $subentity = new OutletEntityConfig($config, $className, $classConf, $this); $this->subclasses[$subentity->getDiscriminatorValue()] = $subentity; $config->addEntity($subentity); } } }