在没有框架的情况下使用 Swiftmailer

编程入门 行业动态 更新时间:2024-10-27 16:39:44
本文介绍了在没有框架的情况下使用 Swiftmailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用 Swiftmailer 作为一个独立的库,没有 Symfony、Laravel、Yii、composer 等.

I am wanting to use Swiftmailer as a standalone library without Symfony, Laravel, Yii, composer, etc.

根据 Swiftmailer 网站,包含库的方法是调用 composer 的自动加载.php,但是在这种情况下我没有使用 composer 并且想知道需要包含/vender/swiftmailer 中的哪些基本文件才能使用库而不是 require_once '/path/to/vendor/autoload.php .php';

According to the Swiftmailer website the way to include the library is by calling composer's autoload.php, however I am not using composer in this case and would like to know which base files in /vender/swiftmailer need to be included in order to use the library instead of require_once '/path/to/vendor/autoload.php';

我查看了 Swiftmailer Google Group,但它已经停止并说来这里.

I looked at the Swiftmailer Google Group, but it's been discontinued and says to come here.

谢谢

推荐答案

正如您所发现的,如果您将 Swiftmailer 放入网站而没有任何帮助加载的内容,您将需要为外部添加您自己的自动加载器依赖.

As you have discovered, if you are putting the Swiftmailer into a website without anything to help with the loading, you will need to add your own autoloader for the external dependencies.

Swiftmailer v6.1.0 有两个:github/egulias/EmailValidator而另一个github/doctrine/lexer

There are two for Swiftmailer v6.1.0: github/egulias/EmailValidator and another github/doctrine/lexer

包含 swiftlib/swift_required.php 会自动加载所有 swift 类.您可以将其他人的自动加载添加到同一个文件中.这是将两个依赖项复制到 swiftlib 文件夹的子目录中的示例:

Including swiftlib/swift_required.php autoloads all the swift classes. You could add the autoload for the others into the same file. Here's an example where the two dependencies have been copied into subdirectories of the swiftlib folder:

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; } } } });

更多推荐

在没有框架的情况下使用 Swiftmailer

本文发布于:2023-11-16 21:23:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607513.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框架   情况下   Swiftmailer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!