kelchiecochrane/themosis-illuminate

此包已被弃用,不再维护。作者建议使用 djgadd/themosis-illuminate 包。

一个实现了 illuminate/cache 打包和 WP_Object_Cache 驱动的 themosis 插件

1.1.5 2018-04-22 19:31 UTC

README

一个为 Themosis 框架实现的 Illuminate 包的包,其中一些替换了 Themosis 包(如 config 和 validator)。还加载了 Laravel 的许多辅助函数(见下文)。

安装

通过 composer 安装:- composer require keltiecochrane/themosis-illuminate

下面说明了如何激活各个包。

以下包已被实现:-

配置

要使用配置(我们推荐使用,因为它实现了 ArrayAccess,这是大多数包实现所必需的)您需要替换 Themosis 的 Service Provider 和 Facade。它与 API 兼容,但实现了额外的功能(看起来 Themosis 将最终迁移到 Illuminate 包 将来也可能如此。)还允许扩展配置文件,这在父子场景中非常有用。

激活

将服务提供者添加到您的 theme/resources/config/providers.config.php:- KeltieCochrane\Illuminate\Config\ConfigServiceProvider::class,

在您的 theme/resources/config/theme.config.php 中替换 facade:- 'Config' => KeltieCochrane\Illuminate\Config\ConfigFacade::class,

注意:您不必现在就添加 facade,因为它实际上与 Themosis facade 做了同样的事情,但将来如果有必要与 Illuminate facade 保持一致,添加它还是值得的。

示例

按照常规使用,例如:-

  // Normal usage
  Config::get('something');

  // Setting a default
  Config::get('theme.locale', 'en-GB');

  // Using ArrayAccess
  app('config')['theme.locale'];

文件系统

文件系统对于翻译和验证是必需的,但它本身就是一个有用的功能。

激活

filesystem.config.php 文件复制到您的 theme/resources/config 文件夹,一些默认设置已为您设置。

将服务提供者添加到您的 theme/resources/config/providers.config.php:- KeltieCochrane\Illuminate\Filesystem\FilesystemServiceProvider::class,

可选地,在您的 theme/resources/config/theme.config.php 中添加 facade:-

  'File' => KeltieCochrane\Illuminate\Filesystem\FileFacade::class,
  'Storage' => KeltieCochrane\Illuminate\Filesystem\StorageFacade::class,

示例

  // Get an array of files in the current directory
  File::files(__DIR__);

  // Make a file in the current directory
  File::put(__DIR__.DS.'file.txt', 'Contents');

  // Put a file in your 'storage' directory
  Storage::disk('local')->put('file.txt', 'Contents');

  // Check if a file exists in your theme's 'dist' directory
  Storage::disk('dist')->exists('css/app.css');

  // Get a file url in your theme's 'dist' directory
  Storage::disk('dist')->url('css/app.css');

有关更多信息,请参阅 Laravel 文档

邮件

邮件是可选的,并且不依赖于任何其他东西,但它比通过 WordPress 发送电子邮件更方便。提供了一个 wp_mail 传输,默认使用,因此如果您的 WordPress 实例可以发送邮件,那么邮件服务也可以。

激活

mail.config.php 文件复制到您的 theme/resources/config 文件夹,并根据需要进行配置。

如果您将要使用外部服务,例如 MailGun 或 SparkPost,您需要在您的 theme/resources/services.config.php 文件中添加以下内容(如果您还没有这个文件,您可能需要创建一个):-

  'mailgun' => [
      'domain' => env('MAILGUN_DOMAIN'),
      'secret' => env('MAILGUN_SECRET'),
  ],

  'ses' => [
      'key' => env('SES_KEY'),
      'secret' => env('SES_SECRET'),
      'region' => 'us-east-1',
  ],

  'sparkpost' => [
      'secret' => env('SPARKPOST_SECRET'),
  ],

将服务提供者添加到您的 theme/resources/config/providers.config.php:- KeltieCochrane\Illuminate\Mail\MailServiceProvider::class,

可选地,在您的 theme/resources/config/theme.config.php 中添加门面:- 'Mail' => KeltieCochrane\Illuminate\Mail\MailFacade::class,

