草庐IT

explicit-interface

全部标签

php - 如何为不同的 "mobile device interfaces"和 "desktop interfaces"组织代码

我正在计划一个网络应用程序。我在Smarty中使用PHP框架Kohana。我的Web应用程序还将具有移动设备界面。现在,这两个接口(interface)将有很多共同的代码和很多单独的代码。我应该如何组织代码以便:没有重复代码。不会加载不必要的代码。例如,桌面UI特定代码不应加载到iPhone界面中,反之亦然。 最佳答案 您真的有多种选择!您可以选择使用共享的Kohana模块走“2个项目”路线-但我个人不喜欢这种方法。我个人会使用类似的方法作为多语言站点-所以...apache(或其他)将重写m.example.tld/my/page

PHP - 在接口(interface)函数声明中使用裸字

查看PHP关于接口(interface)的文档,特别是这里:PHP:ObjectInterfaces-Manual.以下代码作为工作示例给出。有人可以解释一下声明为函数签名一部分的裸词“Baz”是什么吗? 最佳答案 它叫做typehinting.baz()方法要求第一个参数$baz是Baz类型的对象。对象的类型来自构建它的类,或者来自它实现的接口(interface)。 关于PHP-在接口(interface)函数声明中使用裸字,我们在StackOverflow上找到一个类似的问题:

php - 在 Controller 中找不到接口(interface) 'Silex\ControllerProviderInterface'

执行api.php时:Fatalerror:Interface'Silex\ControllerProviderInterface'notfoundinC:\xampp\htdocs\lab\src\Api\UserController.phponline9Composer:{"require":{"silex/silex":"^2.0"},"autoload":{"psr-4":{"Api\\":"src/Api"}}}api.php:mount('/',newApi\UserController());$app->run();src/Api/UserController.php:g

PHP 子类不能实现相同的接口(interface)父类实现

子类不能实现父类实现的相同接口(interface)是正常行为吗?我得到了PHPv5.6interfaceblueprint{publicfunctionimplement_me();}classoneimplementsblueprint{publicfunctionimplement_me(){}}classtwoextendsoneimplementsblueprint{}//nofatalerrortriggeredforclasstwo编辑:所以即使我在子类two中实现了接口(interface)blueprint而没有方法,上面的代码也没有错误或警告>impement_me

php - 如何将 stream_socket_client 绑定(bind)到 php 中的接口(interface)?

我有一些在php中使用stream_socket_client(不是curl)的函数,我有多个eth1eth2...等接口(interface)与不同的ips所以我想在作为客户端连接时使用不同的接口(interface),我可以这样做吗?我在php.ini中找不到任何选项 最佳答案 这里是在stream_socket_client中添加IP接口(interface)的方法//connecttotheinternetusingthe'192.168.0.100'IP$opts=array('socket'=>array('bindto

php - 在使用 PHPUnit 进行测试时使用实现 IteratorAggregate 接口(interface)的 Mock 类时如何防止重新声明错误?

我正在编写依赖于外部类exceptionManager的单元测试。我希望能够预测此类中的一些特定函数将返回什么,所以我使用了一个模拟对象。代码非常简单:$mockExceptionManager=$this->getMock('exceptionManager');问题是,我的异常管理器实现了IteratorAggregate接口(interface),它需要一个如下所示的方法:publicfunctiongetIterator(){returnnewArrayIterator($this->exceptions);}当我运行单元测试时,出现以下错误:Fatalerror:Cannot

php - 如何动态加载php代码并检查类是否实现接口(interface)

我正在PHP中动态加载一个类。该文件和类名是从数据库中获取的。该文件必须包含一个类和一个方法。我试图用一个界面来解决它,但我真的不明白我怎么能以最漂亮的方式做到这一点。您有什么建议? 最佳答案 使用class_exists()确定是否已定义类,method_exists()确定一个类是否有方法和instanceof判断一个类是否实现了一个接口(interface)。 关于php-如何动态加载php代码并检查类是否实现接口(interface),我们在StackOverflow上找到一个类

php - "Class X extends Y (abstract), Y implements Z (interface). "无法调用接口(interface) Z 的抽象方法”

这是我的PHP抽象类。最底层的类是将扩展抽象类并将一些复杂的计算逻辑留给父实现的类之一。接口(interface)类(最顶层的抽象)的要点是强制那些较低的实现有自己的staticpublicfunctionid($params=false){方法。//Mytoplevelabstraction,tobeimplementedonlyby"MyAbstraction"interfaceMyInterface{staticpublicfunctionid();}//Mysecond(lower)levelofabstraction,tobeextended//byallchildclass

php - Invoice::setDueDate() 必须实现接口(interface) DateTimeInterface,使用 calcinai 的 Xero API

我正在关注这个wrapper我有这个错误:Catchablefatalerror:Argument1passedtoXeroPHP\Models\Accounting\Invoice::setDueDate()mustimplementinterfaceDateTimeInterface,stringgiven这是我的代码:try{$lineitem=newLineItem($this->_xi);$lineitem->setAccountCode('200')->setQuantity('5.400')->setDescription('thisisawesometest')->se

PHP - 如果抽象类中的所有方法都是抽象的,那么接口(interface)和抽象类之间有什么区别

抽象类可能有也可能没有抽象方法,但接口(interface)只有未实现的方法。那么,如果我的抽象类的所有方法都标记为抽象,那么使用接口(interface)有什么区别和优势呢? 最佳答案 接口(interface)和抽象真正的用途可以在具有大量类的巨大API中体现出来,这些类遵循经过深思熟虑的灵活结构以供将来编码。它是否会发生——你永远不知道代码是否会被扩展。接口(interface)仅用于语义原因。想象一下,您扩展了一个已弃用的API版本,并负责编辑/更改/实现/更新/改进/扩展/修改代码以使其保持最新,无论原因是什么。如果您不向