我真的很困惑何时使用getServiceLocator以及何时不使用.举个例子:
+ Module
-+ Helloworld
--+ src
---+ Controller
----+ IndexController.php
----+ IndexControllerFactory.php
---+ Service
----+ LogginService.php
----+ GreetingService.php
----+ GreetingServiceFactory.php
Run Code Online (Sandbox Code Playgroud)
GreetingServiceFactory.php有以下内容:
<?php
namespace Helloworld\Service;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class GreetingServiceFactory implements FactoryInterface
{
public function createService (ServiceLocatorInterface $serviceLocator)
{
$greetingService = new GreetingService();
$greetingService->setEventManager($serviceLocator->get('eventManager'));
$loggingService = $serviceLocator->get('loggingService');
$greetingService->getEventManager()->attach('getGreeting', array(
$loggingService,
'onGetGreeting'
));
return $greetingService;
}
}
Run Code Online (Sandbox Code Playgroud)
而IndexControllerFactory.php的内容如下:
<?php
namespace Helloworld\Controller;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class IndexControllerFactory implements FactoryInterface
{
public function createService (ServiceLocatorInterface $serviceLocator)
{
$ctr = new IndexController(); …Run Code Online (Sandbox Code Playgroud) 我希望使用尽可能少的内存和文件磁盘空间将多部分/表单数据(大型)文件直接上传到AWS S3.我怎样才能做到这一点?在线资源仅说明如何上传文件并将其本地存储在服务器上.
我想检测帐户登录是否可疑,就像Google 正在做的那样。我怎样才能实现这一目标,或者我应该查看哪些资源?
场景:我的登录凭据在雅虎的另一次漏洞中被盗,黑客正在使用这些凭据登录服务。我想检测该用户是否不是真正的用户,例如,通过使用登录 IP 地址的位置。
我想知道是否可以在zf2中使用路由/ uris的转换工具.我想要例如en.domain.tld/article/show/1转换为例如的路线de.domain.tld/artikel/anzeigen/1.我不认为正则表达式是去这里的方式,因为它可能导致类似的东西en.domain.tld/artikel/show/1.此外,我想避免为每种语言创建路由,因为随着系统的扩展,它会变得非常混乱.
我想替换一个接口的值,如下所示:
package main
import "fmt"
type Fooer interface {Foo(string)}
type Foo struct {foo string}
func (f *Foo) Foo(bar string) {f.foo = bar}
var z = &Foo{foo : "new"}
func swap(fooer Fooer) {fooer = z}
func main() {
f := &Foo{foo: "old"}
fmt.Printf("%s (want &{old})\n", f)
swap(f)
fmt.Printf("%s (want &{new})", f)
}
Run Code Online (Sandbox Code Playgroud)
但我得到:
&{old}
&{old}
Run Code Online (Sandbox Code Playgroud)
我尝试了各种各样的电话(fooer *= z,*fooer = *z...),但我似乎无法把它弄好.
你可以在play.golang上试试这个例子:http://play.golang.org/p/EZEh3X8yHC
好的,我认为它的工作原理如下:
func swap(fooer Fooer) {
foo, _ := fooer.(*Foo)
*foo = *z
}
Run Code Online (Sandbox Code Playgroud) go ×2
php ×2
amazon-s3 ×1
file-upload ×1
frameworks ×1
pointers ×1
routes ×1
security ×1
translate ×1