ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` ## 命名空间 ``` ``` extend\email\Aindex.php ~~~ namespace email; class Aindex { } ~~~ ~~~ namespace email; use Symfony\Component\OptionsResolver\OptionsResolver; class Aindex { private $options; /** * Email constructor. * * @param array $options */ public function __construct(array $options = []) { $this->setOptions($options); } /** * @return mixed */ public function getOptions() { return $this->options; } /** * @param array $options */ public function setOptions(array $options) //void { $this->options = $this->configureOptions($options, function (OptionsResolver $resolver) { $resolver->setDefaults(['host' => 'smtp.example.org', 'username' => 'user', 'password' => 'password', 'port' => 25,]); $resolver->setRequired(['host', 'username', 'password', 'port']); $resolver->setAllowedTypes('host', 'string'); $resolver->setAllowedTypes('username', 'string'); $resolver->setAllowedTypes('password', 'string'); $resolver->setAllowedTypes('port', 'int'); }); } /** * Configuration options. * * @param \Closure $closure * @param null $object * * @return array */ protected function configureOptions(array $options, $closure, $object = null) { $resolver = new OptionsResolver(); $closure($resolver); if ($object) { return $object->options = $resolver->resolve($options); } if (is_object($object)) { return $object->options = $resolver->resolve($options); } if (is_string($object) && class_exists($object)) { $object = new $object(); return $object->options = $resolver->resolve($options); } return $resolver->resolve($options); } } ~~~ ``` ``` application\copyy\controller\Index.php ~~~ namespace app\copyy\controller; use library\Controller; use think\Loader; /** * 应用入口 * Class Index * @package app\index\controller */ class Index extends Controller { /** * 入口跳转链接 */ public function index() { // $this->redirect('@admin/login'); dump('0123'); $email = new \email\Aindex(); //$email =new \Email([ 'host' => 'smtp.example.org', 'username' => 'user', 'password' => 'password', 'port' => 25, //]); dump($email); } } ~~~ ~~~ namespace app\copyy\controller; use library\Controller; use think\Loader; /** * 应用入口 * Class Index * @package app\index\controller */ class Index extends Controller { /** * 入口跳转链接 */ public function index() { // $this->redirect('@admin/login'); dump('0123'); $s = [ 'host' => 'smtp.example.org', 'username' => 'user', 'password' => 'password', 'port' => '25']; try{ $email = new \email\Aindex($s); }catch(\think\Exception $e){ dump($e); } } } ~~~ ```