我试图根据环境变量将请求代理到不同的目标.我的方法是将目标url放入自定义变量$ target并将其提供给proxy_pass.
但是使用带有proxy_pass的变量似乎不起作用.这个简单的配置导致nginx的"502 Bad Gateway"响应.
server {
listen 8080;
server_name myhost.example.com;
access_log /var/log/nginx/myhost.access.log;
location /proxy {
set $target http://proxytarget.example.com;
proxy_pass $target;
}
}
Run Code Online (Sandbox Code Playgroud)
没有变量的相同配置有效:
server {
listen 8080;
server_name myhost.example.com;
access_log /var/log/nginx/myhost.access.log;
location /proxy {
proxy_pass http://proxytarget.example.com;
}
}
Run Code Online (Sandbox Code Playgroud)
是不是真的不能以这种方式使用proxy_pass,或者我只是做错了什么?
在@param注释中包含类的命名空间是一种好习惯吗?我知道phpdoc不支持名称空间,但是phpdox或Doxygen等其他工具会如何起作用?
哪种方式更好/更常见?
namespace foo\someNamespace;
use foo\someOtherNamespace\MyOtherClass;
--- with namespace ---
/**
* @param \foo\someOtherNamespace\MyOtherClass $otherClass
*/
class myClass(MyOtherClass $otherClass)
{
// do something
}
--- without namespace ---
/**
* @param MyOtherClass $otherClass
*/
class myClass(MyOtherClass $otherClass)
{
// do something
}
Run Code Online (Sandbox Code Playgroud) 我使用Factories(请参阅http://www.php.net/manual/en/language.oop5.patterns.php获取模式)来增加代码的可测试性.一个简单的工厂看起来像这样:
class Factory
{
public function getInstanceFor($type)
{
switch ($type) {
case 'foo':
return new Foo();
case 'bar':
return new Bar();
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是使用该工厂的示例类:
class Sample
{
protected $_factory;
public function __construct(Factory $factory)
{
$this->_factory = $factory;
}
public function doSomething()
{
$foo = $this->_factory->getInstanceFor('foo');
$bar = $this->_factory->getInstanceFor('bar');
/* more stuff done here */
/* ... */
}
}
Run Code Online (Sandbox Code Playgroud)
现在进行适当的单元测试,我需要模拟将返回类的存根的对象,这就是我遇到的问题.我认为有可能这样做:
class SampleTest extends PHPUnit_Framework_TestCase
{
public function testAClassUsingObjectFactory()
{
$fooStub = $this->getMock('Foo');
$barStub = $this->getMock('Bar');
$factoryMock = …
Run Code Online (Sandbox Code Playgroud)