Commit fc72ff4c by zhufx

实体处理

parent 11c6b7ca
......@@ -2,53 +2,14 @@
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/2
* Time: 13:49
* Date: 2018/7/13
* Time: 16:27
*/
namespace Hdll\Services\Common\Entity;
use Swoft\Db\Bean\Collector\EntityCollector;
use Swoft\Db\Model;
class CommonEntity extends Model
{
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$user = User::getIns();
$dbNum = $user->getStoreId() %100;
//获取注解里的table
$res = new \ReflectionClass(static::class);
$commentString = $res->getDocComment();
preg_match('/(?<=Table\(name=").*(?="\))/', $commentString, $matches);
$tableName = isset($matches[0])?$matches[0]:'';
EntityCollector::collect(
static::class,
new \Swoft\Db\Bean\Annotation\Table(['name' => $tableName.'_'.$dbNum])
);
}
public static function getDb()
{
$user = User::getIns();
$dbNum = $user->getStoreId() %100;
//获取注解里的table
$res = new \ReflectionClass(static::class);
$commentString = $res->getDocComment();
preg_match('/(?<=Table\(name=").*(?="\))/', $commentString, $matches);
$tableName = isset($matches[0])?$matches[0]:'';
EntityCollector::collect(
static::class,
new \Swoft\Db\Bean\Annotation\Table(['name' => $tableName.'_'.$dbNum])
);
return new static();
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/2
* Time: 13:49
*/
namespace Hdll\Services\Common\Entity;
use Swoft\Db\Bean\Collector\EntityCollector;
class CommonSplitEntity extends CommonEntity
{
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$user = User::getIns();
$dbNum = $user->getStoreId() %100;
//获取注解里的table
$res = new \ReflectionClass(static::class);
$commentString = $res->getDocComment();
preg_match('/(?<=Table\(name=").*(?="\))/', $commentString, $matches);
$tableName = isset($matches[0])?$matches[0]:'';
EntityCollector::collect(
static::class,
new \Swoft\Db\Bean\Annotation\Table(['name' => $tableName.'_'.$dbNum])
);
}
public static function getDb()
{
$user = User::getIns();
$dbNum = $user->getStoreId() %100;
//获取注解里的table
$res = new \ReflectionClass(static::class);
$commentString = $res->getDocComment();
preg_match('/(?<=Table\(name=").*(?="\))/', $commentString, $matches);
$tableName = isset($matches[0])?$matches[0]:'';
EntityCollector::collect(
static::class,
new \Swoft\Db\Bean\Annotation\Table(['name' => $tableName.'_'.$dbNum])
);
return new static();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment