M
M
Maxim Fedorov2017-08-15 21:30:25
PHP
Maxim Fedorov, 2017-08-15 21:30:25

How to highlight magic classes in Phpstrom?

In one CMS, classes are connected by magic:

Array with classes
// Свойства - Классы API
  private $classes = array(
    'config'     => 'Config',
    'request'    => 'Request',
    'db'         => 'Database',
    'blog'         => 'Blog',
       ...
       );

   /**
   * Магический метод, создает нужный объект API
   */
  public function __get($name)
  {
   // Если такой объект уже существует, возвращаем его
    if(isset(self::$objects[$name]))
    {
      return(self::$objects[$name]);
    }
}


Then, further in the code, an object is created like this (for example, an object of the Blog.php class):
// Выбираем пост из базы
$post = $this->blog->get_post($url);

But Phpstorm does not highlight available methods of this class - how can I do it? Are there any extensions for the IDE?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Pushkarev, 2017-08-15
@Maksclub

It is possible if hands describe each method.

/**
 * Class A
 *
 * @method get_post (string $url)
 */
class A
{
}

If this is a static method, then write like this If you need a call chain, then you need to write it like this (If a class is returned, then replace $this with the name of the class) or@method static get_post (string $url)
19616338ee92491a851b55003bea731d.png

A
Alexey Skobkin, 2017-08-15
@skobkin

1. Look for a plugin for your CMS.
2. Use PhpDoc.
3. Don't use magic.

4
4iloveg, 2017-09-28
@4iloveg

In phalcon 3, the framework is in the form of a C extension. But everything is highlighted due to the documentation with stubs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question