public function register(Application $app) { $default = ['wrapperClass' => 'Pagekit\\Component\\Database\\ConnectionWrapper', 'defaultTableOptions' => []]; $app['dbs'] = function ($app) use($default) { $dbs = []; foreach ($app['config']['database.connections'] as $name => $params) { $params = array_replace($default, $params); foreach (['engine', 'charset', 'collate'] as $option) { if (isset($params[$option])) { $params['defaultTableOptions'][$option] = $params[$option]; } } $events = $app['config']['database.default'] === $name ? $app['events'] : null; $dbs[$name] = new Connection($params, $events); } return $dbs; }; $app['db'] = function ($app) { return $app['dbs'][$app['config']['database.default']]; }; $app['db.em'] = function ($app) { EntityEvent::setApplication($app); return new EntityManager($app['db'], $app['db.metas'], 'Pagekit\\Framework\\Database\\Event\\EntityEvent'); }; $app['db.metas'] = function ($app) { $manager = new MetadataManager($app['db']); $manager->setLoader(new AnnotationLoader()); $manager->setCache($app['cache.phpfile']); return $manager; }; $app['db.debug_stack'] = function ($app) { return new DebugStack($app['profiler.stopwatch']); }; }
/** * Sets a field to a value. The column parameter determines if the "name" is a field or column name. * * @param object $entity * @param string $name * @param mixed $value * @param bool $column * @param bool $convert */ public function setValue($entity, $name, $value, $column = false, $convert = false) { if ($column && isset($this->fieldNames[$name])) { $name = $this->fieldNames[$name]; } if ($convert) { $platform = $this->manager->getConnection()->getDatabasePlatform(); $value = Type::getType($this->fields[$name]['type'])->convertToPHPValue($value, $platform); } $this->reflFields[$name]->setValue($entity, $value); }
/** * Gets the metadata object of an entity class. * * @param mixed $class * @return Metadata */ public function getMetadata($class) { return $this->metadata->get($class); }