我是DDD的初学者,在小型简单领域工作,以便了解所有设计原则.
我有这个简单的域:institutions(Institution)和他们可用的WiFi斑点(Place)保存在数据库中.没有机构就没有地方可以存在.机构有经理user-assignee(User),它有权添加新地点,重新分配或删除现有地点.
代码可以在这里找到.对价值对象的验证暂时搁置.
这是一个正确的DDD设计吗?或者至少接近它?
作为一个以数据为中心的程序员,我仍然想知道如果经验法则通过聚合根访问聚合,我将如何列出所有机构的所有位置?
生成Uuid内部的想法本身(Place::create)好吗?
是否只有受让人(User)可以添加/删除地点的想法应该在域本身上表达,还是应该由客户负责?在这种情况下,如果受让人知道他的管理机构(institutionId在User?),那将是明智的.
是不是Institution::placeById破坏了DDD的任何原则?也许这是存储库的责任?
我正在使用AngularJs和Angular-UI的ui-router创建SPA.现在我正在尝试创建身份验证逻辑.
$rootScope.$on("$stateChangeStart", function (event, toState) {
if(toState.authenticate && !MainService.isAuthenticated()) {
if($cookieStore.get('authToken')) {
MainService.loginWithToken($cookieStore.get('authToken'))
.then(function() {
$state.go(toState.name);
event.preventDefault();
});
}
$rootScope.requestPath = toState.name;
$state.go('public.login');
event.preventDefault();
}
if(toState.url == '/login' && MainService.isAuthenticated()) {
$state.go('private.main');
event.preventDefault();
}
});
Run Code Online (Sandbox Code Playgroud)
在状态更改时,这将检查状态是否需要身份验证并在必要时转移到登录状态.此外,如果用户登录,则会阻止其进入登录状态.身份验证由存储在cookie中的令牌完成.
这是我的量角器测试场景:
describe('Routes', function() {
it('Should go to the selected path if user logged in', function() {
browser.get('/');
expect(browser.getLocationAbsUrl()).toMatch("/login");
browser.manage().addCookie("authToken", "aaa");
browser.manage().getCookie("authToken").then(function(cookie) {
expect(cookie.name).toBe('authToken');
expect(cookie.value).toBe('aaa');
});
browser.get('/');
expect(browser.getLocationAbsUrl()).toMatch("/main");
browser.get('/#/main');
expect(browser.getLocationAbsUrl()).toMatch("/main");
/* This part fails, because, when the user is logged in,
he should be transfered …Run Code Online (Sandbox Code Playgroud) 我有这个Behat设置:
default:
extensions:
Behat\Symfony2Extension: ~
Behat\MinkExtension:
sessions:
default:
symfony2: ~
Run Code Online (Sandbox Code Playgroud)
这个场景:
Scenario: Event list for authenticated user
Given I am authenticated
Then I should see pagination control
And I should be able to change list page
Run Code Online (Sandbox Code Playgroud)
我检查用户是否经过身份验证,如果是,则在Twig中显示他的分页控制:
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
...
Run Code Online (Sandbox Code Playgroud)
相关Behat上下文:
/**
* @Given I am authenticated
*/
public function iAmAuthenticated()
{
$user = new User('test', null, ['ROLE_USER']);
$token = new UsernamePasswordToken($user, null, 'test', $user->getRoles());
$this->getTokenStorage()->setToken($token);
}
/**
* @Then I should see pagination control
*/
public function …Run Code Online (Sandbox Code Playgroud) 如何将Symfony2表单转换为JSON数据结构?寻找合适的捆绑给了我没有结果;
例:
$builder
->add('name', 'text')
->add('password', 'password')
;
Run Code Online (Sandbox Code Playgroud)
会导致类似的事情:
{
fields: {
name: {
type: 'text'
},
password: {
type: 'password'
}
}
}
Run Code Online (Sandbox Code Playgroud)
在$form = $this->createForm(new FormType(), new Entity())没有帮助的情况下迭代表单中的每个元素后,找不到可以在表单构建器中定义的某些属性.