Welcome Guest, Not a member yet? Register   Sign In
New Registrar Feature
#1

(This post was last modified: 10-22-2023, 06:40 PM by donpwinston.)

I'm looking for a way to modify config information without modifying the app/Config/* files. I don't believe I can do all that I want in the .env file. 
For example how would I do this:
PHP Code:
public array $globals = [
        'before' => [
            // 'honeypot',
            // 'csrf',
            // 'invalidchars',
        ],
        'after' => [
            'toolbar',
            // 'honeypot',
            'csrf' => ['except' => ['receive-pdf''receive_pdf']],
            // 'secureheaders',
        ],
    ]; 

Problematic config files for me are Routes.php(not a subclass of BaseConfig), Validation.php, and Filters.php.
When looking around I noticed the new Registrar feature. I'm interested in the implicit way of using this but I don't understand the following:
PHP Code:
<?php

namespace CodeIgniter\Shield\Config;

class 
Registrar
{
    public static function Pager(): array
    {
        return [
            'templates' => [
                'module_pager' => 'MyModule\Views\Pager',
            ],
        ];
    }


What is this CodeIgniter\Shield\Config namespace?

I'm annoyed at having to diff my config files with any new CI upgrade and merge all my changes back into the file after upgrading. There's got to be a better way to do this. The config part should not be affected by upgrades. The config information should be in a non php file like .env and loaded when the app starts or set the class properties in some sort of start up function somewhere. How can I modify the Config classes properties dynamically? I believe I can create my own Config class say MyApp.php. A CI upgrade would not overwrite my config class. In this class can I set the property values of other Config classes? That would mean MyApp.php would have to be evaluated last.
Simpler is always better
Reply
#2

Could this work for you?

CodeIgniter 4 Settings
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(10-22-2023, 06:36 PM)donpwinston Wrote: What is this CodeIgniter\Shield\Config namespace?

It is just sample code. It is a sample namespace.
Probably in your context, a namespace that you use.

Quote:Any namespace may define implicit registrars by using the Config/Registrar.php file. These files are classes whose methods are named for each configuration class you wish to extend.
https://codeigniter4.github.io/CodeIgnit...registrars
Reply
#4

(10-22-2023, 06:36 PM)donpwinston Wrote: I'm annoyed at having to diff my config files with any new CI upgrade and merge all my changes back into the file after upgrading. There's got to be a better way to do this.

Probably many devs use Tatter\Patches. It patches config files automatically.
https://github.com/tattersoftware/codeigniter4-patches

(10-22-2023, 06:36 PM)donpwinston Wrote: The config part should not be affected by upgrades. The config information should be in a non php file like .env and loaded when the app starts or set the class properties in some sort of start up function somewhere.

Frankly, that will be difficult. It would be nice if we could have a new and wonderful Config system that completely replaces the existing Config system.

If you do try that, I would like to see a Config system that works much faster. The current Config has quite many features but insanely slow.

(10-22-2023, 06:36 PM)donpwinston Wrote: How can I modify the Config classes properties dynamically?

A Config object is a PHP object and the properties are public.

PHP Code:
$config->foo 'new value'

But I recommend you don't change the values after instantiation.
Because if the values may change dynamically, you may not be able to use the Config caching.
https://codeigniter4.github.io/CodeIgnit...ig-caching
Reply
#5

(This post was last modified: 10-23-2023, 03:16 AM by donpwinston.)

(10-22-2023, 10:06 PM)kenjis Wrote:
(10-22-2023, 06:36 PM)donpwinston Wrote: What is this CodeIgniter\Shield\Config namespace?

It is just sample code. It is a sample namespace.
Probably in your context, a namespace that you use.

Quote:Any namespace may define implicit registrars by using the Config/Registrar.php file. These files are classes whose methods are named for each configuration class you wish to extend.
https://codeigniter4.github.io/CodeIgnit...registrars

So I could create a app/Config/Registrar.php file like this:
PHP Code:
<?php // $Id$

namespace App\MyConfig;

use 
App\Filters\{DOSFilterHostFilterLoginSecurityFilter};
use 
App\Validation\NcrsEbnRules;

class 
Registrar
{
  public static function Filters(): array
  {
    return [
      'aliases' => [
        'host' => HostFilter::class,
        'dos' => DOSFilter::class,
        'loginsecurity' => LoginSecurityFilter::class,
      ],
      'globals' => [
        'before' => [
          'host',
          'dos',
          'loginsecurity',
        ],
      ],
      'methods' => [
        'post' => ['csrf'],
      ],
    ];
  }

  public static function Validation(): array
  {
    return [
      'ruleSets' => [
        NcrsEbnRules::class,
      ],
    ];
  }

Simpler is always better
Reply
#6

(10-23-2023, 02:49 AM)donpwinston Wrote:
(10-22-2023, 10:06 PM)kenjis Wrote:
(10-22-2023, 06:36 PM)donpwinston Wrote: What is this CodeIgniter\Shield\Config namespace?

It is just sample code. It is a sample namespace.
Probably in your context, a namespace that you use.

Quote:Any namespace may define implicit registrars by using the Config/Registrar.php file. These files are classes whose methods are named for each configuration class you wish to extend.
https://codeigniter4.github.io/CodeIgnit...registrars

So I could create a app/Config/Registrar.php file like this:
PHP Code:
<?php // $Id$

namespace App\MyConfig;

use 
App\Filters\{DOSFilterHostFilterLoginSecurityFilter};
use 
App\Validation\NcrsEbnRules;

class 
Registrar
{
  public static function Filters(): array
  {
    return [
      'aliases' => [
        'host' => HostFilter::class,
        'dos' => DOSFilter::class,
        'loginsecurity' => LoginSecurityFilter::class,
      ],
      'globals' => [
        'before' => [
          'host',
          'dos',
          'loginsecurity',
        ],
      ],
      'methods' => [
        'post' => ['csrf'],
      ],
    ];
  }

  public static function Validation(): array
  {
    return [
      'ruleSets' => [
        NcrsEbnRules::class,
      ],
    ];
  }

This works!
Simpler is always better
Reply




Theme © iAndrew 2016 - Forum software by © MyBB