Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » [Code Assist] Code assist in included files ?
[Code Assist] Code assist in included files ? [message #45883] Thu, 23 August 2007 19:41 Go to next message
Eclipse UserFriend
Originally posted by: user.domain.invalid

Hello. This is my first post in this group.

If I have the following class :

-[Module.php]--------------------------------
class Module {
function execute() {
include('action.php');
}
function foo() {
// Do something
}
}
---------------------------------------------

And the following file :

-[action.php]-----------------------------------
$this->foo();
---------------------------------------------

This is valid PHP code but code assist can not work
in the "action.php" file as the editor doesn't know
what "$this" can be.

Is there a way to make code assist work with a workaround ?


The simpliest trick I've found is the following :

-[Module.php]--------------------------------
/**
* @return Module
*/
function thisModule($module) {
return $module;
}

class Module {
function execute() {
include('action.php');
}
function foo() {
// Do something
}
}
---------------------------------------------

-[action.php]--------------------------------
$This=thisModule($this);
$This->foo();
---------------------------------------------

That works almost good (it gives code assist for all public method,
which is a good start)

Has anyone something lighter ? I look especially for a method that does
not imply the declaration of a specific function (like "thisModule()")
for each class.
Re: [Code Assist] Code assist in included files ? [message #45935 is a reply to message #45883] Thu, 23 August 2007 19:48 Go to previous messageGo to next message
exceptione is currently offline exceptioneFriend
Messages: 96
Registered: July 2009
Member
user@domain.invalid schreef:

> This is valid PHP code but code assist can not work
> in the "action.php" file as the editor doesn't know
> what "$this" can be.
>
> Is there a way to make code assist work with a workaround ?
>

> Has anyone something lighter ? I look especially for a method that does
> not imply the declaration of a specific function (like "thisModule()")
> for each class.

Something like this should work.

-[action.php]--------------------------------
/*
* @var $this Module
*/
Re: [Code Assist] Code assist in included files ? [message #45965 is a reply to message #45935] Thu, 23 August 2007 20:15 Go to previous messageGo to next message
Eric Lestrade is currently offline Eric LestradeFriend
Messages: 3
Registered: July 2009
Junior Member
Exception e a écrit :
> user@domain.invalid schreef:
>
>> This is valid PHP code but code assist can not work
>> in the "action.php" file as the editor doesn't know
>> what "$this" can be.
>>
>> Is there a way to make code assist work with a workaround ?
>>
>
>> Has anyone something lighter ? I look especially for a method that
>> does not imply the declaration of a specific function (like
>> "thisModule()") for each class.
>
> Something like this should work.
>
> -[action.php]--------------------------------
> /*
> * @var $this Module
> */


Thanks but it doesn't work here.

As far as I know, there are two obstacles to find a light workaround :
- you can't PHPDoc an isolated variable (like above)
- you can't cast an object to a given class in PHP
(so I can't write "$This = (Module) $this" )
Re: [Code Assist] Code assist in included files ? [message #45995 is a reply to message #45883] Thu, 23 August 2007 20:28 Go to previous messageGo to next message
Fabio Z is currently offline Fabio ZFriend
Messages: 46
Registered: July 2009
Member
user@domain.invalid wrote:

> Hello. This is my first post in this group.
>
> If I have the following class :
>

[snip]

But... this seems a really confusing way to write code :)
Why don't you follow a more clear OOP way?
Re: [Code Assist] Code assist in included files ? [message #46017 is a reply to message #45995] Thu, 23 August 2007 23:14 Go to previous messageGo to next message
Eric Lestrade is currently offline Eric LestradeFriend
Messages: 3
Registered: July 2009
Junior Member
Fabio a écrit :
> user@domain.invalid wrote:
>
>> Hello. This is my first post in this group.
>>
>> If I have the following class :
>>
>
> [snip]
>
> But... this seems a really confusing way to write code :)
> Why don't you follow a more clear OOP way?


I'm not an advanced programmer but it seems that having one file per
view* and action is a very flexible and extendable way of programming.
It permits to add actions or views without editing and existing file
(so you can add custom functionnalities without modifying the core code).
Exponent CMS (exponentcms.org) is made that way and I was very happy to
release some new modules or even evolutions of existing modules with
only some files to *add*. If a user updates Exponent (the core code) he
doesn't need to re-install my features.
Considering that was a good idea (I am far for pretending it is
Exponent's idea - I am just telling my story) I reproduced it in my own
project.


The best OOP way would surely(?) to use nested classes in a partial class :

-[Module1/Module1.php]--
partial class Module1 {
}
------------------------

-[Module1/Action1.php]--
partial class Module1 {
class Action1 {
}
}
------------------------
But there is no partial class in php.
(nested classes could be replaced by simple methods if they are not
available)


Another way (that I think is not as good as the way above) would be to
use namespaces, but it doesn't exist in PHP either.


Without these solutions I would have to use classes like :
-[Module1/Action1.php]--
class Module1Action1 {
}
------------------------

But I will have dozens (hundreds ?) of classes with long and complicated
names which is not a good thing for extendability.


Moreover, all these solutions add almost useless "decoration" (I will
almost never use these classes as true OOP classes - so why would I
bother myself with declarations such as "class xxx{}" ?).


So I used "include" to execute actions and launch views :

-[Module1/Module1.php]----
class Module1 {
function execute() {
// This function dynamicaly chooses the "right" action.
// The following line is just a simple static example.
include('action1.php');
}
}
--------------------------

-[Module1/action1.php]----
// some actions to do...
--------------------------

This apparently works great.

I am not sure that I want to modify my architecture just to have
completion with "$this"...

note: I have tens of "modules" and each one has tens of actions and views.


* Whan I talk about "view", I talk about the part of the view which
assign variables to an HTML template and call its rendering. Maybe the
right name is "view controller" (?)
Re: [Code Assist] Code assist in included files ? [message #46138 is a reply to message #45965] Fri, 24 August 2007 07:25 Go to previous messageGo to next message
Piotr Szczepanik is currently offline Piotr SzczepanikFriend
Messages: 13
Registered: July 2009
Junior Member
eric.lestrade@libertysurf.fr wrote:
>> user@domain.invalid schreef:
>> Something like this should work.
>>
>> -[action.php]--------------------------------
>> /*
>> * @var $this Module
>> */
> As far as I know, there are two obstacles to find a light workaround :
> - you can't PHPDoc an isolated variable (like above)

First of all this is not a PHPDoc at all, it's rather a type hinting
used to instruct a PDT of the type of variable.

I don't know if it works with $this (which is a special case), but I use
a single line version of it sometimes at the beginning of my templates
and it works.

/* @var $contracts contractsList */

Best regards,
Piotr Szczepanik
Re: [Code Assist] Code assist in included files ? [message #46228 is a reply to message #46138] Fri, 24 August 2007 09:09 Go to previous message
Eric Lestrade is currently offline Eric LestradeFriend
Messages: 3
Registered: July 2009
Junior Member
Piotr Szczepanik a écrit :
> eric.lestrade@libertysurf.fr wrote:
>>> user@domain.invalid schreef:
>>> Something like this should work.
>>>
>>> -[action.php]--------------------------------
>>> /*
>>> * @var $this Module
>>> */
>> As far as I know, there are two obstacles to find a light workaround :
>> - you can't PHPDoc an isolated variable (like above)
>
> First of all this is not a PHPDoc at all, it's rather a type hinting
> used to instruct a PDT of the type of variable.

I agree.
I just thought PDT could understand only valid PHPDoc statements.


> I don't know if it works with $this (which is a special case), but I use
> a single line version of it sometimes at the beginning of my templates
> and it works.
>
> /* @var $contracts contractsList */

Thanks.
The single line version works indeed.

It doesn't work with $this, but I can write $This=$this and instruct PDT
of the type of $This. It tried and it worked.
Previous Topic:simple example for running a php web page
Next Topic:Zend Debugger+suhosin=encrypted cookies=no session debug
Goto Forum:
  


Current Time: Thu Sep 19 19:34:47 GMT 2024

Powered by FUDForum. Page generated in 0.03554 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top