Welcome Guest, Not a member yet? Register   Sign In
Class alias array config in future release of codeigniter
#3

(This post was last modified: 12-30-2015, 11:42 PM by kilishan.)

A few thoughts:

class_alias, IIRC, will load the class into memory on every request, whether it's used or not. So that's not a good solution. What Laravel does is what they call a Facade, which is a magic layer that makes the commands look like simple, static class method calls, but they actually end up getting mapped through a core object that holds instances of the classes and calls it on that. Makes for a nice, clean syntax, bad on performance and a bit hellish when you're trying to debug your app at times. CI has always been more declarative, less magic. Don't expect to see Facades or anything similar show up in CI4.

When working with namespaced classes the easiest thing to do is to use a use statement at the top of the class that provides the full namespaced class. Then, we use access it in your class, you can just use the class name.

Code:
<?php

use \NS1\NS2\A;

class B {
    public function index ()
    {
        $var = new A();
    }
}

You can also use that to create local aliases for classes.

Code:
use \NS3\NS4\CDE as A;

class B {
    public function index ()
    {
        $var = new A();
    }
}

(12-27-2015, 01:56 AM)sv3tli0 Wrote: I was thinking about the same thing few days ago.
My idea was related with easy way to extend core class as Router or other..

With providing 1 real and 1 public namespace for CI System.

The public namespace would be alias of the real but it will checks and configuration if there is some manual set alias which should overwrite the original..
Something as:

Router class..
class CodeIgniter/Router{} - The real Router class
class CI/Router{} - The alias class which will be used from developers inside their apps
class App/System/CustomRouter{} - The custom written Router which will be mapped as CI/Router inside the app configuration..

It's an interesting thought to map one namespace to another and is something to consider. Though, I don't think it's necessary with the current system. If you want to override the Router (or most any part of the system) modify application/config/Services.php and let it know which class to use.
Reply


Messages In This Thread
RE: Class alias array config in future release of codeigniter - by kilishan - 12-30-2015, 11:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB