Page 1 of 1

FEATURE REQUEST: Dynamic Code Completion for Factory methods

PostPosted: Sun Feb 21, 2010 6:24 pm
by gschmick
Often times in the Zend Framework, you use a factory pattern to instantiate child objects. Currently, the best you can do for code completion is to ensure the factory method @return(s) an abstract in order to have partial code completion. I'd like to see the ability to hint to Zend Studio the proper response type.

Example:
Code: Select all
$cache = Zend_Cache::factory('Page',
                             'File',
                             $frontendOptions,
                             $backendOptions);



The above code only sets up Zend Studio with the following @return type: Zend_Cache_Core|Zend_Cache_Frontend

I would love it if I could do something like this:

Code: Select all
$cache = Zend_Cache::factory('Page',
                             'File',
                             $frontendOptions,
                             $backendOptions); // @return: Zend_Cache_Core_Frontend_Page




Obviously this example isn't very great.. but there are literally tons of places where I wish I could programmatically hint to Zend Studio how I want it to behave.

Re: FEATURE REQUEST: Dynamic Code Completion for Factory methods

PostPosted: Mon Feb 22, 2010 1:35 pm
by m_dio
You can simply use:

Code: Select all
/* @var $cache Zend_Cache_Core_Frontend_Page */
$cache = Zend_Cache::factory('Page',
                             'File',
                             $frontendOptions,
                             $backendOptions);



This gives the hint that $cache is an object of the class Zend_Cache_Core_Frontend_Page and should be exactly what you want.

Re: FEATURE REQUEST: Dynamic Code Completion for Factory methods

PostPosted: Mon Feb 22, 2010 9:58 pm
by ziemkowski
Would be nice if that worked to sort of declare the vars for the validator too.

That way PHP-based templates that are given variables can not only suggest a type for the passed in vars, but avoid the "Undefined variable ___" message without having to disable those checks from the entire project.

Is there a way to do that or to set validation preferences by a filetype (eg .tpl files having one set of loose validation rules while .php files have another stricter set)?

Re: FEATURE REQUEST: Dynamic Code Completion for Factory met

PostPosted: Thu Mar 07, 2013 1:14 pm
by fonant
Agree, adding comments with @var descriptions for template files would be very useful, for Drupal templates too.