小编use*_*056的帖子

具有依赖性的可测试控制器

如何解析可测试控制器的依赖关系?

工作原理:URI路由到Controller,Controller可能具有执行某项任务的依赖关系.

<?php

require 'vendor/autoload.php';

/*
 * Registry
 * Singleton
 * Tight coupling
 * Testable?
 */

$request = new Example\Http\Request();

Example\Dependency\Registry::getInstance()->set('request', $request);

$controller = new Example\Controller\RegistryController();

$controller->indexAction();

/*
 * Service Locator
 *
 * Testable? Hard!
 *
 */

$request = new Example\Http\Request();

$serviceLocator = new Example\Dependency\ServiceLocator();

$serviceLocator->set('request', $request);

$controller = new Example\Controller\ServiceLocatorController($serviceLocator);

$controller->indexAction();

/*
 * Poor Man
 *
 * Testable? Yes!
 * Pain in the ass to create with many dependencies, and how do we know specifically what dependencies a controller …
Run Code Online (Sandbox Code Playgroud)

php registry dependencies design-patterns service-locator

19
推荐指数
2
解决办法
2386
查看次数

Phaser 中的精灵和装备精灵衣服

如何在 Phaser 中为精灵装备衣服?假设我使用以下内容:

http://opengameart.org/sites/default/files/ human_base.png

http://opengameart.org/sites/default/files/styles/medium/public/16x18hair-clothingpack_preview2.png

我能想到的唯一方法是制作每个精灵都打开的图像。一定有不同的方法,比如叠加或者其他什么?

javascript phaser-framework

3
推荐指数
1
解决办法
2848
查看次数