When you write public function __ PhpStorm prompt's a list of Magic Methods
So if you, for instance, want to create a constructor for your class, you would use __construct magic method. For example, I typed __con and PhpStorm detect's my intention of creating a constructor thus a prompt window suggests me to auto-create one.
Once you hit Enter the method is created.
While this is pretty nice, I would really love to have the cursor automatically placed between parenthesis like this: public function __construct(|) (the vertical bar "|" illustrates the cursor), and that would give me the ability to write the params needed for the constructor, in case I don't need any properties, I could press Tab and the cursor would move to the body of the method like this:
public function __construct()
{
|
}
From what I read in PhpStorm documentation, I did not found anywhere to be mentioned that you can edit those suggestions by PhpStorm, so I believe that in order to archive what I'm describing I have to go with a live template like this:
So my question is: Is my approach the only way to archive that or there is a way to edit the PhpStorm build-in suggestion for the class constructor magic method?
Thanks!
This is a known problem, please vote for WI-33646.
Related
I am trying to come up with an efficient way to organize clickable menus for the objects in my game. I made a Menu class, from which all possible menus inherit:
class_name Menu extends Control
#contains functions (for buttons) that all menus have in common
func open_menu():
pass
func close_menu():
pass
To make a menu specific to buildings, I inherit all functionalities from the Menu class:
class_name BuildingMenu extends Menu
# contains functions specific to all buildings
func upgrade_building():
pass
func delete_building():
pass
# ... many more ...
Now here's the problem: My HQ is literally just another building with a few extras and the main difference that it can't be deleted, so I'm thinking of inheriting from BuildingMenu. Is there a way to disable the inherited delete_building() function in the HQMenu script?
class_name HQMenu extends BuildingMenu
func delete_building():
# overwriting inherited function like this does not work...
# ... some HQ specific stuff here ...
I could just inherit from Menu and then copy paste everything from BuildingMenu except the delete_building() method, but this seems somewhat clumsy because now I have to edit two files if I want to change/add any building functions.
What is the correct way to do this?
SOLUTION:
Thanks to the suggestion by Thearot I've decided to move the delete_building() function into a new class from which all the regular (non HQ) buildings inherit:
Now here's the problem: My HQ is literally just another building with a few extras and the main difference that it can't be deleted, so I'm thinking of inheriting from BuildingMenu. Is there a way to disable the inherited delete_building() function in the HQMenu script?
This sounds like a violation of Liskov Substitution Principle. From a purely object oriented point of view, it would be preferible to make another class for a subset of buildings with what they have in common, than to have one building inherit from another if it has to disable some methods.
If your base class for all buildings implies that some buildings have to disable some methods, then it does not really have the methods common for all building, it has some extra ones.
To be clear, here I'm suggesting to add another extra intermediary class, and that way you don't have to delete nor duplicate methods.
If that is not an option for you… Congratulations! you have made a mess system complex enough that some kind of component based system begins to make sense. But don't jump the line, don't fret, it is OK.
If I understand correctly you have some contextual menus that show different options depending on what is selected or what you click on, right?
That means that the options are variable. Thus, use a variable. Add an Array field that has the names of the methods that should be linked to the menu. Then have the menu system discover the options by reading that Array, and connecting to functions with the names specified there.
And how you do add or remove options? You add them or remove them form the Array. Simple. You can populate the Array in _init.
To be clear, you can check if an object has a method with has_method. You call a method by name with call, or - of course - you could connect signals to them with connect (if prefer to populate an static menu for the object instead of having a dynamic one). Yes, I'm suggesting late binding.
For fast class prototyping I'm looking for a way to create methods declaration from it's call.
Example :
I'm writing.
$this->doStuff($action);
Magic happens. Following code is generated :
function doStuff ($action) {
//My cursor is here
}
Is it possible with PhpStorm ?
I saw code extraction implementation, it's nice, but it's not the same. Getters and setters inserting is not the same also, because a class property should be declared initially.
Alt + Enter while having caret on such call and choose appropriate option from there.
I'm currently working on a project that involve a re-implementation of the Array class.
This object needs to be an Array for compatibility reasons, while I also need to keep control of what is written in.
I cannot seem to find any way to check property creation inside of a dynamic object in AS3. Something that would work like the Event.ADDED_TO_STAGE but, like, ClassEvent.PROPERTY_ADDED.
I override methods like push, splice etc, but I cannot control direct assignation : MyArray[i] = ...
Is such a thing even possible ?
Of course, I could make some kind of validations elsewhere, but this would involve accessing a part of the code I cannot modify.
Thanks for your time !
I'm not sure I follow you entirely but you may be looking for the Proxy class:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Proxy.html
An example at the bottom shows you how you can override direct assignment:
override flash_proxy function setProperty(name:*, value:*):void {
_item[name] = value;
}
Using this you would be able to dispatch a custom event that would be fired any time an item was added to your ProxyArray
I am still learning PHP so my question may seem a little obvious but...
My question relates to opencart but is probably quite a common practice on many websites. I am creating a opencart module and in that module i have several buttons that complete different tasks. Now I have assigned the button the correct 'href' with the path and appropriate action. eg
$this->data['dosomething'] = $this->url->link('module/modulename/dosomething', 'token=' . $this->session->data['token'], 'SSL');
Note: I have called the module and action a general name for the purposes of my question.
In the controller I then have a private function called 'index', followed by a private function called 'dosomething' like below
public function index() {
* insert code *
}
public function dosomething() {
*insert code*
$this->redirect($this->url->link('module/modulename', 'token=' . $this->session->data['token'], 'SSL'));
}
Now, I would like to know how do I get the button to direct to the module controller and then run the 'dosomething' function. I could put something information in the link, ie action=dosomething and do it this way but most of opencart simply uses the text of the last / as the action. If I use the href stated above I get a error as it is trying to find the controller and template located in 'module/modulename/dosomething' rather than the controller and template located in 'module/modulename' USING the function 'dosomething'.
I hope this makes sense. I see that many other scripts in opencart successfully use this method but I just cant figure out how? I am sure I missing something obvious.
What you are doing is correct. OpenCart's framework will use the third piece of the route if specified as the method. If you try
public function dosomething() {
die('OK');
}
Then go to the url you've got, it should just show a blank white page with OK written on it. My guess is the error doesn't actually relate to the controller being an issue, and more to do with something else you've done. Either that, or the method and the third part of the route aren't a match, or the dosomething method isn't public
Got a question:
Just modified my Swing GUI a bit by resizing some buttons and recompiled...then:
cannot find symbol symbol: variable MachineStatusLabel and more of the same for other Objects...
Yep, this is a Label in my GUI, no idea why it cannot be found. The generated code section contains the usual stuff like
javax.swing.JLabel MachineStatusLabel = new javax.swing.JLabel();
and defines everything. But looking at the Variables declaration - do not modify-Section, almost all GUI Objects disappeared! There are only two left:
// Variables declaration - do not modify
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
// End of variables declaration
Is there a way to let NetBeans rebuild the whole GUI into this generated code? Somehow the GUI Objects seem to have just been messed up by NetBeans :-( Adding the declarations for the missing Objects manually didn't help either...
Thanks in advance!
Patrick
You should double check the value of the 'Generate Components as' property in the Options dialog.
The Option appears of the GUI Builder tab of the Miscellaneous category.
Here is the screenshot...
It sounds like you need to have the property value set as 'Fields in Form Class'.
If you change the option value, you will probably need to make a minor change in your form to trigger a code regeneration, too.