sauls/components-bundle

All Sauls components bundle for Symfony framework

Installs: 53

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

Type:symfony-bundle

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

This package is auto-updated.

Last update: 2024-12-23 03:57:42 UTC


README

Build Status Packagist Total Downloads Coverage Status Scrutinizer Code Quality License

All Sauls components bundle for Symfony framework.

This bundle integrates the following packages:

Requirements

PHP >= 7.2

Installation

Using composer

$ composer require sauls/components-bundle

If you are using Symfony flex the bundle will be auto registered.

Apppend the composer.json file manually

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

Register bundle

If you are using symfony/flex the bundle will be auto registered for you. Otherwise append your bundles.php file.

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

Full configuration

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"

Helpers in 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, '') }}

Widgets support

Create your widget(s)

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

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

Register them to container

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

Or if you are using autowire feature, you don't need to do anything it will be added automatically.

Views

Create your own view(s)

use Sauls\Component\Widget\View\ViewInterface;

class MyView implements ViewInterface

Register them to container

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

Or if you are using autowire feature, you don't need to do anything it will be added automatically.

Additional collection type converters

Create your converter(s)

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

class IntToStringConverter implements ConverterInterface
{
    // Implement the methods
}

Register them to container

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

Or if you are using autowire feature, you don't need to do anything it will be added automatically.

After that you can use your new converter convert_to(1, 'string').