Php 在没有框架的情况下使用Swiftmailer
我想使用Swiftmailer作为一个独立的图书馆,没有Symfony,Laravel,Yii,composer等 根据示例,包含库的方法是调用composer的autoload.php,但是在本例中我没有使用composer,我想知道为了使用库而不是Php 在没有框架的情况下使用Swiftmailer,php,swiftmailer,Php,Swiftmailer,我想使用Swiftmailer作为一个独立的图书馆,没有Symfony,Laravel,Yii,composer等 根据示例,包含库的方法是调用composer的autoload.php,但是在本例中我没有使用composer,我想知道为了使用库而不是require_once'/path/to/vendor/autoload.php',需要包含/vender/swiftmailer中的哪些基本文件 我看了看速递机,但它已经停产了,说要来这里 谢谢正如您所发现的,如果您在没有任何帮助的情况下将Sw
require_once'/path/to/vendor/autoload.php',需要包含/vender/swiftmailer中的哪些基本文件代码>
我看了看速递机,但它已经停产了,说要来这里
谢谢正如您所发现的,如果您在没有任何帮助的情况下将Swiftmailer放入网站,则需要为外部依赖项添加您自己的自动加载器
Swiftmailer v6.1.0有两种版本:
还有一个
包括swiftlib/swift_required.php自动加载所有swift类。您可以将其他文件的自动加载添加到同一文件中。下面是一个示例,其中两个依赖项已复制到swiftlib文件夹的子目录中:
spl_autoload_register(function ($class) {
$load_deps = [
'Egulias\\EmailValidator\\' => __DIR__ . '/EmailValidator/',
'Doctrine\\Common\\Lexer\\' => __DIR__ . '/Doctrine/Common/Lexer/',
];
foreach ($load_deps as $prefix => $base_dir) {
// does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) == 0) {
// get the relative class name
$relative_class = substr($class, $len);
// replace the namespace prefix with the base directory, replace namespace
// separators with directory separators in the relative class name, append
// with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
// if the file exists, require it
if (file_exists($file)) {
require $file;
}
}
}
});
看看他们的,看起来你只需要包含lib/swift_required.php
,你应该很乐意去做。谢谢@rickdenhaan,我会尝试一下。你也可以从GitHub上的存储库下载他们的压缩代码:把它放在你项目的文件夹中,导入lib/swift_required.php文件是的,我做到了,但它仍然是为与composer一起使用而构建的。现在我想知道composer是否正在安装另一个第三方库。我在没有使用git clone编写器的情况下手动安装了Swiftmailer库,当我去实例化Swift_消息类时,我得到以下信息:PHP致命错误:未捕获的ReflectionException:Class Egulias\EmailValidator\EmailValidator在/local/mail handler/vendor/swiftmailer/lib/classes/Swift/DependencyContainer中不存在。PHP:309感谢您的回答。我可以简单地使用composer,它生成了自动加载文件,所以在代码中使用它,我所需要的只是自动加载程序的require语句。很好!我需要你一次path/to/vendor/autoload.php';是的,当您有一个带有composer的开发环境时,您可以使用它来生成自动加载器。你的问题说你不能使用composer,所以我的回答告诉你一种不用它的方法。不过,我很高兴你克服了障碍。