fabricio872/random-message-bundle

Symfony 扩展包,为您提供各种有趣的加载界面或任何需要占位符内容的地方可以显示的消息

安装: 233

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:symfony-bundle

v0.1.12 2023-04-17 17:08 UTC

This package is auto-updated.

Last update: 2024-09-17 20:33:03 UTC


README

GitHub tag (latest by date) GitHub last commit Packagist Downloads GitHub Repo stars

随机消息

Symfony 扩展包,为您提供各种有趣的加载界面或任何需要占位符内容的地方可以显示的消息

安装

请确保已全局安装 Composer,如 Composer 文档的 安装章节 所述。

使用 Symfony Flex 的应用程序

打开命令行,进入您的项目目录并执行

$ composer require fabricio872/random-message-bundle

不使用 Symfony Flex 的应用程序

步骤 1:下载 Bundle

打开命令行,进入您的项目目录并执行以下命令以下载此 Bundle 的最新稳定版本

$ composer require fabricio872/random-message-bundle

步骤 2:启用 Bundle

然后,通过将其添加到项目 config/bundles.php 文件中注册的 Bundle 列表中来启用该 Bundle

// config/bundles.php
return [
    // ...
    Fabricio872\RandomMessageBundle\RandomMessageBundle::class => ['all' => true],
];

配置选项

# config/services.yaml

# ...

# Default configuration for extension with alias: "random_message"
random_message:

 # Define default path where list of messages will be stored.
 path:                 '%kernel.project_dir%/var/random_messages'

 # List of repositories for messages
 repositories:

  # Default:
  - https://github.com/Fabricio872/random-message-repository

 # Define default language.
 default_language:     en

 # Define your email with which commits with messages will be done.
 git_email:            anonym@email.com

 # Define your name with which commits with messages will be done
 git_name:             anonym

 # Access token generated by GitHub you can make one here (https://github.com/settings/tokens)
 git_access_token:     accessToken

# ...

使用方法

首先,我们需要从消息存储库中拉取消息。为此,请执行以下命令:bin/console random_message:pull,此命令将遍历所有配置的存储库,并尝试下载或更新它们。

注意:可能需要在每次执行 composer installcomposer update 时执行此命令,为此在您的 composer.json 中查找 "scripts" 并在 "auto-scripts" 中添加新行 "cache:clear": "symfony-cmd",然后添加 "random_message:pull": "symfony-cmd"

您可以在控制器中使用依赖注入来接收随机消息

// src/Controller/SomeController.php

    // ...

    #[Route('/some_path', 'some_name')]
    public function some_name(RandomMessage $randomMessage)
    {
        $message = $randomMessage->getMessage();
        
        return $this->render('some-view.html.twig', [
            'randomMessage'=> $message
        ]);
    }
    
    // ...

或者可以直接在模板中使用

{# some Twig template #}

    {# ... #}

    {{ random_messge() }}

    {# ... #}

贡献

您可以创建自己的消息,甚至为所有人共享它们

创建和配置存储库

要创建新消息,您需要一个新空白的 Git 存储库,例如在 GitHub 上,并将以下 https 链接添加到您的存储库列表中,如下所示

# config/services.yaml

# ...

# Default configuration for extension with alias: "random_message"
random_message:

 # Define default path where list of messages will be stored.
 path:                 '%kernel.project_dir%/var/random_messages'

 # List of repositories for messages
 repositories:

  # Default:
  - https://github.com/Fabricio872/random-message-repository

 # Define default language.
 default_language:     en

 # Define your email with which commits with messages will be done.
 git_email:            anonym@email.com

 # Define your name with which commits with messages will be done
 git_name:             anonym

 # Access token generated by GitHub you can make one here (https://github.com/settings/tokens)
 git_access_token:     accessToken

# ...

注意:用 <YOUR_NAME> 和 <YOUR_REPO> 替换您的实际值

  • 然后更新 git_emailgit_name 为您用于添加的存储库的实际 Git 名称和电子邮件。
  • 要生成 git_access_token,请访问此页面:https://github.com/settings/tokens 并创建具有推送提交访问权限的令牌。

创建新消息

好吧,关于为您的消息创建新存储库,嗯……实际上并不需要,我在撒谎,您完全可以创建默认存储库中的消息,但您无法在部署服务器上下载它们。
既然您有一个空白的存储库,为什么不直接使用它。

  • 输入命令 bin/console random_message:create,这将询问您要使用哪个存储库,因此请选择新创建的一个
  • 然后它将询问您的消息的 category 和消息将编写的 language

注意:对于语言,请使用 2 个字母的格式,例如英语使用 en

  • 然后您可以添加尽可能多的消息。
  • 如果要在添加新消息后结束,请再次按 enter 并输入空消息

推送消息

因此,我们有一个空的存储库和包含新消息的 JSON 文件,现在是时候将它们实际推送到 GitHub 了。

  • 假设我们已经正确配置了git_name和git_access_token。执行命令bin/console random_message:push,此命令会询问你想要推送到哪个仓库,请选择新创建的那个。

  • 然后它会显示你对该仓库所做的更改,应该有一个包含你刚刚创建的所有json文件的列表。如果你对更改没有异议,请输入“y”并按enter键。

  • 现在你可以输入你的提交信息。在这里输入一些关于你信息的意义,比如来源或者类似的内容,然后再次按enter键。

  • 希望一切正常,你将看到一条绿色消息告诉你仓库已成功更新,你可以在你的GitHub页面上查看新的提交。

向主线仓库贡献信息

如果你想与世界分享你的信息,就按照步骤:创建和配置仓库中的操作进行,但不要创建新的空仓库,而是将此:https://github.com/Fabricio872/random-message-repository进行分支操作。然后继续像处理空仓库一样操作。

注意:要在GitHub上分支一个仓库,请转到你想要分支的仓库,点击右上角的分支按钮。