sauls/components-bundle

Sauls所有组件打包,适用于Symfony框架

安装: 52

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 0

分支: 0

开放问题: 0

类型:symfony-bundle

v1.0.5 2020-08-22 18:09 UTC

This package is auto-updated.

Last update: 2024-09-23 03:32:50 UTC


README

Build Status Packagist Total Downloads Coverage Status Scrutinizer Code Quality License

Sauls所有组件打包,适用于Symfony框架。

此包集成了以下包

需求

PHP >= 7.2

安装

使用composer

$ composer require sauls/components-bundle

如果您使用Symfony flex,则此包将自动注册。

手动添加composer.json文件

{
    "require": {
        "sauls/components-bundle": "^1.0"
    }
}

注册包

如果您使用symfony/flex,则此包将为您自动注册。否则,请手动添加到您的bundles.php文件。

return [
    // ...
    new Sauls\Bundle\Components\SaulsComponentsBundle:class => ['all'],
    //...
];

完整配置

sauls_components:
    helpers: ~ # default true
    widgets: ~ # default true
    components:
      # Access component
      # access: ~ # default false
      access:
        protected_routes: # Routes that only allowed ips can access
          - "secret_route_"
          - "users_"
        allowed_ips:
          - "127.0.0.1/8"

Twig中的助手

{{ '2018-01-12'|elapsed }}
{{ '2017-12-31'|countdown('2018-01-01') }}
{{ 'weird_string'|camelize }}
{{ 'AnotherWeirdString'|snakeify }}
{% set ms = 'super,duper#string'|multi_split([',', '#']) %}
{{ 'test&nottest=2'|base64_url_encode }}
{{ 'dGVzdCZub3R0ZXN0PTI='|base64_url_decode }}
{{ 'one two three'|count_words }}
{{ 'Helllo. World. Is it? Or not?'|count_sentences }}
{{ 'Hello world!'|truncate(5) }}
{{ 'Hello magical world!'|truncate_words(2) }}
{{ 'Hello. World. Are you real?'|truncate_sentences(2, '..') }}
{{ '<p>Hello world!</p>'|truncate_html(5, '') }}
{{ '<p>Hello world of life.</p>'|truncate_html_words(2, '') }}
{{ '<p><span>Hello world.</span> How is your life? is it good?</p>'|truncate_html_sentences(2, '') }}

小部件支持

创建您的widget(s)

class MyWidget extends Widget
{
    // Implement methods or add your own logic
}

class MyViewWidget extends ViewWidget
{
    // Implement methods or add your own logic
}

将它们注册到容器中

services:
    MyWidget: 
      tags: ['sauls_widget.widget']
    MyViewWidget: 
      tags: ['sauls_widget.widget']

或者如果您使用自动注入功能,您不需要做任何事情,它将自动添加。

视图

创建您自己的视图(s)

use Sauls\Component\Widget\View\ViewInterface;

class MyView implements ViewInterface

将它们注册到容器中

services:
    MyWiew:
      tags: ['sauls_widget.view']

或者如果您使用自动注入功能,您不需要做任何事情,它将自动添加。

额外的集合类型转换器

创建您的转换器(s)

use Sauls\Component\Helper\Operation\TypeOperation\Converter\ConverterInterface;

class IntToStringConverter implements ConverterInterface
{
    // Implement the methods
}

将它们注册到容器中

services:
    IntToStringConverter:
      tags: ['sauls_collection.converter']

或者如果您使用自动注入功能,您不需要做任何事情,它将自动添加。

之后,您可以使用您的新转换器 convert_to(1, 'string')