Пример #1
0
 /**
  * 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 (!property_exists($entity, $name) && !isset($entity->{$name})) {
         return;
     }
     if ($convert && isset($this->fields[$name])) {
         $value = Type::getType($this->fields[$name]['type'])->convertToPHPValue($value, $this->manager->getConnection()->getDatabasePlatform());
     }
     $entity->{$name} = $value;
 }
Пример #2
0
 /**
  * Gets the metadata object of an entity class.
  *
  * @param  mixed $class
  * @return Metadata
  */
 public function getMetadata($class)
 {
     return $this->metadata->get($class);
 }
Пример #3
0
use Pagekit\Event\PrefixEventDispatcher;
return ['name' => 'database', 'main' => function ($app) {
    $default = ['wrapperClass' => 'Pagekit\\Database\\Connection'];
    $app['dbs'] = function () use($default) {
        $dbs = [];
        foreach ($this->config['connections'] as $name => $params) {
            $dbs[$name] = DriverManager::getConnection(array_replace($default, $params));
        }
        return $dbs;
    };
    $app['db'] = function ($app) {
        return $app['dbs'][$this->config['default']];
    };
    $app['db.em'] = function ($app) {
        return new EntityManager($app['db'], $app['db.metas'], $app['db.events']);
    };
    $app['db.metas'] = function ($app) {
        $manager = new MetadataManager($app['db'], $app['db.events']);
        $manager->setLoader(new AnnotationLoader());
        $manager->setCache($app['cache.phpfile']);
        return $manager;
    };
    $app['db.events'] = function ($app) {
        return new PrefixEventDispatcher('model.', $app['events']);
    };
    $app['db.debug_stack'] = function () {
        return new DebugStack();
    };
    Type::overrideType(Type::SIMPLE_ARRAY, '\\Pagekit\\Database\\Types\\SimpleArrayType');
    Type::overrideType(Type::JSON_ARRAY, '\\Pagekit\\Database\\Types\\JsonArrayType');
}, 'autoload' => ['Pagekit\\Database\\' => 'src'], 'config' => ['default' => 'mysql', 'connections' => ['mysql' => ['driver' => 'pdo_mysql', 'dbname' => '', 'host' => 'localhost', 'user' => 'root', 'password' => '', 'engine' => 'InnoDB', 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci', 'prefix' => '', 'driverOptions' => [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8 COLLATE utf8_unicode_ci']]]]];