예제 #1
0
 /**
  * Populates a primary key based on a index.
  *
  * @param   Attrs  $attrs
  * @param   Index  $index
  */
 private function populatePrimaryKey($attrs, $index)
 {
     if (!$index->isPrimary()) {
         return;
     }
     $columns = $index->getColumns();
     $key = current($columns);
     // We don't support composite primary keys quite yet.
     if (count($columns) > 1) {
         return;
     }
     $attrs->set($this->deriveName($key), ['key' => $key, 'type' => 'primary']);
 }
예제 #2
0
 public function test_get_typeCallback()
 {
     $mock = Mockery::mock('Mismatch\\Model\\Attr\\AttrInterface');
     Attrs::registerType('callback', function () use($mock) {
         return $mock;
     });
     $this->subject->set('callback', 'callback');
     $this->assertSame($mock, $this->subject->get('callback'));
 }
예제 #3
0
<?php

/**
 * This file is part of Mismatch.
 *
 * @author   ♥ <*****@*****.**>
 * @license  MIT
 */
namespace Mismatch\ORM;

use Mismatch\Model\Attrs;
// Install native ORM types.
foreach (['belongs-to' => 'Mismatch\\ORM\\Attr\\BelongsTo', 'has-many' => 'Mismatch\\ORM\\Attr\\HasMany', 'has-one' => 'Mismatch\\ORM\\Attr\\HasOne'] as $name => $type) {
    Attrs::registerType($name, $type);
}
// Install doctrine-specific types
use Doctrine\DBAL\Types\Type;
use Mismatch\ORM\Attr\Native;
$types = Type::getTypesMap();
foreach ($types as $type => $class) {
    Attrs::registerType($type, function ($name, $opts) use($type) {
        $opts['type'] = Type::getType($type);
        return new Native($name, $opts);
    });
}
예제 #4
0
 public function testDoctrineTypes()
 {
     $doctrineTypes = array_keys(Type::getTypesMap());
     $mismatchTypes = Attrs::availableTypes();
     $this->assertSame($doctrineTypes, array_intersect($doctrineTypes, $mismatchTypes));
 }