Welcome Guest, Not a member yet? Register   Sign In
Bug? Vendor Routes are loaded before Filters
#1

I have an issue where i am trying to set up a route filter in vendor/myname/packagename
Autoloader works fine everything gets discovered but i get

Code:
my-auth filter must have a matching alias defined.

My src/Config/Filters.php

PHP Code:
<?php
namespace MyName\PackageName\Config;

$filters->aliases['my-auth'] = \MyName\PackageName\Filters\Auth::class;

die(
'Filters found!'); // This fires well when i remove routes definition 

My src/Config/Routes.php

PHP Code:
<?php

namespace MyName\PackageName\Config;

$routes->group('area', ['filter' => 'my-auth''namespace' => '\MyName\PackageName\Controllers'], function ($routes) {
    $routes->get('method1''MyController::method1');
    $routes->get('method2''MyController::method2');
}); 

Application app/Config/Modules.php is untouched:

PHP Code:
public $aliases = [
    'events',
    'filters',
    'registrars',
    'routes',
    'services',
]; 

When i remove ['filter' => 'my-auth'] from routes, all works (w/o filtering) and by cleaning src/Config/Routes.php file contents i can play around with $filters in src/Config/Filters.php - they both get discovered and work individualy.

I also stubled on $customfilters in codeigniter system/Filters/Filters.php:116 tried using it everywhere but no effect, googling it also yelded little to no result.

Is my issue a legit one or am i doing something very wrong?
Reply
#2

It's bug
Reply
#3

Go there modules make app more powerful i use too

Create modules folder in app directory

See these are to set up nice modules

https://codeigniter4.github.io/userguide...dules.html

https://onlinewebtutorblog.com/codeignit...-tutorial/

https://imrecsige.dev/garden/creating-mo...igniter-4/
Enlightenment  Is  Freedom
Reply
#4

@stopz Would you please open an Issue for this on GitHub? Should be a straightforward fix
Reply
#5

(05-22-2021, 05:13 AM)MGatner Wrote: @stopz Would you please open an Issue for this on GitHub? Should be a straightforward fix
https://github.com/codeigniter4/CodeIgni...ssues/4720
Reply
#6

I test code modules ci4.1.1 and work nicely
Enlightenment  Is  Freedom
Reply
#7

It also does not work in version 4.1.1.
Reply
#8

(This post was last modified: 05-24-2021, 01:21 AM by stopz.)

(05-22-2021, 10:51 PM)iRedds Wrote: It also does not work in version 4.1.1.

I'm working with 4.1.2 and this bug is kinda rock in my way- made a quick workaround for myself here but thanks for opening bug issue for me Smile

Hope this gets fixed soon!
Reply
#9

If you workaround is something appropriate for a core solution then I encourage you to submit it as a Pull Request! Our team relies on the community for work like this, because we are too small to handle everything ourselves.
Reply
#10

(This post was last modified: 05-24-2021, 02:43 PM by stopz.)

(05-24-2021, 04:33 AM)MGatner Wrote: If you workaround is something appropriate for a core solution then I encourage you to submit it as a Pull Request! Our team relies on the community for work like this, because we are too small to handle everything ourselves.

I would love to contribute to CodeIgniter, in fact it's one of my dreams. I was following good coding practises whilest working around this bug thus i did not touch CI core files- thus right now i have nothing to contribute to CI core.

What i did here on my end is: to have a private function in controller which i'm calling on each public endpoint for a case of early return. Quick and dirty- will do while next update is on it's way.

Shortly in this year i will get some spare time but then i will need some advice/help or welcome-guidance from someone already working with CI core to get me started.

This project is huge and i think focusing me into some narrow slice of it (a branch) would be the best approach. Example: If i am right and Factories::<component> by instanciating new object does not take into account for incoming $arguments at system/Config/Factories.php:120 then there's a huge potential of taking even more out of this technique:

Take an array of 1000 Entities who each have to access a Class Table but all of them are using only 10 different Tables. Thus each Entity would call a table Facotry with constructor parameters to construct that table class.

Now at the moment we're constructing 1000 table classes couse we can't use getShared in order to have different constructor arguments. Understandably we could sort our entities by table's they require and work around this mess to optimize it, but i would rather rely on underlying framework (and the best is CI) to do the heavy lifting for me by hashing

PHP Code:
$argument_hash crc32b(serialize($arguments)); 

and concatinating it to

PHP Code:
self::$instances[$options['component']][$class $argument_hash] = new $class(...$arguments); 

So each time i request a getShared Factory with identical construction arguments i actually get the correct instance of it Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB