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 规则,可用于验证一次有效。

激活

将服务提供者添加到您的 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的正常行为
  • 添加更多包
  • 可能将缓存和日志记录合并到这个包中,以便有一个包可以统治它们所有

支持

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

贡献

任何贡献都将受到鼓励并非常感激,您可以通过以下方式贡献: -

  • 报告错误
  • 建议特性
  • 发送拉取请求