Autocomplete for classes when class name is modified by autoload

Hi,

I'm working on a big project where autoload changes the name of classes by adding "Core" to the class name.

autoload :
     require($root_dir.$classname.'Core']);

Is there a way to tell PhpStorm to recognize those classes?

5 comments
Comment actions Permalink

Hi there,

I'm sorry .. but I do not understand what is the actual problem is.

Generally speaking PhpStorm does not care how your autoloader works -- it works with class names as they are declared

file1.php
class MeowCore {...}

file2.php
load_class("Meow");
...
$v = new MeowCore();

0
Comment actions Permalink

That's exactly my point: classes are not declared as they are called.

classes are declared with "Core":

class FrontControllerCore extends Controller { ... }

But there are instancied without "Core":

$controller = new FrontController();


And it works because the autoload creates dynamically the right instanciation using eval():

eval(($class_infos->isAbstract() ? 'abstract ' : '').'class '.$classname.' extends '.$classname.'Core {}');



I think I can create some PHP file for the IDE containing lines like this:
class FrontController extends FrontControllerCore() {};

But I suppose there may be a better way to do it.

0
Comment actions Permalink

I think I can create some PHP file for the IDE containing lines like this:
class FrontController extends FrontControllerCore() {};

Yes. That's exactly how it's done for other frameworks that use similar idea (e.g. FuelPHP: https://github.com/antitoxic/.fuelphp-phpstorm-workaround or https://gist.github.com/huglester/3860656 )

But I suppose there may be a better way to do it.

No. For example existing ticket WI-9029 for aforementioned FuelPHP is marked as "backlog", which means "maybe one distant day in the future, since usable workaround exist"

0
Comment actions Permalink

Thank you. I created this file and have placed at the root of my project (see attached file).
It works fine for autocomplete but everytime it is opened (with a Ctrl+Click on a classname), PhpStorm compeletely freezes. I suppose it is because it contains to much class definitions (320 lines).



Attachment(s):
__ide_classes.php.zip
0
Comment actions Permalink
I suppose it is because it contains to much class definitions (320 lines).

I guess this is possible (to freeze/slow-down when opening such file).

What you can try to do:

  1. Have each class in separate file (like it's done for aforementioned FuelPHP). Or, at least, split it into few smaller files (group classes by some logic).
  2. Disable syntax colors and other analytics for such file(s) -- click on Inspector guy in the status bar (or find appropriate command in main menu) and adjust such settings there -- may help (or may not)
0

Please sign in to leave a comment.