public function merge(Entity $entity, array $raw) { try { $processor = new Processor(); $configuration = $this; $config = $processor->processConfiguration($configuration, array('database' => $raw)); $entity->setSchema($config['schema']); $entity->setUser($config['username']); $entity->setPassword($config['password']); $entity->setType($config['type']); $entity->setPort($config['port']); $entity->setHost($config['host']); $entity->setUnixSocket($config['socket']); $entity->setCharset($config['charset']); } catch (\Exception $e) { throw new InvalidConfigException($e->getMessage()); } return $entity; }
public function merge(Entity $entity, array $raw) { try { $processor = new Processor(); $configuration = $this; $config = $processor->processConfiguration($configuration, array('database' => $raw)); $entity->setUser($config['username']); $entity->setPassword($config['password']); $entity->setPath($config['database']); $entity->setType($config['phptype']); $entity->setMemory($config['memory']); } catch (\Exception $e) { throw new InvalidConfigException($e->getMessage()); } return $entity; }
public function merge(Entity $entity, array $raw) { try { $processor = new Processor(); $configuration = $this; $config = $processor->processConfiguration($configuration, array('database' => $raw)); $entity->setUser($config['username']); $entity->setPassword($config['password']); if ($config['path'] === false && $config['memory'] === false) { throw new InvalidConfigException('Neither path or memory are set one option must be chosen'); } if ($config['path'] === false) { $entity->setMemory($config['memory']); } else { $entity->setPath($config['path']); } $entity->setType($config['type']); } catch (\Exception $e) { throw new InvalidConfigException($e->getMessage()); } return $entity; }
/** * Loads a config Entity * * @access public * @param string $name the file name * @return Entity a config entity */ public function load($name = '', EntityInterface $ent) { if (empty($name)) { $name = self::DEFAULTNAME . self::EXTENSION; } $config_ary = $this->getIo()->load($name, null); //send it to be validated and normalized using out configTree; if ($config_ary === NULL) { return NULL; } else { $ent->setType($config_ary['type']); $ent->setCharset($config_ary['charset']); $ent->setHost($config_ary['host']); $ent->setMemory($config_ary['memory']); $ent->setPassword($config_ary['password']); $ent->setPath($config_ary['path']); $ent->setPort($config_ary['port']); $ent->setSchema($config_ary['schema']); $ent->setUnixSocket($config_ary['socket']); $ent->setUser($config_ary['user']); } return $ent; }
/** * Writes a config array to a file * * @param EntityInterface $config a key value store * @param string $alias a name for the file * @param boolean $overrite setting true will overwrite a file * @return boolean true on sucessful write false otherwise */ public function write(EntityInterface $entity, $alias, $overrite = FALSE) { $data = var_export(array('type' => $entity->getType(), 'schema' => $entity->getSchema(), 'user' => $entity->getUser(), 'password' => $entity->getPassword(), 'host' => $entity->getHost(), 'port' => $entity->getPort(), 'socket' => $entity->getUnixSocket(), 'path' => $entity->getPath(), 'memory' => $entity->getMemory(), 'charset' => $entity->getCharset()), true); #write to file $file = '<?php' . PHP_EOL; $file .= PHP_EOL; $file .= '/* Database Config file */' . PHP_EOL; $file .= PHP_EOL; $file .= 'return ' . $data . ';' . PHP_EOL; $file .= PHP_EOL; $file .= PHP_EOL; $file .= '/* End of Config File */' . PHP_EOL; #assign file ext to alias if (strpos($alias, '.') === FALSE) { $alias .= self::EXTENSION; } # Write file to the config folder return $this->getIo()->write($alias, null, $file, $overrite); }