Commit c8d8e02d by feixiang

user实体修改

parent 8b1fac02
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:32
*/
namespace Hdll\Services\Common\Bean\Annotation;
use Doctrine\Common\Annotations\Annotation\Target;
/**
* @Annotation
* @Target("ALL")
* Class Auth
* @package App\Bean\Annotation
*/
class Split
{
private $name='';
private $table='';
public function __construct(array $values)
{
if (isset($values['value'])) {
$this->name = $values['value'];
}
if (isset($values['name'])) {
$this->name = $values['name'];
}
if (isset($values['table'])) {
$this->table = $values['table'];
}
}
public function setName($name)
{
$this->name = $name;
}
public function setTable($table)
{
$this->table = $table;
}
public function getName() : string
{
return $this->name;
}
public function getTable()
{
return $this->table;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:44
*/
namespace Hdll\Services\Common\Bean\Collector;
use App\Bean\Annotation\Auth;
use Hdll\Services\Common\Bean\Annotation\Split;
use Swoft\Bean\CollectorInterface;
class SplitCollector implements CollectorInterface
{
/**
* @var array
*/
private static $auth = [];
public static function collect(string $className,
$objectAnnotation = null,
string $propertyName = '',
string $methodName = '',
$propertyValue = null)
{
if ($objectAnnotation instanceof Split) {
$name = $objectAnnotation->getName();
$scope = $objectAnnotation->getScope();
self::$auth[$className]['name'] = $name;
self::$auth[$className]['order'] = $scope;
self::$auth['map'][$className] = $scope;
}
var_dump($className, $objectAnnotation, $propertyName, $methodName);
}
public static function getCollector()
{
return self::$auth;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/12
* Time: 13:43
*/
namespace Hdll\Services\Common\Bean\Parser;
use Hdll\Services\Common\Bean\Collector\SplitCollector;
use Swoft\Bean\Annotation\Scope;
use Swoft\Bean\Parser\AbstractParser;
/**
* @uses SplitParser
* Class AuthParser
* @package App\Bean\Parser
*/
class SplitParser extends AbstractParser
{
public function parser(string $className,
$objectAnnotation = null,
string $propertyName = '',
string $methodName = '',
$propertyValue = null)
{
$beanName = $className;
$scope = Scope::SINGLETON;
var_dump('parser');
SplitCollector::collect($className, $objectAnnotation, $propertyName, $methodName, $propertyValue);
return [$beanName, $scope, ""];
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/9/13
* Time: 13:28
*/
namespace Hdll\Services\Common\Bean\Wrapper;
use Hdll\Services\Common\Bean\Annotation\Split;
use Swoft\Bean\Wrapper\AbstractWrapper;
class SplitWrapper extends AbstractWrapper
{
/**
* @var array 解析哪些注解(类级)
*/
protected $classAnnotations = [
Split::class
];
/**
* @var array 解析哪些注解(属性级)
*/
protected $propertyAnnotations = [
Split::class
]
;
/**
* @var array 解析哪些注解(方法级)
*/
protected $methodAnnotations = [
Split::class
];
/**
* 是否解析类注解
* @param array $annotations
* @return bool
*/
public function isParseClassAnnotations(array $annotations): bool
{
return true;
}
/**
* 是否解析属性注解
* @param array $annotations
* @return bool
*/
public function isParsePropertyAnnotations(array $annotations): bool
{
return false;
}
/**
* 是否解析方法注解
* @param array $annotations
* @return bool
*/
public function isParseMethodAnnotations(array $annotations): bool
{
return true;
}
}
\ No newline at end of file
<?php
/**
* This file is part of Swoft.
*
* @link https://swoft.org
* @document https://doc.swoft.org
* @contact group@swoft.org
* @license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
*/
namespace Swoft\Db;
use Swoft\Core\RequestContext;
/**
* Query
*/
class Query
{
/**
* @param string $tableName
* @param string $alias
*
* @return QueryBuilder
*/
public static function table(string $tableName, string $alias = null): QueryBuilder
{
$query = new QueryBuilder();
$query = $query->table($tableName, $alias);
return $query;
}
private function getTableName($commentString)
{
preg_match('/(?<=Table\(name=").*(?="\))/', $commentString, $matches);
return $tableName = isset($matches[0])?$matches[0]:'';
}
private function getDbNum()
{
$data = RequestContext::getContextData();
$storeId = $data['userInfo']['storeId'];
return $storeId % 100;
}
}
......@@ -13,6 +13,7 @@ namespace Hdll\Services\Common\Entity;
use Hdll\Services\Auth\Enum\AuthError;
use Hdll\Services\Common\Lib\Redis;
use Swoft\Bean\Annotation\Bean;
use Swoft\Core\RequestContext;
/**
* 用户实体
......@@ -25,106 +26,86 @@ use Swoft\Bean\Annotation\Bean;
*/
class User
{
private $id;
private $nickname;
private $storeId;
private $headImg;
private $token;
private $sessionKey;
private $scope;
private $referId;
private $unionid;
private $openId;
public function __construct($token='')
{
}
public function getId()
{
return $this->id;
return $this->getValue('id');
}
public function getNickname()
{
return $this->nickname;
return $this->getValue('nickname');
}
public function getStoreId()
{
return $this->storeId;
return $this->getValue('token');
}
public function getHeadImg()
{
return $this->headImg;
return $this->getValue('headImg');
}
public function getToken()
{
return $this->token;
return $this->getValue('headImg');
}
public function setId($value)
{
return $this->id = $value;
$this->setValue('id', $value);
}
public function setNickname($value)
{
return $this->nickname = $value;
$this->setValue('nickname', $value);
}
public function setStoreId($value)
{
return $this->storeId = $value;
$this->setValue('storeId', $value);
}
public function setHeadImg($value)
{
return $this->headImg = $value;
$this->setValue('headImg', $value);
}
public function setSessionKey($value)
{
$this->sessionKey = $value;
$this->setValue('sessionKey', $value);
}
public function setOpenId($value)
{
$this->openId = $value;
$this->setValue('openId', $value);
}
public function setUnionid($value)
{
$this->unionid = $value;
$this->setValue('unionid', $value);
}
public function setReferId($value)
{
$this->referId = $value;
$this->setValue('referId', $value);
}
public function setScope($value)
{
$this->scope = $value;
$this->setValue('scope', $value);
}
public function setToken($value)
{
$this->token = $value;
$this->setValue('token', $value);
}
......@@ -141,28 +122,28 @@ class User
public function getSessionKey()
{
return $this->sessionKey;
return $this->getValue('sessionKey');
}
public function getOpenId()
{
return $this->openId;
return $this->getValue('openId');
}
public function getUnionid()
{
return $this->unionid;
return $this->getValue('unionid');
}
public function getReferId()
{
return $this->referId;
return $this->getValue('referId');
}
public function getScope()
{
return $this->scope;
return $this->getValue('scope');
}
......@@ -184,13 +165,27 @@ class User
}
$info = json_decode($info, true);
$this->fill($info);
//$this->fill($info);
RequestContext::setContextData(['userInfo' => $info]);
return true;
}
private function getValue($key)
{
$data = RequestContext::getContextData();
return $data['userInfo'][$key]??'';
}
private function setValue($key, $value='')
{
$userInfo = [];
$userInfo['userInfo'][$key] = $value;
RequestContext::setContextData($userInfo);
}
}
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