在php中,您经常检查您获得的对象是否是正确的类型.如果不是,您抛出一个带有如下消息的异常:
use My\Class\MyClass
...
if (!$object instanceof MyClass) {
throw new Exception(
sprintf(
"object must be of type '%s'",
'My\Class\MyClass'
)
);
}
Run Code Online (Sandbox Code Playgroud)
现在我将完整的命名空间和类的名称传递给sprintf.
我如何从类引用中获取它,以便我可以做这样的事情
sprintf("object must be of type '%s'", MyClass::getName())
Run Code Online (Sandbox Code Playgroud)
编辑:
我希望在不添加新方法的情况下为所有类实现此目的.所以它应该是使用一些现有方法或一种php __ MAGIC__方法的解决方案.
我有一个关于验证嵌套json数据的小问题.例如,我有类似的PATCH请求:
{
"awesome": "yes",
"myObject": {
"some_property": "Text Example value",
"another_property": "1965"
}
}
Run Code Online (Sandbox Code Playgroud)
什么是设置过滤器和校验此嵌套数据的正确,也许正确的方式some_property和another_property?
非常感谢您的回答
目标:
我想找出哪个顶点/顶点最接近我点击的点.
建立:
代码我已经有了点击处理程序:
mouse = new THREE.Vector2();
mouse.x = (event.clientX / renderer.domElement.clientWidth) * 2 - 1;
mouse.y = - (event.clientY / renderer.domElement.clientHeight) * 2 + 1;
raycaster.setFromCamera(mouse, camera);
const intersects = raycaster.intersectObject(icosahedron);
// 3D point: intersects[0].point
// Object face: intersects[0].face
Run Code Online (Sandbox Code Playgroud)
谢谢!
我有一个Zend\Form带有多个嵌套Fieldsets的复合体。现在我需要实现交叉验证Fieldset。这意味着,验证规则是指Element来自不同Fieldsets 的多个s。我发现这样做的唯一方法是在 中实现此验证MyForm#isValid(),因为它是唯一的地方,我可以从中访问每个Fieldset地方。
MyForm extends Form
{
public function isValid()
{
$isFormValid = parent::isValid();
$isCrossFieldsetVaidationOk = // my additional validation logic
return $isFormValid && $isCrossFieldsetVaidationOk;
}
}
Run Code Online (Sandbox Code Playgroud)
尚未测试,但它会工作。问题在于添加错误消息。
我试过了
$this->setMessages(array_merge(
$this->getMessages(), ['my new message'])
);
Run Code Online (Sandbox Code Playgroud)
但它不起作用。
如何添加Form错误消息?
我在安装时遇到此错误 pecl/amqp
当我在命令行中键入时: pear install pecl/amqp
警告:php_bin C:\ xampp \ php。\ php.exe似乎有一个后缀。\ php.exe,
但
配置变量php_suffix不匹配
错误:DSP amqp.dsp不存在。
我需要安装它,以便可以RabbitMQ在php上使用amqp()。
我在控制器中有一个功能,需要检查用户是否已登录(我正在使用zfcuser模块),如果没有,则显示登录屏幕.
我的理解是我应该运行这个:
return $this->forward()->dispatch('zfcuser', array('action' => 'authenticate'));
Run Code Online (Sandbox Code Playgroud)
不幸的是,这改变了网址.我想显示登录屏幕,并允许用户登录而不更改网址.通过扩展,这意味着我还希望将用户重定向回同一页面,而不是转到/user页面.
我怎样才能实现这两件事?
我想在我的应用程序中合并访问控制的组件,我看到ZF2提供了:Zend /permissions/Acl而且Zend /permissions/RBAC,我想知道哪个更有效,更安全,又如何Zfc-RBAC?谢谢 。
我随机选择了"在我的场景中走来走去"(某种3D蛇),接下来要做的就是在它的头部设置一个盒子.该行bufferGeometry由设置
var positions1 = new Float32Array( MAX_POINTS * 3 ); // 3 vertices per point
var positions2 = new Float32Array( MAX_POINTS * 3 ); // 3 vertices per point
buffGeometry1.addAttribute( 'position', new THREE.BufferAttribute( positions1, 3 ) );
buffGeometry2.addAttribute( 'position', new THREE.BufferAttribute( positions2, 3 ) );
Run Code Online (Sandbox Code Playgroud)
我选择boxGeometry在它周围设置一个立方体(对象),并使用以下代码行来尝试实现:
var positioning = buffGeometry1.getAttribute('position');
cube.position.x = positioning[0];//(line1.geometry.attributes.position.array[drawCount]);
cube.position.y = positioning[1];//(line1.geometry.attributes.position.array[drawCount + 1]);
cube.position.z = positioning[2];
Run Code Online (Sandbox Code Playgroud)
在调试时,我看到我的positioning数组未定义.所以我觉得出了问题.
谢谢.
我注意到当我围绕Z轴旋转我的模型时,像这样:
model.rotateZ(rotatedAngle * Math.PI / 180);
Run Code Online (Sandbox Code Playgroud)
它似乎围绕轴逆时针旋转.
我有一个平坦的表面,我已经爆炸并镶嵌成三角形.我想获得每张脸的位置来应用动画,但显然我无法做到这一点.
if (intersects.length > 0) {
// if the closest object intersected is not the currently stored intersection object
if (intersects[0].object != INTERSECTED) {
if (INTERSECTED) {
INTERSECTED.face.color.setHex(INTERSECTED.currentHex);
}
INTERSECTED = intersects[0];
INTERSECTED.currentHex = INTERSECTED.face.color.getHex();
INTERSECTED.face.color.setHex(0xc0392b);
INTERSECTED.object.geometry.colorsNeedUpdate = true;
var position = new THREE.Vector3();
position.setFromMatrixPosition( INTERSECTED.matrixWorld );
alert(position.x + ',' + position.y + ',' + position.z);
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用INTERSECTED.face.matrixWorld.getPosition(),如本例中所指定的,但它抛出了一个错误.在这里,您可以找到包含完整代码的JSFiddle.你知道我的代码有什么问题吗?
提前感谢您的回复!