我必须开发一个非常简单的php网站,所以我不需要框架.但它必须支持多语言(EN/FR/CHINESE).我已经找了php内置系统,我找到了两种方法:
我没有没有框架的i18n经验,所以有关支持多语言最简单方法的建议吗?
最后我只需要一个搜索翻译到文件的功能(一个文件按语言).情商:
trans('hello');
=> en.yaml(yaml与否,这是一个例子)
hello: "Hello world!"
Run Code Online (Sandbox Code Playgroud)
=> fr.yaml
hello: "Bonjour tout le monde !"
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我更喜欢Pure PHP实现
我有一些问题来实现twig扩展.我需要创建自己的过滤器(子过滤器).所以我想过使用twig扩展.
我在MyApp\Bundle\WebsiteBundle \上创建了一个名为"Extension"的文件夹,并且文件:WebsiteExtension.php
namespace Bundle\WebsiteBundle\Extension;
class WebsiteExtension extends \Twig_Extension {
public function getFilters() {
return array(
'substr' => new \Twig_Filter_Method($this, 'substrFilter'),
);
}
public function substrFilter($sentence, $start, $end) {
return substr($sentence, $start, $end);
}
public function getName()
{
return 'website_extension';
}
}
Run Code Online (Sandbox Code Playgroud)
然后在/ app/config上的config.yml上
services:
Website.twig.extension:
class: MyApp\Bundle\WebsiteBundle\Extension\WebsiteExtension
tags:
- { name: twig.extension }
Run Code Online (Sandbox Code Playgroud)
但是错误发生了:
"Fatal error: Class 'MyApp\Bundle\WebsiteBundle\Extension\WebsiteExtension' not found in .../appDevDebugProjectContainer.php on line 1391"
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为文件和类存在......我错过了什么,但是什么?
99%的我的依赖是通过@Autowired Spring注释用DI模式管理的.
然而,在特定情况下,我无法确定在运行时使用哪个实现.
最着名的情况是解析器的多重实现.
第一个解决方案是使用多个@Autowired(丑陋模式)
Interface Parser {
<T> T parse();
}
@Component("JsonParser")
class JsonParser implements Parser {
...
}
@Component("XmlParser")
class XmlParser implements Parser {
...
}
class MyService {
@Autowired
@Qualifier("XmlParser")
Parser xmlParser;
@Autowired
@Qualifier("JsonParser")
Parser jsonParser;
...
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我有大量的实现,那是不可接受的.
第二个解决方案是使用Spring的ServiceLocator
interface ParserServiceLocatorFactory {
public Parser getParser(String parserName);
}
interface Parser {
<T> T parse();
}
@Component("JsonParser")
class JsonParser implements Parser {
...
}
@Component("XmlParser")
class XmlParser implements Parser {
...
}
class MyService {
@Autowired
ServiceFactory parserServiceLocatorFactory; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用非常标准的用户管理从现有应用程序设计微服务:具有身份验证和授权,并存储用户数据.
我在深化发展的授权服务器来管理用户认证和授权使用OAuth2的授权.另一方面,我必须存储用户的信息/个人资料.
问题:授权服务器应该管理:
/me获取当前用户,也/users让用户的完整列表./me与用户相关的API,用户微服务会公开/users吗?第一种解决方案稍微简单一点,但授权服务器将变得不那么通用(更少可重用),因为用户应用程序数据模型将成为其一部分(User表的数据库数据模型).
另一个要求是授权服务器应该在授权之前检查用户是否存在.
没有用户自动创建,管理员必须邀请用户才能访问.有了这个要求,第一个解决方案很简单,因为授权服务器可以访问用户数据库,但第二个解决方案授权服务器暗示:
User表(可以重命名Account),管理员不会在用户服务上创建用户,而只在授权服务器上创建用户帐户我认为1.解决方案已经出来但有关于2.和3的任何建议?
3.首先似乎是最好的,但如果我想切换到另一个授权服务器,例如Google,Github,Facebook等公共服务器(OAuth2)......安全性可能会受到影响,因为我们无法控制用户帐户创建.
任何反馈?
我有问题在两个集合之间检索信息.第一个集合存储员工信息:
{
"_id" : ObjectId("4f9643967f8b9a3f0a00005a"),
"birth_date" : "1963-09-09",
"departments" : [
{
"departments_id" : ObjectId("4f9643957f8b9a3f0a000007"),
"from_date" : "1990-01-03",
"to_date" : "1990-01-15"
}
],
"first_name" : "Parviz",
"gender" : "M",
"hire_date" : "1990-01-03",
"last_name" : "Lortz",
}
Run Code Online (Sandbox Code Playgroud)
第二部是部门信息
{
"_id" : ObjectId("4f9643957f8b9a3f0a000004"),
"dept_name" : "Marketing",
"managers" : [
{
"employees_id" : ObjectId("4f96439b7f8b9a3f0a0186a9"),
"from_date" : "1985-01-01",
"to_date" : "1991-10-01"
},
{
"employees_id" : ObjectId("4f96439b7f8b9a3f0a0186aa"),
"from_date" : "1991-10-01",
"to_date" : "9999-01-01"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我试图找到:给定员工的所有部门.
我尝试过类似的东西:
employees = db.employees.find({_id:ObjectId("some_id")});
db.departments.find({_id:{$in:...}});
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在var员工的所有部门的department_id中解释$.
我想,以确保端点Actuators内Spring Boot的项目.但是,使用准备运行Spring Security配置Actuators:
management:
security:
enabled: true
role: ADMINISTRATOR
Run Code Online (Sandbox Code Playgroud)
这太容易我需要Actuators使用我们的自定义安全性(此处为CASSSO).
第一次尝试是增加context-path了Actuators:
management:
security:
enabled: true
role: ADMINISTRATOR
context-path: /management
Run Code Online (Sandbox Code Playgroud)
并更新我的WebSecurityConfigurerAdapter配置
@Override
protected void configure(HttpSecurity http) throws Exception {
...
http.authorizeRequests()..antMatchers("/management/**").hasRole(Role.ADMINISTRATOR.toString());
...
}
Run Code Online (Sandbox Code Playgroud)
它工作但我必须硬编码Actuators context-path,所以当我想要更新时,management.context-path我必须更新我的安全性.
我知道可以检索价值management.context-path但是当价值等于时如何管理它""?
你可以回答我@Autowired EndpointHandlerMapping并检索Actuators端点列表......最后我将复制过去相同的逻辑ManagementSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter.
此外ManagementSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter @ConditionalOnMissingBean是指向自身,但是ManagementSecurityAutoConfiguration.ManagementWebSecurityConfigurerAdapter内部静态受保护的类,所以不能在不传递参数的情况下禁用它management.security.enabled=false,这可能很奇怪,因为你的配置说management.security.enabled=false但实际上端点是安全的...... …
Git基于内容而没有文件,因此我目前了解以下行为,但我想知道是否有特殊选项或黑客来检测这样的事情:
git init
mkdir -p foo/bar
echo "test" foo/a.txt
echo "test2" foo/bar/b.txt
git add -A
git commit -m "test"
rm -fr foo
git add -A
git commit -m "delete whole dir"
git log --name-status
Run Code Online (Sandbox Code Playgroud)
当我检查记录,Git将无法说清楚我foo被删除,但所有的文件foo/a.txt和foo/bar/b.txt被删除
commit d1513a9b36cd546371a194e798566c49e779e3a9
Date: Tue Sep 8 16:58:21 2015 +0200
delete whole dir
D foo/a.txt
D foo/bar/b.txt
commit 135f7ae52dfddcee5eeb7bdfa9f0d5c924fed3af
Date: Tue Sep 8 16:58:10 2015 +0200
test
A foo/a.txt
A foo/bar/b.txt
Run Code Online (Sandbox Code Playgroud)
因此,如果我创建以下提交:
mkdir -p foo/bar
echo "test" > …Run Code Online (Sandbox Code Playgroud) 到目前为止,我正在使用 gitlab-ci 作业在产品中部署,when: manual但最近我需要在计划作业运行时在产品中自动部署(这将添加特定变量)
因此我when: manual对rules关键字进行了如下更改:
rules:
# deploy if schedule is triggered and thus variable is present
- if: '$DEPLOYMENT_SCHEDULE == "true"'
when: always
# Else (if master branch) keep job as manual (as before)
- if: '$CI_COMMIT_REF_NAME == "master"'
when: manual
Run Code Online (Sandbox Code Playgroud)
然而,管道视图发生了一些变化,因为:
when: manual,pipeline就认为是通过了rules:(当在没有 的情况下在 master 上合并时DEPLOYMENT_SCHEDULE),管道被认为是阻塞的有什么我想念的吗?如何才能获得与rules关键字相同的管道结果?
我目前正在使用redis使用"set"结构.
我想知道是否可以自动清空"套装"?
否则找到一个cron/process定期清理空"set"
更新:
更通用的问题,"(nil)"和"(空列表或集合)"之间存在差异(内存使用)
例:
sadd x 1
srem x
smembers x
(empty list or set)
Run Code Online (Sandbox Code Playgroud)
要么
sadd x 1
del x
smembers x
(nil)
Run Code Online (Sandbox Code Playgroud) 首先,我阅读了上一个问题:在spring数据REST中公开集合实体上的链接
但问题仍然存在,没有诡计.
实际上,如果我想公开集合资源的链接,我正在使用以下代码:
@Component
public class FooProcessor implements ResourceProcessor<PagedResources<Resource<Foo>>> {
private final FooLinks fooLinks;
@Inject
public FooProcessor(FooLinks fooLinks) {
this.FooLinks = fooLinks;
}
@Override
public PagedResources<Resource<Foo>> process(PagedResources<Resource<Foo>> resource) {
resource.add(fooLinks.getMyCustomLink());
return resource;
}
}
Run Code Online (Sandbox Code Playgroud)
这是正常的,除非收集是空的...
唯一可行的方法是将以下代码替换为:
@Component
public class FooProcessor implements ResourceProcessor<PagedResources> {
private final FooLinks fooLinks;
@Inject
public FooProcessor(FooLinks fooLinks) {
this.FooLinks = fooLinks;
}
@Override
public PagedResources process(PagedResources resource) {
resource.add(fooLinks.getMyCustomLink());
return resource;
}
}
Run Code Online (Sandbox Code Playgroud)
但通过这样做,链接将暴露给所有集合.
我可以创造条件只暴露我想要的但我认为不干净.