[英]Interface '…' not found in (PHP SQL Query Builder)
I'm trying to use P HP SQL Query Builder in a project I'm working on. 我正在尝试在正在处理的项目中使用P HP SQL查询生成器 。 I am installing it manually. 我正在手动安装它。 I did this by copying the src directory into my project and then using the following code within my class: 通过将src目录复制到我的项目中,然后在类中使用以下代码来完成此操作:
$this->builder = new NilPortugues\\Sql\\QueryBuilder\\Builder\\GenericBuilder();
The error I get whenever the builder is used is: 每当使用构建器时,我得到的错误是:
[18-Apr-2017 12:57:48 UTC] PHP Fatal error: Interface 'NilPortugues\Sql\QueryBuilder\Builder\BuilderInterface' not found in /home/thomassm/public_html/php/lib/sqlbuilder/Builder/GenericBuilder.php on line 24
GenericBuilder.php GenericBuilder.php
namespace NilPortugues\Sql\QueryBuilder\Builder;
use NilPortugues\Sql\QueryBuilder\Builder\Syntax\WriterFactory;
use NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery;
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface;
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryFactory;
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;
use NilPortugues\Sql\QueryBuilder\Syntax\Column;
use NilPortugues\Sql\QueryBuilder\Syntax\Table;
/**
* Class Generic.
*/
class GenericBuilder implements BuilderInterface
{//...}
BuilderInterface.php BuilderInterface.php
namespace NilPortugues\Sql\QueryBuilder\Builder;
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface;
/**
* Interface BuilderInterface.
*/
interface BuilderInterface
{
/**
* @param QueryInterface $query
*
* @return string
*/
public function write(QueryInterface $query);
/**
* @param QueryInterface $query
*
* @return string
*/
public function writeFormatted(QueryInterface $query);
}
I assume the error is somehow caused by the way the files are called, any suggestions? 我认为错误是由文件调用方式引起的,有什么建议吗?
I am installing it manually. 我正在手动安装它。 I did this by copying the src directory into my project and then using the following code within my class: ... 通过将src目录复制到我的项目中,然后在我的类中使用以下代码来完成此操作:...
Every source file should be included through include
/ requrie
before using. 使用之前,应通过include
/ requrie
包含每个源文件。 But PHP allow to setup autoloading for classes, interfaces and traits. 但是PHP允许为类,接口和特征设置自动加载 。 In short, when runtime meets an undefined class then a special callback invokes, which can load the relevant file. 简而言之,当运行时遇到未定义的类时,将调用特殊的回调,该回调可以加载相关文件。
Although formally the autoloading rules can be arbitrary, but most of the modern projects supports the common community standard: PSR-4 Autoloader . 尽管形式上自动加载规则可以是任意的,但是大多数现代项目都支持通用的社区标准: PSR-4 Autoloader 。 So, you need an implementation of this standard. 因此,您需要此标准的实现。
As said in the library description, the recommended way to install is through Composer : 如库描述中所述,建议的安装方式是通过Composer :
php composer.phar require nilportugues/sql-query-builder
Composer provides own PSR-4 implementation and generates file vendor/autoload.php
. Composer提供了自己的PSR-4实现,并生成文件vendor/autoload.php
。 Usually this file included at the application entry point. 通常,此文件包含在应用程序入口点。 It allow using the classes from all required libraries. 它允许使用所有必需库中的类。
You can use the packages without the Composer ( relevant answer ). 您可以在不使用Composer的情况下使用软件包( 相关答案 )。 But it requires a lot of work (you still need an PSR-4 autoloader) and this way is rarely used today. 但这需要大量工作(您仍然需要PSR-4自动装带器),这种方式如今很少使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.