示例

  // Send an email
  Mail::send('mail.welcome', ['with' => 'Some data for the view.'], function ($mailer) {
    $attachmentPath = Storage::disk('dist')->getDriver()->getAdapter()->getPathPrefix().'images/call-icon.svg';

    $mailer->to('someone@somecompany.tld')
      ->bcc('mailbin@somecompany.tld')
      ->subject('Subject')
      ->attach($attachmentPath);
  });

有关更多信息,请参阅 Laravel 文档

翻译

翻译需要加载 Filesystem,并由验证所需要。

激活

将服务提供者添加到您的 theme/resources/config/providers.config.php:- KeltieCochrane\Illuminate\Translation\TranslationServiceProvider::class,

可选地,在您的 theme/resources/config/theme.config.php 中添加门面:- 'Lang' => KeltieCochrane\Illuminate\Translation\LangFacade::class,

文件

您可以从 Laravel 添加翻译,您需要将它们添加到您的 theme/resources/lang 文件夹中,目前值得复制的只有一个验证文件(如果您确实使用了验证。)当然,您也可以创建自己的文件以在您的网站上添加翻译,但我们仍然建议使用翻译插件。

示例

  // Is there a translation available in 'file' under 'key'
  Lang::has('file.key');

  // Is there a translation under the 'it' locale for 'file' under 'key'
  // Refuse to use the fall back locale
  Lang::has('file.key', 'it', false);

  // Get the translation
  Lang::trans('file.key');

  // Get the translation and replace some text in it
  Lang::trans('file.key', ['name' => 'John']);

  // Get the 'it' translation and replace some text in it
  // Refuse to use the fall back locale
  Lang::trans('file.key', ['name' => 'John'], 'it', false);

有关更多信息,请参阅 Laravel 文档

验证

验证需要翻译和文件系统。它替换了内置的 Themosis 验证器(如果您使用门面),它更像是清洁器而不是验证器。验证器已扩展了 valid_nonce 规则,可用于验证 nonce。

激活

将服务提供者添加到您的 theme/resources/config/providers.config.php:- KeltieCochrane\Illuminate\Validation\ValidationServiceProvider::class,

在您的 theme/resources/config/theme.config.php 中添加门面:- 'Validator' => KeltieCochrane\Illuminate\Validation\ValidatorFacade::class,

示例

  $validator = Validator::make($request->all(), [
    'title' => 'required|max:255',
    'body' => 'required',
    'nonce' => 'valid_nonce:action',
  ]);

  if ($validator->fails()) {
    return view()->with([
	  'errors' => $validator->errors(),
    ]);
  }

有关更多信息,请参阅 Laravel 文档

辅助函数

以下(额外的)辅助函数可用:-

  • array_add
  • array_collapse
  • array_divide
  • array_dot
  • array_first
  • array_flatten
  • array_forget
  • array_has
  • array_last
  • array_only
  • array_pluck
  • array_prepend
  • array_pull
  • array_sort
  • array_sort_recursive
  • array_where
  • array_wrap
  • camel_case
  • class_basename
  • class_uses_recursive
  • collect
  • config
  • data_fill
  • data_get
  • data_set
  • ends_with
  • env
  • head
  • kebab_case
  • last
  • object_get
  • preg_replace_array
  • retry
  • request
  • snake_case
  • str_finish
  • str_limit
  • str_plural
  • str_random
  • str_replace_array
  • str_replace_first
  • str_replace_last
  • str_singular
  • str_slug
  • studly_case
  • tap
  • title_case
  • trait_uses_recursive
  • trans
  • trans_choice
  • validator
  • windows_os

有关更多信息,请参阅 Laravel 文档

待办事项

  • 测试 - 大部分是信任Laravel包和Themosis的行为表现
  • 添加更多包
  • 可能将缓存和日志合并到这个包中,以便有一个包可以统治它们

支持

此包提供原样,尽管我们会尽力帮助。

贡献

任何贡献都将受到鼓励和高度赞赏,您可以通过以下方式贡献: -

  • 报告错误
  • 建议功能
  • 发送拉取请求